]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/smc.c
a few #ifdef CONFIG_X_ENCODER, patch by (Roine Gustafsson <roine users.sourceforge...
[ffmpeg] / libavcodec / smc.c
index a6864882e6ffc78106a3cf400fb142ce3f384ed3..dbb5adef1db98bd5ed3a1120525a6c65b00950dc 100644 (file)
@@ -47,7 +47,6 @@ typedef struct SmcContext {
     AVCodecContext *avctx;
     DSPContext dsp;
     AVFrame frame;
-    AVFrame prev_frame;
 
     unsigned char *buf;
     int size;
@@ -59,11 +58,6 @@ typedef struct SmcContext {
 
 } SmcContext;
 
-#define BE_16(x)  ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
-#define BE_32(x)  ((((uint8_t*)(x))[0] << 24) | \
-                   (((uint8_t*)(x))[1] << 16) | \
-                   (((uint8_t*)(x))[2] << 8) | \
-                    ((uint8_t*)(x))[3])
 #define GET_BLOCK_COUNT() \
   (opcode & 0x10) ? (1 + s->buf[stream_ptr++]) : 1 + (opcode & 0x0F);
 
@@ -78,7 +72,7 @@ typedef struct SmcContext {
     total_blocks--; \
     if (total_blocks < 0) \
     { \
-        printf("warning: block counter just went negative (this should not happen)\n"); \
+        av_log(s->avctx, AV_LOG_INFO, "warning: block counter just went negative (this should not happen)\n"); \
         return; \
     } \
 }
@@ -99,7 +93,6 @@ static void smc_decode_stream(SmcContext *s)
     unsigned int flag_mask;
 
     unsigned char *pixels = s->frame.data[0];
-    unsigned char *prev_pixels = s->prev_frame.data[0];
 
     int image_size = height * s->frame.linesize[0];
     int row_ptr = 0;
@@ -128,24 +121,24 @@ static void smc_decode_stream(SmcContext *s)
     chunk_size = BE_32(&s->buf[stream_ptr]) & 0x00FFFFFF;
     stream_ptr += 4;
     if (chunk_size != s->size)
-        printf("warning: MOV chunk size != encoded chunk size (%d != %d); using MOV chunk size\n",
+        av_log(s->avctx, AV_LOG_INFO, "warning: MOV chunk size != encoded chunk size (%d != %d); using MOV chunk size\n",
             chunk_size, s->size);
 
     chunk_size = s->size;
-    total_blocks = (s->avctx->width * s->avctx->height) / (4 * 4);
+    total_blocks = ((s->avctx->width + 3) / 4) * ((s->avctx->height + 3) / 4);
 
     /* traverse through the blocks */
     while (total_blocks) {
         /* sanity checks */
         /* make sure stream ptr hasn't gone out of bounds */
         if (stream_ptr > chunk_size) {
-            printf("SMC decoder just went out of bounds (stream ptr = %d, chunk size = %d)\n",
+            av_log(s->avctx, AV_LOG_INFO, "SMC decoder just went out of bounds (stream ptr = %d, chunk size = %d)\n",
                 stream_ptr, chunk_size);
             return;
         }
         /* make sure the row pointer hasn't gone wild */
         if (row_ptr >= image_size) {
-            printf("SMC decoder just went out of bounds (row ptr = %d, height = %d)\n",
+            av_log(s->avctx, AV_LOG_INFO, "SMC decoder just went out of bounds (row ptr = %d, height = %d)\n",
                 row_ptr, image_size);
             return;
         }
@@ -157,14 +150,6 @@ static void smc_decode_stream(SmcContext *s)
         case 0x10:
             n_blocks = GET_BLOCK_COUNT();
             while (n_blocks--) {
-                block_ptr = row_ptr + pixel_ptr;
-                for (pixel_y = 0; pixel_y < 4; pixel_y++) {
-                    for (pixel_x = 0; pixel_x < 4; pixel_x++) {
-                        pixels[block_ptr] = prev_pixels[block_ptr];
-                        block_ptr++;
-                    }
-                    block_ptr += row_inc;
-                }
                 ADVANCE_BLOCK();
             }
             break;
@@ -176,7 +161,7 @@ static void smc_decode_stream(SmcContext *s)
 
             /* sanity check */
             if ((row_ptr == 0) && (pixel_ptr == 0)) {
-                printf("encountered repeat block opcode (%02X) but no blocks rendered yet\n",
+                av_log(s->avctx, AV_LOG_INFO, "encountered repeat block opcode (%02X) but no blocks rendered yet\n",
                     opcode & 0xF0);
                 break;
             }
@@ -210,7 +195,7 @@ static void smc_decode_stream(SmcContext *s)
 
             /* sanity check */
             if ((row_ptr == 0) && (pixel_ptr < 2 * 4)) {
-                printf("encountered repeat block opcode (%02X) but not enough blocks rendered yet\n",
+               av_log(s->avctx, AV_LOG_INFO, "encountered repeat block opcode (%02X) but not enough blocks rendered yet\n",
                     opcode & 0xF0);
                 break;
             }
@@ -437,7 +422,7 @@ static void smc_decode_stream(SmcContext *s)
             break;
 
         case 0xF0:
-            printf("0xF0 opcode seen in SMC chunk (xine developers would like to know)\n");
+            av_log(s->avctx, AV_LOG_INFO, "0xF0 opcode seen in SMC chunk (contact the developers)\n");
             break;
         }
     }
@@ -452,7 +437,7 @@ static int smc_decode_init(AVCodecContext *avctx)
     avctx->has_b_frames = 0;
     dsputil_init(&s->dsp, avctx);
 
-    s->frame.data[0] = s->prev_frame.data[0] = NULL;
+    s->frame.data[0] = NULL;
 
     return 0;
 }
@@ -467,19 +452,15 @@ static int smc_decode_frame(AVCodecContext *avctx,
     s->size = buf_size;
 
     s->frame.reference = 1;
-    if (avctx->get_buffer(avctx, &s->frame)) {
-        printf ("  smc Video: get_buffer() failed\n");
+    s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | 
+                            FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE;
+    if (avctx->reget_buffer(avctx, &s->frame)) {
+        av_log(s->avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
         return -1;
     }
 
     smc_decode_stream(s);
 
-    if (s->prev_frame.data[0])
-        avctx->release_buffer(avctx, &s->prev_frame);
-
-    /* shuffle frames */
-    s->prev_frame = s->frame;
-
     *data_size = sizeof(AVFrame);
     *(AVFrame*)data = s->frame;
 
@@ -491,8 +472,8 @@ static int smc_decode_end(AVCodecContext *avctx)
 {
     SmcContext *s = (SmcContext *)avctx->priv_data;
 
-    if (s->prev_frame.data[0])
-        avctx->release_buffer(avctx, &s->prev_frame);
+    if (s->frame.data[0])
+        avctx->release_buffer(avctx, &s->frame);
 
     return 0;
 }