60#define CHECKPOINT(x) \
63 if (bytestream2_get_bytes_left(gbc) < 4) \
64 return AVERROR_INVALIDDATA; \
65 value = bytestream2_get_le32(gbc); \
76 idx = (bytestream2_get_byte(gbc) + 2) * x; \
78 av_log(avctx, AV_LOG_ERROR, "idx %d > %d\n", idx, pos); \
79 return AVERROR_INVALIDDATA; \
83 idx = (bytestream2_get_le16(gbc) + 0x102) * x; \
85 av_log(avctx, AV_LOG_ERROR, "idx %d > %d\n", idx, pos); \
86 return AVERROR_INVALIDDATA; \
97 int idx = 0,
state = 0;
101 AV_WL32(
ctx->tex_data, bytestream2_get_le32(gbc));
102 AV_WL32(
ctx->tex_data + 4, bytestream2_get_le32(gbc));
105 while (
pos + 2 <=
ctx->tex_size / 4) {
123 prev = bytestream2_get_le32(gbc);
132 prev = bytestream2_get_le32(gbc);
150 int value, counter = 0, rshift = 10, lshift = 30;
152 mask = bytestream2_get_le32(gb) >> 2;
165 input = bytestream2_get_le16(gb);
166 mask += input << lshift;
176 for (; !
table[counter - 1]; counter--)
180 *nb_elements = counter;
183 memset(&
table[counter], 0, 4 * (256 - counter));
193 unsigned table2[256] = { 0 };
195 int val0, val1,
i, j = 2, k = 0;
197 table2[0] = table0[0];
198 for (
i = 0;
i < nb_elements - 1;
i++, table2[
i] = val0) {
199 val0 = table0[
i + 1] + table2[
i];
205 }
while (!table2[k]);
209 for (
i = 1024;
i > 0;
i--) {
210 for (table1[x].val1 = k; k < 256 && j > table2[k]; k++);
211 x = (x - 383) & 0x3FF;
216 memcpy(&table2[0], table0, 4 * nb_elements);
218 for (
i = 0;
i < 1024;
i++) {
219 val0 = table1[
i].
val1;
225 table1[
i].
val2 = 10 - x;
226 table1[
i].
next = (val1 << table1[
i].
val2) - 1024;
235 int sum, x,
val, lshift, rshift, ret,
i, idx;
237 unsigned endoffset, newoffset,
offset;
245 size_in_bits = bytestream2_get_le32(gb);
246 endoffset = ((size_in_bits + 7) >> 3) - 4;
252 rshift = (((size_in_bits & 0xFF) - 1) & 7) + 15;
253 lshift = 32 - rshift;
254 idx = (next >> rshift) & 0x3FF;
255 for (
i = 0;
i < op_size;
i++) {
259 x = (next << lshift) >> 1 >> (31 -
val);
260 newoffset =
offset - (sum >> 3);
262 idx = x + optable[idx].
next;
277 int flag = bytestream2_peek_byte(gb);
279 if ((
flag & 3) == 0) {
282 if (read_size != op_size)
284 }
else if ((
flag & 3) == 1) {
286 memset(dstp, bytestream2_get_byte(gb), op_size);
302 uint8_t *tex_data,
int tex_size,
303 uint8_t *op_data,
int *oindex,
305 uint8_t **dstp,
int *statep,
306 uint8_t **tab0, uint8_t **
tab1,
309 uint8_t *
dst = *dstp;
310 uint8_t *tptr0, *tptr1, *tptr3;
318 opcode = op_data[oi++];
320 v = bytestream2_get_byte(gb);
325 opcode = bytestream2_get_le16(gb);
327 }
while (opcode == 0xFFFF);
341 vv = (8 +
offset) * (bytestream2_get_le16(gb) + 1);
342 if (vv < 0 || vv >
dst - tex_data)
348 tab0[0x9E3779B1 * (uint16_t)v >> 24] =
dst;
358 tptr3 =
tab1[bytestream2_get_byte(gb)];
365 dst[7] = bytestream2_get_byte(gb);
369 tptr3 =
tab1[bytestream2_get_byte(gb)];
374 dst[4] = bytestream2_get_byte(gb);
381 tptr0 =
tab1[bytestream2_get_byte(gb)];
384 tptr1 =
tab1[bytestream2_get_byte(gb)];
395 v = (8 +
offset) * (bytestream2_get_le16(gb) + 1);
396 if (v < 0 || v >
dst - tex_data)
406 tptr1 = tab0[bytestream2_get_byte(gb)];
415 tptr1 = tab0[bytestream2_get_byte(gb)];
418 tptr3 =
tab1[bytestream2_get_byte(gb)];
425 dst[7] = bytestream2_get_byte(gb);
429 tptr1 = tab0[bytestream2_get_byte(gb)];
432 tptr3 =
tab1[bytestream2_get_byte(gb)];
437 dst[4] = bytestream2_get_byte(gb);
443 tptr0 = tab0[bytestream2_get_byte(gb)];
446 tptr3 =
tab1[bytestream2_get_byte(gb)];
449 tptr1 =
tab1[bytestream2_get_byte(gb)];
459 tptr1 = tab0[bytestream2_get_byte(gb)];
462 v = (8 +
offset) * (bytestream2_get_le16(gb) + 1);
463 if (v < 0 || v >
dst - tex_data)
478 tptr3 =
tab1[bytestream2_get_byte(gb)];
485 dst[7] = bytestream2_get_byte(gb);
489 tptr3 =
tab1[bytestream2_get_byte(gb)];
494 dst[4] = bytestream2_get_byte(gb);
500 tptr3 =
tab1[bytestream2_get_byte(gb)];
503 tptr1 =
tab1[bytestream2_get_byte(gb)];
513 v = (8 +
offset) * (bytestream2_get_le16(gb) + 1);
514 if (v < 0 || v >
dst - tex_data)
530 if (
dst - tex_data + 8 > tex_size)
542 uint8_t *tex_data,
int tex_size,
543 uint8_t *op_data0, uint8_t *op_data1,
544 int max_op_size0,
int max_op_size1)
546 uint8_t *
dst, *
tab2[256] = { 0 }, *tab0[256] = { 0 }, *tab3[256] = { 0 }, *
tab1[256] = { 0 };
547 int op_offset = bytestream2_get_le32(gb);
548 unsigned op_size0 = bytestream2_get_le32(gb);
549 unsigned op_size1 = bytestream2_get_le32(gb);
551 int skip0, skip1, oi0 = 0, oi1 = 0;
552 int ret, state0 = 0, state1 = 0;
559 if (op_size0 > max_op_size0)
564 if (op_size1 > max_op_size1)
579 tab3[0x9E3779B1 * (
AV_RL32(
dst + 10) & 0xFFFFFF) >> 24] =
dst + 10;
581 while (
dst + 10 < tex_data + tex_size) {
592 bytestream2_seek(gb, data_start - 12 + op_offset + skip0 + skip1, SEEK_SET);
598 uint8_t *tex_data,
int tex_size,
599 uint8_t *op_data,
int max_op_size)
601 int op_offset = bytestream2_get_le32(gb);
602 unsigned op_size = bytestream2_get_le32(gb);
604 uint8_t *
dst, *table0[256] = { 0 }, *table1[256] = { 0 };
612 if (op_size > max_op_size)
619 v = bytestream2_get_le32(gb);
621 vv = bytestream2_get_le32(gb);
622 table0[0x9E3779B1 * (uint16_t)v >> 24] =
dst;
624 table1[0x9E3779B1 * (
AV_RL32(
dst + 2) & 0xFFFFFF) >> 24] =
dst + 2;
627 while (
dst < tex_data + tex_size) {
646 ctx->op_data[0],
ctx->op_size[0]);
651 ctx->op_data[1],
ctx->op_data[2],
652 ctx->op_size[1],
ctx->op_size[2]);
662 ctx->op_data[0],
ctx->op_data[3],
663 ctx->op_size[0],
ctx->op_size[3]);
668 ctx->op_data[1],
ctx->op_data[2],
669 ctx->op_size[1],
ctx->op_size[2]);
683 AV_WL32(
ctx->tex_data + 0, bytestream2_get_le32(gbc));
684 AV_WL32(
ctx->tex_data + 4, bytestream2_get_le32(gbc));
685 AV_WL32(
ctx->tex_data + 8, bytestream2_get_le32(gbc));
686 AV_WL32(
ctx->tex_data + 12, bytestream2_get_le32(gbc));
689 while (
pos + 2 <=
ctx->tex_size / 4) {
703 value = bytestream2_get_le32(gbc);
713 check = bytestream2_get_byte(gbc) + 1;
716 probe = bytestream2_get_le16(gbc);
718 }
while (
probe == 0xFFFF);
745 run = bytestream2_get_byte(gbc);
748 probe = bytestream2_get_le16(gbc);
750 }
while (
probe == 0xFFFF);
764 idx = 8 + 4 * bytestream2_get_le16(gbc);
765 if (idx >
pos || (
unsigned int)(
pos - idx) + 2 >
ctx->tex_size / 4)
777 prev = bytestream2_get_le32(gbc);
781 prev = bytestream2_get_le32(gbc);
789 if (
pos + 2 >
ctx->tex_size / 4)
794 if (idx >
pos || (
unsigned int)(
pos - idx) + 2 >
ctx->tex_size / 4)
806 if (
op && (idx >
pos || (
unsigned int)(
pos - idx) + 2 >
ctx->tex_size / 4))
811 prev = bytestream2_get_le32(gbc);
820 prev = bytestream2_get_le32(gbc);
832 unsigned old_size =
ctx->tex_data_size;
834 old_size =
FFMAX(old_size,
ctx->tex_size);
835 if (
ctx->tex_data_size > old_size)
836 memset(
ctx->tex_data + old_size, 0,
ctx->tex_data_size - old_size);
859 const char *msgcomp, *msgtext;
861 int version_major, version_minor = 0;
862 int size = 0, old_type = 0;
870 tag = bytestream2_get_le32(gbc);
910 msgcomp =
"YAOCOCG10";
918 old_type =
tag >> 24;
919 version_major = (old_type & 0x0F) - 1;
921 if (old_type & 0x80) {
929 if (old_type & 0x40) {
936 }
else if (old_type & 0x20 || version_major == 1) {
959 version_major = bytestream2_get_byte(gbc) - 1;
960 version_minor = bytestream2_get_byte(gbc);
963 if (bytestream2_get_byte(gbc)) {
969 size = bytestream2_get_le32(gbc);
972 "%s compression with %s texture (version %d.%d)\n",
973 msgcomp, msgtext, version_major, version_minor);
977 "Incomplete or invalid file (header %d, left %u).\n",
985 unsigned old_size =
ctx->tex_data_size;
991 if (
ctx->tex_data_size > old_size)
992 memset(
ctx->tex_data + old_size, 0,
ctx->tex_data_size - old_size);
1006 old_size =
ctx->ctex_data_size;
1010 ctx->ctex_data = ptr;
1011 if (old_size < ctx->ctex_data_size)
1012 memset(
ctx->ctex_data + old_size, 0,
ctx->ctex_data_size - old_size);
1014 for (
i = 0;
i < 4;
i++) {
1015 old_size =
ctx->op_data_size[
i];
1019 ctx->op_data[
i] = ptr;
1024 ret = decompress_tex(avctx);
1106 ctx->tex_data_size = 0;
1109 ctx->ctex_data_size = 0;
1115 memset(
ctx->op_data_size, 0,
sizeof(
ctx->op_data_size));
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static int probe(const AVProbeData *p)
static double val(void *priv, double ch)
const FFCodec ff_dxv_decoder
static AVFormatContext * ctx
Libavcodec external API header.
static void BS_FUNC skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
static av_always_inline int bytestream2_tell(const GetByteContext *g)
#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...
static int dxv_decompress_yg10(AVCodecContext *avctx)
static int dxv_decompress_cgo(DXVContext *ctx, GetByteContext *gb, uint8_t *tex_data, int tex_size, uint8_t *op_data, int *oindex, int op_size, uint8_t **dstp, int *statep, uint8_t **tab0, uint8_t **tab1, int offset)
static int dxv_decompress_dxt1(AVCodecContext *avctx)
static int dxv_decompress_cocg(DXVContext *ctx, GetByteContext *gb, uint8_t *tex_data, int tex_size, uint8_t *op_data0, uint8_t *op_data1, int max_op_size0, int max_op_size1)
static av_cold int dxv_init(AVCodecContext *avctx)
static int fill_optable(unsigned *table0, OpcodeTable *table1, int nb_elements)
static int dxv_decompress_dxt5(AVCodecContext *avctx)
static int get_opcodes(GetByteContext *gb, uint32_t *table, uint8_t *dst, int op_size, int nb_elements)
static int dxv_decompress_raw(AVCodecContext *avctx)
static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
static int dxv_decompress_yo(DXVContext *ctx, GetByteContext *gb, uint8_t *tex_data, int tex_size, uint8_t *op_data, int max_op_size)
static int dxv_decompress_ycg6(AVCodecContext *avctx)
static int fill_ltable(GetByteContext *gb, uint32_t *table, int *nb_elements)
static av_cold int dxv_close(AVCodecContext *avctx)
static int dxv_decompress_opcodes(GetByteContext *gb, void *dstp, size_t op_size)
static int dxv_decompress_lzf(AVCodecContext *avctx)
static struct @346255127015250356166251341105367306144006377143 state
static const uint8_t bits[8]
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
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...
static int op(uint8_t **dst, const uint8_t *dst_end, GetByteContext *gb, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
Multithreading API for decoders.
Macro definitions for various function/variable attributes.
int ff_lzf_uncompress(GetByteContext *gb, uint8_t **buf, size_t *size, unsigned *allocated_size)
Decompress LZF data into *buf, reallocating it as needed.
static const uint16_t mask[17]
Memory handling functions.
static uint8_t half(int a, int b)
#define check(x, y, S, v)
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
static const uint16_t table[]
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
static const ElemCat * elements[ELEMENT_COUNT]
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
enum AVColorSpace colorspace
YUV colorspace type.
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
int coded_width
Bitstream width / height, may be different from width/height e.g.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
union TextureDSPThreadContext::@274301011315177304000236374320052224260127200145 frame_data
int(* tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
union TextureDSPThreadContext::@343301224315114336214156165306265310104165221120 tex_data
av_cold void ff_texturedsp_init(TextureDSPContext *c)
Texture block (4x4) module.
int ff_texturedsp_exec_decompress_threads(struct AVCodecContext *avctx, TextureDSPThreadContext *ctx)