62 uint8_t *plane1, ptrdiff_t stride1,
74 for (
i = 0;
i < 8;
i++)
75 dst[
i] = (
tmp >> (
i * 3)) & 0x7;
88 }
else if (
code == 0) {
90 }
else if (
code == 1) {
95 (
code - 1) * yo1) / 7);
99 }
else if (
code == 7) {
103 (
code - 1) * yo1) / 5);
112 uint8_t *plane1, ptrdiff_t stride1,
126 for (y = 0; y < 4; y++) {
127 for (x = 0; x < 4; x++) {
128 int co_code = co_indices[x + y * 4];
129 int cg_code = cg_indices[x + y * 4];
150 for (y = 0; y < 4; y++) {
151 for (x = 0; x < 4; x++) {
152 int yo_code = yo_indices[x + y * 4];
161 uint8_t *unused0, ptrdiff_t unused1,
175 uint8_t *plane3, ptrdiff_t stride1,
194 int slice,
int thread_nb)
202 int start_slice, end_slice;
204 start_slice = h_block * slice /
ctx->slice_count;
205 end_slice = h_block * (slice + 1) /
ctx->slice_count;
207 if (
ctx->tex_funct) {
208 for (y = start_slice; y < end_slice; y++) {
210 int off = y * w_block;
211 for (x = 0; x < w_block; x++) {
213 d + (off + x) *
ctx->tex_step);
219 for (y = start_slice; y < end_slice; y++) {
222 int off = y * w_block;
223 for (x = 0; x < w_block; x++) {
226 d + (off + x) *
ctx->tex_step);
232 start_slice = h_block * slice /
ctx->slice_count;
233 end_slice = h_block * (slice + 1) /
ctx->slice_count;
235 for (y = start_slice; y < end_slice; y++) {
238 int off = y * w_block;
239 for (x = 0; x < w_block; x++) {
242 c + (off + x) *
ctx->ctex_step);
256 #define CHECKPOINT(x) \
259 if (bytestream2_get_bytes_left(gbc) < 4) \
260 return AVERROR_INVALIDDATA; \
261 value = bytestream2_get_le32(gbc); \
272 idx = (bytestream2_get_byte(gbc) + 2) * x; \
274 av_log(avctx, AV_LOG_ERROR, "idx %d > %d\n", idx, pos); \
275 return AVERROR_INVALIDDATA; \
279 idx = (bytestream2_get_le16(gbc) + 0x102) * x; \
281 av_log(avctx, AV_LOG_ERROR, "idx %d > %d\n", idx, pos); \
282 return AVERROR_INVALIDDATA; \
293 int idx = 0,
state = 0;
297 AV_WL32(
ctx->tex_data, bytestream2_get_le32(gbc));
298 AV_WL32(
ctx->tex_data + 4, bytestream2_get_le32(gbc));
301 while (
pos + 2 <=
ctx->tex_size / 4) {
319 prev = bytestream2_get_le32(gbc);
328 prev = bytestream2_get_le32(gbc);
345 unsigned half = 512,
bits = 1023, left = 1024, input,
mask;
346 int value, counter = 0, rshift = 10, lshift = 30;
348 mask = bytestream2_get_le32(gb) >> 2;
361 input = bytestream2_get_le16(gb);
362 mask += input << lshift;
372 for (; !
table[counter - 1]; counter--)
376 *nb_elements = counter;
379 memset(&
table[counter], 0, 4 * (256 - counter));
389 unsigned table2[256] = { 0 };
391 int val0, val1,
i, j = 2, k = 0;
393 table2[0] = table0[0];
394 for (
i = 0;
i < nb_elements - 1;
i++, table2[
i] = val0) {
395 val0 = table0[
i + 1] + table2[
i];
401 }
while (!table2[k]);
405 for (
i = 1024;
i > 0;
i--) {
406 for (table1[x].val1 = k; k < 256 && j > table2[k]; k++);
407 x = (x - 383) & 0x3FF;
412 memcpy(&table2[0], table0, 4 * nb_elements);
414 for (
i = 0;
i < 1024;
i++) {
415 val0 = table1[
i].
val1;
421 table1[
i].
val2 = 10 - x;
422 table1[
i].
next = (val1 << table1[
i].
val2) - 1024;
431 int sum, x,
val, lshift, rshift, ret,
i, idx;
433 unsigned endoffset, newoffset,
offset;
441 size_in_bits = bytestream2_get_le32(gb);
442 endoffset = ((size_in_bits + 7) >> 3) - 4;
448 rshift = (((size_in_bits & 0xFF) - 1) & 7) + 15;
449 lshift = 32 - rshift;
450 idx = (next >> rshift) & 0x3FF;
451 for (
i = 0;
i < op_size;
i++) {
452 dst[
i] = optable[idx].
val1;
455 x = (next << lshift) >> 1 >> (31 -
val);
456 newoffset =
offset - (sum >> 3);
458 idx = x + optable[idx].
next;
473 int flag = bytestream2_peek_byte(gb);
475 if ((
flag & 3) == 0) {
478 if (read_size != op_size)
480 }
else if ((
flag & 3) == 1) {
482 memset(dstp, bytestream2_get_byte(gb), op_size);
498 uint8_t *tex_data,
int tex_size,
506 uint8_t *tptr0, *tptr1, *tptr3;
514 opcode = op_data[oi++];
516 v = bytestream2_get_byte(gb);
521 opcode = bytestream2_get_le16(gb);
523 }
while (opcode == 0xFFFF);
537 vv = (8 +
offset) * (bytestream2_get_le16(gb) + 1);
538 if (vv < 0 || vv > dst - tex_data)
544 tab0[0x9E3779B1 * (uint16_t)v >> 24] = dst;
545 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
548 AV_WL32(dst, bytestream2_get_le32(gb));
549 AV_WL32(dst + 4, bytestream2_get_le32(gb));
550 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
551 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
554 tptr3 =
tab1[bytestream2_get_byte(gb)];
557 AV_WL16(dst, bytestream2_get_le16(gb));
560 AV_WL16(dst + 5, bytestream2_get_le16(gb));
561 dst[7] = bytestream2_get_byte(gb);
562 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
565 tptr3 =
tab1[bytestream2_get_byte(gb)];
568 AV_WL16(dst, bytestream2_get_le16(gb));
569 AV_WL16(dst + 2, bytestream2_get_le16(gb));
570 dst[4] = bytestream2_get_byte(gb);
573 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
574 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
577 tptr0 =
tab1[bytestream2_get_byte(gb)];
580 tptr1 =
tab1[bytestream2_get_byte(gb)];
583 AV_WL16(dst, bytestream2_get_le16(gb));
588 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
591 v = (8 +
offset) * (bytestream2_get_le16(gb) + 1);
592 if (v < 0 || v > dst - tex_data)
595 AV_WL16(dst, bytestream2_get_le16(gb));
598 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
599 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
602 tptr1 = tab0[bytestream2_get_byte(gb)];
606 AV_WL16(dst + 2, bytestream2_get_le16(gb));
607 AV_WL32(dst + 4, bytestream2_get_le32(gb));
608 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
611 tptr1 = tab0[bytestream2_get_byte(gb)];
614 tptr3 =
tab1[bytestream2_get_byte(gb)];
620 AV_WL16(dst + 5, bytestream2_get_le16(gb));
621 dst[7] = bytestream2_get_byte(gb);
622 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
625 tptr1 = tab0[bytestream2_get_byte(gb)];
628 tptr3 =
tab1[bytestream2_get_byte(gb)];
632 AV_WL16(dst + 2, bytestream2_get_le16(gb));
633 dst[4] = bytestream2_get_byte(gb);
636 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
639 tptr0 = tab0[bytestream2_get_byte(gb)];
642 tptr3 =
tab1[bytestream2_get_byte(gb)];
645 tptr1 =
tab1[bytestream2_get_byte(gb)];
655 tptr1 = tab0[bytestream2_get_byte(gb)];
658 v = (8 +
offset) * (bytestream2_get_le16(gb) + 1);
659 if (v < 0 || v > dst - tex_data)
665 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
669 AV_WL16(dst + 2, bytestream2_get_le16(gb));
670 AV_WL32(dst + 4, bytestream2_get_le32(gb));
671 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
674 tptr3 =
tab1[bytestream2_get_byte(gb)];
680 AV_WL16(dst + 5, bytestream2_get_le16(gb));
681 dst[7] = bytestream2_get_byte(gb);
682 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
685 tptr3 =
tab1[bytestream2_get_byte(gb)];
689 AV_WL16(dst + 2, bytestream2_get_le16(gb));
690 dst[4] = bytestream2_get_byte(gb);
693 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
696 tptr3 =
tab1[bytestream2_get_byte(gb)];
699 tptr1 =
tab1[bytestream2_get_byte(gb)];
709 v = (8 +
offset) * (bytestream2_get_le16(gb) + 1);
710 if (v < 0 || v > dst - tex_data)
715 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
726 if (dst - tex_data + 8 > tex_size)
738 uint8_t *tex_data,
int tex_size,
740 int max_op_size0,
int max_op_size1)
742 uint8_t *dst, *
tab2[256] = { 0 }, *tab0[256] = { 0 }, *tab3[256] = { 0 }, *
tab1[256] = { 0 };
743 int op_offset = bytestream2_get_le32(gb);
744 unsigned op_size0 = bytestream2_get_le32(gb);
745 unsigned op_size1 = bytestream2_get_le32(gb);
747 int skip0, skip1, oi0 = 0, oi1 = 0;
748 int ret, state0 = 0, state1 = 0;
755 if (op_size0 > max_op_size0)
760 if (op_size1 > max_op_size1)
767 AV_WL32(dst, bytestream2_get_le32(gb));
768 AV_WL32(dst + 4, bytestream2_get_le32(gb));
769 AV_WL32(dst + 8, bytestream2_get_le32(gb));
770 AV_WL32(dst + 12, bytestream2_get_le32(gb));
772 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
773 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF) >> 24] = dst + 2;
774 tab2[0x9E3779B1 *
AV_RL16(dst + 8) >> 24] = dst + 8;
775 tab3[0x9E3779B1 * (
AV_RL32(dst + 10) & 0xFFFFFF) >> 24] = dst + 10;
777 while (dst + 10 < tex_data + tex_size) {
779 &dst, &state0, tab0,
tab1, 8);
783 &dst, &state1,
tab2, tab3, 8);
788 bytestream2_seek(gb, data_start - 12 + op_offset + skip0 + skip1, SEEK_SET);
794 uint8_t *tex_data,
int tex_size,
795 uint8_t *op_data,
int max_op_size)
797 int op_offset = bytestream2_get_le32(gb);
798 unsigned op_size = bytestream2_get_le32(gb);
800 uint8_t *dst, *table0[256] = { 0 }, *table1[256] = { 0 };
801 int ret,
state = 0, skip, oi = 0, v, vv;
808 if (op_size > max_op_size)
815 v = bytestream2_get_le32(gb);
817 vv = bytestream2_get_le32(gb);
818 table0[0x9E3779B1 * (uint16_t)v >> 24] = dst;
820 table1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF) >> 24] = dst + 2;
823 while (dst < tex_data + tex_size) {
825 &dst, &
state, table0, table1, 0);
842 ctx->op_data[0],
ctx->op_size[0]);
847 ctx->op_data[1],
ctx->op_data[2],
848 ctx->op_size[1],
ctx->op_size[2]);
858 ctx->op_data[0],
ctx->op_data[3],
859 ctx->op_size[0],
ctx->op_size[3]);
864 ctx->op_data[1],
ctx->op_data[2],
865 ctx->op_size[1],
ctx->op_size[2]);
879 AV_WL32(
ctx->tex_data + 0, bytestream2_get_le32(gbc));
880 AV_WL32(
ctx->tex_data + 4, bytestream2_get_le32(gbc));
881 AV_WL32(
ctx->tex_data + 8, bytestream2_get_le32(gbc));
882 AV_WL32(
ctx->tex_data + 12, bytestream2_get_le32(gbc));
885 while (
pos + 2 <=
ctx->tex_size / 4) {
899 value = bytestream2_get_le32(gbc);
909 check = bytestream2_get_byte(gbc) + 1;
912 probe = bytestream2_get_le16(gbc);
914 }
while (
probe == 0xFFFF);
941 run = bytestream2_get_byte(gbc);
944 probe = bytestream2_get_le16(gbc);
946 }
while (
probe == 0xFFFF);
960 idx = 8 + bytestream2_get_le16(gbc);
961 if (idx >
pos || (
unsigned int)(
pos - idx) + 2 >
ctx->tex_size / 4)
973 prev = bytestream2_get_le32(gbc);
977 prev = bytestream2_get_le32(gbc);
985 if (
pos + 2 >
ctx->tex_size / 4)
990 if (idx >
pos || (
unsigned int)(
pos - idx) + 2 >
ctx->tex_size / 4)
1002 if (
op && (idx >
pos || (
unsigned int)(
pos - idx) + 2 >
ctx->tex_size / 4))
1007 prev = bytestream2_get_le32(gbc);
1016 prev = bytestream2_get_le32(gbc);
1050 const char *msgcomp, *msgtext;
1052 int version_major, version_minor = 0;
1053 int size = 0, old_type = 0;
1058 ctx->texture_block_h = 4;
1059 ctx->texture_block_w = 4;
1065 ctx->tex_funct_planar[0] =
NULL;
1066 ctx->tex_funct_planar[1] =
NULL;
1068 tag = bytestream2_get_le32(gbc);
1070 case MKBETAG(
'D',
'X',
'T',
'1'):
1072 ctx->tex_funct =
ctx->texdsp.dxt1_block;
1078 case MKBETAG(
'D',
'X',
'T',
'5'):
1080 ctx->tex_funct =
ctx->texdsp.dxt5_block;
1086 case MKBETAG(
'Y',
'C',
'G',
'6'):
1092 ctx->ctex_step = 16;
1093 msgcomp =
"YOCOCG6";
1096 ctx->texture_block_h = 4;
1097 ctx->texture_block_w = 16;
1098 ctx->ctexture_block_h = 4;
1099 ctx->ctexture_block_w = 4;
1103 case MKBETAG(
'Y',
'G',
'1',
'0'):
1109 ctx->ctex_step = 16;
1110 msgcomp =
"YAOCOCG10";
1113 ctx->texture_block_h = 4;
1114 ctx->texture_block_w = 16;
1115 ctx->ctexture_block_h = 4;
1116 ctx->ctexture_block_w = 4;
1123 old_type =
tag >> 24;
1124 version_major = (old_type & 0x0F) - 1;
1126 if (old_type & 0x80) {
1134 if (old_type & 0x40) {
1137 ctx->tex_funct =
ctx->texdsp.dxt5_block;
1139 }
else if (old_type & 0x20 || version_major == 1) {
1142 ctx->tex_funct =
ctx->texdsp.dxt1_block;
1156 ctx->ctexture_block_h));
1160 version_major = bytestream2_get_byte(gbc) - 1;
1161 version_minor = bytestream2_get_byte(gbc);
1164 if (bytestream2_get_byte(gbc)) {
1171 size = bytestream2_get_le32(gbc);
1174 "%s compression with %s texture (version %d.%d)\n",
1175 msgcomp, msgtext, version_major, version_minor);
1179 "Incomplete or invalid file (header %d, left %u).\n",
1189 if (
ctx->ctex_size) {
1200 for (
i = 0;
i < 4;
i++) {
1208 ret = decompress_tex(avctx);
1214 if (w_block * h_block *
ctx->tex_step >
ctx->tex_size * 8LL)
static int probe(const AVProbeData *p)
static double val(void *priv, double ch)
Libavcodec external API header.
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(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(GetByteContext *g)
#define MKBETAG(a, b, c, d)
static int dxv_decompress_yg10(AVCodecContext *avctx)
static void decompress_indices(uint8_t *dst, const uint8_t *src)
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_close(AVCodecContext *avctx)
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 int extract_component(int yo0, int yo1, int code)
static int fill_optable(unsigned *table0, OpcodeTable *table1, int nb_elements)
static int dxv_decompress_dxt5(AVCodecContext *avctx)
static int yo_block(uint8_t *dst, ptrdiff_t stride, uint8_t *unused0, ptrdiff_t unused1, const uint8_t *block)
static int dxv_decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
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 decompress_texture_thread(AVCodecContext *avctx, void *arg, int slice, int thread_nb)
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 dxv_init(AVCodecContext *avctx)
static int fill_ltable(GetByteContext *gb, uint32_t *table, int *nb_elements)
static int yao_block(uint8_t *plane0, ptrdiff_t stride0, uint8_t *plane3, ptrdiff_t stride1, const uint8_t *block)
static void yao_subblock(uint8_t *dst, uint8_t *yo_indices, ptrdiff_t stride, const uint8_t *block)
static int dxv_decompress_opcodes(GetByteContext *gb, void *dstp, size_t op_size)
static int cocg_block(uint8_t *plane0, ptrdiff_t stride0, uint8_t *plane1, ptrdiff_t stride1, const uint8_t *block)
static int dxv_decompress_lzf(AVCodecContext *avctx)
#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.
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
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...
@ AV_PICTURE_TYPE_I
Intra.
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.
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int ff_lzf_uncompress(GetByteContext *gb, uint8_t **buf, int64_t *size)
static const uint16_t mask[17]
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)
static const uint16_t table[]
FF_ENABLE_DEPRECATION_WARNINGS int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *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(* execute2)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count)
The codec may call this to execute several independent things.
int coded_width
Bitstream width / height, may be different from width/height e.g.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int key_frame
1 -> keyframe, 0-> not
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
enum AVPictureType pict_type
Picture type of the frame.
This structure stores compressed data.
int(* tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
int(* tex_funct_planar[2])(uint8_t *plane0, ptrdiff_t stride0, uint8_t *plane1, ptrdiff_t stride1, const uint8_t *block)
av_cold void ff_texturedsp_init(TextureDSPContext *c)
Texture block (4x4) module.
static const uint8_t offset[127][2]