84#define FLAG_KEYFRAME 16
85#define FLAG_INTERFRAME 8
86#define FLAG_INTERPOLATED 4
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 * (1U << 16))) * 2;
194 return (lo + (lo * (1U << 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;
416 if (
s->w !=
s->avctx->width ||
s->h !=
s->avctx->height ||
417 new_pix_fmt !=
s->avctx->pix_fmt) {
419 s->avctx->sample_aspect_ratio = (
AVRational){ 1 << width_shift, 1 };
420 s->avctx->pix_fmt = new_pix_fmt;
427 av_fast_malloc(&
s->vert_pred, &
s->vert_pred_size,
s->avctx->width *
sizeof(
unsigned int));
435 s->mb_change_bits_row_size = ((
s->avctx->width >> (2 - width_shift)) + 7) >> 3;
437 if ((
header.deltaset !=
s->last_deltaset) || (
header.vectable !=
s->last_vectable))
449 s->mb_change_bits =
s->buf +
header.header_size;
452 s->index_stream =
s->mb_change_bits;
453 if (
s->avctx->width *
s->avctx->height / 2048 +
header.header_size >
s->size)
457 s->index_stream =
s->mb_change_bits +
458 (
s->mb_change_bits_row_size * (
s->avctx->height >> 2));
460 s->index_stream_size =
s->size - (
s->index_stream -
s->buf);
462 s->last_deltaset =
header.deltaset;
463 s->last_vectable =
header.vectable;
464 s->compression =
header.compression;
471 s->last_deltaset,
s->last_vectable,
s->compression,
s->block_width,
472 s->block_height,
s->block_type,
478 return header.header_size;
499 av_fast_malloc(&
s->vert_pred, &
s->vert_pred_size,
s->avctx->width *
sizeof(
unsigned int));
532#define GET_NEXT_INDEX() \
534 if (index_stream_index >= s->index_stream_size) { \
535 av_log(s->avctx, AV_LOG_INFO, " help! truemotion1 decoder went out of bounds\n"); \
538 index = s->index_stream[index_stream_index++] * 4; \
543 if (index >= 1023) { \
544 av_log(s->avctx, AV_LOG_ERROR, "Invalid index value.\n"); \
550#define APPLY_C_PREDICTOR() \
551 predictor_pair = s->c_predictor_table[index]; \
552 horiz_pred += (predictor_pair >> 1); \
553 if (predictor_pair & 1) { \
557 predictor_pair = s->c_predictor_table[index]; \
558 horiz_pred += ((predictor_pair >> 1) * 5); \
559 if (predictor_pair & 1) \
567#define APPLY_C_PREDICTOR_24() \
568 predictor_pair = s->c_predictor_table[index]; \
569 horiz_pred += (predictor_pair >> 1); \
570 if (predictor_pair & 1) { \
574 predictor_pair = s->fat_c_predictor_table[index]; \
575 horiz_pred += (predictor_pair >> 1); \
576 if (predictor_pair & 1) \
585#define APPLY_Y_PREDICTOR() \
586 predictor_pair = s->y_predictor_table[index]; \
587 horiz_pred += (predictor_pair >> 1); \
588 if (predictor_pair & 1) { \
592 predictor_pair = s->y_predictor_table[index]; \
593 horiz_pred += ((predictor_pair >> 1) * 5); \
594 if (predictor_pair & 1) \
602#define APPLY_Y_PREDICTOR_24() \
603 predictor_pair = s->y_predictor_table[index]; \
604 horiz_pred += (predictor_pair >> 1); \
605 if (predictor_pair & 1) { \
609 predictor_pair = s->fat_y_predictor_table[index]; \
610 horiz_pred += (predictor_pair >> 1); \
611 if (predictor_pair & 1) \
619#define OUTPUT_PIXEL_PAIR() \
620 *current_pixel_pair = *vert_pred + horiz_pred; \
621 *vert_pred++ = *current_pixel_pair++;
627 unsigned int predictor_pair;
628 unsigned int horiz_pred;
629 unsigned int *vert_pred;
630 unsigned int *current_pixel_pair;
631 unsigned char *current_line =
s->frame->data[0];
635 const unsigned char *mb_change_bits =
s->mb_change_bits;
636 unsigned char mb_change_byte;
637 unsigned char mb_change_byte_mask;
641 int index_stream_index = 0;
645 memset(
s->vert_pred, 0,
s->avctx->width *
sizeof(
unsigned int));
649 for (y = 0; y <
s->avctx->height; y++) {
653 current_pixel_pair = (
unsigned int *)current_line;
654 vert_pred =
s->vert_pred;
657 mb_change_byte = mb_change_bits[mb_change_index++];
658 mb_change_byte_mask = 0x01;
659 pixels_left =
s->avctx->width;
661 while (pixels_left > 0) {
663 if (keyframe || ((mb_change_byte & mb_change_byte_mask) == 0)) {
669 if (
s->block_width == 2) {
723 *vert_pred++ = *current_pixel_pair++;
724 horiz_pred = *current_pixel_pair - *vert_pred;
725 *vert_pred++ = *current_pixel_pair++;
730 mb_change_byte_mask <<= 1;
733 if (!mb_change_byte_mask) {
734 mb_change_byte = mb_change_bits[mb_change_index++];
735 mb_change_byte_mask = 0x01;
743 if (((y + 1) & 3) == 0)
744 mb_change_bits +=
s->mb_change_bits_row_size;
746 current_line +=
s->frame->linesize[0];
754 unsigned int predictor_pair;
755 unsigned int horiz_pred;
756 unsigned int *vert_pred;
757 unsigned int *current_pixel_pair;
758 unsigned char *current_line =
s->frame->data[0];
762 const unsigned char *mb_change_bits =
s->mb_change_bits;
763 unsigned char mb_change_byte;
764 unsigned char mb_change_byte_mask;
768 int index_stream_index = 0;
772 memset(
s->vert_pred, 0,
s->avctx->width *
sizeof(
unsigned int));
776 for (y = 0; y <
s->avctx->height; y++) {
780 current_pixel_pair = (
unsigned int *)current_line;
781 vert_pred =
s->vert_pred;
783 mb_change_byte = mb_change_bits[mb_change_index++];
784 mb_change_byte_mask = 0x01;
785 pixels_left =
s->avctx->width;
787 while (pixels_left > 0) {
789 if (keyframe || ((mb_change_byte & mb_change_byte_mask) == 0)) {
795 if (
s->block_width == 2) {
849 *vert_pred++ = *current_pixel_pair++;
850 horiz_pred = *current_pixel_pair - *vert_pred;
851 *vert_pred++ = *current_pixel_pair++;
856 mb_change_byte_mask <<= 1;
859 if (!mb_change_byte_mask) {
860 mb_change_byte = mb_change_bits[mb_change_index++];
861 mb_change_byte_mask = 0x01;
869 if (((y + 1) & 3) == 0)
870 mb_change_bits +=
s->mb_change_bits_row_size;
872 current_line +=
s->frame->linesize[0];
880 const uint8_t *buf = avpkt->
data;
881 int ret, buf_size = avpkt->
size;
919 .p.name =
"truemotion1",
const FFCodec ff_truemotion1_decoder
static av_cold void close(AVCodecParserContext *s)
Libavcodec external API header.
#define FF_DEBUG_PICT_INFO
#define i(width, name, range_min, range_max)
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#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_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Identical in function to ff_get_buffer(), except it reuses the existing buffer if available.
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
int(* init)(AVBSFContext *ctx)
#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.
common internal API header
Memory handling functions.
#define AV_PIX_FMT_0RGB32
#define AV_PIX_FMT_RGB555
static const uint8_t header[24]
main external API structure.
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 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]
static int truemotion1_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, AVPacket *avpkt)
#define APPLY_Y_PREDICTOR_24()
#define APPLY_C_PREDICTOR_24()
static void select_delta_tables(TrueMotion1Context *s, int delta_table_index)
#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[]