avcodec/xbmenc: Do not add last comma into output

There is a minor bug in xbm encode which adds a trailing comma at the end
of data. This isn't a big problem, but it would be nicer to be more
technically true to an array of data (by not including the last comma).

This bug fixes the output from something like this (having 4 values):
static unsigned char image_bits[] = { 0x00, 0x11, 0x22, }
to C code that looks like this instead (having 3 values):
static unsigned char image_bits[] = { 0x00, 0x11, 0x22 }
which is the intended results.
Subject: [PATCH 1/3] avcodec/xbmenc: Do not add last comma into output array

xbm outputs c arrays of data.
Including a comma at the end means there is another value to be added.
This bug fix changes something like this:
static unsigned char image_bits[] = { 0x00, 0x11, 0x22, }
to C code like this:
static unsigned char image_bits[] = { 0x00, 0x11, 0x22 }

Signed-off-by: Joe Da Silva <digital@joescat.com>
This commit is contained in:
Jose Da Silva 2021-01-18 21:42:57 -08:00 committed by Paul B Mahol
parent 9267e2ff0d
commit 41b8fd3a16
2 changed files with 10 additions and 6 deletions

View File

@ -27,11 +27,12 @@
static int xbm_encode_frame(AVCodecContext *avctx, AVPacket *pkt, static int xbm_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *p, int *got_packet) const AVFrame *p, int *got_packet)
{ {
int i, j, ret, size, linesize; int i, j, commas, ret, size, linesize;
uint8_t *ptr, *buf; uint8_t *ptr, *buf;
linesize = (avctx->width + 7) / 8; linesize = (avctx->width + 7) / 8;
size = avctx->height * (linesize * 7 + 2) + 110; commas = avctx->height * linesize;
size = avctx->height * (linesize * 7 + 2) + 109;
if ((ret = ff_alloc_packet2(avctx, pkt, size, 0)) < 0) if ((ret = ff_alloc_packet2(avctx, pkt, size, 0)) < 0)
return ret; return ret;
@ -42,8 +43,11 @@ static int xbm_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
buf += snprintf(buf, 33, "#define image_height %u\n", avctx->height); buf += snprintf(buf, 33, "#define image_height %u\n", avctx->height);
buf += snprintf(buf, 40, "static unsigned char image_bits[] = {\n"); buf += snprintf(buf, 40, "static unsigned char image_bits[] = {\n");
for (i = 0; i < avctx->height; i++) { for (i = 0; i < avctx->height; i++) {
for (j = 0; j < linesize; j++) for (j = 0; j < linesize; j++) {
buf += snprintf(buf, 7, " 0x%02X,", ff_reverse[*ptr++]); buf += snprintf(buf, 6, " 0x%02X", ff_reverse[*ptr++]);
if (--commas > 0)
buf += snprintf(buf, 2, ",");
}
ptr += p->linesize[0] - linesize; ptr += p->linesize[0] - linesize;
buf += snprintf(buf, 2, "\n"); buf += snprintf(buf, 2, "\n");
} }

View File

@ -1,3 +1,3 @@
0629055fd82366317c651a0af4bb82d7 *tests/data/images/xbm/02.xbm 83ed197cc88f382d9253365ffef70ec5 *tests/data/images/xbm/02.xbm
tests/data/images/xbm/%02d.xbm CRC=0xc9a20204 tests/data/images/xbm/%02d.xbm CRC=0xc9a20204
76411 tests/data/images/xbm/02.xbm 76410 tests/data/images/xbm/02.xbm