Go to the documentation of this file.
83 #define FLAG_SPRITE 32
84 #define FLAG_KEYFRAME 16
85 #define FLAG_INTERFRAME 8
86 #define FLAG_INTERPOLATED 4
107 #define ALGO_RGB16V 1
108 #define ALGO_RGB16H 2
109 #define ALGO_RGB24H 3
153 if (delta_table_index > 3)
156 memcpy(
s->ydt,
ydts[delta_table_index], 8 *
sizeof(int16_t));
157 memcpy(
s->cdt,
cdts[delta_table_index], 8 *
sizeof(int16_t));
158 memcpy(
s->fat_ydt,
fat_ydts[delta_table_index], 8 *
sizeof(int16_t));
159 memcpy(
s->fat_cdt,
fat_cdts[delta_table_index], 8 *
sizeof(int16_t));
163 for (
i = 0;
i < 8;
i++)
181 lo += (lo * 32) + (lo * 1024);
183 hi += (hi * 32) + (hi * 1024);
184 return (lo + (hi * (1
U << 16))) * 2;
194 return (lo + (lo * (1
U << 16))) * 2;
206 lo += (lo << 6) + (lo << 11);
208 hi += (hi << 6) + (hi << 11);
209 return (lo + (hi << 16)) << 1;
219 return (lo + (lo * (1 << 16))) * 2;
228 return (lo + (hi * (1 << 8)) + (hi * (1 << 16))) * 2;
236 r = cdt[p1] * (1 << 16);
243 unsigned char delta_pair;
245 for (
i = 0;
i < 1024;
i += 4)
247 len = *sel_vector_table++ / 2;
248 for (j = 0; j <
len; j++)
250 delta_pair = *sel_vector_table++;
251 s->y_predictor_table[
i+j] = 0xfffffffe &
253 s->c_predictor_table[
i+j] = 0xfffffffe &
256 s->y_predictor_table[
i+(j-1)] |= 1;
257 s->c_predictor_table[
i+(j-1)] |= 1;
264 unsigned char delta_pair;
266 for (
i = 0;
i < 1024;
i += 4)
268 len = *sel_vector_table++ / 2;
269 for (j = 0; j <
len; j++)
271 delta_pair = *sel_vector_table++;
272 s->y_predictor_table[
i+j] = 0xfffffffe &
274 s->c_predictor_table[
i+j] = 0xfffffffe &
277 s->y_predictor_table[
i+(j-1)] |= 1;
278 s->c_predictor_table[
i+(j-1)] |= 1;
285 unsigned char delta_pair;
287 for (
i = 0;
i < 1024;
i += 4)
289 len = *sel_vector_table++ / 2;
290 for (j = 0; j <
len; j++)
292 delta_pair = *sel_vector_table++;
293 s->y_predictor_table[
i+j] = 0xfffffffe &
295 s->c_predictor_table[
i+j] = 0xfffffffe &
297 s->fat_y_predictor_table[
i+j] = 0xfffffffe &
299 s->fat_c_predictor_table[
i+j] = 0xfffffffe &
302 s->y_predictor_table[
i+(j-1)] |= 1;
303 s->c_predictor_table[
i+(j-1)] |= 1;
304 s->fat_y_predictor_table[
i+(j-1)] |= 1;
305 s->fat_c_predictor_table[
i+(j-1)] |= 1;
317 uint8_t header_buffer[128] = { 0 };
318 const uint8_t *sel_vector_table;
320 header.header_size = ((
s->buf[0] >> 5) | (
s->buf[0] << 3)) & 0x7f;
321 if (
s->buf[0] < 0x10)
327 if (
header.header_size + 1 >
s->size) {
334 header_buffer[
i - 1] =
s->buf[
i] ^
s->buf[
i + 1];
336 header.compression = header_buffer[0];
337 header.deltaset = header_buffer[1];
338 header.vectable = header_buffer[2];
342 header.version = header_buffer[9];
343 header.header_type = header_buffer[10];
344 header.flags = header_buffer[11];
345 header.control = header_buffer[12];
350 if (
header.header_type > 3)
354 }
else if ((
header.header_type == 2) || (
header.header_type == 3)) {
370 if (
header.header_type < 2) {
371 if ((
s->w < 213) && (
s->h >= 176))
379 if (
header.compression >= 17) {
384 if ((
header.deltaset !=
s->last_deltaset) ||
385 (
header.vectable !=
s->last_vectable))
405 s->w >>= width_shift;
411 if (
s->w !=
s->avctx->width ||
s->h !=
s->avctx->height ||
412 new_pix_fmt !=
s->avctx->pix_fmt) {
414 s->avctx->sample_aspect_ratio = (
AVRational){ 1 << width_shift, 1 };
415 s->avctx->pix_fmt = new_pix_fmt;
422 av_fast_malloc(&
s->vert_pred, &
s->vert_pred_size,
s->avctx->width *
sizeof(
unsigned int));
430 s->mb_change_bits_row_size = ((
s->avctx->width >> (2 - width_shift)) + 7) >> 3;
432 if ((
header.deltaset !=
s->last_deltaset) || (
header.vectable !=
s->last_vectable))
444 s->mb_change_bits =
s->buf +
header.header_size;
447 s->index_stream =
s->mb_change_bits;
448 if (
s->avctx->width *
s->avctx->height / 2048 +
header.header_size >
s->size)
452 s->index_stream =
s->mb_change_bits +
453 (
s->mb_change_bits_row_size * (
s->avctx->height >> 2));
455 s->index_stream_size =
s->size - (
s->index_stream -
s->buf);
457 s->last_deltaset =
header.deltaset;
458 s->last_vectable =
header.vectable;
459 s->compression =
header.compression;
466 s->last_deltaset,
s->last_vectable,
s->compression,
s->block_width,
467 s->block_height,
s->block_type,
473 return header.header_size;
494 av_fast_malloc(&
s->vert_pred, &
s->vert_pred_size,
s->avctx->width *
sizeof(
unsigned int));
527 #define GET_NEXT_INDEX() \
529 if (index_stream_index >= s->index_stream_size) { \
530 av_log(s->avctx, AV_LOG_INFO, " help! truemotion1 decoder went out of bounds\n"); \
533 index = s->index_stream[index_stream_index++] * 4; \
538 if (index >= 1023) { \
539 av_log(s->avctx, AV_LOG_ERROR, "Invalid index value.\n"); \
545 #define APPLY_C_PREDICTOR() \
546 predictor_pair = s->c_predictor_table[index]; \
547 horiz_pred += (predictor_pair >> 1); \
548 if (predictor_pair & 1) { \
552 predictor_pair = s->c_predictor_table[index]; \
553 horiz_pred += ((predictor_pair >> 1) * 5); \
554 if (predictor_pair & 1) \
562 #define APPLY_C_PREDICTOR_24() \
563 predictor_pair = s->c_predictor_table[index]; \
564 horiz_pred += (predictor_pair >> 1); \
565 if (predictor_pair & 1) { \
569 predictor_pair = s->fat_c_predictor_table[index]; \
570 horiz_pred += (predictor_pair >> 1); \
571 if (predictor_pair & 1) \
580 #define APPLY_Y_PREDICTOR() \
581 predictor_pair = s->y_predictor_table[index]; \
582 horiz_pred += (predictor_pair >> 1); \
583 if (predictor_pair & 1) { \
587 predictor_pair = s->y_predictor_table[index]; \
588 horiz_pred += ((predictor_pair >> 1) * 5); \
589 if (predictor_pair & 1) \
597 #define APPLY_Y_PREDICTOR_24() \
598 predictor_pair = s->y_predictor_table[index]; \
599 horiz_pred += (predictor_pair >> 1); \
600 if (predictor_pair & 1) { \
604 predictor_pair = s->fat_y_predictor_table[index]; \
605 horiz_pred += (predictor_pair >> 1); \
606 if (predictor_pair & 1) \
614 #define OUTPUT_PIXEL_PAIR() \
615 *current_pixel_pair = *vert_pred + horiz_pred; \
616 *vert_pred++ = *current_pixel_pair++;
622 unsigned int predictor_pair;
623 unsigned int horiz_pred;
624 unsigned int *vert_pred;
625 unsigned int *current_pixel_pair;
626 unsigned char *current_line =
s->frame->data[0];
630 const unsigned char *mb_change_bits =
s->mb_change_bits;
631 unsigned char mb_change_byte;
632 unsigned char mb_change_byte_mask;
636 int index_stream_index = 0;
640 memset(
s->vert_pred, 0,
s->avctx->width *
sizeof(
unsigned int));
644 for (y = 0; y <
s->avctx->height; y++) {
648 current_pixel_pair = (
unsigned int *)current_line;
649 vert_pred =
s->vert_pred;
652 mb_change_byte = mb_change_bits[mb_change_index++];
653 mb_change_byte_mask = 0x01;
654 pixels_left =
s->avctx->width;
656 while (pixels_left > 0) {
658 if (keyframe || ((mb_change_byte & mb_change_byte_mask) == 0)) {
664 if (
s->block_width == 2) {
718 *vert_pred++ = *current_pixel_pair++;
719 horiz_pred = *current_pixel_pair - *vert_pred;
720 *vert_pred++ = *current_pixel_pair++;
725 mb_change_byte_mask <<= 1;
728 if (!mb_change_byte_mask) {
729 mb_change_byte = mb_change_bits[mb_change_index++];
730 mb_change_byte_mask = 0x01;
738 if (((y + 1) & 3) == 0)
739 mb_change_bits +=
s->mb_change_bits_row_size;
741 current_line +=
s->frame->linesize[0];
749 unsigned int predictor_pair;
750 unsigned int horiz_pred;
751 unsigned int *vert_pred;
752 unsigned int *current_pixel_pair;
753 unsigned char *current_line =
s->frame->data[0];
757 const unsigned char *mb_change_bits =
s->mb_change_bits;
758 unsigned char mb_change_byte;
759 unsigned char mb_change_byte_mask;
763 int index_stream_index = 0;
767 memset(
s->vert_pred, 0,
s->avctx->width *
sizeof(
unsigned int));
771 for (y = 0; y <
s->avctx->height; y++) {
775 current_pixel_pair = (
unsigned int *)current_line;
776 vert_pred =
s->vert_pred;
778 mb_change_byte = mb_change_bits[mb_change_index++];
779 mb_change_byte_mask = 0x01;
780 pixels_left =
s->avctx->width;
782 while (pixels_left > 0) {
784 if (keyframe || ((mb_change_byte & mb_change_byte_mask) == 0)) {
790 if (
s->block_width == 2) {
844 *vert_pred++ = *current_pixel_pair++;
845 horiz_pred = *current_pixel_pair - *vert_pred;
846 *vert_pred++ = *current_pixel_pair++;
851 mb_change_byte_mask <<= 1;
854 if (!mb_change_byte_mask) {
855 mb_change_byte = mb_change_bits[mb_change_index++];
856 mb_change_byte_mask = 0x01;
864 if (((y + 1) & 3) == 0)
865 mb_change_bits +=
s->mb_change_bits_row_size;
867 current_line +=
s->frame->linesize[0];
875 const uint8_t *buf = avpkt->
data;
876 int ret, buf_size = avpkt->
size;
914 .
p.
name =
"truemotion1",
uint32_t fat_y_predictor_table[1024]
#define APPLY_C_PREDICTOR()
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static const int16_t *const fat_cdts[]
static av_cold int truemotion1_decode_init(AVCodecContext *avctx)
static int make_cdt16_entry(int p1, int p2, int16_t *cdt)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
static void truemotion1_decode_16bit(TrueMotion1Context *s)
@ AV_CODEC_ID_TRUEMOTION1
#define APPLY_C_PREDICTOR_24()
uint32_t y_predictor_table[1024]
#define FF_DEBUG_PICT_INFO
static const int16_t *const cdts[]
uint32_t c_predictor_table[1024]
static const int16_t *const fat_ydts[]
AVCodec p
The public AVCodec.
Writing a table generator This documentation is preliminary Parts of the API are not good and should be changed Basic concepts A table generator consists of two *_tablegen c and *_tablegen h The h file will provide the variable declarations and initialization code for the tables
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void select_delta_tables(TrueMotion1Context *s, int delta_table_index)
static const uint8_t pc_tbl2[]
#define FF_CODEC_DECODE_CB(func)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
static int make_ydt16_entry(int p1, int p2, int16_t *ydt)
const FFCodec ff_truemotion1_decoder
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static int make_ydt15_entry(int p1, int p2, int16_t *ydt)
static void gen_vector_table16(TrueMotion1Context *s, const uint8_t *sel_vector_table)
Rational number (pair of numerator and denominator).
#define FLAG_INTERPOLATED
#define OUTPUT_PIXEL_PAIR()
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
static int make_cdt24_entry(int p1, int p2, int16_t *cdt)
static int make_cdt15_entry(int p1, int p2, int16_t *cdt)
static const uint8_t header[24]
static void gen_vector_table15(TrueMotion1Context *s, const uint8_t *sel_vector_table)
#define APPLY_Y_PREDICTOR_24()
#define AV_LOG_INFO
Standard information.
#define i(width, name, range_min, range_max)
static void gen_vector_table24(TrueMotion1Context *s, const uint8_t *sel_vector_table)
#define APPLY_Y_PREDICTOR()
uint32_t fat_c_predictor_table[1024]
#define AV_PIX_FMT_RGB555
#define xf(width, name, var, range_min, range_max, subs,...)
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
const char * name
Name of the codec implementation.
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.
static const comp_types compression_types[17]
#define AV_PIX_FMT_0RGB32
static const int16_t *const ydts[]
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
main external API structure.
static void truemotion1_decode_24bit(TrueMotion1Context *s)
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
#define avpriv_request_sample(...)
const uint8_t * index_stream
This structure stores compressed data.
const uint8_t * mb_change_bits
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int truemotion1_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, AVPacket *avpkt)
static av_cold int truemotion1_decode_end(AVCodecContext *avctx)
static int truemotion1_decode_header(TrueMotion1Context *s)
int mb_change_bits_row_size
static int make_ydt24_entry(int p1, int p2, int16_t *ydt)