32 #define TM2_ESCAPE 0x80000000
107 huff->
bits[huff->
num] = prefix;
108 huff->
lens[huff->
num] = length;
114 if(
tm2_read_tree(ctx, (prefix << 1) | 1, length + 1, huff) == -1)
138 if((huff.
nodes <= 0) || (huff.
nodes > 0x10000)) {
166 huff.
lens,
sizeof(
int),
sizeof(
int),
167 huff.
bits,
sizeof(uint32_t),
sizeof(uint32_t), 0);
177 for(i = 0; i < code->
length; i++)
203 #define TM2_OLD_HEADER_MAGIC 0x00000100
204 #define TM2_NEW_HEADER_MAGIC 0x00000101
229 if((d < 1) || (d >
TM2_DELTAS) || (mb < 1) || (mb > 32)) {
234 for(i = 0; i < d; i++) {
236 if(v & (1 << (mb - 1)))
237 ctx->
deltas[stream_id][i] = v - (1 << mb);
239 ctx->
deltas[stream_id][i] = v;
242 ctx->
deltas[stream_id][i] = 0;
257 len = bytestream2_get_be32(&gb);
263 if (len >= INT_MAX/4-1 || len < 0 || len > buf_size) {
268 toks = bytestream2_get_be32(&gb);
270 len = bytestream2_get_be32(&gb);
272 len = bytestream2_get_be32(&gb);
285 len = bytestream2_get_be32(&gb);
302 if((toks < 0) || (toks > 0xFFFFFF)){
309 len = bytestream2_get_be32(&gb);
315 for(i = 0; i < toks; i++) {
321 if (stream_id <= TM2_MOT && ctx->tokens[stream_id][i] >=
TM2_DELTAS) {
323 ctx->
tokens[stream_id][i], stream_id, i);
328 for(i = 0; i < toks; i++) {
330 if (stream_id <= TM2_MOT && ctx->tokens[stream_id][i] >=
TM2_DELTAS) {
332 ctx->
tokens[stream_id][i], stream_id, i);
355 #define TM2_INIT_POINTERS() \
358 int Ystride, Ustride, Vstride;\
360 Ystride = ctx->y_stride;\
361 Vstride = ctx->uv_stride;\
362 Ustride = ctx->uv_stride;\
363 Y = (ctx->cur?ctx->Y2:ctx->Y1) + by * 4 * Ystride + bx * 4;\
364 V = (ctx->cur?ctx->V2:ctx->V1) + by * 2 * Vstride + bx * 2;\
365 U = (ctx->cur?ctx->U2:ctx->U1) + by * 2 * Ustride + bx * 2;\
366 last = ctx->last + bx * 4;\
367 clast = ctx->clast + bx * 4;
369 #define TM2_INIT_POINTERS_2() \
371 int oYstride, oUstride, oVstride;\
373 TM2_INIT_POINTERS();\
377 Yo = (ctx->cur?ctx->Y1:ctx->Y2) + by * 4 * oYstride + bx * 4;\
378 Vo = (ctx->cur?ctx->V1:ctx->V2) + by * 2 * oVstride + bx * 2;\
379 Uo = (ctx->cur?ctx->U1:ctx->U2) + by * 2 * oUstride + bx * 2;
382 #define TM2_RECALC_BLOCK(CHR, stride, last, CD) {\
383 CD[0] = CHR[1] - last[1];\
384 CD[1] = (int)CHR[stride + 1] - (int)CHR[1];\
385 last[0] = (int)CHR[stride + 0];\
386 last[1] = (int)CHR[stride + 1];}
394 for(j = 0; j < 4; j++){
396 for(i = 0; i < 4; i++){
397 d = deltas[i + j * 4];
400 Y[i] = av_clip_uint8(last[i]);
410 for(j = 0; j < 2; j++){
411 for(i = 0; i < 2; i++){
412 CD[j] += deltas[i + j * 2];
430 t = (CD[0] + CD[1]) >> 1;
431 l = (prev - CD[0] - CD[1] + clast[1]) >> 1;
432 CD[1] = CD[0] + CD[1] -
t;
446 for(i = 0; i < 4; i++) {
454 for(i = 0; i < 16; i++)
468 deltas[1] = deltas[2] = deltas[3] = 0;
472 deltas[1] = deltas[2] = deltas[3] = 0;
476 for(i = 0; i < 16; i++)
491 deltas[1] = deltas[2] = deltas[3] = 0;
495 deltas[1] = deltas[2] = deltas[3] = 0;
499 for(i = 0; i < 16; i++)
508 last[0] = (last[-1] - ctx->
D[0] - ctx->
D[1] - ctx->
D[2] - ctx->
D[3] + last[1]) >> 1;
510 last[0] = (last[1] - ctx->
D[0] - ctx->
D[1] - ctx->
D[2] - ctx->
D[3])>> 1;
511 last[2] = (last[1] + last[3]) >> 1;
513 t1 = ctx->
D[0] + ctx->
D[1];
515 ctx->
D[1] = t1 - (t1 >> 1);
516 t2 = ctx->
D[2] + ctx->
D[3];
518 ctx->
D[3] = t2 - (t2 >> 1);
527 int left, right, diff;
532 deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
535 deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
539 for(i = 0; i < 16; i++)
542 ct = ctx->
D[0] + ctx->
D[1] + ctx->
D[2] + ctx->
D[3];
545 left = last[-1] - ct;
551 last[0] = left + (diff >> 2);
552 last[1] = left + (diff >> 1);
553 last[2] = right - (diff >> 2);
558 ctx->
D[0] = (tp + (ct >> 2)) - left;
560 ctx->
D[1] = (tp + (ct >> 1)) - left;
562 ctx->
D[2] = ((tp + ct) - (ct >> 2)) - left;
564 ctx->
D[3] = (tp + ct) - left;
575 for(j = 0; j < 2; j++){
576 for(i = 0; i < 2; i++){
580 U += Ustride;
V += Vstride;
581 Uo += oUstride; Vo += oVstride;
589 ctx->
D[0] = Yo[3] - last[3];
590 ctx->
D[1] = Yo[3 + oYstride] - Yo[3];
591 ctx->
D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
592 ctx->
D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
594 for(j = 0; j < 4; j++){
595 for(i = 0; i < 4; i++){
611 for(j = 0; j < 2; j++){
612 for(i = 0; i < 2; i++){
616 U += Ustride;
V += Vstride;
617 Uo += oUstride; Vo += oVstride;
625 ctx->
D[0] = Yo[3] - last[3];
626 ctx->
D[1] = Yo[3 + oYstride] - Yo[3];
627 ctx->
D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
628 ctx->
D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
630 for(j = 0; j < 4; j++){
632 for(i = 0; i < 4; i++){
636 ctx->
D[j] = last[3] - d;
650 mx = av_clip(mx, -(bx * 4 + 4), ctx->
avctx->
width - bx * 4);
651 my = av_clip(my, -(by * 4 + 4), ctx->
avctx->
height - by * 4);
653 Yo += my * oYstride + mx;
654 Uo += (my >> 1) * oUstride + (mx >> 1);
655 Vo += (my >> 1) * oVstride + (mx >> 1);
658 for(j = 0; j < 2; j++){
659 for(i = 0; i < 2; i++){
663 U += Ustride;
V += Vstride;
664 Uo += oUstride; Vo += oVstride;
672 for(j = 0; j < 4; j++){
673 for(i = 0; i < 4; i++){
681 ctx->
D[0] =
Y[3] - last[3];
682 ctx->
D[1] =
Y[3 + Ystride] -
Y[3];
683 ctx->
D[2] = Y[3 + Ystride * 2] - Y[3 + Ystride];
684 ctx->
D[3] = Y[3 + Ystride * 3] - Y[3 + Ystride * 2];
685 for(i = 0; i < 4; i++)
686 last[i] = Y[i + Ystride * 3];
706 memset(ctx->
last, 0, 4 * bw *
sizeof(
int));
707 memset(ctx->
clast, 0, 4 * bw *
sizeof(
int));
709 for(j = 0; j < bh; j++) {
710 memset(ctx->
D, 0, 4 *
sizeof(
int));
711 memset(ctx->
CD, 0, 4 *
sizeof(
int));
712 for(i = 0; i < bw; i++) {
746 Y = (ctx->
cur?ctx->
Y2:ctx->
Y1);
747 U = (ctx->
cur?ctx->
U2:ctx->
U1);
748 V = (ctx->
cur?ctx->
V2:ctx->
V1);
750 for(j = 0; j < h; j++){
751 for(i = 0; i < w; i++){
752 int y = Y[i], u = U[i >> 1], v = V[i >> 1];
753 dst[3*i+0] = av_clip_uint8(y + v);
754 dst[3*i+1] = av_clip_uint8(y);
755 dst[3*i+2] = av_clip_uint8(y + u);
759 Y[-4] = Y[-3] = Y[-2] = Y[-1] = Y[0];
760 Y[w + 3] = Y[w + 2] = Y[w + 1] = Y[w] = Y[w - 1];
768 }
else if (j == h - 1) {
778 U[-2] = U[-1] = U[0];
779 V[-2] = V[-1] = V[0];
780 U[cw + 1] = U[cw] = U[cw - 1];
781 V[cw + 1] = V[cw] = V[cw - 1];
789 }
else if (j == h - 1) {
809 #define TM2_HEADER_SIZE 40
812 void *
data,
int *got_frame,
816 int buf_size = avpkt->
size & ~3;
835 l->
dsp.
bswap_buf((uint32_t*)swbuf, (
const uint32_t*)buf, buf_size >> 2);
843 if (offset >= buf_size) {
953 .
name =
"truemotion2",
static void tm2_low_chroma(int *data, int stride, int *clast, int *CD, int *deltas, int bx)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx)
struct TM2Huff TM2Huff
structure for gathering Huffman codes information
This structure describes decoded (raw) audio or video data.
int buffer_hints
codec suggestion on buffer type if != 0
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
int * recode
table for converting from code indexes to values
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
AVCodec ff_truemotion2_decoder
int(* reget_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called at the beginning of a frame to get cr buffer for it.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
int num
current number filled
static int tm2_read_header(TM2Context *ctx, const uint8_t *buf)
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
structure for gathering Huffman codes information
static const int tm2_stream_order[TM2_NUM_STREAMS]
int max_bits
maximum length of code
static int tm2_read_deltas(TM2Context *ctx, int stream_id)
static void tm2_free_codes(TM2Codes *code)
int min_bits
minimum length of code
static int get_bits_count(const GetBitContext *s)
static int tm2_read_tree(TM2Context *ctx, uint32_t prefix, int length, TM2Huff *huff)
VLC vlc
table for Libav bitstream reader
bitstream reader API header.
static void tm2_hi_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
static int tm2_read_stream(TM2Context *ctx, const uint8_t *buf, int stream_id, int buf_size)
static int init(AVCodecParserContext *s)
static void tm2_update_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
static int get_bits_left(GetBitContext *gb)
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
int val_bits
length of literal
int reference
is this picture used as reference The values for this are the same as the MpegEncContext.picture_structure variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
void(* bswap_buf)(uint32_t *dst, const uint32_t *src, int w)
static int tm2_build_huff_table(TM2Context *ctx, TM2Codes *code)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static void tm2_low_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static int tm2_decode_blocks(TM2Context *ctx, AVFrame *p)
int * tokens[TM2_NUM_STREAMS]
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
struct TM2Codes TM2Codes
Huffman codes for each of streams.
int max_num
total number of codes
enum AVPictureType pict_type
Picture type of the frame, see ?_TYPE below.
static int GET_TOK(TM2Context *ctx, int type)
int width
picture width / height.
#define TM2_OLD_HEADER_MAGIC
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
packed RGB 8:8:8, 24bpp, BGRBGR...
static int tm2_get_token(GetBitContext *gb, TM2Codes *code)
int nodes
total number of nodes in tree
static av_cold int decode_end(AVCodecContext *avctx)
static av_always_inline int bytestream2_tell(GetByteContext *g)
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
#define TM2_INIT_POINTERS_2()
main external API structure.
static void close(AVCodecParserContext *s)
static void tm2_still_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
static unsigned int get_bits1(GetBitContext *s)
#define TM2_INIT_POINTERS()
void av_log_missing_feature(void *avc, const char *feature, int want_sample)
Log a generic warning message about a missing feature.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define FF_INPUT_BUFFER_PADDING_SIZE
static void tm2_med_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
#define FF_BUFFER_HINTS_REUSABLE
static void tm2_motion_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static void tm2_apply_deltas(TM2Context *ctx, int *Y, int stride, int *deltas, int *last)
#define TM2_RECALC_BLOCK(CHR, stride, last, CD)
#define FF_BUFFER_HINTS_PRESERVE
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
static void tm2_null_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
int deltas[TM2_NUM_STREAMS][TM2_DELTAS]
static av_cold int decode_init(AVCodecContext *avctx)
#define AVERROR_INVALIDDATA
#define TM2_NEW_HEADER_MAGIC
VLC_TYPE(* table)[2]
code, bits
int tok_lens[TM2_NUM_STREAMS]
int key_frame
1 -> keyframe, 0-> not
static void tm2_high_chroma(int *data, int stride, int *last, int *CD, int *deltas)
struct TM2Context TM2Context
#define FF_BUFFER_HINTS_VALID
Huffman codes for each of streams.
int tok_ptrs[TM2_NUM_STREAMS]
This structure stores compressed data.
void ff_free_vlc(VLC *vlc)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
if(!(ptr_align%ac->ptr_align)&&samples_align >=aligned_len)