FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/xwd_parser.c
Date: 2022-12-06 04:36:11
Exec Total Coverage
Lines: 35 38 92.1%
Functions: 1 1 100.0%
Branches: 13 16 81.2%

Line Branch Exec Source
1 /*
2 * XWD parser
3 * Copyright (c) 2022 Paul B Mahol
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * XWD parser
25 **/
26
27 #include "libavutil/intreadwrite.h"
28 #include "parser.h"
29 #include "xwd.h"
30
31 typedef struct XWDParseContext {
32 ParseContext pc;
33 int left;
34 int idx;
35 uint8_t hdr[XWD_HEADER_SIZE];
36 } XWDParseContext;
37
38 1883 static int xwd_parse(AVCodecParserContext *s, AVCodecContext *avctx,
39 const uint8_t **poutbuf, int *poutbuf_size,
40 const uint8_t *buf, int buf_size)
41 {
42 1883 XWDParseContext *t = s->priv_data;
43 1883 ParseContext *pc = &t->pc;
44 1883 int next = END_NOT_FOUND;
45
46 1883 s->pict_type = AV_PICTURE_TYPE_NONE;
47
48 1883 *poutbuf = NULL;
49 1883 *poutbuf_size = 0;
50
51
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1883 times.
1883 if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
52 next = buf_size;
53 } else {
54
2/2
✓ Branch 0 taken 7605999 times.
✓ Branch 1 taken 1859 times.
7607858 for (int i = 0; i < buf_size; i++) {
55
2/2
✓ Branch 0 taken 7603499 times.
✓ Branch 1 taken 2500 times.
7605999 if (t->left > 0) {
56 7603499 t->left--;
57
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 7603475 times.
7603499 if (t->left == 0) {
58 24 next = i;
59 24 break;
60 }
61 7603475 continue;
62 }
63
64
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2500 times.
2500 if (t->idx >= 100) {
65 t->idx = 99;
66 memmove(&t->hdr[0], &t->hdr[1], XWD_HEADER_SIZE-1);
67 }
68
69 2500 t->hdr[t->idx++] = buf[i];
70
71
3/4
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 2475 times.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
2500 if (t->idx >= 100 && AV_RB32(t->hdr + 4) == XWD_VERSION) {
72 25 uint32_t header_size = AV_RB32(t->hdr + 0);
73 25 uint32_t height = AV_RB32(t->hdr + 20);
74 25 uint32_t lsize = AV_RB32(t->hdr + 48);
75 25 uint32_t ncolors = AV_RB32(t->hdr + 76);
76 25 uint32_t size = header_size + ncolors * XWD_CMAP_SIZE + height * lsize;
77 25 pc->frame_start_found = 1;
78 25 t->left = size - XWD_HEADER_SIZE + 1;
79 25 t->idx = 0;
80 25 memset(t->hdr, 0, sizeof(t->hdr));
81 }
82 }
83
84
2/2
✓ Branch 1 taken 1857 times.
✓ Branch 2 taken 26 times.
1883 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0)
85 1857 return buf_size;
86 }
87
88 26 *poutbuf = buf;
89 26 *poutbuf_size = buf_size;
90
91 26 s->pict_type = AV_PICTURE_TYPE_I;
92 26 s->key_frame = 1;
93 26 s->duration = 1;
94
95 26 return next;
96 }
97
98 const AVCodecParser ff_xwd_parser = {
99 .codec_ids = { AV_CODEC_ID_XWD },
100 .priv_data_size = sizeof(XWDParseContext),
101 .parser_parse = xwd_parse,
102 .parser_close = ff_parse_close,
103 };
104