38 #include "libavutil/imgutils.h"
40 #include "libavutil/intreadwrite.h"
41 #include "libavutil/mem.h"
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));
162 for (i = 0; i < 8; i++)
180 lo += (lo << 5) + (lo << 10);
182 hi += (hi << 5) + (hi << 10);
183 return (lo + (hi << 16)) << 1;
193 return (lo + (lo << 16)) << 1;
205 lo += (lo << 6) + (lo << 11);
207 hi += (hi << 6) + (hi << 11);
208 return (lo + (hi << 16)) << 1;
218 return (lo + (lo << 16)) << 1;
227 return (lo + (hi << 8) + (hi << 16)) << 1;
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++;
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++;
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++;
316 uint8_t header_buffer[128] = { 0 };
317 const uint8_t *sel_vector_table;
328 header_buffer[i - 1] = s->
buf[i] ^ s->
buf[i + 1];
336 header.
version = header_buffer[9];
338 header.
flags = header_buffer[11];
339 header.
control = header_buffer[12];
365 if ((s->
w < 213) && (s->
h >= 176))
399 s->
w >>= width_shift;
510 #define GET_NEXT_INDEX() \
512 if (index_stream_index >= s->index_stream_size) { \
513 av_log(s->avctx, AV_LOG_INFO, " help! truemotion1 decoder went out of bounds\n"); \
516 index = s->index_stream[index_stream_index++] * 4; \
519 #define APPLY_C_PREDICTOR() \
521 av_log(s->avctx, AV_LOG_ERROR, " index %d went out of bounds\n", index); \
524 predictor_pair = s->c_predictor_table[index]; \
525 horiz_pred += (predictor_pair >> 1); \
526 if (predictor_pair & 1) { \
530 predictor_pair = s->c_predictor_table[index]; \
531 horiz_pred += ((predictor_pair >> 1) * 5); \
532 if (predictor_pair & 1) \
540 #define APPLY_C_PREDICTOR_24() \
542 av_log(s->avctx, AV_LOG_ERROR, " index %d went out of bounds\n", index); \
545 predictor_pair = s->c_predictor_table[index]; \
546 horiz_pred += (predictor_pair >> 1); \
547 if (predictor_pair & 1) { \
551 predictor_pair = s->fat_c_predictor_table[index]; \
552 horiz_pred += (predictor_pair >> 1); \
553 if (predictor_pair & 1) \
562 #define APPLY_Y_PREDICTOR() \
564 av_log(s->avctx, AV_LOG_ERROR, " index %d went out of bounds\n", index); \
567 predictor_pair = s->y_predictor_table[index]; \
568 horiz_pred += (predictor_pair >> 1); \
569 if (predictor_pair & 1) { \
573 predictor_pair = s->y_predictor_table[index]; \
574 horiz_pred += ((predictor_pair >> 1) * 5); \
575 if (predictor_pair & 1) \
583 #define APPLY_Y_PREDICTOR_24() \
585 av_log(s->avctx, AV_LOG_ERROR, " index %d went out of bounds\n", index); \
588 predictor_pair = s->y_predictor_table[index]; \
589 horiz_pred += (predictor_pair >> 1); \
590 if (predictor_pair & 1) { \
594 predictor_pair = s->fat_y_predictor_table[index]; \
595 horiz_pred += (predictor_pair >> 1); \
596 if (predictor_pair & 1) \
604 #define OUTPUT_PIXEL_PAIR() \
605 *current_pixel_pair = *vert_pred + horiz_pred; \
606 *vert_pred++ = *current_pixel_pair++;
612 unsigned int predictor_pair;
613 unsigned int horiz_pred;
614 unsigned int *vert_pred;
615 unsigned int *current_pixel_pair;
616 unsigned char *current_line = s->
frame.
data[0];
621 unsigned char mb_change_byte;
622 unsigned char mb_change_byte_mask;
626 int index_stream_index = 0;
638 current_pixel_pair = (
unsigned int *)current_line;
641 mb_change_byte = mb_change_bits[mb_change_index++];
642 mb_change_byte_mask = 0x01;
645 while (pixels_left > 0) {
647 if (keyframe || ((mb_change_byte & mb_change_byte_mask) == 0)) {
707 *vert_pred++ = *current_pixel_pair++;
708 horiz_pred = *current_pixel_pair - *vert_pred;
709 *vert_pred++ = *current_pixel_pair++;
714 mb_change_byte_mask <<= 1;
717 if (!mb_change_byte_mask) {
718 mb_change_byte = mb_change_bits[mb_change_index++];
719 mb_change_byte_mask = 0x01;
727 if (((y + 1) & 3) == 0)
738 unsigned int predictor_pair;
739 unsigned int horiz_pred;
740 unsigned int *vert_pred;
741 unsigned int *current_pixel_pair;
742 unsigned char *current_line = s->
frame.
data[0];
747 unsigned char mb_change_byte;
748 unsigned char mb_change_byte_mask;
752 int index_stream_index = 0;
764 current_pixel_pair = (
unsigned int *)current_line;
767 mb_change_byte = mb_change_bits[mb_change_index++];
768 mb_change_byte_mask = 0x01;
771 while (pixels_left > 0) {
773 if (keyframe || ((mb_change_byte & mb_change_byte_mask) == 0)) {
833 *vert_pred++ = *current_pixel_pair++;
834 horiz_pred = *current_pixel_pair - *vert_pred;
835 *vert_pred++ = *current_pixel_pair++;
840 mb_change_byte_mask <<= 1;
843 if (!mb_change_byte_mask) {
844 mb_change_byte = mb_change_bits[mb_change_index++];
845 mb_change_byte_mask = 0x01;
853 if (((y + 1) & 3) == 0)
862 void *
data,
int *got_frame,
866 int ret, buf_size = avpkt->
size;
904 .
name =
"truemotion1",
#define AVERROR_PATCHWELCOME
This structure describes decoded (raw) audio or video data.
static const int16_t *const fat_ydts[]
static av_cold int init(AVCodecContext *avctx)
#define OUTPUT_PIXEL_PAIR()
static void truemotion1_decode_16bit(TrueMotion1Context *s)
void avcodec_set_dimensions(AVCodecContext *s, int width, int height)
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static void gen_vector_table24(TrueMotion1Context *s, const uint8_t *sel_vector_table)
AVCodec ff_truemotion1_decoder
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
static int truemotion1_decode_header(TrueMotion1Context *s)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
const uint8_t * index_stream
#define AV_PIX_FMT_RGB555
const char * name
Name of the codec implementation.
int av_frame_ref(AVFrame *dst, AVFrame *src)
Setup a new reference to the data described by a given frame.
int mb_change_bits_row_size
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static av_cold int truemotion1_decode_end(AVCodecContext *avctx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static void truemotion1_decode_24bit(TrueMotion1Context *s)
Libavcodec external API header.
static const uint8_t *const tables[]
static const uint8_t pc_tbl2[]
uint32_t c_predictor_table[1024]
common internal API header
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
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...
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int width
picture width / height.
static int make_ydt15_entry(int p1, int p2, int16_t *ydt)
static int make_cdt24_entry(int p1, int p2, int16_t *cdt)
static const comp_types compression_types[17]
#define APPLY_C_PREDICTOR_24()
static int make_ydt24_entry(int p1, int p2, int16_t *ydt)
#define AV_LOG_INFO
Standard information.
static const int16_t *const cdts[]
static void gen_vector_table16(TrueMotion1Context *s, const uint8_t *sel_vector_table)
static const int16_t *const ydts[]
main external API structure.
uint32_t fat_c_predictor_table[1024]
static void close(AVCodecParserContext *s)
static int make_cdt15_entry(int p1, int p2, int16_t *cdt)
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
rational number numerator/denominator
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static av_cold int truemotion1_decode_init(AVCodecContext *avctx)
static int truemotion1_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
#define FF_DEBUG_PICT_INFO
#define APPLY_Y_PREDICTOR()
#define APPLY_C_PREDICTOR()
common internal api header.
static int make_ydt16_entry(int p1, int p2, int16_t *ydt)
static void gen_vector_table15(TrueMotion1Context *s, const uint8_t *sel_vector_table)
static int make_cdt16_entry(int p1, int p2, int16_t *cdt)
uint32_t fat_y_predictor_table[1024]
#define AVERROR_INVALIDDATA
uint32_t y_predictor_table[1024]
static const int16_t *const fat_cdts[]
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static void select_delta_tables(TrueMotion1Context *s, int delta_table_index)
#define APPLY_Y_PREDICTOR_24()
const uint8_t * mb_change_bits
#define FLAG_INTERPOLATED
This structure stores compressed data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.