From patchwork Tue Jan 19 05:42:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jose Da Silva X-Patchwork-Id: 25033 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 3E5B54496CE for ; Tue, 19 Jan 2021 07:43:09 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 109CF688298; Tue, 19 Jan 2021 07:43:09 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mx0-10.i-mecca.net (mx0-10.i-mecca.net [76.74.184.244]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A245668029C for ; Tue, 19 Jan 2021 07:43:02 +0200 (EET) Received: from mx0.ehosting.ca (localhost [127.0.0.1]) by mx0.i-mecca.net (Postfix) with ESMTP id B0A4B16172B for ; Mon, 18 Jan 2021 21:42:59 -0800 (PST) Received: from ns2.i-mecca.net (unknown [192.168.1.2]) by mx0.i-mecca.net (Postfix) with ESMTP id E9EF216170E for ; Mon, 18 Jan 2021 21:42:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joescat.com; s=mail; h=date:from:to:subject; bh=eePNylkPBvcg2AOIwmAjrveK0oC+A/rC+bB1EzuJw5Y=; b=fQ1tYnCrb/mGhzgiIDvHUAHJ9tR6fBhdnX3AUSRdseBuDGRbtFkjpREw+y2U61yHdk iCVBZ6IGGLWxjYrihq8uqdwt27vz9ESVt3J1jOhGtKrFQ6b3eoQ/In3cgLNLOPfdWQMs i39MMjIPY2hBo6T3rMR/alGydi+Byb1qd5yu7uBY9VIMa5D0MRGTpkoRISxmxhQlJhjw 1aYQujyNfVdkANz/2uqmeqY3dc9/ZW/Etjl6AEqozHiLi0v0XzdMdqilNaEBRTLTZ0MZ wxcaZrhWrubluzka/UoYg7sHAlGq/RZ5jK7aFtszAPcqN5/3U/8DUlGb2rvQAymKRMFk q1Gg== X-MES: 1.0 X-MM: 1.0 Received: from drived.localnet (d66-183-117-75.bchsia.telus.net [66.183.117.75]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ns2.i-mecca.net (Postfix) with ESMTPSA id 744C53001F6 for ; Tue, 19 Jan 2021 00:42:57 -0500 (EST) From: Jose Da Silva To: ffmpeg-devel@ffmpeg.org Date: Mon, 18 Jan 2021 21:42:57 -0800 User-Agent: KMail/1.13.7 (Linux/2.6.38.8-desktop586-10.mga; KDE/4.6.5; i686; ; ) MIME-Version: 1.0 Message-Id: <202101182142.58008.digital@joescat.com> Subject: [FFmpeg-devel] [PATCH 1/3] avcodec/xbmenc: Do not add last comma into output X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 --- libavcodec/xbmenc.c | 12 ++++++++---- tests/ref/lavf/xbm | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/libavcodec/xbmenc.c b/libavcodec/xbmenc.c index b25615f2a4..3fc0e3185a 100644 --- a/libavcodec/xbmenc.c +++ b/libavcodec/xbmenc.c @@ -27,11 +27,12 @@ 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"); } diff --git a/tests/ref/lavf/xbm b/tests/ref/lavf/xbm index bc157834ff..e54d6bc226 100644 --- a/tests/ref/lavf/xbm +++ b/tests/ref/lavf/xbm @@ -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