]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/xbmenc: Do not add last comma into output
authorJose Da Silva <digital@joescat.com>
Tue, 19 Jan 2021 05:42:57 +0000 (21:42 -0800)
committerPaul B Mahol <onemda@gmail.com>
Thu, 28 Jan 2021 14:50:09 +0000 (15:50 +0100)
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>
libavcodec/xbmenc.c
tests/ref/lavf/xbm

index b25615f2a47251e904fd1fd0aa43102133cbba92..3fc0e3185acc2ee48af89fa888f9f513b3cfbc5b 100644 (file)
 static int xbm_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                             const AVFrame *p, int *got_packet)
 {
-    int i, j, ret, size, linesize;
+    int i, j, commas, ret, size, linesize;
     uint8_t *ptr, *buf;
 
     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)
         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, 40, "static unsigned char image_bits[] = {\n");
     for (i = 0; i < avctx->height; i++) {
-        for (j = 0; j < linesize; j++)
-            buf += snprintf(buf, 7, " 0x%02X,", ff_reverse[*ptr++]);
+        for (j = 0; j < linesize; j++) {
+            buf += snprintf(buf, 6, " 0x%02X", ff_reverse[*ptr++]);
+            if (--commas > 0)
+                buf += snprintf(buf, 2, ",");
+        }
         ptr += p->linesize[0] - linesize;
         buf += snprintf(buf, 2, "\n");
     }
index bc157834ffb98596ae3404270064fec65182fec9..e54d6bc2266c32fb14f7d521438963c5ffd58265 100644 (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
-76411 tests/data/images/xbm/02.xbm
+76410 tests/data/images/xbm/02.xbm