Mercurial > libavcodec.hg
comparison truemotion2.c @ 2910:a1d02ca0d339 libavcodec
TM2 fixes by Kostya
author | melanson |
---|---|
date | Sat, 15 Oct 2005 14:33:11 +0000 |
parents | 21068c2fcb1d |
children | 4b3626936f09 |
comparison
equal
deleted
inserted
replaced
2909:7c6e1c80d5e3 | 2910:a1d02ca0d339 |
---|---|
27 #include "common.h" | 27 #include "common.h" |
28 #include "bitstream.h" | 28 #include "bitstream.h" |
29 #include "dsputil.h" | 29 #include "dsputil.h" |
30 | 30 |
31 #define TM2_ESCAPE 0x80000000 | 31 #define TM2_ESCAPE 0x80000000 |
32 #define TM2_DELTAS 32 | 32 #define TM2_DELTAS 64 |
33 /* Huffman-coded streams of different types of blocks */ | 33 /* Huffman-coded streams of different types of blocks */ |
34 enum TM2_STREAMS{ TM2_C_HI = 0, TM2_C_LO, TM2_L_HI, TM2_L_LO, | 34 enum TM2_STREAMS{ TM2_C_HI = 0, TM2_C_LO, TM2_L_HI, TM2_L_LO, |
35 TM2_UPD, TM2_MOT, TM2_TYPE, TM2_NUM_STREAMS}; | 35 TM2_UPD, TM2_MOT, TM2_TYPE, TM2_NUM_STREAMS}; |
36 /* Block types */ | 36 /* Block types */ |
37 enum TM2_BLOCKS{ TM2_HI_RES = 0, TM2_MED_RES, TM2_LOW_RES, TM2_NULL_RES, | 37 enum TM2_BLOCKS{ TM2_HI_RES = 0, TM2_MED_RES, TM2_LOW_RES, TM2_NULL_RES, |
216 int w, h, size, flags, xr, yr; | 216 int w, h, size, flags, xr, yr; |
217 | 217 |
218 length = LE_32(buf); | 218 length = LE_32(buf); |
219 buf += 4; | 219 buf += 4; |
220 | 220 |
221 init_get_bits(&ctx->gb, buf, 32); | 221 init_get_bits(&ctx->gb, buf, 32 * 8); |
222 size = get_bits_long(&ctx->gb, 31); | 222 size = get_bits_long(&ctx->gb, 31); |
223 h = get_bits(&ctx->gb, 15); | 223 h = get_bits(&ctx->gb, 15); |
224 w = get_bits(&ctx->gb, 15); | 224 w = get_bits(&ctx->gb, 15); |
225 flags = get_bits_long(&ctx->gb, 31); | 225 flags = get_bits_long(&ctx->gb, 31); |
226 yr = get_bits(&ctx->gb, 9); | 226 yr = get_bits(&ctx->gb, 9); |
279 len = BE_32(buf); buf += 4; cur += 4; | 279 len = BE_32(buf); buf += 4; cur += 4; |
280 if(len == TM2_ESCAPE) { | 280 if(len == TM2_ESCAPE) { |
281 len = BE_32(buf); buf += 4; cur += 4; | 281 len = BE_32(buf); buf += 4; cur += 4; |
282 } | 282 } |
283 if(len > 0) { | 283 if(len > 0) { |
284 init_get_bits(&ctx->gb, buf, skip - cur); | 284 init_get_bits(&ctx->gb, buf, (skip - cur) * 8); |
285 if(tm2_read_deltas(ctx, stream_id) == -1) | 285 if(tm2_read_deltas(ctx, stream_id) == -1) |
286 return -1; | 286 return -1; |
287 buf += ((get_bits_count(&ctx->gb) + 31) >> 5) << 2; | 287 buf += ((get_bits_count(&ctx->gb) + 31) >> 5) << 2; |
288 cur += ((get_bits_count(&ctx->gb) + 31) >> 5) << 2; | 288 cur += ((get_bits_count(&ctx->gb) + 31) >> 5) << 2; |
289 } | 289 } |
293 buf += 4; cur += 4; /* some unknown length - could be escaped too */ | 293 buf += 4; cur += 4; /* some unknown length - could be escaped too */ |
294 } | 294 } |
295 buf += 4; cur += 4; | 295 buf += 4; cur += 4; |
296 buf += 4; cur += 4; /* unused by decoder */ | 296 buf += 4; cur += 4; /* unused by decoder */ |
297 | 297 |
298 init_get_bits(&ctx->gb, buf, skip - cur); | 298 init_get_bits(&ctx->gb, buf, (skip - cur) * 8); |
299 if(tm2_build_huff_table(ctx, &codes) == -1) | 299 if(tm2_build_huff_table(ctx, &codes) == -1) |
300 return -1; | 300 return -1; |
301 buf += ((get_bits_count(&ctx->gb) + 31) >> 5) << 2; | 301 buf += ((get_bits_count(&ctx->gb) + 31) >> 5) << 2; |
302 cur += ((get_bits_count(&ctx->gb) + 31) >> 5) << 2; | 302 cur += ((get_bits_count(&ctx->gb) + 31) >> 5) << 2; |
303 | 303 |
310 } | 310 } |
311 ctx->tokens[stream_id] = av_realloc(ctx->tokens[stream_id], toks * sizeof(int)); | 311 ctx->tokens[stream_id] = av_realloc(ctx->tokens[stream_id], toks * sizeof(int)); |
312 ctx->tok_lens[stream_id] = toks; | 312 ctx->tok_lens[stream_id] = toks; |
313 len = BE_32(buf); buf += 4; cur += 4; | 313 len = BE_32(buf); buf += 4; cur += 4; |
314 if(len > 0) { | 314 if(len > 0) { |
315 init_get_bits(&ctx->gb, buf, skip - cur); | 315 init_get_bits(&ctx->gb, buf, (skip - cur) * 8); |
316 for(i = 0; i < toks; i++) | 316 for(i = 0; i < toks; i++) |
317 ctx->tokens[stream_id][i] = tm2_get_token(&ctx->gb, &codes); | 317 ctx->tokens[stream_id][i] = tm2_get_token(&ctx->gb, &codes); |
318 } else { | 318 } else { |
319 memset(ctx->tokens[stream_id], 0, toks * sizeof(int)); | 319 for(i = 0; i < toks; i++) |
320 ctx->tokens[stream_id][i] = codes.recode[0]; | |
320 } | 321 } |
321 tm2_free_codes(&codes); | 322 tm2_free_codes(&codes); |
322 | 323 |
323 return skip; | 324 return skip; |
324 } | 325 } |
763 TM2Context * const l = avctx->priv_data; | 764 TM2Context * const l = avctx->priv_data; |
764 AVFrame * const p= (AVFrame*)&l->pic; | 765 AVFrame * const p= (AVFrame*)&l->pic; |
765 int skip, t; | 766 int skip, t; |
766 | 767 |
767 p->reference = 1; | 768 p->reference = 1; |
768 if(avctx->get_buffer(avctx, p) < 0){ | 769 p->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; |
770 if(avctx->reget_buffer(avctx, p) < 0){ | |
769 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); | 771 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
770 return -1; | 772 return -1; |
771 } | 773 } |
772 | 774 |
773 l->dsp.bswap_buf((uint32_t*)buf, (uint32_t*)buf, buf_size >> 2); | 775 l->dsp.bswap_buf((uint32_t*)buf, (uint32_t*)buf, buf_size >> 2); |