yading@10: /* yading@10: * Renderware TeXture Dictionary (.txd) image decoder yading@10: * Copyright (c) 2007 Ivo van Poorten yading@10: * yading@10: * See also: http://wiki.multimedia.cx/index.php?title=TXD yading@10: * yading@10: * This file is part of FFmpeg. yading@10: * yading@10: * FFmpeg is free software; you can redistribute it and/or yading@10: * modify it under the terms of the GNU Lesser General Public yading@10: * License as published by the Free Software Foundation; either yading@10: * version 2.1 of the License, or (at your option) any later version. yading@10: * yading@10: * FFmpeg is distributed in the hope that it will be useful, yading@10: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@10: * Lesser General Public License for more details. yading@10: * yading@10: * You should have received a copy of the GNU Lesser General Public yading@10: * License along with FFmpeg; if not, write to the Free Software yading@10: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@10: */ yading@10: yading@10: #include "libavutil/intreadwrite.h" yading@10: #include "libavutil/imgutils.h" yading@10: #include "bytestream.h" yading@10: #include "avcodec.h" yading@10: #include "internal.h" yading@10: #include "s3tc.h" yading@10: yading@10: static int txd_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, yading@10: AVPacket *avpkt) { yading@10: GetByteContext gb; yading@10: AVFrame * const p = data; yading@10: unsigned int version, w, h, d3d_format, depth, stride, flags; yading@10: unsigned int y, v; yading@10: uint8_t *ptr; yading@10: uint32_t *pal; yading@10: int ret; yading@10: yading@10: bytestream2_init(&gb, avpkt->data, avpkt->size); yading@10: version = bytestream2_get_le32(&gb); yading@10: bytestream2_skip(&gb, 72); yading@10: d3d_format = bytestream2_get_le32(&gb); yading@10: w = bytestream2_get_le16(&gb); yading@10: h = bytestream2_get_le16(&gb); yading@10: depth = bytestream2_get_byte(&gb); yading@10: bytestream2_skip(&gb, 2); yading@10: flags = bytestream2_get_byte(&gb); yading@10: yading@10: if (version < 8 || version > 9) { yading@10: av_log(avctx, AV_LOG_ERROR, "texture data version %i is unsupported\n", yading@10: version); yading@10: return AVERROR_PATCHWELCOME; yading@10: } yading@10: yading@10: if (depth == 8) { yading@10: avctx->pix_fmt = AV_PIX_FMT_PAL8; yading@10: } else if (depth == 16 || depth == 32) { yading@10: avctx->pix_fmt = AV_PIX_FMT_RGB32; yading@10: } else { yading@10: av_log(avctx, AV_LOG_ERROR, "depth of %i is unsupported\n", depth); yading@10: return AVERROR_PATCHWELCOME; yading@10: } yading@10: yading@10: if ((ret = av_image_check_size(w, h, 0, avctx)) < 0) yading@10: return ret; yading@10: if (w != avctx->width || h != avctx->height) yading@10: avcodec_set_dimensions(avctx, w, h); yading@10: if ((ret = ff_get_buffer(avctx, p, 0)) < 0) yading@10: return ret; yading@10: yading@10: p->pict_type = AV_PICTURE_TYPE_I; yading@10: yading@10: ptr = p->data[0]; yading@10: stride = p->linesize[0]; yading@10: yading@10: if (depth == 8) { yading@10: pal = (uint32_t *) p->data[1]; yading@10: for (y = 0; y < 256; y++) { yading@10: v = bytestream2_get_be32(&gb); yading@10: pal[y] = (v >> 8) + (v << 24); yading@10: } yading@10: if (bytestream2_get_bytes_left(&gb) < w * h) yading@10: return AVERROR_INVALIDDATA; yading@10: bytestream2_skip(&gb, 4); yading@10: for (y=0; ysize; yading@10: yading@10: unsupported: yading@10: av_log(avctx, AV_LOG_ERROR, "unsupported d3d format (%08x)\n", d3d_format); yading@10: return AVERROR_PATCHWELCOME; yading@10: } yading@10: yading@10: AVCodec ff_txd_decoder = { yading@10: .name = "txd", yading@10: .type = AVMEDIA_TYPE_VIDEO, yading@10: .id = AV_CODEC_ID_TXD, yading@10: .decode = txd_decode_frame, yading@10: .capabilities = CODEC_CAP_DR1, yading@10: .long_name = NULL_IF_CONFIG_SMALL("Renderware TXD (TeXture Dictionary) image"), yading@10: };