35 #define TM2_ESCAPE 0x80000000
129 huff->
bits[huff->
num] = prefix;
130 huff->
lens[huff->
num] = length;
134 if ((ret =
tm2_read_tree(ctx, prefix << 1, length + 1, huff)) < 0)
136 if ((ret =
tm2_read_tree(ctx, (prefix << 1) | 1, length + 1, huff)) < 0)
160 if ((huff.
nodes <= 0) || (huff.
nodes > 0x10000)) {
162 "nodes: %i\n", huff.
nodes);
188 huff.
lens,
sizeof(
int),
sizeof(
int),
189 huff.
bits,
sizeof(uint32_t),
sizeof(uint32_t), 0);
196 for (i = 0; i < code->
length; i++)
222 #define TM2_OLD_HEADER_MAGIC 0x00000100
223 #define TM2_NEW_HEADER_MAGIC 0x00000101
250 if ((d < 1) || (d >
TM2_DELTAS) || (mb < 1) || (mb > 32)) {
255 for (i = 0; i < d; i++) {
257 if (v & (1 << (mb - 1)))
258 ctx->
deltas[stream_id][i] = v - (1 << mb);
260 ctx->
deltas[stream_id][i] = v;
263 ctx->
deltas[stream_id][i] = 0;
278 len = bytestream2_get_be32(&gb);
284 if (len >= INT_MAX/4-1 || len < 0 || len > buf_size) {
289 toks = bytestream2_get_be32(&gb);
291 len = bytestream2_get_be32(&gb);
293 len = bytestream2_get_be32(&gb);
306 len = bytestream2_get_be32(&gb);
323 if ((toks < 0) || (toks > 0xFFFFFF)) {
330 len = bytestream2_get_be32(&gb);
336 for (i = 0; i < toks; i++) {
342 if (stream_id <= TM2_MOT && ctx->tokens[stream_id][i] >=
TM2_DELTAS) {
344 ctx->
tokens[stream_id][i], stream_id, i);
349 for (i = 0; i < toks; i++) {
351 if (stream_id <= TM2_MOT && ctx->tokens[stream_id][i] >=
TM2_DELTAS) {
353 ctx->
tokens[stream_id][i], stream_id, i);
377 #define TM2_INIT_POINTERS() \
380 int Ystride, Ustride, Vstride;\
382 Ystride = ctx->y_stride;\
383 Vstride = ctx->uv_stride;\
384 Ustride = ctx->uv_stride;\
385 Y = (ctx->cur?ctx->Y2:ctx->Y1) + by * 4 * Ystride + bx * 4;\
386 V = (ctx->cur?ctx->V2:ctx->V1) + by * 2 * Vstride + bx * 2;\
387 U = (ctx->cur?ctx->U2:ctx->U1) + by * 2 * Ustride + bx * 2;\
388 last = ctx->last + bx * 4;\
389 clast = ctx->clast + bx * 4;
391 #define TM2_INIT_POINTERS_2() \
393 int oYstride, oUstride, oVstride;\
395 TM2_INIT_POINTERS();\
399 Yo = (ctx->cur?ctx->Y1:ctx->Y2) + by * 4 * oYstride + bx * 4;\
400 Vo = (ctx->cur?ctx->V1:ctx->V2) + by * 2 * oVstride + bx * 2;\
401 Uo = (ctx->cur?ctx->U1:ctx->U2) + by * 2 * oUstride + bx * 2;
404 #define TM2_RECALC_BLOCK(CHR, stride, last, CD) {\
405 CD[0] = CHR[1] - last[1];\
406 CD[1] = (int)CHR[stride + 1] - (int)CHR[1];\
407 last[0] = (int)CHR[stride + 0];\
408 last[1] = (int)CHR[stride + 1];}
416 for (j = 0; j < 4; j++){
418 for (i = 0; i < 4; i++){
419 d = deltas[i + j * 4];
422 Y[i] = av_clip_uint8(last[i]);
432 for (j = 0; j < 2; j++) {
433 for (i = 0; i < 2; i++) {
434 CD[j] += deltas[i + j * 2];
452 t = (CD[0] + CD[1]) >> 1;
453 l = (prev - CD[0] - CD[1] + clast[1]) >> 1;
454 CD[1] = CD[0] + CD[1] - t;
468 for (i = 0; i < 4; i++) {
476 for (i = 0; i < 16; i++)
490 deltas[1] = deltas[2] = deltas[3] = 0;
494 deltas[1] = deltas[2] = deltas[3] = 0;
498 for (i = 0; i < 16; i++)
513 deltas[1] = deltas[2] = deltas[3] = 0;
517 deltas[1] = deltas[2] = deltas[3] = 0;
521 for (i = 0; i < 16; i++)
530 last[0] = (last[-1] - ctx->
D[0] - ctx->
D[1] - ctx->
D[2] - ctx->
D[3] + last[1]) >> 1;
532 last[0] = (last[1] - ctx->
D[0] - ctx->
D[1] - ctx->
D[2] - ctx->
D[3])>> 1;
533 last[2] = (last[1] + last[3]) >> 1;
535 t1 = ctx->
D[0] + ctx->
D[1];
537 ctx->
D[1] = t1 - (t1 >> 1);
538 t2 = ctx->
D[2] + ctx->
D[3];
540 ctx->
D[3] = t2 - (t2 >> 1);
549 int left, right, diff;
554 deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
557 deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
561 for (i = 0; i < 16; i++)
564 ct = ctx->
D[0] + ctx->
D[1] + ctx->
D[2] + ctx->
D[3];
567 left = last[-1] - ct;
573 last[0] = left + (diff >> 2);
574 last[1] = left + (diff >> 1);
575 last[2] = right - (diff >> 2);
580 ctx->
D[0] = (tp + (ct >> 2)) - left;
582 ctx->
D[1] = (tp + (ct >> 1)) - left;
584 ctx->
D[2] = ((tp + ct) - (ct >> 2)) - left;
586 ctx->
D[3] = (tp + ct) - left;
597 for (j = 0; j < 2; j++) {
598 for (i = 0; i < 2; i++){
602 U += Ustride;
V += Vstride;
603 Uo += oUstride; Vo += oVstride;
611 ctx->
D[0] = Yo[3] - last[3];
612 ctx->
D[1] = Yo[3 + oYstride] - Yo[3];
613 ctx->
D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
614 ctx->
D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
616 for (j = 0; j < 4; j++) {
617 for (i = 0; i < 4; i++) {
633 for (j = 0; j < 2; j++) {
634 for (i = 0; i < 2; i++) {
649 ctx->
D[0] = Yo[3] - last[3];
650 ctx->
D[1] = Yo[3 + oYstride] - Yo[3];
651 ctx->
D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
652 ctx->
D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
654 for (j = 0; j < 4; j++) {
656 for (i = 0; i < 4; i++) {
660 ctx->
D[j] = last[3] - d;
674 mx = av_clip(mx, -(bx * 4 + 4), ctx->
avctx->
width - bx * 4);
675 my = av_clip(my, -(by * 4 + 4), ctx->
avctx->
height - by * 4);
677 Yo += my * oYstride + mx;
678 Uo += (my >> 1) * oUstride + (mx >> 1);
679 Vo += (my >> 1) * oVstride + (mx >> 1);
682 for (j = 0; j < 2; j++) {
683 for (i = 0; i < 2; i++) {
698 for (j = 0; j < 4; j++) {
699 for (i = 0; i < 4; i++) {
707 ctx->
D[0] =
Y[3] - last[3];
708 ctx->
D[1] =
Y[3 + Ystride] -
Y[3];
709 ctx->
D[2] = Y[3 + Ystride * 2] - Y[3 + Ystride];
710 ctx->
D[3] = Y[3 + Ystride * 3] - Y[3 + Ystride * 2];
711 for (i = 0; i < 4; i++)
712 last[i] = Y[i + Ystride * 3];
732 memset(ctx->
last, 0, 4 * bw *
sizeof(
int));
733 memset(ctx->
clast, 0, 4 * bw *
sizeof(
int));
735 for (j = 0; j < bh; j++) {
736 memset(ctx->
D, 0, 4 *
sizeof(
int));
737 memset(ctx->
CD, 0, 4 *
sizeof(
int));
738 for (i = 0; i < bw; i++) {
772 Y = (ctx->
cur?ctx->
Y2:ctx->
Y1);
773 U = (ctx->
cur?ctx->
U2:ctx->
U1);
774 V = (ctx->
cur?ctx->
V2:ctx->
V1);
776 for (j = 0; j < h; j++) {
777 for (i = 0; i < w; i++) {
778 int y = Y[i], u = U[i >> 1], v = V[i >> 1];
779 dst[3*i+0] = av_clip_uint8(y + v);
780 dst[3*i+1] = av_clip_uint8(y);
781 dst[3*i+2] = av_clip_uint8(y + u);
785 Y[-4] = Y[-3] = Y[-2] = Y[-1] = Y[0];
786 Y[w + 3] = Y[w + 2] = Y[w + 1] = Y[w] = Y[w - 1];
794 }
else if (j == h - 1) {
804 U[-2] = U[-1] = U[0];
805 V[-2] = V[-1] = V[0];
806 U[cw + 1] = U[cw] = U[cw - 1];
807 V[cw + 1] = V[cw] = V[cw - 1];
815 }
else if (j == h - 1) {
835 #define TM2_HEADER_SIZE 40
838 void *
data,
int *got_frame,
843 int buf_size = avpkt->
size & ~3;
861 l->
bdsp.
bswap_buf((uint32_t *) swbuf, (
const uint32_t *) buf,
870 if (offset >= buf_size) {
893 return (ret < 0) ? ret : buf_size;
983 .
name =
"truemotion2",
void(* bswap_buf)(uint32_t *dst, const uint32_t *src, int w)
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 ...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
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
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)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
structure for gathering Huffman codes information
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static const int tm2_stream_order[TM2_NUM_STREAMS]
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
int max_bits
maximum length of code
static int tm2_read_deltas(TM2Context *ctx, int stream_id)
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
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 void tm2_update_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
static int get_bits_left(GetBitContext *gb)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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
static int tm2_build_huff_table(TM2Context *ctx, TM2Codes *code)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
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. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
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.
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
int max_num
total number of codes
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame)
Identical in function to av_frame_make_writable(), except it uses ff_get_buffer() to allocate the buf...
enum AVPictureType pict_type
Picture type of the frame.
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
if(ac->has_optimized_func)
static av_cold int decode_end(AVCodecContext *avctx)
static av_always_inline int bytestream2_tell(GetByteContext *g)
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
#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()
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static void tm2_med_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
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)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
common internal api header.
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)
static av_cold int init(AVCodecParserContext *s)
#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)
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)