annotate ffmpeg/libavcodec/dxtory.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 6840f77b83aa
children
rev   line source
yading@10 1 /*
yading@10 2 * Dxtory decoder
yading@10 3 *
yading@10 4 * Copyright (c) 2011 Konstantin Shishkov
yading@10 5 *
yading@10 6 * This file is part of Libav.
yading@10 7 *
yading@10 8 * Libav is free software; you can redistribute it and/or
yading@10 9 * modify it under the terms of the GNU Lesser General Public
yading@10 10 * License as published by the Free Software Foundation; either
yading@10 11 * version 2.1 of the License, or (at your option) any later version.
yading@10 12 *
yading@10 13 * Libav is distributed in the hope that it will be useful,
yading@10 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@10 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@10 16 * Lesser General Public License for more details.
yading@10 17 *
yading@10 18 * You should have received a copy of the GNU Lesser General Public
yading@10 19 * License along with Libav; if not, write to the Free Software
yading@10 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@10 21 */
yading@10 22
yading@10 23 #include "avcodec.h"
yading@10 24 #include "internal.h"
yading@10 25 #include "libavutil/common.h"
yading@10 26 #include "libavutil/intreadwrite.h"
yading@10 27
yading@10 28 static av_cold int decode_init(AVCodecContext *avctx)
yading@10 29 {
yading@10 30 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
yading@10 31
yading@10 32 return 0;
yading@10 33 }
yading@10 34
yading@10 35 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
yading@10 36 AVPacket *avpkt)
yading@10 37 {
yading@10 38 int h, w;
yading@10 39 AVFrame *pic = data;
yading@10 40 const uint8_t *src = avpkt->data;
yading@10 41 uint8_t *Y1, *Y2, *U, *V;
yading@10 42 int ret;
yading@10 43
yading@10 44 if (avpkt->size < avctx->width * avctx->height * 3 / 2 + 16) {
yading@10 45 av_log(avctx, AV_LOG_ERROR, "packet too small\n");
yading@10 46 return AVERROR_INVALIDDATA;
yading@10 47 }
yading@10 48
yading@10 49 if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
yading@10 50 return ret;
yading@10 51
yading@10 52 pic->pict_type = AV_PICTURE_TYPE_I;
yading@10 53 pic->key_frame = 1;
yading@10 54
yading@10 55 if (AV_RL32(src) != 0x01000002) {
yading@10 56 avpriv_request_sample(avctx, "Frame header %X", AV_RL32(src));
yading@10 57 return AVERROR_PATCHWELCOME;
yading@10 58 }
yading@10 59 src += 16;
yading@10 60
yading@10 61 Y1 = pic->data[0];
yading@10 62 Y2 = pic->data[0] + pic->linesize[0];
yading@10 63 U = pic->data[1];
yading@10 64 V = pic->data[2];
yading@10 65 for (h = 0; h < avctx->height; h += 2) {
yading@10 66 for (w = 0; w < avctx->width; w += 2) {
yading@10 67 AV_COPY16(Y1 + w, src);
yading@10 68 AV_COPY16(Y2 + w, src + 2);
yading@10 69 U[w >> 1] = src[4] + 0x80;
yading@10 70 V[w >> 1] = src[5] + 0x80;
yading@10 71 src += 6;
yading@10 72 }
yading@10 73 Y1 += pic->linesize[0] << 1;
yading@10 74 Y2 += pic->linesize[0] << 1;
yading@10 75 U += pic->linesize[1];
yading@10 76 V += pic->linesize[2];
yading@10 77 }
yading@10 78
yading@10 79 *got_frame = 1;
yading@10 80
yading@10 81 return avpkt->size;
yading@10 82 }
yading@10 83
yading@10 84 AVCodec ff_dxtory_decoder = {
yading@10 85 .name = "dxtory",
yading@10 86 .long_name = NULL_IF_CONFIG_SMALL("Dxtory"),
yading@10 87 .type = AVMEDIA_TYPE_VIDEO,
yading@10 88 .id = AV_CODEC_ID_DXTORY,
yading@10 89 .init = decode_init,
yading@10 90 .decode = decode_frame,
yading@10 91 .capabilities = CODEC_CAP_DR1,
yading@10 92 };