62 uint8_t *plane1, ptrdiff_t stride1,
70 for (block = 0; block < 2; block++) {
74 for (i = 0; i < 8; i++)
75 dst[i] = (tmp >> (i * 3)) & 0x7;
88 }
else if (code == 0) {
90 }
else if (code == 1) {
94 yo = (
uint8_t) (((8 - code) * yo0 +
95 (code - 1) * yo1) / 7);
99 }
else if (code == 7) {
102 yo = (
uint8_t) (((6 - code) * yo0 +
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,
183 yao_subblock(plane0 + 4, yo_indices, stride0, block + 16);
184 yao_subblock(plane3 + 4, a_indices, stride1, block + 24);
185 yao_subblock(plane0 + 8, yo_indices, stride0, block + 32);
186 yao_subblock(plane3 + 8, a_indices, stride1, block + 40);
187 yao_subblock(plane0 + 12, yo_indices, stride0, block + 48);
188 yao_subblock(plane3 + 12, a_indices, stride1, block + 56);
194 int slice,
int thread_nb)
202 int start_slice, end_slice;
205 end_slice = h_block * (slice + 1) / ctx->
slice_count;
208 for (y = start_slice; y < end_slice; y++) {
210 int off = y * w_block;
211 for (x = 0; x < w_block; x++) {
219 for (y = start_slice; y < end_slice; y++) {
222 int off = y * w_block;
223 for (x = 0; x < w_block; x++) {
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++) {
256 #define CHECKPOINT(x) \
259 value = bytestream2_get_le32(gbc); \
270 idx = (bytestream2_get_byte(gbc) + 2) * x; \
272 av_log(avctx, AV_LOG_ERROR, "idx %d > %d\n", idx, pos); \
273 return AVERROR_INVALIDDATA; \
277 idx = (bytestream2_get_le16(gbc) + 0x102) * x; \
279 av_log(avctx, AV_LOG_ERROR, "idx %d > %d\n", idx, pos); \
280 return AVERROR_INVALIDDATA; \
291 int idx = 0,
state = 0;
299 while (pos + 2 <= ctx->
tex_size / 4) {
317 prev = bytestream2_get_le32(gbc);
326 prev = bytestream2_get_le32(gbc);
343 unsigned half = 512, bits = 1023, left = 1024, input,
mask;
344 int value, counter = 0, rshift = 10, lshift = 30;
346 mask = bytestream2_get_le32(gb) >> 2;
354 table[counter++] =
value;
359 input = bytestream2_get_le16(gb);
360 mask += input << lshift;
370 for (; !table[counter - 1]; counter--)
374 *nb_elements = counter;
377 memset(&table[counter], 0, 4 * (256 - counter));
387 unsigned table2[256] = { 0 };
389 int val0, val1, i, j = 2, k = 0;
391 table2[0] = table0[0];
392 for (i = 0; i < nb_elements - 1; i++, table2[i] = val0) {
393 val0 = table0[i + 1] + table2[i];
399 }
while (!table2[k]);
403 for (i = 1024; i > 0; i--) {
404 for (table1[x].val1 = k; k < 256 && j > table2[k]; k++);
405 x = (x - 383) & 0x3FF;
410 memcpy(&table2[0], table0, 4 * nb_elements);
412 for (i = 0; i < 1024; i++) {
413 val0 = table1[i].
val1;
419 table1[i].
val2 = 10 - x;
420 table1[i].
next = (val1 << table1[i].
val2) - 1024;
429 int sum, x,
val, lshift, rshift, ret, size_in_bits, i, idx;
430 unsigned endoffset, newoffset,
offset;
438 size_in_bits = bytestream2_get_le32(gb);
439 endoffset = ((size_in_bits + 7) >> 3) - 4;
444 next =
AV_RL32(src + endoffset);
445 rshift = (((size_in_bits & 0xFF) - 1) & 7) + 15;
446 lshift = 32 - rshift;
447 idx = (next >> rshift) & 0x3FF;
448 for (i = 0; i < op_size; i++) {
449 dst[i] = optable[idx].
val1;
450 val = optable[idx].
val2;
452 x = (next << lshift) >> 1 >> (31 -
val);
453 newoffset = offset - (sum >> 3);
455 idx = x + optable[idx].
next;
457 if (offset > endoffset)
470 int flag = bytestream2_peek_byte(gb);
472 if ((flag & 3) == 0) {
475 }
else if ((flag & 3) == 1) {
477 memset(dstp, bytestream2_get_byte(gb), op_size);
485 ret =
get_opcodes(gb, table, dstp, op_size, elements);
493 uint8_t *tex_data,
int tex_size,
501 uint8_t *tptr0, *tptr1, *tptr3;
509 opcode = op_data[oi++];
511 v = bytestream2_get_byte(gb);
516 opcode = bytestream2_get_le16(gb);
518 }
while (opcode == 0xFFFF);
532 vv = (8 +
offset) * (bytestream2_get_le16(gb) + 1);
533 if (vv < 0 || vv > dst - tex_data)
539 tab0[0x9E3779B1 * (uint16_t)v >> 24] = dst;
540 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
543 AV_WL32(dst, bytestream2_get_le32(gb));
544 AV_WL32(dst + 4, bytestream2_get_le32(gb));
545 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
546 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
549 tptr3 = tab1[bytestream2_get_byte(gb)];
552 AV_WL16(dst, bytestream2_get_le16(gb));
555 AV_WL16(dst + 5, bytestream2_get_le16(gb));
556 dst[7] = bytestream2_get_byte(gb);
557 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
560 tptr3 = tab1[bytestream2_get_byte(gb)];
563 AV_WL16(dst, bytestream2_get_le16(gb));
564 AV_WL16(dst + 2, bytestream2_get_le16(gb));
565 dst[4] = bytestream2_get_byte(gb);
568 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
569 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
572 tptr0 = tab1[bytestream2_get_byte(gb)];
575 tptr1 = tab1[bytestream2_get_byte(gb)];
578 AV_WL16(dst, bytestream2_get_le16(gb));
583 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
586 v = (8 +
offset) * (bytestream2_get_le16(gb) + 1);
587 if (v < 0 || v > dst - tex_data)
590 AV_WL16(dst, bytestream2_get_le16(gb));
593 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
594 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
597 tptr1 = tab0[bytestream2_get_byte(gb)];
601 AV_WL16(dst + 2, bytestream2_get_le16(gb));
602 AV_WL32(dst + 4, bytestream2_get_le32(gb));
603 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
606 tptr1 = tab0[bytestream2_get_byte(gb)];
609 tptr3 = tab1[bytestream2_get_byte(gb)];
615 AV_WL16(dst + 5, bytestream2_get_le16(gb));
616 dst[7] = bytestream2_get_byte(gb);
617 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
620 tptr1 = tab0[bytestream2_get_byte(gb)];
623 tptr3 = tab1[bytestream2_get_byte(gb)];
627 AV_WL16(dst + 2, bytestream2_get_le16(gb));
628 dst[4] = bytestream2_get_byte(gb);
631 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
634 tptr0 = tab0[bytestream2_get_byte(gb)];
637 tptr3 = tab1[bytestream2_get_byte(gb)];
640 tptr1 = tab1[bytestream2_get_byte(gb)];
650 tptr1 = tab0[bytestream2_get_byte(gb)];
653 v = (8 +
offset) * (bytestream2_get_le16(gb) + 1);
654 if (v < 0 || v > dst - tex_data)
660 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
664 AV_WL16(dst + 2, bytestream2_get_le16(gb));
665 AV_WL32(dst + 4, bytestream2_get_le32(gb));
666 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
669 tptr3 = tab1[bytestream2_get_byte(gb)];
675 AV_WL16(dst + 5, bytestream2_get_le16(gb));
676 dst[7] = bytestream2_get_byte(gb);
677 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
680 tptr3 = tab1[bytestream2_get_byte(gb)];
684 AV_WL16(dst + 2, bytestream2_get_le16(gb));
685 dst[4] = bytestream2_get_byte(gb);
688 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
691 tptr3 = tab1[bytestream2_get_byte(gb)];
694 tptr1 = tab1[bytestream2_get_byte(gb)];
704 v = (8 +
offset) * (bytestream2_get_le16(gb) + 1);
705 if (v < 0 || v > dst - tex_data)
710 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
721 if (dst - tex_data + 8 > tex_size)
733 uint8_t *tex_data,
int tex_size,
735 int max_op_size0,
int max_op_size1)
737 uint8_t *dst, *
tab2[256] = { 0 }, *tab0[256] = { 0 }, *tab3[256] = { 0 }, *
tab1[256] = { 0 };
738 int op_offset = bytestream2_get_le32(gb);
739 unsigned op_size0 = bytestream2_get_le32(gb);
740 unsigned op_size1 = bytestream2_get_le32(gb);
742 int skip0, skip1, oi0 = 0, oi1 = 0;
743 int ret, state0 = 0, state1 = 0;
747 if (op_size0 > max_op_size0)
753 if (op_size1 > max_op_size1)
760 AV_WL32(dst, bytestream2_get_le32(gb));
761 AV_WL32(dst + 4, bytestream2_get_le32(gb));
762 AV_WL32(dst + 8, bytestream2_get_le32(gb));
763 AV_WL32(dst + 12, bytestream2_get_le32(gb));
765 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
766 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF) >> 24] = dst + 2;
767 tab2[0x9E3779B1 *
AV_RL16(dst + 8) >> 24] = dst + 8;
768 tab3[0x9E3779B1 * (
AV_RL32(dst + 10) & 0xFFFFFF) >> 24] = dst + 10;
770 while (dst + 10 < tex_data + tex_size) {
772 &dst, &state0, tab0,
tab1, 8);
776 &dst, &state1, tab2, tab3, 8);
781 bytestream2_seek(gb, data_start + op_offset + skip0 + skip1 - 12, SEEK_SET);
787 uint8_t *tex_data,
int tex_size,
788 uint8_t *op_data,
int max_op_size)
790 int op_offset = bytestream2_get_le32(gb);
791 unsigned op_size = bytestream2_get_le32(gb);
793 uint8_t *dst, *table0[256] = { 0 }, *table1[256] = { 0 };
794 int ret,
state = 0, skip, oi = 0, v, vv;
798 if (op_size > max_op_size)
805 v = bytestream2_get_le32(gb);
807 vv = bytestream2_get_le32(gb);
808 table0[0x9E3779B1 * (uint16_t)v >> 24] = dst;
810 table1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF) >> 24] = dst + 2;
813 while (dst < tex_data + tex_size) {
815 &dst, &state, table0, table1, 0);
863 int idx, prev,
state = 0;
875 while (pos + 2 <= ctx->
tex_size / 4) {
889 value = bytestream2_get_le32(gbc);
899 check = bytestream2_get_byte(gbc) + 1;
902 probe = bytestream2_get_le16(gbc);
904 }
while (probe == 0xFFFF);
906 while (check && pos + 4 <= ctx->
tex_size / 4) {
931 run = bytestream2_get_byte(gbc);
934 probe = bytestream2_get_le16(gbc);
936 }
while (probe == 0xFFFF);
950 idx = 8 + bytestream2_get_le16(gbc);
951 if (idx > pos || (
unsigned int)(pos - idx) + 2 > ctx->
tex_size / 4)
963 prev = bytestream2_get_le32(gbc);
967 prev = bytestream2_get_le32(gbc);
980 if (idx > pos || (
unsigned int)(pos - idx) + 2 > ctx->
tex_size / 4)
992 if (op && (idx > pos || (
unsigned int)(pos - idx) + 2 > ctx->
tex_size / 4))
997 prev = bytestream2_get_le32(gbc);
1006 prev = bytestream2_get_le32(gbc);
1040 const char *msgcomp, *msgtext;
1042 int version_major, version_minor = 0;
1043 int size = 0, old_type = 0;
1054 tag = bytestream2_get_le32(gbc);
1056 case MKBETAG(
'D',
'X',
'T',
'1'):
1064 case MKBETAG(
'D',
'X',
'T',
'5'):
1072 case MKBETAG(
'Y',
'C',
'G',
'6'):
1079 msgcomp =
"YOCOCG6";
1089 case MKBETAG(
'Y',
'G',
'1',
'0'):
1096 msgcomp =
"YAOCOCG10";
1108 size = tag & 0x00FFFFFF;
1109 old_type = tag >> 24;
1110 version_major = (old_type & 0x0F) - 1;
1112 if (old_type & 0x80) {
1120 if (old_type & 0x40) {
1125 }
else if (old_type & 0x20 || version_major == 1) {
1144 version_major = bytestream2_get_byte(gbc) - 1;
1145 version_minor = bytestream2_get_byte(gbc);
1148 if (bytestream2_get_byte(gbc)) {
1155 size = bytestream2_get_le32(gbc);
1158 "%s compression with %s texture (version %d.%d)\n",
1159 msgcomp, msgtext, version_major, version_minor);
1163 "Incomplete or invalid file (header %d, left %u).\n",
1184 for (i = 0; i < 4; i++) {
1192 ret = decompress_tex(avctx);
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
const char const char void * val
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
int coded_width
Bitstream width / height, may be different from width/height e.g.
int(* dxt1_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Texture block (4x4) module.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static int dxv_decompress_dxt1(AVCodecContext *avctx)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static int dxv_decompress_ycg6(AVCodecContext *avctx)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
static int get_opcodes(GetByteContext *gb, uint32_t *table, uint8_t *dst, int op_size, int nb_elements)
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
static int dxv_decompress_dxt5(AVCodecContext *avctx)
int(* tex_funct_planar[2])(uint8_t *plane0, ptrdiff_t stride0, uint8_t *plane1, ptrdiff_t stride1, const uint8_t *block)
static int yao_block(uint8_t *plane0, ptrdiff_t stride0, uint8_t *plane3, ptrdiff_t stride1, const uint8_t *block)
Multithreading support functions.
#define u(width, name, range_min, range_max)
static int dxv_decompress_yg10(AVCodecContext *avctx)
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 fill_ltable(GetByteContext *gb, uint32_t *table, int *nb_elements)
static int probe(AVProbeData *p)
static const uint16_t table[]
int ff_lzf_uncompress(GetByteContext *gb, uint8_t **buf, int64_t *size)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int decompress_texture_thread(AVCodecContext *avctx, void *arg, int slice, int thread_nb)
static const uint16_t mask[17]
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
static int dxv_close(AVCodecContext *avctx)
const char * name
Name of the codec implementation.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_RL24
int(* dxt5_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
static const uint8_t offset[127][2]
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
static int dxv_decompress_lzf(AVCodecContext *avctx)
static int yo_block(uint8_t *dst, ptrdiff_t stride, uint8_t *unused0, ptrdiff_t unused1, const uint8_t *block)
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_cold void ff_texturedsp_init(TextureDSPContext *c)
enum AVPictureType pict_type
Picture type of the frame.
int width
picture width / height.
static const ElemCat * elements[ELEMENT_COUNT]
GLsizei GLboolean const GLfloat * value
static int dxv_decompress_opcodes(GetByteContext *gb, void *dstp, size_t op_size)
static void decompress_indices(uint8_t *dst, const uint8_t *src)
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)
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
static av_always_inline int bytestream2_tell(GetByteContext *g)
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
Libavcodec external API header.
static int cocg_block(uint8_t *plane0, ptrdiff_t stride0, uint8_t *plane1, ptrdiff_t stride1, const uint8_t *block)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
main external API structure.
static void yao_subblock(uint8_t *dst, uint8_t *yo_indices, ptrdiff_t stride, const uint8_t *block)
enum AVColorSpace colorspace
YUV colorspace type.
static int dxv_init(AVCodecContext *avctx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int(* tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
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.
GLint GLenum GLboolean GLsizei stride
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static int dxv_decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
common internal api header.
#define MKBETAG(a, b, c, d)
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
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 key_frame
1 -> keyframe, 0-> not
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
static int fill_optable(unsigned *table0, OpcodeTable *table1, int nb_elements)
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 extract_component(int yo0, int yo1, int code)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static int dxv_decompress_raw(AVCodecContext *avctx)
#define check(x, y, S, v)