[FFmpeg-cvslog] avcodec/aliaspixenc: Remove redundant counter

Andreas Rheinhardt git at videolan.org
Thu Oct 7 13:06:12 EEST 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Wed Oct  6 13:57:42 2021 +0200| [5e1b5b52fe7fdfa6d9e1a78ac0576cf5931a82bb] | committer: Andreas Rheinhardt

avcodec/aliaspixenc: Remove redundant counter

Improves performance by 33.8% for BGR24 and by 26.4% for GRAY8.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5e1b5b52fe7fdfa6d9e1a78ac0576cf5931a82bb
---

 libavcodec/aliaspixenc.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavcodec/aliaspixenc.c b/libavcodec/aliaspixenc.c
index 01461c984b..fa273df9c2 100644
--- a/libavcodec/aliaspixenc.c
+++ b/libavcodec/aliaspixenc.c
@@ -31,8 +31,8 @@
 static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                         const AVFrame *frame, int *got_packet)
 {
-    int width, height, bits_pixel, i, j, length, ret;
-    uint8_t *in_buf, *buf;
+    int width, height, bits_pixel, length, ret;
+    uint8_t *buf;
 
     width  = avctx->width;
     height = avctx->height;
@@ -66,15 +66,16 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     bytestream_put_be32(&buf, 0); /* X, Y offset */
     bytestream_put_be16(&buf, bits_pixel);
 
-    for (j = 0; j < height; j++) {
-        in_buf = frame->data[0] + frame->linesize[0] * j;
-        for (i = 0; i < width; ) {
+    for (int j = 0, bytes_pixel = bits_pixel >> 3; j < height; j++) {
+        const uint8_t *in_buf = frame->data[0] + frame->linesize[0] * j;
+        const uint8_t *const line_end = in_buf + bytes_pixel * width;
+        while (in_buf < line_end) {
             int count = 0;
             int pixel;
 
             if (avctx->pix_fmt == AV_PIX_FMT_GRAY8) {
                 pixel = *in_buf;
-                while (count < 255 && count + i < width && pixel == *in_buf) {
+                while (count < 255 && in_buf < line_end && pixel == *in_buf) {
                     count++;
                     in_buf++;
                 }
@@ -82,7 +83,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                 bytestream_put_byte(&buf, pixel);
             } else { /* AV_PIX_FMT_BGR24 */
                 pixel = AV_RB24(in_buf);
-                while (count < 255 && count + i < width &&
+                while (count < 255 && in_buf < line_end &&
                        pixel == AV_RB24(in_buf)) {
                     count++;
                     in_buf += 3;
@@ -90,7 +91,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                 bytestream_put_byte(&buf, count);
                 bytestream_put_be24(&buf, pixel);
             }
-            i += count;
         }
     }
 



More information about the ffmpeg-cvslog mailing list