]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/zmbv.c
avcodec: Constify AVCodecs
[ffmpeg] / libavcodec / zmbv.c
index e07009d0fbdf2a807c75dd558bdafbabab8d2c3f..e1aba7f059945a6f3af5fd19db98afe6592b0861 100644 (file)
@@ -69,8 +69,8 @@ typedef struct ZmbvContext {
     int stride;
     int bw, bh, bx, by;
     int decomp_len;
+    int got_keyframe;
     z_stream zstream;
-    int (*decode_intra)(struct ZmbvContext *c);
     int (*decode_xor)(struct ZmbvContext *c);
 } ZmbvContext;
 
@@ -121,6 +121,8 @@ static int zmbv_decode_xor_8(ZmbvContext *c)
             for (j = 0; j < bh2; j++) {
                 if (my + j < 0 || my + j >= c->height) {
                     memset(out, 0, bw2);
+                } else if (mx >= 0 && mx + bw2 <= c->width){
+                    memcpy(out, tprev, sizeof(*out) * bw2);
                 } else {
                     for (i = 0; i < bw2; i++) {
                         if (mx + i < 0 || mx + i >= c->width)
@@ -193,6 +195,8 @@ static int zmbv_decode_xor_16(ZmbvContext *c)
             for (j = 0; j < bh2; j++) {
                 if (my + j < 0 || my + j >= c->height) {
                     memset(out, 0, bw2 * 2);
+                } else if (mx >= 0 && mx + bw2 <= c->width){
+                    memcpy(out, tprev, sizeof(*out) * bw2);
                 } else {
                     for (i = 0; i < bw2; i++) {
                         if (mx + i < 0 || mx + i >= c->width)
@@ -270,6 +274,8 @@ static int zmbv_decode_xor_24(ZmbvContext *c)
             for (j = 0; j < bh2; j++) {
                 if (my + j < 0 || my + j >= c->height) {
                     memset(out, 0, bw2 * 3);
+                } else if (mx >= 0 && mx + bw2 <= c->width){
+                    memcpy(out, tprev, 3 * bw2);
                 } else {
                     for (i = 0; i < bw2; i++){
                         if (mx + i < 0 || mx + i >= c->width) {
@@ -303,7 +309,7 @@ static int zmbv_decode_xor_24(ZmbvContext *c)
         prev += stride * c->bh;
     }
     if (src - c->decomp_buf != c->decomp_len)
-        av_log(c->avctx, AV_LOG_ERROR, "Used %i of %i bytes\n",
+        av_log(c->avctx, AV_LOG_ERROR, "Used %"PTRDIFF_SPECIFIER" of %i bytes\n",
                src-c->decomp_buf, c->decomp_len);
     return 0;
 }
@@ -351,6 +357,8 @@ static int zmbv_decode_xor_32(ZmbvContext *c)
             for (j = 0; j < bh2; j++) {
                 if (my + j < 0 || my + j >= c->height) {
                     memset(out, 0, bw2 * 4);
+                } else if (mx >= 0 && mx + bw2 <= c->width){
+                    memcpy(out, tprev, sizeof(*out) * bw2);
                 } else {
                     for (i = 0; i < bw2; i++){
                         if (mx + i < 0 || mx + i >= c->width)
@@ -417,8 +425,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
     c->flags = buf[0];
     buf++; len--;
     if (c->flags & ZMBV_KEYFRAME) {
-        void *decode_intra = NULL;
-        c->decode_intra= NULL;
+        c->got_keyframe = 0;
 
         if (len < 6)
             return AVERROR_INVALIDDATA;
@@ -428,7 +435,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
         c->fmt = buf[3];
         c->bw = buf[4];
         c->bh = buf[5];
-        c->decode_intra = NULL;
         c->decode_xor = NULL;
 
         buf += 6;
@@ -452,7 +458,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
         switch (c->fmt) {
         case ZMBV_FMT_8BPP:
             c->bpp = 8;
-            decode_intra = zmbv_decode_intra;
             c->decode_xor = zmbv_decode_xor_8;
             avctx->pix_fmt = AV_PIX_FMT_PAL8;
             c->stride = c->width;
@@ -460,7 +465,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
         case ZMBV_FMT_15BPP:
         case ZMBV_FMT_16BPP:
             c->bpp = 16;
-            decode_intra = zmbv_decode_intra;
             c->decode_xor = zmbv_decode_xor_16;
             if (c->fmt == ZMBV_FMT_15BPP)
                 avctx->pix_fmt = AV_PIX_FMT_RGB555LE;
@@ -471,15 +475,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
 #ifdef ZMBV_ENABLE_24BPP
         case ZMBV_FMT_24BPP:
             c->bpp = 24;
-            decode_intra = zmbv_decode_intra;
             c->decode_xor = zmbv_decode_xor_24;
-            avctx->pix_fmt = AV_PIX_FMT_RGB24;
+            avctx->pix_fmt = AV_PIX_FMT_BGR24;
             c->stride = c->width * 3;
             break;
 #endif //ZMBV_ENABLE_24BPP
         case ZMBV_FMT_32BPP:
             c->bpp = 32;
-            decode_intra = zmbv_decode_intra;
             c->decode_xor = zmbv_decode_xor_32;
             avctx->pix_fmt = AV_PIX_FMT_BGR0;
             c->stride = c->width * 4;
@@ -509,7 +511,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
         }
         memset(c->cur, 0, avctx->width * avctx->height * (c->bpp / 8));
         memset(c->prev, 0, avctx->width * avctx->height * (c->bpp / 8));
-        c->decode_intra= decode_intra;
+        c->got_keyframe = 1;
     }
     if (c->flags & ZMBV_KEYFRAME) {
         expected_size = avctx->width * avctx->height * (c->bpp / 8);
@@ -520,7 +522,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
         (c->flags & (ZMBV_DELTAPAL | ZMBV_KEYFRAME)))
         expected_size += 768;
 
-    if (!c->decode_intra) {
+    if (!c->got_keyframe) {
         av_log(avctx, AV_LOG_ERROR, "Error! Got no format or no keyframe!\n");
         return AVERROR_INVALIDDATA;
     }
@@ -534,7 +536,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
         c->decomp_len = len;
     } else { // ZLIB-compressed data
         c->zstream.total_in = c->zstream.total_out = 0;
-        c->zstream.next_in = (uint8_t*)buf;
+        c->zstream.next_in = buf;
         c->zstream.avail_in = len;
         c->zstream.next_out = c->decomp_buf;
         c->zstream.avail_out = c->decomp_size;
@@ -556,7 +558,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
     if (c->flags & ZMBV_KEYFRAME) {
         frame->key_frame = 1;
         frame->pict_type = AV_PICTURE_TYPE_I;
-        c->decode_intra(c);
+        zmbv_decode_intra(c);
     } else {
         frame->key_frame = 0;
         frame->pict_type = AV_PICTURE_TYPE_P;
@@ -652,7 +654,7 @@ static av_cold int decode_end(AVCodecContext *avctx)
     return 0;
 }
 
-AVCodec ff_zmbv_decoder = {
+const AVCodec ff_zmbv_decoder = {
     .name           = "zmbv",
     .long_name      = NULL_IF_CONFIG_SMALL("Zip Motion Blocks Video"),
     .type           = AVMEDIA_TYPE_VIDEO,