]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/scpr.h
avformat: Remove deprecated filename field from AVFormatContext
[ffmpeg] / libavcodec / scpr.h
index a013d7e6005db9924e4d8a43f12b438e3768fb50..15cb87c464e687c9aeae08c7287da8e3aeed07a3 100644 (file)
@@ -78,120 +78,136 @@ typedef struct SCPRContext {
 } SCPRContext;
 
 static int decode_run_i(AVCodecContext *avctx, uint32_t ptype, int run,
-                        int *x, int *y, uint32_t clr, uint32_t *dst,
-                        int linesize, uint32_t *lx, uint32_t *ly,
+                        int *px, int *py, uint32_t clr, uint32_t *dst,
+                        int linesize, uint32_t *plx, uint32_t *ply,
                         uint32_t backstep, int off, int *cx, int *cx1)
 {
     uint32_t r, g, b;
     int z;
+    int x = *px,
+        y = *py;
+    uint32_t lx = *plx,
+             ly = *ply;
+
+    if (y >= avctx->height)
+        return AVERROR_INVALIDDATA;
 
     switch (ptype) {
     case 0:
         while (run-- > 0) {
-            if (*y >= avctx->height)
-                return AVERROR_INVALIDDATA;
-
-            dst[*y * linesize + *x] = clr;
-            *lx = *x;
-            *ly = *y;
-            (*x)++;
-            if (*x >= avctx->width) {
-                *x = 0;
-                (*y)++;
+            dst[y * linesize + x] = clr;
+            lx = x;
+            ly = y;
+            (x)++;
+            if (x >= avctx->width) {
+                x = 0;
+                (y)++;
+                if (y >= avctx->height && run)
+                    return AVERROR_INVALIDDATA;
             }
         }
         break;
     case 1:
         while (run-- > 0) {
-            if (*y >= avctx->height)
-                return AVERROR_INVALIDDATA;
-
-            dst[*y * linesize + *x] = dst[*ly * linesize + *lx];
-            *lx = *x;
-            *ly = *y;
-            (*x)++;
-            if (*x >= avctx->width) {
-                *x = 0;
-                (*y)++;
+            dst[y * linesize + x] = dst[ly * linesize + lx];
+            lx = x;
+            ly = y;
+            (x)++;
+            if (x >= avctx->width) {
+                x = 0;
+                (y)++;
+                if (y >= avctx->height && run)
+                    return AVERROR_INVALIDDATA;
             }
         }
-        clr = dst[*ly * linesize + *lx];
+        clr = dst[ly * linesize + lx];
         break;
     case 2:
-        while (run-- > 0) {
-            if (*y < 1 || *y >= avctx->height)
-                return AVERROR_INVALIDDATA;
+        if (y < 1)
+            return AVERROR_INVALIDDATA;
 
-            clr = dst[*y * linesize + *x + off + 1];
-            dst[*y * linesize + *x] = clr;
-            *lx = *x;
-            *ly = *y;
-            (*x)++;
-            if (*x >= avctx->width) {
-                *x = 0;
-                (*y)++;
+        while (run-- > 0) {
+            clr = dst[y * linesize + x + off + 1];
+            dst[y * linesize + x] = clr;
+            lx = x;
+            ly = y;
+            (x)++;
+            if (x >= avctx->width) {
+                x = 0;
+                (y)++;
+                if (y >= avctx->height && run)
+                    return AVERROR_INVALIDDATA;
             }
         }
         break;
     case 4:
+        if (y < 1 || (y == 1 && x == 0))
+            return AVERROR_INVALIDDATA;
+
         while (run-- > 0) {
             uint8_t *odst = (uint8_t *)dst;
+            int off1 = (ly * linesize + lx) * 4;
+            int off2 = ((y * linesize + x) + off) * 4;
 
-            if (*y < 1 || *y >= avctx->height ||
-                (*y == 1 && *x == 0))
-                return AVERROR_INVALIDDATA;
-
-            if (*x == 0) {
-                z = backstep;
+            if (x == 0) {
+                z = backstep * 4;
             } else {
                 z = 0;
             }
 
-            r = odst[(*ly * linesize + *lx) * 4] +
-                odst[((*y * linesize + *x) + off) * 4 + 4] -
-                odst[((*y * linesize + *x) + off - z) * 4];
-            g = odst[(*ly * linesize + *lx) * 4 + 1] +
-                odst[((*y * linesize + *x) + off) * 4 + 5] -
-                odst[((*y * linesize + *x) + off - z) * 4 + 1];
-            b = odst[(*ly * linesize + *lx) * 4 + 2] +
-                odst[((*y * linesize + *x) + off) * 4 + 6] -
-                odst[((*y * linesize + *x) + off - z) * 4 + 2];
+            r = odst[off1] +
+                odst[off2 + 4] -
+                odst[off2 - z ];
+            g = odst[off1 + 1] +
+                odst[off2 + 5] -
+                odst[off2 - z  + 1];
+            b = odst[off1 + 2] +
+                odst[off2 + 6] -
+                odst[off2 - z  + 2];
             clr = ((b & 0xFF) << 16) + ((g & 0xFF) << 8) + (r & 0xFF);
-            dst[*y * linesize + *x] = clr;
-            *lx = *x;
-            *ly = *y;
-            (*x)++;
-            if (*x >= avctx->width) {
-                *x = 0;
-                (*y)++;
+            dst[y * linesize + x] = clr;
+            lx = x;
+            ly = y;
+            (x)++;
+            if (x >= avctx->width) {
+                x = 0;
+                (y)++;
+                if (y >= avctx->height && run)
+                    return AVERROR_INVALIDDATA;
             }
         }
         break;
     case 5:
-        while (run-- > 0) {
-            if (*y < 1 || *y >= avctx->height ||
-                (*y == 1 && *x == 0))
-                return AVERROR_INVALIDDATA;
+        if (y < 1 || (y == 1 && x == 0))
+            return AVERROR_INVALIDDATA;
 
-            if (*x == 0) {
+        while (run-- > 0) {
+            if (x == 0) {
                 z = backstep;
             } else {
                 z = 0;
             }
 
-            clr = dst[*y * linesize + *x + off - z];
-            dst[*y * linesize + *x] = clr;
-            *lx = *x;
-            *ly = *y;
-            (*x)++;
-            if (*x >= avctx->width) {
-                *x = 0;
-                (*y)++;
+            clr = dst[y * linesize + x + off - z];
+            dst[y * linesize + x] = clr;
+            lx = x;
+            ly = y;
+            (x)++;
+            if (x >= avctx->width) {
+                x = 0;
+                (y)++;
+                if (y >= avctx->height && run)
+                    return AVERROR_INVALIDDATA;
             }
         }
         break;
     }
 
+    *px = x;
+    *py = y;
+    *plx= lx;
+    *ply= ly;
+
     if (avctx->bits_per_coded_sample == 16) {
         *cx1 = (clr & 0x3F00) >> 2;
         *cx = (clr & 0x3FFFFF) >> 16;