Browse code

Decoding to bgr15/16 from 16bit input. Decoding of 24bit input added, not yet finished, but at least the picture can be recognized

Originally committed as revision 3488 to svn://svn.ffmpeg.org/ffmpeg/trunk

Alex Beregszaszi authored on 2004/09/22 02:37:28
Showing 1 changed files
... ...
@@ -24,7 +24,7 @@
24 24
  * Mike Melanson (melanson@pcisys.net)
25 25
  *
26 26
  * The TrueMotion v1 decoder presently only decodes 16-bit TM1 data and
27
- * outputs RGB555 data. 24-bit TM1 data is not supported yet.
27
+ * outputs RGB555 (or RGB565) data. 24-bit TM1 data is not supported yet.
28 28
  */
29 29
 
30 30
 #include <stdio.h>
... ...
@@ -43,12 +43,12 @@ typedef struct TrueMotion1Context {
43 43
     AVFrame frame;
44 44
     AVFrame prev_frame;
45 45
 
46
-    unsigned char *buf;
46
+    uint8_t *buf;
47 47
     int size;
48 48
 
49
-    unsigned char *mb_change_bits;
49
+    uint8_t *mb_change_bits;
50 50
     int mb_change_bits_row_size;
51
-    unsigned char *index_stream;
51
+    uint8_t *index_stream;
52 52
     int index_stream_size;
53 53
 
54 54
     int flags;
... ...
@@ -56,6 +56,8 @@ typedef struct TrueMotion1Context {
56 56
     
57 57
     uint32_t y_predictor_table[1024];
58 58
     uint32_t c_predictor_table[1024];
59
+    uint32_t fat_y_predictor_table[1024];
60
+    uint32_t fat_c_predictor_table[1024];
59 61
     
60 62
     int compression;
61 63
     int block_type;
... ...
@@ -109,12 +111,12 @@ struct frame_header {
109 109
 
110 110
 typedef struct comp_types {
111 111
     int algorithm;
112
-    int block_width;
113
-    int block_height;
112
+    int block_width; // vres
113
+    int block_height; // hres
114 114
     int block_type;
115 115
 } comp_types;
116 116
 
117
-/* { valid for metatype }, algorithm, num of deltas, horiz res, vert res */
117
+/* { valid for metatype }, algorithm, num of deltas, vert res, horiz res */
118 118
 static comp_types compression_types[17] = {
119 119
     { ALGO_NOP,    0, 0, 0 },
120 120
 
... ...
@@ -163,9 +165,9 @@ static void select_delta_tables(TrueMotion1Context *s, int delta_table_index)
163 163
 }
164 164
 
165 165
 #ifdef WORDS_BIGENDIAN
166
-static int make_ydt_entry(int p2, int p1, int16_t *ydt)
166
+static int make_ydt15_entry(int p2, int p1, int16_t *ydt)
167 167
 #else
168
-static int make_ydt_entry(int p1, int p2, int16_t *ydt)
168
+static int make_ydt15_entry(int p1, int p2, int16_t *ydt)
169 169
 #endif
170 170
 {
171 171
     int lo, hi;
... ...
@@ -178,9 +180,9 @@ static int make_ydt_entry(int p1, int p2, int16_t *ydt)
178 178
 }
179 179
 
180 180
 #ifdef WORDS_BIGENDIAN
181
-static int make_cdt_entry(int p2, int p1, int16_t *cdt)
181
+static int make_cdt15_entry(int p2, int p1, int16_t *cdt)
182 182
 #else
183
-static int make_cdt_entry(int p1, int p2, int16_t *cdt)
183
+static int make_cdt15_entry(int p1, int p2, int16_t *cdt)
184 184
 #endif
185 185
 {
186 186
     int r, b, lo;
... ...
@@ -191,7 +193,104 @@ static int make_cdt_entry(int p1, int p2, int16_t *cdt)
191 191
     return ((lo + (lo << 16)) << 1);
192 192
 }
193 193
 
194
-static void gen_vector_table(TrueMotion1Context *s, uint8_t *sel_vector_table)
194
+#ifdef WORDS_BIGENDIAN
195
+static int make_ydt16_entry(int p2, int p1, int16_t *ydt)
196
+#else
197
+static int make_ydt16_entry(int p1, int p2, int16_t *ydt)
198
+#endif
199
+{
200
+    int lo, hi;
201
+    
202
+    lo = ydt[p1];
203
+    lo += (lo << 6) + (lo << 11);
204
+    hi = ydt[p2];
205
+    hi += (hi << 6) + (hi << 11);
206
+    return ((lo + (hi << 16)) << 1);
207
+}
208
+
209
+#ifdef WORDS_BIGENDIAN
210
+static int make_cdt16_entry(int p2, int p1, int16_t *cdt)
211
+#else
212
+static int make_cdt16_entry(int p1, int p2, int16_t *cdt)
213
+#endif
214
+{
215
+    int r, b, lo;
216
+    
217
+    b = cdt[p2];
218
+    r = cdt[p1] << 11;
219
+    lo = b + r;
220
+    return ((lo + (lo << 16)) << 1);
221
+}
222
+
223
+#ifdef WORDS_BIGENDIAN
224
+static int make_ydt24_entry(int p2, int p1, int16_t *ydt)
225
+#else
226
+static int make_ydt24_entry(int p1, int p2, int16_t *ydt)
227
+#endif
228
+{
229
+    int lo, hi;
230
+    
231
+    lo = ydt[p1];
232
+    hi = ydt[p2];
233
+    return ((lo + (hi << 8)) << 1);
234
+}
235
+
236
+#ifdef WORDS_BIGENDIAN
237
+static int make_cdt24_entry(int p2, int p1, int16_t *cdt)
238
+#else
239
+static int make_cdt24_entry(int p1, int p2, int16_t *cdt)
240
+#endif
241
+{
242
+    int r, b;
243
+    
244
+    b = cdt[p2];
245
+    r = cdt[p1]<<16;
246
+    return ((b+r) << 1);
247
+}
248
+
249
+static void gen_vector_table15(TrueMotion1Context *s, uint8_t *sel_vector_table)
250
+{
251
+    int len, i, j;
252
+    unsigned char delta_pair;
253
+    
254
+    for (i = 0; i < 1024; i += 4)
255
+    {
256
+        len = *sel_vector_table++ / 2;
257
+        for (j = 0; j < len; j++)
258
+        {
259
+            delta_pair = *sel_vector_table++;
260
+            s->y_predictor_table[i+j] = 0xfffffffe & 
261
+                make_ydt15_entry(delta_pair >> 4, delta_pair & 0xf, s->ydt);
262
+            s->c_predictor_table[i+j] = 0xfffffffe & 
263
+                make_cdt15_entry(delta_pair >> 4, delta_pair & 0xf, s->cdt);
264
+        }
265
+        s->y_predictor_table[i+(j-1)] |= 1;
266
+        s->c_predictor_table[i+(j-1)] |= 1;
267
+    }
268
+}
269
+
270
+static void gen_vector_table16(TrueMotion1Context *s, uint8_t *sel_vector_table)
271
+{
272
+    int len, i, j;
273
+    unsigned char delta_pair;
274
+    
275
+    for (i = 0; i < 1024; i += 4)
276
+    {
277
+        len = *sel_vector_table++ / 2;
278
+        for (j = 0; j < len; j++)
279
+        {
280
+            delta_pair = *sel_vector_table++;
281
+            s->y_predictor_table[i+j] = 0xfffffffe & 
282
+                make_ydt16_entry(delta_pair >> 4, delta_pair & 0xf, s->ydt);
283
+            s->c_predictor_table[i+j] = 0xfffffffe & 
284
+                make_cdt16_entry(delta_pair >> 4, delta_pair & 0xf, s->cdt);
285
+        }
286
+        s->y_predictor_table[i+(j-1)] |= 1;
287
+        s->c_predictor_table[i+(j-1)] |= 1;
288
+    }
289
+}
290
+
291
+static void gen_vector_table24(TrueMotion1Context *s, uint8_t *sel_vector_table)
195 292
 {
196 293
     int len, i, j;
197 294
     unsigned char delta_pair;
... ...
@@ -203,12 +302,18 @@ static void gen_vector_table(TrueMotion1Context *s, uint8_t *sel_vector_table)
203 203
         {
204 204
             delta_pair = *sel_vector_table++;
205 205
             s->y_predictor_table[i+j] = 0xfffffffe & 
206
-                make_ydt_entry(delta_pair >> 4, delta_pair & 0xf, s->ydt);
206
+                make_ydt24_entry(delta_pair >> 4, delta_pair & 0xf, s->ydt);
207 207
             s->c_predictor_table[i+j] = 0xfffffffe & 
208
-                make_cdt_entry(delta_pair >> 4, delta_pair & 0xf, s->cdt);
208
+                make_cdt24_entry(delta_pair >> 4, delta_pair & 0xf, s->cdt);
209
+            s->fat_y_predictor_table[i+j] = 0xfffffffe & 
210
+                make_ydt24_entry(delta_pair >> 4, delta_pair & 0xf, s->fat_ydt);
211
+            s->fat_c_predictor_table[i+j] = 0xfffffffe & 
212
+                make_cdt24_entry(delta_pair >> 4, delta_pair & 0xf, s->fat_cdt);
209 213
         }
210 214
         s->y_predictor_table[i+(j-1)] |= 1;
211 215
         s->c_predictor_table[i+(j-1)] |= 1;
216
+        s->fat_y_predictor_table[i+(j-1)] |= 1;
217
+        s->fat_c_predictor_table[i+(j-1)] |= 1;
212 218
     }
213 219
 }
214 220
 
... ...
@@ -229,14 +334,15 @@ static int truemotion1_decode_header(TrueMotion1Context *s)
229 229
     header.header_size = ((s->buf[0] >> 5) | (s->buf[0] << 3)) & 0x7f;
230 230
     if (s->buf[0] < 0x10)
231 231
     {
232
-        av_log(s->avctx, AV_LOG_ERROR, "invalid header size\n");
232
+	av_log(s->avctx, AV_LOG_ERROR, "invalid header size (%d)\n", s->buf[0]);
233 233
         return -1;
234 234
     }
235 235
 
236 236
     /* unscramble the header bytes with a XOR operation */
237 237
     memset(header_buffer, 0, 128);
238 238
     for (i = 1; i < header.header_size; i++)
239
-    header_buffer[i - 1] = s->buf[i] ^ s->buf[i + 1];
239
+	header_buffer[i - 1] = s->buf[i] ^ s->buf[i + 1];
240
+
240 241
     header.compression = header_buffer[0];
241 242
     header.deltaset = header_buffer[1];
242 243
     header.vectable = header_buffer[2];
... ...
@@ -253,7 +359,7 @@ static int truemotion1_decode_header(TrueMotion1Context *s)
253 253
     {
254 254
         if (header.header_type > 3)
255 255
         {
256
-            av_log(s->avctx, AV_LOG_ERROR, "truemotion1: invalid header type\n");
256
+            av_log(s->avctx, AV_LOG_ERROR, "invalid header type (%d)\n", header.header_type);
257 257
             return -1;
258 258
         } else if ((header.header_type == 2) || (header.header_type == 3)) {
259 259
             s->flags = header.flags;
... ...
@@ -265,6 +371,7 @@ static int truemotion1_decode_header(TrueMotion1Context *s)
265 265
         s->flags = FLAG_KEYFRAME;
266 266
     
267 267
     if (s->flags & FLAG_SPRITE) {
268
+	av_log(s->avctx, AV_LOG_INFO, "SPRITE frame found, please report the sample to the developers\n");
268 269
         s->w = header.width;
269 270
         s->h = header.height;
270 271
         s->x = header.xoffset;
... ...
@@ -274,7 +381,10 @@ static int truemotion1_decode_header(TrueMotion1Context *s)
274 274
         s->h = header.ysize;
275 275
         if (header.header_type < 2) {
276 276
             if ((s->w < 213) && (s->h >= 176))
277
+	    {
277 278
                 s->flags |= FLAG_INTERPOLATED;
279
+	        av_log(s->avctx, AV_LOG_INFO, "INTERPOLATION selected, please report the sample to the developers\n");
280
+	    }
278 281
         }
279 282
     }
280 283
 
... ...
@@ -297,15 +407,22 @@ static int truemotion1_decode_header(TrueMotion1Context *s)
297 297
             return -1;
298 298
         }
299 299
     }
300
+    
301
+    // FIXME: where to place this ?!?!
302
+    if (compression_types[header.compression].algorithm == ALGO_RGB24H)
303
+        s->avctx->pix_fmt = PIX_FMT_BGR24;
304
+    else
305
+	s->avctx->pix_fmt = PIX_FMT_RGB555; // RGB565 is supported aswell
300 306
 
301 307
     if ((header.deltaset != s->last_deltaset) || (header.vectable != s->last_vectable))
302 308
     {
303 309
         if (compression_types[header.compression].algorithm == ALGO_RGB24H)
304
-        {
305
-            av_log(s->avctx, AV_LOG_ERROR, "24bit compression not yet supported\n");
306
-        }
310
+            gen_vector_table24(s, sel_vector_table);
307 311
         else
308
-            gen_vector_table(s, sel_vector_table);
312
+	if (s->avctx->pix_fmt == PIX_FMT_RGB555)
313
+            gen_vector_table15(s, sel_vector_table);
314
+	else
315
+            gen_vector_table16(s, sel_vector_table);
309 316
     }
310 317
 
311 318
     /* set up pointers to the other key data chunks */
... ...
@@ -327,6 +444,15 @@ static int truemotion1_decode_header(TrueMotion1Context *s)
327 327
     s->block_height = compression_types[header.compression].block_height;
328 328
     s->block_type = compression_types[header.compression].block_type;
329 329
 
330
+    if (s->avctx->debug & FF_DEBUG_PICT_INFO)
331
+	av_log(s->avctx, AV_LOG_INFO, "tables: %d / %d c:%d %dx%d t:%d %s%s%s%s\n",
332
+	    s->last_deltaset, s->last_vectable, s->compression, s->block_width,
333
+	    s->block_height, s->block_type,
334
+	    s->flags & FLAG_KEYFRAME ? " KEY" : "",
335
+	    s->flags & FLAG_INTERFRAME ? " INTER" : "",
336
+	    s->flags & FLAG_SPRITE ? " SPRITE" : "",
337
+	    s->flags & FLAG_INTERPOLATED ? " INTERPOL" : "");
338
+
330 339
     return header.header_size;    
331 340
 }
332 341
 
... ...
@@ -336,7 +462,12 @@ static int truemotion1_decode_init(AVCodecContext *avctx)
336 336
 
337 337
     s->avctx = avctx;
338 338
 
339
-    avctx->pix_fmt = PIX_FMT_RGB555;
339
+    // FIXME: it may change ?
340
+//    if (avctx->bits_per_sample == 24)
341
+//	avctx->pix_fmt = PIX_FMT_RGB24;
342
+//    else
343
+//	avctx->pix_fmt = PIX_FMT_RGB555;
344
+
340 345
     avctx->has_b_frames = 0;
341 346
     s->frame.data[0] = s->prev_frame.data[0] = NULL;
342 347
 
... ...
@@ -348,6 +479,32 @@ static int truemotion1_decode_init(AVCodecContext *avctx)
348 348
     return 0;
349 349
 }
350 350
 
351
+/*
352
+Block decoding order:
353
+
354
+dxi: Y-Y
355
+dxic: Y-C-Y
356
+dxic2: Y-C-Y-C
357
+
358
+hres,vres,i,i%vres (0 < i < 4)
359
+2x2 0: 0 dxic2
360
+2x2 1: 1 dxi
361
+2x2 2: 0 dxic2
362
+2x2 3: 1 dxi
363
+2x4 0: 0 dxic2
364
+2x4 1: 1 dxi
365
+2x4 2: 2 dxi
366
+2x4 3: 3 dxi
367
+4x2 0: 0 dxic
368
+4x2 1: 1 dxi
369
+4x2 2: 0 dxic
370
+4x2 3: 1 dxi
371
+4x4 0: 0 dxic
372
+4x4 1: 1 dxi
373
+4x4 2: 2 dxi
374
+4x4 3: 3 dxi
375
+*/
376
+
351 377
 #define GET_NEXT_INDEX() \
352 378
 {\
353 379
     if (index_stream_index >= s->index_stream_size) { \
... ...
@@ -374,6 +531,25 @@ static int truemotion1_decode_init(AVCodecContext *avctx)
374 374
     } else \
375 375
         index++;
376 376
 
377
+#define APPLY_C_PREDICTOR_24() \
378
+    predictor_pair = s->c_predictor_table[index]; \
379
+    c_horiz_pred += (predictor_pair >> 1); \
380
+    if (predictor_pair & 1) { \
381
+        GET_NEXT_INDEX() \
382
+        if (!index) { \
383
+            GET_NEXT_INDEX() \
384
+            predictor_pair = s->fat_c_predictor_table[index]; \
385
+            c_horiz_pred += (predictor_pair >> 1); \
386
+            if (predictor_pair & 1) \
387
+                GET_NEXT_INDEX() \
388
+            else \
389
+                index++; \
390
+        } \
391
+    } else \
392
+        index++; 
393
+//    c_last+coff = clast+c_horiz_pred;
394
+
395
+
377 396
 #define APPLY_Y_PREDICTOR() \
378 397
     predictor_pair = s->y_predictor_table[index]; \
379 398
     horiz_pred += (predictor_pair >> 1); \
... ...
@@ -391,6 +567,23 @@ static int truemotion1_decode_init(AVCodecContext *avctx)
391 391
     } else \
392 392
         index++;
393 393
 
394
+#define APPLY_Y_PREDICTOR_24() \
395
+    predictor_pair = s->y_predictor_table[index]; \
396
+    horiz_pred += (predictor_pair >> 1); \
397
+    if (predictor_pair & 1) { \
398
+        GET_NEXT_INDEX() \
399
+        if (!index) { \
400
+            GET_NEXT_INDEX() \
401
+            predictor_pair = s->fat_y_predictor_table[index]; \
402
+            horiz_pred += (predictor_pair >> 1); \
403
+            if (predictor_pair & 1) \
404
+                GET_NEXT_INDEX() \
405
+            else \
406
+                index++; \
407
+        } \
408
+    } else \
409
+        index++;
410
+
394 411
 #define OUTPUT_PIXEL_PAIR() \
395 412
     *current_pixel_pair = *vert_pred + horiz_pred; \
396 413
     *vert_pred++ = *current_pixel_pair++; \
... ...
@@ -528,6 +721,149 @@ static void truemotion1_decode_16bit(TrueMotion1Context *s)
528 528
     }
529 529
 }
530 530
 
531
+static void truemotion1_decode_24bit(TrueMotion1Context *s)
532
+{
533
+    int y;
534
+    int pixels_left;  /* remaining pixels on this line */
535
+    unsigned int predictor_pair;
536
+    unsigned int horiz_pred;
537
+    unsigned int c_horiz_pred;
538
+    unsigned int *vert_pred;
539
+    unsigned int *current_pixel_pair;
540
+    unsigned int *prev_pixel_pair;
541
+    unsigned char *current_line = s->frame.data[0];
542
+    unsigned char *prev_line = s->prev_frame.data[0];
543
+    int keyframe = s->flags & FLAG_KEYFRAME;
544
+
545
+    /* these variables are for managing the stream of macroblock change bits */
546
+    unsigned char *mb_change_bits = s->mb_change_bits;
547
+    unsigned char mb_change_byte;
548
+    unsigned char mb_change_byte_mask;
549
+    int mb_change_index;
550
+
551
+    /* these variables are for managing the main index stream */
552
+    int index_stream_index = 0;  /* yes, the index into the index stream */
553
+    int index;
554
+
555
+    /* clean out the line buffer */
556
+    memset(s->vert_pred, 0, s->avctx->width * sizeof(unsigned short));
557
+
558
+    GET_NEXT_INDEX();
559
+
560
+    for (y = 0; y < s->avctx->height; y++) {
561
+
562
+        /* re-init variables for the next line iteration */
563
+        horiz_pred = c_horiz_pred = 0;
564
+        current_pixel_pair = (unsigned int *)current_line;
565
+        prev_pixel_pair = (unsigned int *)prev_line;
566
+        vert_pred = s->vert_pred;
567
+        mb_change_index = 0;
568
+        mb_change_byte = mb_change_bits[mb_change_index++];
569
+        mb_change_byte_mask = 0x01;
570
+        pixels_left = s->avctx->width;
571
+
572
+        while (pixels_left > 0) {
573
+
574
+            if (keyframe || ((mb_change_byte & mb_change_byte_mask) == 0)) {
575
+
576
+                switch (y & 3) {
577
+                case 0:
578
+                    /* if macroblock width is 2, apply C-Y-C-Y; else 
579
+                     * apply C-Y-Y */
580
+                    if (s->block_width == 2) {
581
+                        APPLY_C_PREDICTOR_24();
582
+                        APPLY_Y_PREDICTOR_24();
583
+                        OUTPUT_PIXEL_PAIR();
584
+//                        OUTPUT_PIXEL_PAIR_24_C();
585
+                        APPLY_C_PREDICTOR_24();
586
+                        APPLY_Y_PREDICTOR_24();
587
+                        OUTPUT_PIXEL_PAIR();
588
+//                        OUTPUT_PIXEL_PAIR_24_C();
589
+                    } else {
590
+                        APPLY_C_PREDICTOR_24();
591
+                        APPLY_Y_PREDICTOR_24();
592
+                        OUTPUT_PIXEL_PAIR();
593
+//                        OUTPUT_PIXEL_PAIR_24_C();
594
+                        APPLY_Y_PREDICTOR_24();
595
+                        OUTPUT_PIXEL_PAIR();
596
+//                        OUTPUT_PIXEL_PAIR_24_C();
597
+                    }
598
+                    break;
599
+
600
+                case 1:
601
+                case 3:
602
+                    /* always apply 2 Y predictors on these iterations */
603
+                    APPLY_Y_PREDICTOR_24();
604
+                    OUTPUT_PIXEL_PAIR();
605
+                    APPLY_Y_PREDICTOR_24();
606
+                    OUTPUT_PIXEL_PAIR();
607
+                    break;
608
+
609
+                case 2:
610
+                    /* this iteration might be C-Y-C-Y, Y-Y, or C-Y-Y 
611
+                     * depending on the macroblock type */
612
+                    if (s->block_type == BLOCK_2x2) {
613
+                        APPLY_C_PREDICTOR_24();
614
+                        APPLY_Y_PREDICTOR_24();
615
+                        OUTPUT_PIXEL_PAIR();
616
+//                        OUTPUT_PIXEL_PAIR_24_C();
617
+                        APPLY_C_PREDICTOR_24();
618
+                        APPLY_Y_PREDICTOR_24();
619
+                        OUTPUT_PIXEL_PAIR();
620
+//                        OUTPUT_PIXEL_PAIR_24_C();
621
+                    } else if (s->block_type == BLOCK_4x2) {
622
+                        APPLY_C_PREDICTOR_24();
623
+                        APPLY_Y_PREDICTOR_24();
624
+                        OUTPUT_PIXEL_PAIR();
625
+//                        OUTPUT_PIXEL_PAIR_24_C();
626
+                        APPLY_Y_PREDICTOR_24();
627
+                        OUTPUT_PIXEL_PAIR();
628
+//                        OUTPUT_PIXEL_PAIR_24_C();
629
+                    } else {
630
+                        APPLY_Y_PREDICTOR_24();
631
+                        OUTPUT_PIXEL_PAIR();
632
+                        APPLY_Y_PREDICTOR_24();
633
+                        OUTPUT_PIXEL_PAIR();
634
+                    }
635
+                    break;
636
+                }
637
+
638
+            } else {
639
+
640
+                /* skip (copy) four pixels, but reassign the horizontal 
641
+                 * predictor */
642
+                *current_pixel_pair = *prev_pixel_pair++;
643
+                *vert_pred++ = *current_pixel_pair++;
644
+                *current_pixel_pair = *prev_pixel_pair++;
645
+                horiz_pred = *current_pixel_pair - *vert_pred;
646
+//		c_horiz_pred = *current_pixel_pair - *vert_pred;
647
+                *vert_pred++ = *current_pixel_pair++;
648
+                
649
+            }
650
+
651
+            if (!keyframe) {
652
+                mb_change_byte_mask <<= 1;
653
+
654
+                /* next byte */
655
+                if (!mb_change_byte_mask) {
656
+                    mb_change_byte = mb_change_bits[mb_change_index++];
657
+                    mb_change_byte_mask = 0x01;
658
+                }
659
+            }
660
+
661
+            pixels_left -= 4;
662
+        }
663
+
664
+        /* next change row */
665
+        if (((y + 1) & 3) == 0)
666
+            mb_change_bits += s->mb_change_bits_row_size;
667
+
668
+        current_line += s->frame.linesize[0];
669
+        prev_line += s->prev_frame.linesize[0];
670
+    }
671
+}
672
+
673
+
531 674
 static int truemotion1_decode_frame(AVCodecContext *avctx,
532 675
                                     void *data, int *data_size,
533 676
                                     uint8_t *buf, int buf_size)
... ...
@@ -537,12 +873,6 @@ static int truemotion1_decode_frame(AVCodecContext *avctx,
537 537
     s->buf = buf;
538 538
     s->size = buf_size;
539 539
 
540
-    s->frame.reference = 1;
541
-    if (avctx->get_buffer(avctx, &s->frame) < 0) {
542
-        av_log(s->avctx, AV_LOG_ERROR, "truemotion1: get_buffer() failed\n");
543
-        return -1;
544
-    }
545
-
546 540
     /* no supplementary picture */
547 541
     if (buf_size == 0)
548 542
         return 0;
... ...
@@ -550,13 +880,19 @@ static int truemotion1_decode_frame(AVCodecContext *avctx,
550 550
     if (truemotion1_decode_header(s) == -1)
551 551
         return -1;
552 552
 
553
+    s->frame.reference = 1;
554
+    if (avctx->get_buffer(avctx, &s->frame) < 0) {
555
+        av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
556
+        return -1;
557
+    }
558
+
553 559
     /* check for a do-nothing frame and copy the previous frame */
554 560
     if (compression_types[s->compression].algorithm == ALGO_NOP)
555 561
     {
556 562
         memcpy(s->frame.data[0], s->prev_frame.data[0],
557 563
             s->frame.linesize[0] * s->avctx->height);
558 564
     } else if (compression_types[s->compression].algorithm == ALGO_RGB24H) {
559
-        av_log(s->avctx, AV_LOG_ERROR, "24bit compression not yet supported\n");
565
+        truemotion1_decode_24bit(s);
560 566
     } else {
561 567
         truemotion1_decode_16bit(s);
562 568
     }