FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/xbmenc.c
Date: 2024-03-29 01:21:52
Exec Total Coverage
Lines: 33 36 91.7%
Functions: 1 1 100.0%
Branches: 10 12 83.3%

Line Branch Exec Source
1 /*
2 * XBM image format
3 *
4 * Copyright (c) 2012 Paul B Mahol
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "avcodec.h"
24 #include "codec_internal.h"
25 #include "encode.h"
26
27 #define ANSI_MIN_READLINE 509
28
29 38 static int xbm_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
30 const AVFrame *p, int *got_packet)
31 {
32 int i, j, l, commas, ret, size, linesize, lineout, rowsout;
33 const uint8_t *ptr;
34 uint8_t *buf;
35
36 38 linesize = lineout = (avctx->width + 7) / 8;
37 38 commas = avctx->height * linesize;
38
39 /* ANSI worst case minimum readline is 509 chars. */
40 38 rowsout = avctx->height;
41
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 38 times.
38 if (lineout > (ANSI_MIN_READLINE / 6)) {
42 lineout = ANSI_MIN_READLINE / 6;
43 rowsout = (commas + lineout - 1) / lineout;
44 }
45
46 38 size = rowsout * (lineout * 6 + 1) + 106;
47
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 38 times.
38 if ((ret = ff_alloc_packet(avctx, pkt, size)) < 0)
48 return ret;
49
50 38 buf = pkt->data;
51 38 ptr = p->data[0];
52
53 38 buf += snprintf(buf, 32, "#define image_width %u\n", avctx->width);
54 38 buf += snprintf(buf, 33, "#define image_height %u\n", avctx->height);
55 38 buf += snprintf(buf, 39, "static unsigned char image_bits[] = {\n");
56
2/2
✓ Branch 0 taken 10944 times.
✓ Branch 1 taken 38 times.
10982 for (i = 0, l = lineout; i < avctx->height; i++) {
57
2/2
✓ Branch 0 taken 481536 times.
✓ Branch 1 taken 10906 times.
492442 for (j = 0; j < linesize; j++) {
58 // 0..15 bitreversed as chars
59 static const char lut[] = {
60 '0', '8', '4', 'C', '2', 'A', '6', 'E',
61 '1', '9', '5', 'D', '3', 'B', '7', 'F'
62 };
63 481536 buf[0] = ' ';
64 481536 buf[1] = '0';
65 481536 buf[2] = 'x';
66 481536 buf[3] = lut[*ptr & 0xF];
67 481536 buf[4] = lut[*ptr >> 4];
68 481536 buf += 5;
69 481536 ptr++;
70
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 481498 times.
481536 if (--commas <= 0) {
71 38 *buf++ = '\n';
72 38 break;
73 }
74 481498 *buf++ = ',';
75
2/2
✓ Branch 0 taken 10906 times.
✓ Branch 1 taken 470592 times.
481498 if (--l <= 0) {
76 10906 *buf++ = '\n';
77 10906 l = lineout;
78 }
79 }
80 10944 ptr += p->linesize[0] - linesize;
81 }
82 38 buf += snprintf(buf, 5, " };\n");
83
84 38 pkt->size = buf - pkt->data;
85 38 *got_packet = 1;
86 38 return 0;
87 }
88
89 const FFCodec ff_xbm_encoder = {
90 .p.name = "xbm",
91 CODEC_LONG_NAME("XBM (X BitMap) image"),
92 .p.type = AVMEDIA_TYPE_VIDEO,
93 .p.id = AV_CODEC_ID_XBM,
94 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
95 FF_CODEC_ENCODE_CB(xbm_encode_frame),
96 .p.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_MONOWHITE,
97 AV_PIX_FMT_NONE },
98 };
99