35 #define TM2_ESCAPE 0x80000000 137 huff->
bits[huff->
num] = prefix;
138 huff->
lens[huff->
num] = length;
142 if ((ret2 =
tm2_read_tree(ctx, prefix << 1, length + 1, huff)) < 0)
144 if ((ret =
tm2_read_tree(ctx, (prefix << 1) | 1, length + 1, huff)) < 0)
147 return FFMAX(ret, ret2);
168 if ((huff.
nodes <= 0) || (huff.
nodes > 0x10000)) {
170 "nodes: %i\n", huff.
nodes);
190 if (res >= 0 && res != huff.
max_bits) {
204 huff.
lens,
sizeof(
int),
sizeof(
int),
205 huff.
bits,
sizeof(uint32_t),
sizeof(uint32_t), 0);
241 #define TM2_OLD_HEADER_MAGIC 0x00000100 242 #define TM2_NEW_HEADER_MAGIC 0x00000101 270 if ((d < 1) || (d >
TM2_DELTAS) || (mb < 1)) {
275 for (i = 0; i < d; i++) {
277 if (v & (1 << (mb - 1)))
283 ctx->
deltas[stream_id][i] = 0;
303 len = bytestream2_get_be32(&gb);
308 if (len >= INT_MAX / 4 - 1 || len < 0 || len * 4 + 4 > buf_size) {
314 toks = bytestream2_get_be32(&gb);
316 len = bytestream2_get_be32(&gb);
318 len = bytestream2_get_be32(&gb);
331 len = bytestream2_get_be32(&gb);
348 if ((toks < 0) || (toks > 0xFFFFFF)) {
359 len = bytestream2_get_be32(&gb);
367 for (i = 0; i < toks; i++) {
376 ctx->
tokens[stream_id][i], stream_id, i);
386 for (i = 0; i < toks; i++) {
390 ctx->
tokens[stream_id][i], stream_id, i);
424 #define TM2_INIT_POINTERS() \ 427 int Ystride, Ustride, Vstride;\ 429 Ystride = ctx->y_stride;\ 430 Vstride = ctx->uv_stride;\ 431 Ustride = ctx->uv_stride;\ 432 Y = (ctx->cur?ctx->Y2:ctx->Y1) + by * 4 * Ystride + bx * 4;\ 433 V = (ctx->cur?ctx->V2:ctx->V1) + by * 2 * Vstride + bx * 2;\ 434 U = (ctx->cur?ctx->U2:ctx->U1) + by * 2 * Ustride + bx * 2;\ 435 last = ctx->last + bx * 4;\ 436 clast = ctx->clast + bx * 4; 438 #define TM2_INIT_POINTERS_2() \ 439 unsigned *Yo, *Uo, *Vo;\ 440 int oYstride, oUstride, oVstride;\ 442 TM2_INIT_POINTERS();\ 446 Yo = (ctx->cur?ctx->Y1:ctx->Y2) + by * 4 * oYstride + bx * 4;\ 447 Vo = (ctx->cur?ctx->V1:ctx->V2) + by * 2 * oVstride + bx * 2;\ 448 Uo = (ctx->cur?ctx->U1:ctx->U2) + by * 2 * oUstride + bx * 2; 451 #define TM2_RECALC_BLOCK(CHR, stride, last, CD) {\ 452 CD[0] = (unsigned)CHR[ 1] - (unsigned)last[1];\ 453 CD[1] = (unsigned)CHR[stride + 1] - (unsigned) CHR[1];\ 454 last[0] = (int)CHR[stride + 0];\ 455 last[1] = (int)CHR[stride + 1];} 463 for (j = 0; j < 4; j++){
465 for (i = 0; i < 4; i++){
466 d = deltas[i + j * 4];
469 Y[
i] = av_clip_uint8(last[i]);
479 for (j = 0; j < 2; j++) {
480 for (i = 0; i < 2; i++) {
481 CD[j] += deltas[i + j * 2];
499 t = (
int)(CD[0] + CD[1]) >> 1;
500 l = (
int)(prev - CD[0] - CD[1] + clast[1]) >> 1;
501 CD[1] = CD[0] + CD[1] - t;
515 for (i = 0; i < 4; i++) {
523 for (i = 0; i < 16; i++)
537 deltas[1] = deltas[2] = deltas[3] = 0;
541 deltas[1] = deltas[2] = deltas[3] = 0;
545 for (i = 0; i < 16; i++)
560 deltas[1] = deltas[2] = deltas[3] = 0;
564 deltas[1] = deltas[2] = deltas[3] = 0;
568 for (i = 0; i < 16; i++)
577 last[0] = (
int)((
unsigned)
last[-1] - ctx->
D[0] - ctx->
D[1] - ctx->
D[2] - ctx->
D[3] +
last[1]) >> 1;
579 last[0] = (
int)((
unsigned)
last[1] - ctx->
D[0] - ctx->
D[1] - ctx->
D[2] - ctx->
D[3])>> 1;
582 t1 = ctx->
D[0] + (unsigned)ctx->
D[1];
584 ctx->
D[1] = t1 - (t1 >> 1);
585 t2 = ctx->
D[2] + (unsigned)ctx->
D[3];
587 ctx->
D[3] = t2 - (t2 >> 1);
596 unsigned left, right;
602 deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
605 deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
609 for (i = 0; i < 16; i++)
612 ct = (unsigned)ctx->
D[0] + ctx->
D[1] + ctx->
D[2] + ctx->
D[3];
615 left =
last[-1] - (unsigned)ct;
621 last[0] = left + (diff >> 2);
622 last[1] = left + (diff >> 1);
623 last[2] = right - (diff >> 2);
628 ctx->
D[0] = (tp + (ct >> 2)) - left;
630 ctx->
D[1] = (tp + (ct >> 1)) - left;
632 ctx->
D[2] = ((tp + ct) - (ct >> 2)) - left;
634 ctx->
D[3] = (tp + ct) - left;
645 for (j = 0; j < 2; j++) {
646 for (i = 0; i < 2; i++){
650 U += Ustride;
V += Vstride;
651 Uo += oUstride; Vo += oVstride;
659 ctx->
D[0] = Yo[3] -
last[3];
660 ctx->
D[1] = Yo[3 + oYstride] - Yo[3];
661 ctx->
D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
662 ctx->
D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
664 for (j = 0; j < 4; j++) {
665 for (i = 0; i < 4; i++) {
681 for (j = 0; j < 2; j++) {
682 for (i = 0; i < 2; i++) {
697 ctx->
D[0] = Yo[3] -
last[3];
698 ctx->
D[1] = Yo[3 + oYstride] - Yo[3];
699 ctx->
D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
700 ctx->
D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
702 for (j = 0; j < 4; j++) {
704 for (i = 0; i < 4; i++) {
708 ctx->
D[j] = last[3] - d;
722 mx = av_clip(mx, -(bx * 4 + 4), ctx->
avctx->
width - bx * 4);
723 my = av_clip(my, -(by * 4 + 4), ctx->
avctx->
height - by * 4);
730 Yo += my * oYstride + mx;
731 Uo += (my >> 1) * oUstride + (mx >> 1);
732 Vo += (my >> 1) * oVstride + (mx >> 1);
735 for (j = 0; j < 2; j++) {
736 for (i = 0; i < 2; i++) {
751 for (j = 0; j < 4; j++) {
752 for (i = 0; i < 4; i++) {
760 ctx->
D[0] = (unsigned)
Y[3] -
last[3];
761 ctx->
D[1] = (unsigned)
Y[3 + Ystride] -
Y[3];
762 ctx->
D[2] = (unsigned)
Y[3 + Ystride * 2] -
Y[3 + Ystride];
763 ctx->
D[3] = (unsigned)
Y[3 + Ystride * 3] -
Y[3 + Ystride * 2];
764 for (i = 0; i < 4; i++)
765 last[i] =
Y[i + Ystride * 3];
785 memset(ctx->
last, 0, 4 * bw *
sizeof(
int));
786 memset(ctx->
clast, 0, 4 * bw *
sizeof(
int));
788 for (j = 0; j < bh; j++) {
789 memset(ctx->
D, 0, 4 *
sizeof(
int));
790 memset(ctx->
CD, 0, 4 *
sizeof(
int));
791 for (i = 0; i < bw; i++) {
827 Y = (ctx->
cur?ctx->
Y2:ctx->
Y1);
828 U = (ctx->
cur?ctx->
U2:ctx->
U1);
829 V = (ctx->
cur?ctx->
V2:ctx->
V1);
831 for (j = 0; j <
h; j++) {
832 for (i = 0; i <
w; i++) {
833 unsigned y = Y[
i],
u = U[i >> 1], v = V[i >> 1];
834 dst[3*i+0] = av_clip_uint8(y + v);
835 dst[3*i+1] = av_clip_uint8(y);
836 dst[3*i+2] = av_clip_uint8(y + u);
840 Y[-4] = Y[-3] = Y[-2] = Y[-1] = Y[0];
841 Y[w + 3] = Y[w + 2] = Y[w + 1] = Y[
w] = Y[w - 1];
849 }
else if (j == h - 1) {
859 U[-2] = U[-1] = U[0];
860 V[-2] = V[-1] = V[0];
861 U[cw + 1] = U[cw] = U[cw - 1];
862 V[cw + 1] = V[cw] = V[cw - 1];
870 }
else if (j == h - 1) {
890 #define TM2_HEADER_SIZE 40 893 void *
data,
int *got_frame,
898 int buf_size = avpkt->
size & ~3;
922 if (offset >= buf_size) {
947 return (ret < 0) ? ret : buf_size;
1040 .
name =
"truemotion2",
#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.
static av_cold int init(AVCodecContext *avctx)
#define avpriv_request_sample(...)
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)
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
AVCodec ff_truemotion2_decoder
#define init_vlc(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
int num
current number filled
static int tm2_read_header(TM2Context *ctx, const uint8_t *buf)
structure for gathering Huffman codes information
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
void(* bswap_buf)(uint32_t *dst, const uint32_t *src, int w)
static const int tm2_stream_order[TM2_NUM_STREAMS]
static av_cold int end(AVCodecContext *avctx)
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
#define u(width, name, range_min, range_max)
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 FFmpeg 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 i(width, name, range_min, range_max)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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. ...
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Identical in function to ff_get_buffer(), except it reuses the existing buffer if available...
#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]
const char * name
Name of the codec implementation.
static const uint8_t offset[127][2]
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate, or free an array through a pointer to a pointer.
int max_num
total number of codes
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
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()
static void tm2_low_chroma(int *data, int stride, int *clast, unsigned *CD, int *deltas, int bx)
main external API structure.
static void tm2_still_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
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.
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 void tm2_high_chroma(int *data, int stride, int *last, unsigned *CD, int *deltas)
#define TM2_NEW_HEADER_MAGIC
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
static av_always_inline int diff(const uint32_t a, const uint32_t b)
VLC_TYPE(* table)[2]
code, bits
int tok_lens[TM2_NUM_STREAMS]
int key_frame
1 -> keyframe, 0-> not
Huffman codes for each of streams.
#define av_malloc_array(a, b)
int tok_ptrs[TM2_NUM_STREAMS]
static double val(void *priv, double ch)
This structure stores compressed data.
void ff_free_vlc(VLC *vlc)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)