FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/wbmpdec.c
Date: 2024-04-12 08:31:17
Exec Total Coverage
Lines: 31 35 88.6%
Functions: 3 3 100.0%
Branches: 9 14 64.3%

Line Branch Exec Source
1 /*
2 * WBMP (Wireless Application Protocol Bitmap) image
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "avcodec.h"
22 #include "bytestream.h"
23 #include "codec_internal.h"
24 #include "decode.h"
25 #include "thread.h"
26
27 42 static unsigned int getv(GetByteContext * gb)
28 {
29 int i;
30 42 unsigned int v = 0;
31
32 do {
33 70 i = bytestream2_get_byte(gb);
34 70 v = (v << 7) | (i & 0x7F);
35
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 42 times.
70 } while (i & 0x80);
36 42 return v;
37 }
38
39 14 static void readbits(uint8_t * dst, int width, int height, int linesize, const uint8_t * src, int size)
40 {
41 14 int wpad = (width + 7) / 8;
42
3/4
✓ Branch 0 taken 4032 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 4032 times.
✗ Branch 3 not taken.
4046 for (int j = 0; j < height && size > 0; j++) {
43 4032 memcpy(dst, src, FFMIN(wpad, size));
44 4032 src += wpad;
45 4032 size -= wpad;
46 4032 dst += linesize;
47 }
48 14 }
49
50 14 static int wbmp_decode_frame(AVCodecContext *avctx, AVFrame *p,
51 int *got_frame, AVPacket *avpkt)
52 {
53 14 const uint8_t *buf = avpkt->data;
54 14 int buf_size = avpkt->size, width, height, ret;
55 GetByteContext gb;
56
57 14 bytestream2_init(&gb, buf, buf_size);
58
59
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
14 if (getv(&gb))
60 return AVERROR_INVALIDDATA;
61 14 bytestream2_skip(&gb, 1);
62 14 width = getv(&gb);
63 14 height = getv(&gb);
64
65
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
14 if ((ret = ff_set_dimensions(avctx, width, height)) < 0)
66 return ret;
67
68 14 avctx->pix_fmt = AV_PIX_FMT_MONOBLACK;
69
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
14 if ((ret = ff_thread_get_buffer(avctx, p, 0)) < 0)
70 return ret;
71
72
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (p->linesize[0] == (width + 7) / 8)
73 bytestream2_get_buffer(&gb, p->data[0], height * ((width + 7) / 8));
74 else
75 14 readbits(p->data[0], width, height, p->linesize[0], gb.buffer, gb.buffer_end - gb.buffer);
76
77 14 p->flags |= AV_FRAME_FLAG_KEY;
78 14 p->pict_type = AV_PICTURE_TYPE_I;
79
80 14 *got_frame = 1;
81
82 14 return buf_size;
83 }
84
85 const FFCodec ff_wbmp_decoder = {
86 .p.name = "wbmp",
87 CODEC_LONG_NAME("WBMP (Wireless Application Protocol Bitmap) image"),
88 .p.type = AVMEDIA_TYPE_VIDEO,
89 .p.id = AV_CODEC_ID_WBMP,
90 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
91 FF_CODEC_DECODE_CB(wbmp_decode_frame),
92 };
93