diff mbox series

[FFmpeg-devel,2/3] avcodec/xbmenc: xbm Lower memory use

Message ID 202101182143.05604.digital@joescat.com
State Accepted
Commit cb70e1921aeda4df11ad77ee550e7bdcdca2b834
Headers show
Series [FFmpeg-devel,1/3] avcodec/xbmenc: Do not add last comma into output
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Jose Da Silva Jan. 19, 2021, 5:43 a.m. UTC
Two minor memory improvements.

First bug reduces memory needed to about 6/7 the needed amount, which 
allows you to host almost 7 pictures in the same memory needed for 6
Second is a recalculation of the total additional memory for headers etc.

size = avctx->height x (linesize * 6 + 1) + (31+32+38+4+1)
Subject: [PATCH 2/3] avcodec/xbmenc: xbm Lower memory use

Small 6/7th size memory reduction.
size = avctx->height x (linesize * 6 + 1) + (31+32+38+4+1)

Signed-off-by: Joe Da Silva <digital@joescat.com>
---
 libavcodec/xbmenc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/xbmenc.c b/libavcodec/xbmenc.c
index 3fc0e3185a..193ced652a 100644
--- a/libavcodec/xbmenc.c
+++ b/libavcodec/xbmenc.c
@@ -32,7 +32,7 @@  static int xbm_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
 
     linesize = (avctx->width + 7) / 8;
     commas   = avctx->height * linesize;
-    size     = avctx->height * (linesize * 7 + 2) + 109;
+    size     = avctx->height * (linesize * 6 + 1) + 106;
     if ((ret = ff_alloc_packet2(avctx, pkt, size, 0)) < 0)
         return ret;
 
@@ -41,7 +41,7 @@  static int xbm_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
 
     buf += snprintf(buf, 32, "#define image_width %u\n", avctx->width);
     buf += snprintf(buf, 33, "#define image_height %u\n", avctx->height);
-    buf += snprintf(buf, 40, "static unsigned char image_bits[] = {\n");
+    buf += snprintf(buf, 39, "static unsigned char image_bits[] = {\n");
     for (i = 0; i < avctx->height; i++) {
         for (j = 0; j < linesize; j++) {
             buf += snprintf(buf, 6, " 0x%02X", ff_reverse[*ptr++]);