42
static int txd_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
44
static int txd_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
44
const uint8_t *buf = avpkt->data;
45
46
TXDContext * const s = avctx->priv_data;
46
48
AVFrame *picture = data;
47
49
AVFrame * const p = &s->picture;
48
unsigned int version, w, h, d3d_format, depth, stride, mipmap_count, flags;
50
unsigned int version, w, h, d3d_format, depth, stride, flags;
51
const uint8_t *cur = buf;
52
const uint32_t *palette = (const uint32_t *)(cur + 88);
55
version = AV_RL32(cur);
56
d3d_format = AV_RL32(cur+76);
59
depth = AV_RL8 (cur+84);
60
mipmap_count = AV_RL8 (cur+85);
61
flags = AV_RL8 (cur+87);
55
bytestream2_init(&gb, avpkt->data, avpkt->size);
56
version = bytestream2_get_le32(&gb);
57
bytestream2_skip(&gb, 72);
58
d3d_format = bytestream2_get_le32(&gb);
59
w = bytestream2_get_le16(&gb);
60
h = bytestream2_get_le16(&gb);
61
depth = bytestream2_get_byte(&gb);
62
bytestream2_skip(&gb, 2);
63
flags = bytestream2_get_byte(&gb);
64
65
if (version < 8 || version > 9) {
65
66
av_log(avctx, AV_LOG_ERROR, "texture data version %i is unsupported\n",
71
avctx->pix_fmt = PIX_FMT_PAL8;
73
} else if (depth == 16 || depth == 32)
74
avctx->pix_fmt = PIX_FMT_RGB32;
72
avctx->pix_fmt = AV_PIX_FMT_PAL8;
73
} else if (depth == 16 || depth == 32) {
74
avctx->pix_fmt = AV_PIX_FMT_RGB32;
76
76
av_log(avctx, AV_LOG_ERROR, "depth of %i is unsupported\n", depth);
85
85
if (w != avctx->width || h != avctx->height)
86
86
avcodec_set_dimensions(avctx, w, h);
87
if (avctx->get_buffer(avctx, p) < 0) {
87
if (ff_get_buffer(avctx, p) < 0) {
88
88
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
98
98
pal = (uint32_t *) p->data[1];
99
for (y=0; y<256; y++) {
100
v = AV_RB32(palette+y);
101
pal[y] = (v>>8) + (v<<24);
99
for (y = 0; y < 256; y++) {
100
v = bytestream2_get_be32(&gb);
101
pal[y] = (v >> 8) + (v << 24);
103
bytestream2_skip(&gb, 4);
103
104
for (y=0; y<h; y++) {
105
bytestream2_get_buffer(&gb, ptr, w);
108
108
} else if (depth == 16) {
109
bytestream2_skip(&gb, 4);
109
110
switch (d3d_format) {
111
112
if (!(flags & 1))
112
113
goto unsupported;
113
114
case FF_S3TC_DXT1:
114
ff_decode_dxt1(cur, ptr, w, h, stride);
115
ff_decode_dxt1(&gb, ptr, w, h, stride);
116
117
case FF_S3TC_DXT3:
117
ff_decode_dxt3(cur, ptr, w, h, stride);
118
ff_decode_dxt3(&gb, ptr, w, h, stride);
120
121
goto unsupported;
137
for (; mipmap_count > 1; mipmap_count--)
138
cur += AV_RL32(cur) + 4;
140
137
*picture = s->picture;
141
*data_size = sizeof(AVPicture);
146
143
av_log(avctx, AV_LOG_ERROR, "unsupported d3d format (%08x)\n", d3d_format);
159
156
AVCodec ff_txd_decoder = {
161
158
.type = AVMEDIA_TYPE_VIDEO,
159
.id = AV_CODEC_ID_TXD,
163
160
.priv_data_size = sizeof(TXDContext),
164
161
.init = txd_init,
165
162
.close = txd_end,
166
163
.decode = txd_decode_frame,
167
164
.capabilities = CODEC_CAP_DR1,
168
.long_name = NULL_IF_CONFIG_SMALL("Renderware TXD (TeXture Dictionary) image"),
165
.long_name = NULL_IF_CONFIG_SMALL("Renderware TXD (TeXture Dictionary) image"),