00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "avcodec.h"
00024 #include "internal.h"
00025 #include "libavutil/common.h"
00026 #include "libavutil/intreadwrite.h"
00027
00028 static av_cold int decode_init(AVCodecContext *avctx)
00029 {
00030 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
00031 avctx->coded_frame = avcodec_alloc_frame();
00032 if (!avctx->coded_frame)
00033 return AVERROR(ENOMEM);
00034
00035 return 0;
00036 }
00037
00038 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
00039 AVPacket *avpkt)
00040 {
00041 int h, w;
00042 AVFrame *pic = avctx->coded_frame;
00043 const uint8_t *src = avpkt->data;
00044 uint8_t *Y1, *Y2, *U, *V;
00045 int ret;
00046
00047 if (pic->data[0])
00048 avctx->release_buffer(avctx, pic);
00049
00050 if (avpkt->size < avctx->width * avctx->height * 3 / 2 + 16) {
00051 av_log(avctx, AV_LOG_ERROR, "packet too small\n");
00052 return AVERROR_INVALIDDATA;
00053 }
00054
00055 pic->reference = 0;
00056 if ((ret = ff_get_buffer(avctx, pic)) < 0)
00057 return ret;
00058
00059 pic->pict_type = AV_PICTURE_TYPE_I;
00060 pic->key_frame = 1;
00061
00062 if (AV_RL32(src) != 0x01000002) {
00063 av_log_ask_for_sample(avctx, "Unknown frame header %X\n", AV_RL32(src));
00064 return AVERROR_PATCHWELCOME;
00065 }
00066 src += 16;
00067
00068 Y1 = pic->data[0];
00069 Y2 = pic->data[0] + pic->linesize[0];
00070 U = pic->data[1];
00071 V = pic->data[2];
00072 for (h = 0; h < avctx->height; h += 2) {
00073 for (w = 0; w < avctx->width; w += 2) {
00074 AV_COPY16(Y1 + w, src);
00075 AV_COPY16(Y2 + w, src + 2);
00076 U[w >> 1] = src[4] + 0x80;
00077 V[w >> 1] = src[5] + 0x80;
00078 src += 6;
00079 }
00080 Y1 += pic->linesize[0] << 1;
00081 Y2 += pic->linesize[0] << 1;
00082 U += pic->linesize[1];
00083 V += pic->linesize[2];
00084 }
00085
00086 *got_frame = 1;
00087 *(AVFrame*)data = *pic;
00088
00089 return avpkt->size;
00090 }
00091
00092 static av_cold int decode_close(AVCodecContext *avctx)
00093 {
00094 AVFrame *pic = avctx->coded_frame;
00095 if (pic->data[0])
00096 avctx->release_buffer(avctx, pic);
00097 av_freep(&avctx->coded_frame);
00098
00099 return 0;
00100 }
00101
00102 AVCodec ff_dxtory_decoder = {
00103 .name = "dxtory",
00104 .long_name = NULL_IF_CONFIG_SMALL("Dxtory"),
00105 .type = AVMEDIA_TYPE_VIDEO,
00106 .id = AV_CODEC_ID_DXTORY,
00107 .init = decode_init,
00108 .close = decode_close,
00109 .decode = decode_frame,
00110 .capabilities = CODEC_CAP_DR1,
00111 };