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 }
else if ((
flag & 3) == 1) {
480 memset(dstp, bytestream2_get_byte(gb), op_size);
496 uint8_t *tex_data,
int tex_size,
504 uint8_t *tptr0, *tptr1, *tptr3;
512 opcode = op_data[oi++];
514 v = bytestream2_get_byte(gb);
519 opcode = bytestream2_get_le16(gb);
521 }
while (opcode == 0xFFFF);
535 vv = (8 +
offset) * (bytestream2_get_le16(gb) + 1);
536 if (vv < 0 || vv > dst - tex_data)
542 tab0[0x9E3779B1 * (uint16_t)v >> 24] = dst;
543 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
546 AV_WL32(dst, bytestream2_get_le32(gb));
547 AV_WL32(dst + 4, bytestream2_get_le32(gb));
548 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
549 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
552 tptr3 =
tab1[bytestream2_get_byte(gb)];
555 AV_WL16(dst, bytestream2_get_le16(gb));
558 AV_WL16(dst + 5, bytestream2_get_le16(gb));
559 dst[7] = bytestream2_get_byte(gb);
560 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
563 tptr3 =
tab1[bytestream2_get_byte(gb)];
566 AV_WL16(dst, bytestream2_get_le16(gb));
567 AV_WL16(dst + 2, bytestream2_get_le16(gb));
568 dst[4] = bytestream2_get_byte(gb);
571 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
572 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
575 tptr0 =
tab1[bytestream2_get_byte(gb)];
578 tptr1 =
tab1[bytestream2_get_byte(gb)];
581 AV_WL16(dst, bytestream2_get_le16(gb));
586 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
589 v = (8 +
offset) * (bytestream2_get_le16(gb) + 1);
590 if (v < 0 || v > dst - tex_data)
593 AV_WL16(dst, bytestream2_get_le16(gb));
596 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
597 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
600 tptr1 = tab0[bytestream2_get_byte(gb)];
604 AV_WL16(dst + 2, bytestream2_get_le16(gb));
605 AV_WL32(dst + 4, bytestream2_get_le32(gb));
606 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
609 tptr1 = tab0[bytestream2_get_byte(gb)];
612 tptr3 =
tab1[bytestream2_get_byte(gb)];
618 AV_WL16(dst + 5, bytestream2_get_le16(gb));
619 dst[7] = bytestream2_get_byte(gb);
620 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
623 tptr1 = tab0[bytestream2_get_byte(gb)];
626 tptr3 =
tab1[bytestream2_get_byte(gb)];
630 AV_WL16(dst + 2, bytestream2_get_le16(gb));
631 dst[4] = bytestream2_get_byte(gb);
634 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
637 tptr0 = tab0[bytestream2_get_byte(gb)];
640 tptr3 =
tab1[bytestream2_get_byte(gb)];
643 tptr1 =
tab1[bytestream2_get_byte(gb)];
653 tptr1 = tab0[bytestream2_get_byte(gb)];
656 v = (8 +
offset) * (bytestream2_get_le16(gb) + 1);
657 if (v < 0 || v > dst - tex_data)
663 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
667 AV_WL16(dst + 2, bytestream2_get_le16(gb));
668 AV_WL32(dst + 4, bytestream2_get_le32(gb));
669 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
672 tptr3 =
tab1[bytestream2_get_byte(gb)];
678 AV_WL16(dst + 5, bytestream2_get_le16(gb));
679 dst[7] = bytestream2_get_byte(gb);
680 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
683 tptr3 =
tab1[bytestream2_get_byte(gb)];
687 AV_WL16(dst + 2, bytestream2_get_le16(gb));
688 dst[4] = bytestream2_get_byte(gb);
691 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
694 tptr3 =
tab1[bytestream2_get_byte(gb)];
697 tptr1 =
tab1[bytestream2_get_byte(gb)];
707 v = (8 +
offset) * (bytestream2_get_le16(gb) + 1);
708 if (v < 0 || v > dst - tex_data)
713 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFFu) >> 24] = dst + 2;
724 if (dst - tex_data + 8 > tex_size)
736 uint8_t *tex_data,
int tex_size,
738 int max_op_size0,
int max_op_size1)
740 uint8_t *dst, *
tab2[256] = { 0 }, *tab0[256] = { 0 }, *tab3[256] = { 0 }, *
tab1[256] = { 0 };
741 int op_offset = bytestream2_get_le32(gb);
742 unsigned op_size0 = bytestream2_get_le32(gb);
743 unsigned op_size1 = bytestream2_get_le32(gb);
745 int skip0, skip1, oi0 = 0, oi1 = 0;
746 int ret, state0 = 0, state1 = 0;
753 if (op_size0 > max_op_size0)
758 if (op_size1 > max_op_size1)
765 AV_WL32(dst, bytestream2_get_le32(gb));
766 AV_WL32(dst + 4, bytestream2_get_le32(gb));
767 AV_WL32(dst + 8, bytestream2_get_le32(gb));
768 AV_WL32(dst + 12, bytestream2_get_le32(gb));
770 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
771 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF) >> 24] = dst + 2;
772 tab2[0x9E3779B1 *
AV_RL16(dst + 8) >> 24] = dst + 8;
773 tab3[0x9E3779B1 * (
AV_RL32(dst + 10) & 0xFFFFFF) >> 24] = dst + 10;
775 while (dst + 10 < tex_data + tex_size) {
777 &dst, &state0, tab0,
tab1, 8);
781 &dst, &state1,
tab2, tab3, 8);
786 bytestream2_seek(gb, data_start - 12 + op_offset + skip0 + skip1, SEEK_SET);
792 uint8_t *tex_data,
int tex_size,
793 uint8_t *op_data,
int max_op_size)
795 int op_offset = bytestream2_get_le32(gb);
796 unsigned op_size = bytestream2_get_le32(gb);
798 uint8_t *dst, *table0[256] = { 0 }, *table1[256] = { 0 };
799 int ret,
state = 0, skip, oi = 0, v, vv;
806 if (op_size > max_op_size)
813 v = bytestream2_get_le32(gb);
815 vv = bytestream2_get_le32(gb);
816 table0[0x9E3779B1 * (uint16_t)v >> 24] = dst;
818 table1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF) >> 24] = dst + 2;
821 while (dst < tex_data + tex_size) {
823 &dst, &
state, table0, table1, 0);
840 ctx->op_data[0],
ctx->op_size[0]);
845 ctx->op_data[1],
ctx->op_data[2],
846 ctx->op_size[1],
ctx->op_size[2]);
856 ctx->op_data[0],
ctx->op_data[3],
857 ctx->op_size[0],
ctx->op_size[3]);
862 ctx->op_data[1],
ctx->op_data[2],
863 ctx->op_size[1],
ctx->op_size[2]);
877 AV_WL32(
ctx->tex_data + 0, bytestream2_get_le32(gbc));
878 AV_WL32(
ctx->tex_data + 4, bytestream2_get_le32(gbc));
879 AV_WL32(
ctx->tex_data + 8, bytestream2_get_le32(gbc));
880 AV_WL32(
ctx->tex_data + 12, bytestream2_get_le32(gbc));
883 while (
pos + 2 <=
ctx->tex_size / 4) {
897 value = bytestream2_get_le32(gbc);
907 check = bytestream2_get_byte(gbc) + 1;
910 probe = bytestream2_get_le16(gbc);
912 }
while (
probe == 0xFFFF);
939 run = bytestream2_get_byte(gbc);
942 probe = bytestream2_get_le16(gbc);
944 }
while (
probe == 0xFFFF);
958 idx = 8 + bytestream2_get_le16(gbc);
959 if (idx >
pos || (
unsigned int)(
pos - idx) + 2 >
ctx->tex_size / 4)
971 prev = bytestream2_get_le32(gbc);
975 prev = bytestream2_get_le32(gbc);
983 if (
pos + 2 >
ctx->tex_size / 4)
988 if (idx >
pos || (
unsigned int)(
pos - idx) + 2 >
ctx->tex_size / 4)
1000 if (
op && (idx >
pos || (
unsigned int)(
pos - idx) + 2 >
ctx->tex_size / 4))
1005 prev = bytestream2_get_le32(gbc);
1014 prev = bytestream2_get_le32(gbc);
1048 const char *msgcomp, *msgtext;
1050 int version_major, version_minor = 0;
1051 int size = 0, old_type = 0;
1056 ctx->texture_block_h = 4;
1057 ctx->texture_block_w = 4;
1063 ctx->tex_funct_planar[0] =
NULL;
1064 ctx->tex_funct_planar[1] =
NULL;
1066 tag = bytestream2_get_le32(gbc);
1068 case MKBETAG(
'D',
'X',
'T',
'1'):
1070 ctx->tex_funct =
ctx->texdsp.dxt1_block;
1076 case MKBETAG(
'D',
'X',
'T',
'5'):
1078 ctx->tex_funct =
ctx->texdsp.dxt5_block;
1084 case MKBETAG(
'Y',
'C',
'G',
'6'):
1090 ctx->ctex_step = 16;
1091 msgcomp =
"YOCOCG6";
1094 ctx->texture_block_h = 4;
1095 ctx->texture_block_w = 16;
1096 ctx->ctexture_block_h = 4;
1097 ctx->ctexture_block_w = 4;
1101 case MKBETAG(
'Y',
'G',
'1',
'0'):
1107 ctx->ctex_step = 16;
1108 msgcomp =
"YAOCOCG10";
1111 ctx->texture_block_h = 4;
1112 ctx->texture_block_w = 16;
1113 ctx->ctexture_block_h = 4;
1114 ctx->ctexture_block_w = 4;
1121 old_type =
tag >> 24;
1122 version_major = (old_type & 0x0F) - 1;
1124 if (old_type & 0x80) {
1132 if (old_type & 0x40) {
1135 ctx->tex_funct =
ctx->texdsp.dxt5_block;
1137 }
else if (old_type & 0x20 || version_major == 1) {
1140 ctx->tex_funct =
ctx->texdsp.dxt1_block;
1152 ctx->ctexture_block_h));
1156 version_major = bytestream2_get_byte(gbc) - 1;
1157 version_minor = bytestream2_get_byte(gbc);
1160 if (bytestream2_get_byte(gbc)) {
1167 size = bytestream2_get_le32(gbc);
1170 "%s compression with %s texture (version %d.%d)\n",
1171 msgcomp, msgtext, version_major, version_minor);
1175 "Incomplete or invalid file (header %d, left %u).\n",
1185 if (
ctx->ctex_size) {
1196 for (
i = 0;
i < 4;
i++) {
1204 ret = decompress_tex(avctx);
1210 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]