82 #define FLAG_SPRITE 32
83 #define FLAG_KEYFRAME 16
84 #define FLAG_INTERFRAME 8
85 #define FLAG_INTERPOLATED 4
106 #define ALGO_RGB16V 1
107 #define ALGO_RGB16H 2
108 #define ALGO_RGB24H 3
152 if (delta_table_index > 3)
155 memcpy(
s->ydt,
ydts[delta_table_index], 8 *
sizeof(int16_t));
156 memcpy(
s->cdt,
cdts[delta_table_index], 8 *
sizeof(int16_t));
157 memcpy(
s->fat_ydt,
fat_ydts[delta_table_index], 8 *
sizeof(int16_t));
158 memcpy(
s->fat_cdt,
fat_cdts[delta_table_index], 8 *
sizeof(int16_t));
162 for (
i = 0;
i < 8;
i++)
180 lo += (lo * 32) + (lo * 1024);
182 hi += (hi * 32) + (hi * 1024);
183 return (lo + (hi * (1U << 16))) * 2;
193 return (lo + (lo * (1U << 16))) * 2;
205 lo += (lo << 6) + (lo << 11);
207 hi += (hi << 6) + (hi << 11);
208 return (lo + (hi << 16)) << 1;
218 return (lo + (lo * (1 << 16))) * 2;
227 return (lo + (hi * (1 << 8)) + (hi * (1 << 16))) * 2;
235 r = cdt[p1] * (1 << 16);
242 unsigned char delta_pair;
244 for (
i = 0;
i < 1024;
i += 4)
246 len = *sel_vector_table++ / 2;
247 for (j = 0; j <
len; j++)
249 delta_pair = *sel_vector_table++;
250 s->y_predictor_table[
i+j] = 0xfffffffe &
252 s->c_predictor_table[
i+j] = 0xfffffffe &
255 s->y_predictor_table[
i+(j-1)] |= 1;
256 s->c_predictor_table[
i+(j-1)] |= 1;
263 unsigned char delta_pair;
265 for (
i = 0;
i < 1024;
i += 4)
267 len = *sel_vector_table++ / 2;
268 for (j = 0; j <
len; j++)
270 delta_pair = *sel_vector_table++;
271 s->y_predictor_table[
i+j] = 0xfffffffe &
273 s->c_predictor_table[
i+j] = 0xfffffffe &
276 s->y_predictor_table[
i+(j-1)] |= 1;
277 s->c_predictor_table[
i+(j-1)] |= 1;
284 unsigned char delta_pair;
286 for (
i = 0;
i < 1024;
i += 4)
288 len = *sel_vector_table++ / 2;
289 for (j = 0; j <
len; j++)
291 delta_pair = *sel_vector_table++;
292 s->y_predictor_table[
i+j] = 0xfffffffe &
294 s->c_predictor_table[
i+j] = 0xfffffffe &
296 s->fat_y_predictor_table[
i+j] = 0xfffffffe &
298 s->fat_c_predictor_table[
i+j] = 0xfffffffe &
301 s->y_predictor_table[
i+(j-1)] |= 1;
302 s->c_predictor_table[
i+(j-1)] |= 1;
303 s->fat_y_predictor_table[
i+(j-1)] |= 1;
304 s->fat_c_predictor_table[
i+(j-1)] |= 1;
316 uint8_t header_buffer[128] = { 0 };
317 const uint8_t *sel_vector_table;
319 header.header_size = ((
s->buf[0] >> 5) | (
s->buf[0] << 3)) & 0x7f;
320 if (
s->buf[0] < 0x10)
326 if (
header.header_size + 1 >
s->size) {
333 header_buffer[
i - 1] =
s->buf[
i] ^
s->buf[
i + 1];
335 header.compression = header_buffer[0];
336 header.deltaset = header_buffer[1];
337 header.vectable = header_buffer[2];
341 header.version = header_buffer[9];
342 header.header_type = header_buffer[10];
343 header.flags = header_buffer[11];
344 header.control = header_buffer[12];
349 if (
header.header_type > 3)
353 }
else if ((
header.header_type == 2) || (
header.header_type == 3)) {
369 if (
header.header_type < 2) {
370 if ((
s->w < 213) && (
s->h >= 176))
378 if (
header.compression >= 17) {
383 if ((
header.deltaset !=
s->last_deltaset) ||
384 (
header.vectable !=
s->last_vectable))
404 s->w >>= width_shift;
415 if (
s->w !=
s->avctx->width ||
s->h !=
s->avctx->height ||
416 new_pix_fmt !=
s->avctx->pix_fmt) {
418 s->avctx->sample_aspect_ratio = (
AVRational){ 1 << width_shift, 1 };
419 s->avctx->pix_fmt = new_pix_fmt;
426 av_fast_malloc(&
s->vert_pred, &
s->vert_pred_size,
s->avctx->width *
sizeof(
unsigned int));
434 s->mb_change_bits_row_size = ((
s->avctx->width >> (2 - width_shift)) + 7) >> 3;
436 if ((
header.deltaset !=
s->last_deltaset) || (
header.vectable !=
s->last_vectable))
448 s->mb_change_bits =
s->buf +
header.header_size;
451 s->index_stream =
s->mb_change_bits;
452 if (
s->avctx->width *
s->avctx->height / 2048 +
header.header_size >
s->size)
456 s->index_stream =
s->mb_change_bits +
457 (
s->mb_change_bits_row_size * (
s->avctx->height >> 2));
459 s->index_stream_size =
s->size - (
s->index_stream -
s->buf);
461 s->last_deltaset =
header.deltaset;
462 s->last_vectable =
header.vectable;
463 s->compression =
header.compression;
470 s->last_deltaset,
s->last_vectable,
s->compression,
s->block_width,
471 s->block_height,
s->block_type,
477 return header.header_size;
498 av_fast_malloc(&
s->vert_pred, &
s->vert_pred_size,
s->avctx->width *
sizeof(
unsigned int));
531 #define GET_NEXT_INDEX() \
533 if (index_stream_index >= s->index_stream_size) { \
534 av_log(s->avctx, AV_LOG_INFO, " help! truemotion1 decoder went out of bounds\n"); \
537 index = s->index_stream[index_stream_index++] * 4; \
542 if (index >= 1023) { \
543 av_log(s->avctx, AV_LOG_ERROR, "Invalid index value.\n"); \
549 #define APPLY_C_PREDICTOR() \
550 predictor_pair = s->c_predictor_table[index]; \
551 horiz_pred += (predictor_pair >> 1); \
552 if (predictor_pair & 1) { \
556 predictor_pair = s->c_predictor_table[index]; \
557 horiz_pred += ((predictor_pair >> 1) * 5); \
558 if (predictor_pair & 1) \
566 #define APPLY_C_PREDICTOR_24() \
567 predictor_pair = s->c_predictor_table[index]; \
568 horiz_pred += (predictor_pair >> 1); \
569 if (predictor_pair & 1) { \
573 predictor_pair = s->fat_c_predictor_table[index]; \
574 horiz_pred += (predictor_pair >> 1); \
575 if (predictor_pair & 1) \
584 #define APPLY_Y_PREDICTOR() \
585 predictor_pair = s->y_predictor_table[index]; \
586 horiz_pred += (predictor_pair >> 1); \
587 if (predictor_pair & 1) { \
591 predictor_pair = s->y_predictor_table[index]; \
592 horiz_pred += ((predictor_pair >> 1) * 5); \
593 if (predictor_pair & 1) \
601 #define APPLY_Y_PREDICTOR_24() \
602 predictor_pair = s->y_predictor_table[index]; \
603 horiz_pred += (predictor_pair >> 1); \
604 if (predictor_pair & 1) { \
608 predictor_pair = s->fat_y_predictor_table[index]; \
609 horiz_pred += (predictor_pair >> 1); \
610 if (predictor_pair & 1) \
618 #define OUTPUT_PIXEL_PAIR() \
619 *current_pixel_pair = *vert_pred + horiz_pred; \
620 *vert_pred++ = *current_pixel_pair++;
626 unsigned int predictor_pair;
627 unsigned int horiz_pred;
628 unsigned int *vert_pred;
629 unsigned int *current_pixel_pair;
630 unsigned char *current_line =
s->frame->data[0];
634 const unsigned char *mb_change_bits =
s->mb_change_bits;
635 unsigned char mb_change_byte;
636 unsigned char mb_change_byte_mask;
640 int index_stream_index = 0;
644 memset(
s->vert_pred, 0,
s->avctx->width *
sizeof(
unsigned int));
648 for (y = 0; y <
s->avctx->height; y++) {
652 current_pixel_pair = (
unsigned int *)current_line;
653 vert_pred =
s->vert_pred;
656 mb_change_byte = mb_change_bits[mb_change_index++];
657 mb_change_byte_mask = 0x01;
658 pixels_left =
s->avctx->width;
660 while (pixels_left > 0) {
662 if (keyframe || ((mb_change_byte & mb_change_byte_mask) == 0)) {
668 if (
s->block_width == 2) {
722 *vert_pred++ = *current_pixel_pair++;
723 horiz_pred = *current_pixel_pair - *vert_pred;
724 *vert_pred++ = *current_pixel_pair++;
729 mb_change_byte_mask <<= 1;
732 if (!mb_change_byte_mask) {
733 mb_change_byte = mb_change_bits[mb_change_index++];
734 mb_change_byte_mask = 0x01;
742 if (((y + 1) & 3) == 0)
743 mb_change_bits +=
s->mb_change_bits_row_size;
745 current_line +=
s->frame->linesize[0];
753 unsigned int predictor_pair;
754 unsigned int horiz_pred;
755 unsigned int *vert_pred;
756 unsigned int *current_pixel_pair;
757 unsigned char *current_line =
s->frame->data[0];
761 const unsigned char *mb_change_bits =
s->mb_change_bits;
762 unsigned char mb_change_byte;
763 unsigned char mb_change_byte_mask;
767 int index_stream_index = 0;
771 memset(
s->vert_pred, 0,
s->avctx->width *
sizeof(
unsigned int));
775 for (y = 0; y <
s->avctx->height; y++) {
779 current_pixel_pair = (
unsigned int *)current_line;
780 vert_pred =
s->vert_pred;
782 mb_change_byte = mb_change_bits[mb_change_index++];
783 mb_change_byte_mask = 0x01;
784 pixels_left =
s->avctx->width;
786 while (pixels_left > 0) {
788 if (keyframe || ((mb_change_byte & mb_change_byte_mask) == 0)) {
794 if (
s->block_width == 2) {
848 *vert_pred++ = *current_pixel_pair++;
849 horiz_pred = *current_pixel_pair - *vert_pred;
850 *vert_pred++ = *current_pixel_pair++;
855 mb_change_byte_mask <<= 1;
858 if (!mb_change_byte_mask) {
859 mb_change_byte = mb_change_bits[mb_change_index++];
860 mb_change_byte_mask = 0x01;
868 if (((y + 1) & 3) == 0)
869 mb_change_bits +=
s->mb_change_bits_row_size;
871 current_line +=
s->frame->linesize[0];
877 void *
data,
int *got_frame,
881 int ret, buf_size = avpkt->
size;
919 .
name =
"truemotion1",
Libavcodec external API header.
#define FF_DEBUG_PICT_INFO
static av_cold int init(AVCodecContext *avctx)
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 void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
@ AV_CODEC_ID_TRUEMOTION1
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
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.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Memory handling functions.
#define AV_PIX_FMT_0RGB32
#define AV_PIX_FMT_RGB555
static const uint8_t header[24]
main external API structure.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
Rational number (pair of numerator and denominator).
uint32_t c_predictor_table[1024]
const uint8_t * mb_change_bits
uint32_t y_predictor_table[1024]
const uint8_t * index_stream
int mb_change_bits_row_size
uint32_t fat_y_predictor_table[1024]
uint32_t fat_c_predictor_table[1024]
#define avpriv_request_sample(...)
static int make_ydt15_entry(int p1, int p2, int16_t *ydt)
static void gen_vector_table24(TrueMotion1Context *s, const uint8_t *sel_vector_table)
static int make_cdt24_entry(int p1, int p2, int16_t *cdt)
#define APPLY_Y_PREDICTOR()
static int truemotion1_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static int make_ydt24_entry(int p1, int p2, int16_t *ydt)
static void gen_vector_table15(TrueMotion1Context *s, const uint8_t *sel_vector_table)
#define FLAG_INTERPOLATED
static void truemotion1_decode_16bit(TrueMotion1Context *s)
static int make_cdt16_entry(int p1, int p2, int16_t *cdt)
static int make_cdt15_entry(int p1, int p2, int16_t *cdt)
static void truemotion1_decode_24bit(TrueMotion1Context *s)
static void gen_vector_table16(TrueMotion1Context *s, const uint8_t *sel_vector_table)
static av_cold int truemotion1_decode_end(AVCodecContext *avctx)
#define APPLY_C_PREDICTOR()
static int make_ydt16_entry(int p1, int p2, int16_t *ydt)
static int truemotion1_decode_header(TrueMotion1Context *s)
static const comp_types compression_types[17]
#define APPLY_Y_PREDICTOR_24()
#define APPLY_C_PREDICTOR_24()
static void select_delta_tables(TrueMotion1Context *s, int delta_table_index)
AVCodec ff_truemotion1_decoder
#define OUTPUT_PIXEL_PAIR()
static av_cold int truemotion1_decode_init(AVCodecContext *avctx)
static const uint8_t *const tables[]
static const int16_t *const cdts[]
static const int16_t *const ydts[]
static const uint8_t pc_tbl2[]
static const int16_t *const fat_cdts[]
static const int16_t *const fat_ydts[]