Browse code

avcodec/ffv1dec: Support decoding planes as raw PCM in 1.4

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2013/09/10 02:56:44
Showing 2 changed files
... ...
@@ -128,6 +128,8 @@ typedef struct FFV1Context {
128 128
     int slice_height;
129 129
     int slice_x;
130 130
     int slice_y;
131
+    int slice_reset_contexts;
132
+    int slice_coding_mode;
131 133
 } FFV1Context;
132 134
 
133 135
 int ffv1_common_init(AVCodecContext *avctx);
... ...
@@ -105,6 +105,19 @@ static av_always_inline void decode_line(FFV1Context *s, int w,
105 105
     int run_mode  = 0;
106 106
     int run_index = s->run_index;
107 107
 
108
+    if (s->slice_coding_mode == 1) {
109
+        int i;
110
+        for (x = 0; x < w; x++) {
111
+            int v = 0;
112
+            for (i=0; i<bits; i++) {
113
+                uint8_t state = 128;
114
+                v += v + get_rac(c, &state);
115
+            }
116
+            sample[1][x] = v;
117
+        }
118
+        return;
119
+    }
120
+
108 121
     for (x = 0; x < w; x++) {
109 122
         int diff, context, sign;
110 123
 
... ...
@@ -233,10 +246,10 @@ static void decode_rgb_frame(FFV1Context *s, uint8_t *src[3], int w, int h, int
233 233
 
234 234
             sample[p][1][-1]= sample[p][0][0  ];
235 235
             sample[p][0][ w]= sample[p][0][w-1];
236
-            if (lbd)
236
+            if (lbd && s->slice_coding_mode == 0)
237 237
                 decode_line(s, w, sample[p], (p + 1)/2, 9);
238 238
             else
239
-                decode_line(s, w, sample[p], (p + 1)/2, bits + 1);
239
+                decode_line(s, w, sample[p], (p + 1)/2, bits + (s->slice_coding_mode != 1));
240 240
         }
241 241
         for (x = 0; x < w; x++) {
242 242
             int g = sample[0][1][x];
... ...
@@ -244,11 +257,13 @@ static void decode_rgb_frame(FFV1Context *s, uint8_t *src[3], int w, int h, int
244 244
             int r = sample[2][1][x];
245 245
             int a = sample[3][1][x];
246 246
 
247
-            b -= offset;
248
-            r -= offset;
249
-            g -= (b + r) >> 2;
250
-            b += g;
251
-            r += g;
247
+            if (s->slice_coding_mode != 1) {
248
+                b -= offset;
249
+                r -= offset;
250
+                g -= (b + r) >> 2;
251
+                b += g;
252
+                r += g;
253
+            }
252 254
 
253 255
             if (lbd)
254 256
                 *((uint32_t*)(src[0] + x*4 + stride[0]*y)) = b + (g<<8) + (r<<16) + (a<<24);
... ...
@@ -315,7 +330,10 @@ static int decode_slice_header(FFV1Context *f, FFV1Context *fs)
315 315
     }
316 316
     f->cur->sample_aspect_ratio.num = get_symbol(c, state, 0);
317 317
     f->cur->sample_aspect_ratio.den = get_symbol(c, state, 0);
318
-
318
+    if (fs->version > 3) {
319
+        fs->slice_reset_contexts = get_rac(c, state);
320
+        fs->slice_coding_mode = get_symbol(c, state, 0);
321
+    }
319 322
     return 0;
320 323
 }
321 324
 
... ...
@@ -373,7 +391,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
373 373
     }
374 374
     if ((ret = ffv1_init_slice_state(f, fs)) < 0)
375 375
         return ret;
376
-    if (f->cur->key_frame)
376
+    if (f->cur->key_frame || fs->slice_reset_contexts)
377 377
         ffv1_clear_slice_state(f, fs);
378 378
 
379 379
     width  = fs->slice_width;