#include "libavutil/imgutils.h"
#include "avcodec.h"
#include "bytestream.h"
-#include "s3tc.h"
+#include "internal.h"
+#include "texturedsp.h"
-typedef struct TXDContext {
- AVFrame picture;
-} TXDContext;
+#define TXD_DXT1 0x31545844
+#define TXD_DXT3 0x33545844
-static av_cold int txd_init(AVCodecContext *avctx) {
- TXDContext *s = avctx->priv_data;
-
- avcodec_get_frame_defaults(&s->picture);
- avctx->coded_frame = &s->picture;
-
- return 0;
-}
-
-static int txd_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
+static int txd_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
AVPacket *avpkt) {
- TXDContext * const s = avctx->priv_data;
GetByteContext gb;
- AVFrame *picture = data;
- AVFrame * const p = &s->picture;
+ TextureDSPContext dxtc;
+ AVFrame * const p = data;
unsigned int version, w, h, d3d_format, depth, stride, flags;
unsigned int y, v;
uint8_t *ptr;
uint32_t *pal;
+ int i, j;
+ int ret;
+
+ ff_texturedsp_init(&dxtc);
bytestream2_init(&gb, avpkt->data, avpkt->size);
version = bytestream2_get_le32(&gb);
flags = bytestream2_get_byte(&gb);
if (version < 8 || version > 9) {
- av_log(avctx, AV_LOG_ERROR, "texture data version %i is unsupported\n",
- version);
- return -1;
+ avpriv_report_missing_feature(avctx, "Texture data version %u", version);
+ return AVERROR_PATCHWELCOME;
}
if (depth == 8) {
- avctx->pix_fmt = PIX_FMT_PAL8;
+ avctx->pix_fmt = AV_PIX_FMT_PAL8;
} else if (depth == 16 || depth == 32) {
- avctx->pix_fmt = PIX_FMT_RGB32;
+ avctx->pix_fmt = AV_PIX_FMT_RGBA;
} else {
- av_log(avctx, AV_LOG_ERROR, "depth of %i is unsupported\n", depth);
- return -1;
+ avpriv_report_missing_feature(avctx, "Color depth of %u", depth);
+ return AVERROR_PATCHWELCOME;
}
- if (p->data[0])
- avctx->release_buffer(avctx, p);
+ if ((ret = ff_set_dimensions(avctx, w, h)) < 0)
+ return ret;
+
+ avctx->coded_width = FFALIGN(w, 4);
+ avctx->coded_height = FFALIGN(h, 4);
- if (av_image_check_size(w, h, 0, avctx))
- return -1;
- if (w != avctx->width || h != avctx->height)
- avcodec_set_dimensions(avctx, w, h);
- if (avctx->get_buffer(avctx, p) < 0) {
+ if ((ret = ff_get_buffer(avctx, p, 0)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
+ return ret;
}
p->pict_type = AV_PICTURE_TYPE_I;
case 0:
if (!(flags & 1))
goto unsupported;
- case FF_S3TC_DXT1:
- ff_decode_dxt1(&gb, ptr, w, h, stride);
+ case TXD_DXT1:
+ for (j = 0; j < avctx->height; j += 4) {
+ for (i = 0; i < avctx->width; i += 4) {
+ uint8_t *p = ptr + i * 4 + j * stride;
+ int step = dxtc.dxt1_block(p, stride, gb.buffer);
+ bytestream2_skip(&gb, step);
+ }
+ }
break;
- case FF_S3TC_DXT3:
- ff_decode_dxt3(&gb, ptr, w, h, stride);
+ case TXD_DXT3:
+ for (j = 0; j < avctx->height; j += 4) {
+ for (i = 0; i < avctx->width; i += 4) {
+ uint8_t *p = ptr + i * 4 + j * stride;
+ int step = dxtc.dxt3_block(p, stride, gb.buffer);
+ bytestream2_skip(&gb, step);
+ }
+ }
break;
default:
goto unsupported;
}
}
- *picture = s->picture;
- *data_size = sizeof(AVPicture);
+ *got_frame = 1;
return avpkt->size;
unsupported:
- av_log(avctx, AV_LOG_ERROR, "unsupported d3d format (%08x)\n", d3d_format);
- return -1;
-}
-
-static av_cold int txd_end(AVCodecContext *avctx) {
- TXDContext *s = avctx->priv_data;
-
- if (s->picture.data[0])
- avctx->release_buffer(avctx, &s->picture);
-
- return 0;
+ avpriv_report_missing_feature(avctx, "d3d format (%08x)", d3d_format);
+ return AVERROR_PATCHWELCOME;
}
AVCodec ff_txd_decoder = {
.name = "txd",
+ .long_name = NULL_IF_CONFIG_SMALL("Renderware TXD (TeXture Dictionary) image"),
.type = AVMEDIA_TYPE_VIDEO,
- .id = CODEC_ID_TXD,
- .priv_data_size = sizeof(TXDContext),
- .init = txd_init,
- .close = txd_end,
+ .id = AV_CODEC_ID_TXD,
.decode = txd_decode_frame,
- .capabilities = CODEC_CAP_DR1,
- .long_name = NULL_IF_CONFIG_SMALL("Renderware TXD (TeXture Dictionary) image"),
+ .capabilities = AV_CODEC_CAP_DR1,
};