Coverage Report

Created: 2026-01-16 07:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/wbmpenc.c
Line
Count
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
static void putv(uint8_t ** bufp, unsigned int v)
27
23.0k
{
28
23.0k
    unsigned int vv = 0;
29
23.0k
    int n = 0;
30
31
41.5k
    while (vv != v)
32
18.5k
        vv += v & (0x7F << 7 * n++);
33
34
26.2k
    while (--n > 0)
35
3.22k
        bytestream_put_byte(bufp, 0x80 | (v & (0x7F << 7 * n)) >> 7 * n);
36
37
23.0k
    bytestream_put_byte(bufp, v & 0x7F);
38
23.0k
}
39
40
static void writebits(uint8_t ** bufp, const uint8_t * src, int width, int height, int linesize)
41
5.84k
{
42
5.84k
    int wpad = (width + 7) / 8;
43
2.12M
    for (int j = 0; j < height; j++) {
44
2.11M
        memcpy(*bufp, src, wpad);
45
2.11M
        *bufp += wpad;
46
2.11M
        src += linesize;
47
2.11M
    }
48
5.84k
}
49
50
static int wbmp_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
51
                            const AVFrame *frame, int *got_packet)
52
7.67k
{
53
7.67k
    int64_t size = avctx->height * ((avctx->width + 7) / 8) + 32;
54
7.67k
    uint8_t *buf;
55
7.67k
    int ret;
56
57
7.67k
    if ((ret = ff_get_encode_buffer(avctx, pkt, size, 0)) < 0)
58
0
        return ret;
59
60
7.67k
    buf = pkt->data;
61
62
7.67k
    putv(&buf, 0);
63
7.67k
    bytestream_put_byte(&buf, 0);
64
7.67k
    putv(&buf, avctx->width);
65
7.67k
    putv(&buf, avctx->height);
66
67
7.67k
    if (frame->linesize[0] == (avctx->width + 7) / 8)
68
1.83k
        bytestream_put_buffer(&buf, frame->data[0], avctx->height * ((avctx->width + 7) / 8));
69
5.84k
    else
70
5.84k
        writebits(&buf, frame->data[0], avctx->width, avctx->height, frame->linesize[0]);
71
72
7.67k
    av_shrink_packet(pkt, buf - pkt->data);
73
74
7.67k
    *got_packet = 1;
75
7.67k
    return 0;
76
7.67k
}
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
    CODEC_PIXFMTS(AV_PIX_FMT_MONOBLACK),
87
};