FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/wbmpenc.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 29 31 93.5%
Functions: 3 3 100.0%
Branches: 8 10 80.0%

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 "encode.h"
25
26 39 static void putv(uint8_t ** bufp, unsigned int v)
27 {
28 39 unsigned int vv = 0;
29 39 int n = 0;
30
31
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 39 times.
91 while (vv != v)
32 52 vv += v & (0x7F << 7 * n++);
33
34
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 39 times.
65 while (--n > 0)
35 26 bytestream_put_byte(bufp, 0x80 | (v & (0x7F << 7 * n)) >> 7 * n);
36
37 39 bytestream_put_byte(bufp, v & 0x7F);
38 39 }
39
40 13 static void writebits(uint8_t ** bufp, const uint8_t * src, int width, int height, int linesize)
41 {
42 13 int wpad = (width + 7) / 8;
43
2/2
✓ Branch 0 taken 3744 times.
✓ Branch 1 taken 13 times.
3757 for (int j = 0; j < height; j++) {
44 3744 memcpy(*bufp, src, wpad);
45 3744 *bufp += wpad;
46 3744 src += linesize;
47 }
48 13 }
49
50 13 static int wbmp_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
51 const AVFrame *frame, int *got_packet)
52 {
53 13 int64_t size = avctx->height * ((avctx->width + 7) / 8) + 32;
54 uint8_t *buf;
55 int ret;
56
57
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
13 if ((ret = ff_get_encode_buffer(avctx, pkt, size, 0)) < 0)
58 return ret;
59
60 13 buf = pkt->data;
61
62 13 putv(&buf, 0);
63 13 bytestream_put_byte(&buf, 0);
64 13 putv(&buf, avctx->width);
65 13 putv(&buf, avctx->height);
66
67
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 if (frame->linesize[0] == (avctx->width + 7) / 8)
68 bytestream_put_buffer(&buf, frame->data[0], avctx->height * ((avctx->width + 7) / 8));
69 else
70 13 writebits(&buf, frame->data[0], avctx->width, avctx->height, frame->linesize[0]);
71
72 13 av_shrink_packet(pkt, buf - pkt->data);
73
74 13 *got_packet = 1;
75 13 return 0;
76 }
77
78 const FFCodec ff_wbmp_encoder = {
79 .p.name = "wbmp",
80 CODEC_LONG_NAME("WBMP (Wireless Application Protocol Bitmap) image"),
81 .p.type = AVMEDIA_TYPE_VIDEO,
82 .p.id = AV_CODEC_ID_WBMP,
83 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
84 AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
85 FF_CODEC_ENCODE_CB(wbmp_encode_frame),
86 .p.pix_fmts = (const enum AVPixelFormat[]){
87 AV_PIX_FMT_MONOBLACK,
88 AV_PIX_FMT_NONE
89 },
90 };
91