]> git.sesse.net Git - ffmpeg/commitdiff
sunrast: Add support for negative linesize.
authorAneesh Dogra <lionaneesh@gmail.com>
Fri, 23 Mar 2012 17:54:00 +0000 (23:24 +0530)
committerJustin Ruggles <justin.ruggles@gmail.com>
Sat, 24 Mar 2012 15:27:20 +0000 (11:27 -0400)
Signed-off-by: Justin Ruggles <justin.ruggles@gmail.com>
libavcodec/sunrastenc.c

index a9b47497585c4f22dda59c5a5d73a0fc06f1eda1..1ed1d6eddbb6e3639018d3c3b658aec50c37617f 100644 (file)
@@ -83,15 +83,18 @@ static void sunrast_image_write_image(AVCodecContext *avctx,
      if (s->type == RT_BYTE_ENCODED) {
         uint8_t value, value2;
         int run;
-        const uint8_t *end = pixels + avctx->height * linesize;
+        const uint8_t *start = linesize < 0 ? pixels + (avctx->height - 1) * linesize
+                                            : pixels;
+        const uint8_t *end   = linesize < 0 ? pixels - linesize
+                                            : pixels + avctx->height * linesize;
 
         ptr = pixels;
 
-#define GET_VALUE ptr >= end ? 0 : x >= len ? ptr[len-1] : ptr[x]
+#define GET_VALUE ptr >= end || ptr < start ? 0 : x >= len ? ptr[len-1] : ptr[x]
 
         x = 0;
         value2 = GET_VALUE;
-        while (ptr < end) {
+        while (ptr < end && ptr >= start) {
             run = 1;
             value = value2;
             x++;
@@ -101,7 +104,7 @@ static void sunrast_image_write_image(AVCodecContext *avctx,
             }
 
             value2 = GET_VALUE;
-            while (value2 == value && run < 256 && ptr < end) {
+            while (value2 == value && run < 256 && ptr < end && ptr >= start) {
                 x++;
                 run++;
                 if (x >= alen) {