summaryrefslogtreecommitdiff
path: root/libavcodec/txd.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2015-06-22 21:15:50 +0200
committerMichael Niedermayer <michaelni@gmx.at>2015-06-22 21:15:50 +0200
commita5b2b22d9a45c9634e6947d43945ebafe121abec (patch)
tree576acfb06100809f34f224253b7a15ad5b933c09 /libavcodec/txd.c
parentd1dc22dddd7937232a1d073b9d72c51587c0b9ab (diff)
parentc0b105756f61d253bdabcc2bb49453a2557e7c3b (diff)
Merge commit 'c0b105756f61d253bdabcc2bb49453a2557e7c3b'
* commit 'c0b105756f61d253bdabcc2bb49453a2557e7c3b': txd: Use the TextureDSP module for decoding Conflicts: configure libavcodec/s3tc.c libavcodec/s3tc.h libavcodec/txd.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/txd.c')
-rw-r--r--libavcodec/txd.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/libavcodec/txd.c b/libavcodec/txd.c
index d2884ad1c6..43c2273486 100644
--- a/libavcodec/txd.c
+++ b/libavcodec/txd.c
@@ -26,18 +26,25 @@
#include "bytestream.h"
#include "avcodec.h"
#include "internal.h"
-#include "s3tc.h"
+#include "texturedsp.h"
+
+#define TXD_DXT1 0x31545844
+#define TXD_DXT3 0x33545844
static int txd_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
AVPacket *avpkt) {
GetByteContext gb;
+ 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);
bytestream2_skip(&gb, 72);
@@ -57,7 +64,7 @@ static int txd_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
if (depth == 8) {
avctx->pix_fmt = AV_PIX_FMT_PAL8;
} else if (depth == 16 || depth == 32) {
- avctx->pix_fmt = AV_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 AVERROR_PATCHWELCOME;
@@ -66,6 +73,9 @@ static int txd_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
if ((ret = ff_set_dimensions(avctx, w, h)) < 0)
return ret;
+ avctx->coded_width = FFALIGN(w, 4);
+ avctx->coded_height = FFALIGN(h, 4);
+
if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
return ret;
@@ -93,15 +103,27 @@ static int txd_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
case 0:
if (!(flags & 1))
goto unsupported;
- case FF_S3TC_DXT1:
+ case TXD_DXT1:
if (bytestream2_get_bytes_left(&gb) < FF_CEIL_RSHIFT(w, 2) * FF_CEIL_RSHIFT(h, 2) * 8)
return AVERROR_INVALIDDATA;
- ff_decode_dxt1(&gb, ptr, w, h, stride);
+ 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:
+ case TXD_DXT3:
if (bytestream2_get_bytes_left(&gb) < FF_CEIL_RSHIFT(w, 2) * FF_CEIL_RSHIFT(h, 2) * 16)
return AVERROR_INVALIDDATA;
- ff_decode_dxt3(&gb, ptr, w, h, stride);
+ 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;