33#define BITSTREAM_READER_LE
39#define EA_PREAMBLE_SIZE 8
40#define kVGT_TAG MKTAG('k', 'V', 'G', 'T')
73static int unpack(
const uint8_t *
src,
const uint8_t *src_end,
78 uint8_t *dst_start =
dst;
85 if (src_end -
src < 3)
90 while (
size > 0 &&
src < src_end) {
98 size1 = (((
src[0] & 31) + 1) << 2);
103 size2 = ((
src[0] & 0xC) << 6) +
src[3] + 5;
107 size1 = ((
src[1] & 0xC0) >> 6);
109 size2 = (
src[0] & 0x3F) + 4;
114 size2 = ((
src[0] & 0x1C) >> 2) + 3;
120 if (size1 > src_end -
src)
149 const uint8_t *buf,
const uint8_t *buf_end)
153 int num_blocks_packed;
158 const uint8_t *blocks_raw;
160 if(buf_end - buf < 12)
164 num_blocks_raw =
AV_RL16(&buf[2]);
165 num_blocks_packed =
AV_RL16(&buf[4]);
166 vector_bits =
AV_RL16(&buf[6]);
171 "Invalid value for motion vector bits: %d\n", vector_bits);
185 if (num_blocks_packed >
s->num_blocks_packed) {
187 if ((err =
av_reallocp(&
s->block_codebook, num_blocks_packed * 16)) < 0) {
188 s->num_blocks_packed = 0;
191 s->num_blocks_packed = num_blocks_packed;
195 mvbits = (
num_mvs * 2 * 10 + 31) & ~31;
197 if (buf_end - buf < (mvbits>>3) + 16*num_blocks_raw + 8*num_blocks_packed)
209 buf += num_blocks_raw * 16;
213 for (
i = 0;
i < num_blocks_packed;
i++) {
215 for (j = 0; j < 4; j++)
217 for (j = 0; j < 16; j++)
222 (
s->avctx->height / 4) * (
s->avctx->width / 4))
226 for (y = 0; y <
s->avctx->height / 4; y++)
227 for (x = 0; x <
s->avctx->width / 4; x++) {
228 unsigned int vector =
get_bits(&gb, vector_bits);
230 ptrdiff_t src_stride;
233 int mx = x * 4 +
s->mv_codebook[vector][0];
234 int my = y * 4 +
s->mv_codebook[vector][1];
242 src =
s->last_frame->data[0] +
mx +
my *
s->last_frame->linesize[0];
243 src_stride =
s->last_frame->linesize[0];
246 if (
offset < num_blocks_raw)
248 else if (
offset - num_blocks_raw < num_blocks_packed)
249 src =
s->block_codebook[
offset - num_blocks_raw];
255 for (j = 0; j < 4; j++)
256 for (
i = 0;
i < 4;
i++)
257 frame->data[0][(y * 4 + j) *
frame->linesize[0] + (x * 4 +
i)] =
258 src[j * src_stride +
i];
267 const uint8_t *buf = avpkt->
data;
268 int buf_size = avpkt->
size;
270 const uint8_t *buf_end = buf + buf_size;
281 if(buf_end - buf < 12) {
288 if (
s->avctx->width !=
s->width ||
s->avctx->height !=
s->height) {
298 s->palette[
i] = 0xFFU << 24 |
AV_RB24(buf);
301 if (buf_end - buf < 5) {
316 if (!
s->frame_buffer &&
320 if (
unpack(buf, buf_end,
s->frame_buffer,
s->avctx->width,
s->avctx->height) < 0) {
324 for (y = 0; y <
s->height; y++)
325 memcpy(
frame->data[0] + y *
frame->linesize[0],
326 s->frame_buffer + y *
s->width,
329 if (!
s->last_frame->data[0]) {
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t my
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t mx
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFCodec ff_eatgv_decoder
static av_cold void close(AVCodecParserContext *s)
Libavcodec external API header.
#define i(width, name, range_min, range_max)
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
int(* init)(AVBSFContext *ctx)
static av_cold int tgv_decode_init(AVCodecContext *avctx)
static int unpack(const uint8_t *src, const uint8_t *src_end, uint8_t *dst, int width, int height)
Unpack buffer.
static av_cold int tgv_decode_end(AVCodecContext *avctx)
static int tgv_decode_inter(TgvContext *s, AVFrame *frame, const uint8_t *buf, const uint8_t *buf_end)
Decode inter-frame.
static int tgv_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
bitstream reader API header.
static int get_sbits(GetBitContext *s, int n)
static int get_bits_left(GetBitContext *gb)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int av_frame_replace(AVFrame *dst, const AVFrame *src)
Ensure the destination frame refers to the same 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_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
Overlapping memcpy() implementation.
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate an array through a pointer to a pointer.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
Memory handling functions.
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
static const int num_mvs[RV34_MB_TYPES]
number of motion vectors in each macroblock type
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
Rational number (pair of numerator and denominator).
uint8_t(* block_codebook)[16]
int num_blocks_packed
current length of block_codebook
int num_mvs
current length of mv_codebook
uint32_t palette[AVPALETTE_COUNT]