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, i, idx;
430 int64_t size_in_bits;
431 unsigned endoffset, newoffset,
offset;
439 size_in_bits = bytestream2_get_le32(gb);
440 endoffset = ((size_in_bits + 7) >> 3) - 4;
445 next =
AV_RL32(src + endoffset);
446 rshift = (((size_in_bits & 0xFF) - 1) & 7) + 15;
447 lshift = 32 - rshift;
448 idx = (next >> rshift) & 0x3FF;
449 for (i = 0; i <
op_size; i++) {
450 dst[i] = optable[idx].
val1;
451 val = optable[idx].
val2;
453 x = (next << lshift) >> 1 >> (31 -
val);
454 newoffset = offset - (sum >> 3);
456 idx = x + optable[idx].
next;
458 if (offset > endoffset)
471 int flag = bytestream2_peek_byte(gb);
473 if ((flag & 3) == 0) {
476 }
else if ((flag & 3) == 1) {
478 memset(dstp, bytestream2_get_byte(gb), op_size);
486 ret =
get_opcodes(gb, table, dstp, op_size, elements);
502 uint8_t *tptr0, *tptr1, *tptr3;
510 opcode = op_data[oi++];
512 v = bytestream2_get_byte(gb);
517 opcode = bytestream2_get_le16(gb);
519 }
while (opcode == 0xFFFF);
533 vv = (8 +
offset) * (bytestream2_get_le16(gb) + 1);
534 if (vv < 0 || vv > dst - tex_data)
540 tab0[0x9E3779B1 * (uint16_t)v >> 24] = dst;
541 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
544 AV_WL32(dst, bytestream2_get_le32(gb));
545 AV_WL32(dst + 4, bytestream2_get_le32(gb));
546 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
547 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
550 tptr3 = tab1[bytestream2_get_byte(gb)];
553 AV_WL16(dst, bytestream2_get_le16(gb));
556 AV_WL16(dst + 5, bytestream2_get_le16(gb));
557 dst[7] = bytestream2_get_byte(gb);
558 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
561 tptr3 = tab1[bytestream2_get_byte(gb)];
564 AV_WL16(dst, bytestream2_get_le16(gb));
565 AV_WL16(dst + 2, bytestream2_get_le16(gb));
566 dst[4] = bytestream2_get_byte(gb);
569 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
570 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
573 tptr0 = tab1[bytestream2_get_byte(gb)];
576 tptr1 = tab1[bytestream2_get_byte(gb)];
579 AV_WL16(dst, bytestream2_get_le16(gb));
584 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
587 v = (8 +
offset) * (bytestream2_get_le16(gb) + 1);
588 if (v < 0 || v > dst - tex_data)
591 AV_WL16(dst, bytestream2_get_le16(gb));
594 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
595 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
598 tptr1 = tab0[bytestream2_get_byte(gb)];
602 AV_WL16(dst + 2, bytestream2_get_le16(gb));
603 AV_WL32(dst + 4, bytestream2_get_le32(gb));
604 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
607 tptr1 = tab0[bytestream2_get_byte(gb)];
610 tptr3 = tab1[bytestream2_get_byte(gb)];
616 AV_WL16(dst + 5, bytestream2_get_le16(gb));
617 dst[7] = bytestream2_get_byte(gb);
618 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
621 tptr1 = tab0[bytestream2_get_byte(gb)];
624 tptr3 = tab1[bytestream2_get_byte(gb)];
628 AV_WL16(dst + 2, bytestream2_get_le16(gb));
629 dst[4] = bytestream2_get_byte(gb);
632 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
635 tptr0 = tab0[bytestream2_get_byte(gb)];
638 tptr3 = tab1[bytestream2_get_byte(gb)];
641 tptr1 = tab1[bytestream2_get_byte(gb)];
651 tptr1 = tab0[bytestream2_get_byte(gb)];
654 v = (8 +
offset) * (bytestream2_get_le16(gb) + 1);
655 if (v < 0 || v > dst - tex_data)
661 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
665 AV_WL16(dst + 2, bytestream2_get_le16(gb));
666 AV_WL32(dst + 4, bytestream2_get_le32(gb));
667 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
670 tptr3 = tab1[bytestream2_get_byte(gb)];
676 AV_WL16(dst + 5, bytestream2_get_le16(gb));
677 dst[7] = bytestream2_get_byte(gb);
678 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
681 tptr3 = tab1[bytestream2_get_byte(gb)];
685 AV_WL16(dst + 2, bytestream2_get_le16(gb));
686 dst[4] = bytestream2_get_byte(gb);
689 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
692 tptr3 = tab1[bytestream2_get_byte(gb)];
695 tptr1 = tab1[bytestream2_get_byte(gb)];
705 v = (8 +
offset) * (bytestream2_get_le16(gb) + 1);
706 if (v < 0 || v > dst - tex_data)
711 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF
u) >> 24] = dst + 2;
722 if (dst - tex_data + 8 > tex_size)
736 int max_op_size0,
int max_op_size1)
738 uint8_t *dst, *
tab2[256] = { 0 }, *tab0[256] = { 0 }, *tab3[256] = { 0 }, *
tab1[256] = { 0 };
739 int op_offset = bytestream2_get_le32(gb);
740 unsigned op_size0 = bytestream2_get_le32(gb);
741 unsigned op_size1 = bytestream2_get_le32(gb);
743 int skip0, skip1, oi0 = 0, oi1 = 0;
744 int ret, state0 = 0, state1 = 0;
751 if (op_size0 > max_op_size0)
757 if (op_size1 > max_op_size1)
764 AV_WL32(dst, bytestream2_get_le32(gb));
765 AV_WL32(dst + 4, bytestream2_get_le32(gb));
766 AV_WL32(dst + 8, bytestream2_get_le32(gb));
767 AV_WL32(dst + 12, bytestream2_get_le32(gb));
769 tab0[0x9E3779B1 *
AV_RL16(dst) >> 24] = dst;
770 tab1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF) >> 24] = dst + 2;
771 tab2[0x9E3779B1 *
AV_RL16(dst + 8) >> 24] = dst + 8;
772 tab3[0x9E3779B1 * (
AV_RL32(dst + 10) & 0xFFFFFF) >> 24] = dst + 10;
774 while (dst + 10 < tex_data + tex_size) {
776 &dst, &state0, tab0,
tab1, 8);
780 &dst, &state1, tab2, tab3, 8);
785 bytestream2_seek(gb, data_start + op_offset + skip0 + skip1 - 12, SEEK_SET);
794 int op_offset = bytestream2_get_le32(gb);
795 unsigned op_size = bytestream2_get_le32(gb);
797 uint8_t *dst, *table0[256] = { 0 }, *table1[256] = { 0 };
798 int ret,
state = 0, skip, oi = 0, v, vv;
802 if (op_size > max_op_size)
809 v = bytestream2_get_le32(gb);
811 vv = bytestream2_get_le32(gb);
812 table0[0x9E3779B1 * (uint16_t)v >> 24] = dst;
814 table1[0x9E3779B1 * (
AV_RL32(dst + 2) & 0xFFFFFF) >> 24] = dst + 2;
817 while (dst < tex_data + tex_size) {
819 &dst, &state, table0, table1, 0);
867 int idx, prev,
state = 0;
879 while (pos + 2 <= ctx->
tex_size / 4) {
893 value = bytestream2_get_le32(gbc);
903 check = bytestream2_get_byte(gbc) + 1;
906 probe = bytestream2_get_le16(gbc);
908 }
while (probe == 0xFFFF);
910 while (check && pos + 4 <= ctx->
tex_size / 4) {
935 run = bytestream2_get_byte(gbc);
938 probe = bytestream2_get_le16(gbc);
940 }
while (probe == 0xFFFF);
954 idx = 8 + bytestream2_get_le16(gbc);
955 if (idx > pos || (
unsigned int)(pos - idx) + 2 > ctx->
tex_size / 4)
967 prev = bytestream2_get_le32(gbc);
971 prev = bytestream2_get_le32(gbc);
984 if (idx > pos || (
unsigned int)(pos - idx) + 2 > ctx->
tex_size / 4)
996 if (op && (idx > pos || (
unsigned int)(pos - idx) + 2 > ctx->
tex_size / 4))
1001 prev = bytestream2_get_le32(gbc);
1010 prev = bytestream2_get_le32(gbc);
1044 const char *msgcomp, *msgtext;
1046 int version_major, version_minor = 0;
1047 int size = 0, old_type = 0;
1062 tag = bytestream2_get_le32(gbc);
1064 case MKBETAG(
'D',
'X',
'T',
'1'):
1072 case MKBETAG(
'D',
'X',
'T',
'5'):
1080 case MKBETAG(
'Y',
'C',
'G',
'6'):
1087 msgcomp =
"YOCOCG6";
1097 case MKBETAG(
'Y',
'G',
'1',
'0'):
1104 msgcomp =
"YAOCOCG10";
1116 size = tag & 0x00FFFFFF;
1117 old_type = tag >> 24;
1118 version_major = (old_type & 0x0F) - 1;
1120 if (old_type & 0x80) {
1128 if (old_type & 0x40) {
1133 }
else if (old_type & 0x20 || version_major == 1) {
1152 version_major = bytestream2_get_byte(gbc) - 1;
1153 version_minor = bytestream2_get_byte(gbc);
1156 if (bytestream2_get_byte(gbc)) {
1163 size = bytestream2_get_le32(gbc);
1166 "%s compression with %s texture (version %d.%d)\n",
1167 msgcomp, msgtext, version_major, version_minor);
1171 "Incomplete or invalid file (header %d, left %u).\n",
1192 for (i = 0; i < 4; i++) {
1200 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.
int(* dxt5_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
This structure describes decoded (raw) audio or video data.
int coded_width
Bitstream width / height, may be different from width/height e.g.
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)
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.
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]
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(* 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 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)
int(* dxt1_block)(uint8_t *dst, 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.
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.
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 key_frame
1 -> keyframe, 0-> not
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
int(* tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
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)
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)