annotate ffmpeg/libavcodec/eatqi.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 * Electronic Arts TQI Video Decoder
yading@10 3 * Copyright (c) 2007-2009 Peter Ross <pross@xvid.org>
yading@10 4 *
yading@10 5 * This file is part of FFmpeg.
yading@10 6 *
yading@10 7 * FFmpeg is free software; you can redistribute it and/or
yading@10 8 * modify it under the terms of the GNU Lesser General Public
yading@10 9 * License as published by the Free Software Foundation; either
yading@10 10 * version 2.1 of the License, or (at your option) any later version.
yading@10 11 *
yading@10 12 * FFmpeg is distributed in the hope that it will be useful,
yading@10 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@10 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@10 15 * Lesser General Public License for more details.
yading@10 16 *
yading@10 17 * You should have received a copy of the GNU Lesser General Public
yading@10 18 * License along with FFmpeg; if not, write to the Free Software
yading@10 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
yading@10 20 */
yading@10 21
yading@10 22 /**
yading@10 23 * @file
yading@10 24 * Electronic Arts TQI Video Decoder
yading@10 25 * @author Peter Ross <pross@xvid.org>
yading@10 26 * @see http://wiki.multimedia.cx/index.php?title=Electronic_Arts_TQI
yading@10 27 */
yading@10 28
yading@10 29 #include "avcodec.h"
yading@10 30 #include "get_bits.h"
yading@10 31 #include "aandcttab.h"
yading@10 32 #include "eaidct.h"
yading@10 33 #include "internal.h"
yading@10 34 #include "mpeg12.h"
yading@10 35 #include "mpegvideo.h"
yading@10 36
yading@10 37 typedef struct TqiContext {
yading@10 38 MpegEncContext s;
yading@10 39 void *bitstream_buf;
yading@10 40 unsigned int bitstream_buf_size;
yading@10 41 DECLARE_ALIGNED(16, int16_t, block)[6][64];
yading@10 42 } TqiContext;
yading@10 43
yading@10 44 static av_cold int tqi_decode_init(AVCodecContext *avctx)
yading@10 45 {
yading@10 46 TqiContext *t = avctx->priv_data;
yading@10 47 MpegEncContext *s = &t->s;
yading@10 48 s->avctx = avctx;
yading@10 49 ff_dsputil_init(&s->dsp, avctx);
yading@10 50 ff_init_scantable_permutation(s->dsp.idct_permutation, FF_NO_IDCT_PERM);
yading@10 51 ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable, ff_zigzag_direct);
yading@10 52 s->qscale = 1;
yading@10 53 avctx->time_base = (AVRational){1, 15};
yading@10 54 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
yading@10 55 ff_mpeg12_init_vlcs();
yading@10 56 return 0;
yading@10 57 }
yading@10 58
yading@10 59 static int tqi_decode_mb(MpegEncContext *s, int16_t (*block)[64])
yading@10 60 {
yading@10 61 int n;
yading@10 62 s->dsp.clear_blocks(block[0]);
yading@10 63 for (n=0; n<6; n++)
yading@10 64 if (ff_mpeg1_decode_block_intra(s, block[n], n) < 0)
yading@10 65 return -1;
yading@10 66
yading@10 67 return 0;
yading@10 68 }
yading@10 69
yading@10 70 static inline void tqi_idct_put(TqiContext *t, AVFrame *frame, int16_t (*block)[64])
yading@10 71 {
yading@10 72 MpegEncContext *s = &t->s;
yading@10 73 int linesize = frame->linesize[0];
yading@10 74 uint8_t *dest_y = frame->data[0] + (s->mb_y * 16* linesize ) + s->mb_x * 16;
yading@10 75 uint8_t *dest_cb = frame->data[1] + (s->mb_y * 8 * frame->linesize[1]) + s->mb_x * 8;
yading@10 76 uint8_t *dest_cr = frame->data[2] + (s->mb_y * 8 * frame->linesize[2]) + s->mb_x * 8;
yading@10 77
yading@10 78 ff_ea_idct_put_c(dest_y , linesize, block[0]);
yading@10 79 ff_ea_idct_put_c(dest_y + 8, linesize, block[1]);
yading@10 80 ff_ea_idct_put_c(dest_y + 8*linesize , linesize, block[2]);
yading@10 81 ff_ea_idct_put_c(dest_y + 8*linesize + 8, linesize, block[3]);
yading@10 82 if(!(s->avctx->flags&CODEC_FLAG_GRAY)) {
yading@10 83 ff_ea_idct_put_c(dest_cb, frame->linesize[1], block[4]);
yading@10 84 ff_ea_idct_put_c(dest_cr, frame->linesize[2], block[5]);
yading@10 85 }
yading@10 86 }
yading@10 87
yading@10 88 static void tqi_calculate_qtable(MpegEncContext *s, int quant)
yading@10 89 {
yading@10 90 const int qscale = (215 - 2*quant)*5;
yading@10 91 int i;
yading@10 92 s->intra_matrix[0] = (ff_inv_aanscales[0]*ff_mpeg1_default_intra_matrix[0])>>11;
yading@10 93 for(i=1; i<64; i++)
yading@10 94 s->intra_matrix[i] = (ff_inv_aanscales[i]*ff_mpeg1_default_intra_matrix[i]*qscale + 32)>>14;
yading@10 95 }
yading@10 96
yading@10 97 static int tqi_decode_frame(AVCodecContext *avctx,
yading@10 98 void *data, int *got_frame,
yading@10 99 AVPacket *avpkt)
yading@10 100 {
yading@10 101 const uint8_t *buf = avpkt->data;
yading@10 102 int buf_size = avpkt->size;
yading@10 103 const uint8_t *buf_end = buf+buf_size;
yading@10 104 TqiContext *t = avctx->priv_data;
yading@10 105 MpegEncContext *s = &t->s;
yading@10 106 AVFrame *frame = data;
yading@10 107 int ret;
yading@10 108
yading@10 109 s->width = AV_RL16(&buf[0]);
yading@10 110 s->height = AV_RL16(&buf[2]);
yading@10 111 tqi_calculate_qtable(s, buf[4]);
yading@10 112 buf += 8;
yading@10 113
yading@10 114 if (s->avctx->width!=s->width || s->avctx->height!=s->height)
yading@10 115 avcodec_set_dimensions(s->avctx, s->width, s->height);
yading@10 116
yading@10 117 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
yading@10 118 return ret;
yading@10 119
yading@10 120 av_fast_padded_malloc(&t->bitstream_buf, &t->bitstream_buf_size,
yading@10 121 buf_end - buf);
yading@10 122 if (!t->bitstream_buf)
yading@10 123 return AVERROR(ENOMEM);
yading@10 124 s->dsp.bswap_buf(t->bitstream_buf, (const uint32_t*)buf, (buf_end-buf)/4);
yading@10 125 init_get_bits(&s->gb, t->bitstream_buf, 8*(buf_end-buf));
yading@10 126
yading@10 127 s->last_dc[0] = s->last_dc[1] = s->last_dc[2] = 0;
yading@10 128 for (s->mb_y=0; s->mb_y<(avctx->height+15)/16; s->mb_y++)
yading@10 129 for (s->mb_x=0; s->mb_x<(avctx->width+15)/16; s->mb_x++)
yading@10 130 {
yading@10 131 if (tqi_decode_mb(s, t->block) < 0)
yading@10 132 goto end;
yading@10 133 tqi_idct_put(t, frame, t->block);
yading@10 134 }
yading@10 135 end:
yading@10 136
yading@10 137 *got_frame = 1;
yading@10 138 return buf_size;
yading@10 139 }
yading@10 140
yading@10 141 static av_cold int tqi_decode_end(AVCodecContext *avctx)
yading@10 142 {
yading@10 143 TqiContext *t = avctx->priv_data;
yading@10 144 av_free(t->bitstream_buf);
yading@10 145 return 0;
yading@10 146 }
yading@10 147
yading@10 148 AVCodec ff_eatqi_decoder = {
yading@10 149 .name = "eatqi",
yading@10 150 .type = AVMEDIA_TYPE_VIDEO,
yading@10 151 .id = AV_CODEC_ID_TQI,
yading@10 152 .priv_data_size = sizeof(TqiContext),
yading@10 153 .init = tqi_decode_init,
yading@10 154 .close = tqi_decode_end,
yading@10 155 .decode = tqi_decode_frame,
yading@10 156 .capabilities = CODEC_CAP_DR1,
yading@10 157 .long_name = NULL_IF_CONFIG_SMALL("Electronic Arts TQI Video"),
yading@10 158 };