2 * AVID Meridien decoder
4 * Copyright (c) 2012 Carl Eugen Hoyos
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 static av_cold int avui_decode_init(AVCodecContext *avctx)
27 avctx->pix_fmt = PIX_FMT_YUVA422P;
29 avctx->coded_frame = avcodec_alloc_frame();
31 if (!avctx->coded_frame) {
32 av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
33 return AVERROR(ENOMEM);
39 static int avui_decode_frame(AVCodecContext *avctx, void *data,
40 int *data_size, AVPacket *avpkt)
42 AVFrame *pic = avctx->coded_frame;
43 const uint8_t *src = avpkt->data;
44 const uint8_t *srca = src + 2 * (avctx->height + 16) * avctx->width + 9;
45 uint8_t *y, *u, *v, *a;
46 int transparent = 0, i, j, k;
49 avctx->release_buffer(avctx, pic);
51 if (avpkt->size < 2 * avctx->width * (avctx->height + 16) + 4) {
52 av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n");
53 return AVERROR(EINVAL);
55 if (avpkt->size >= 4 * avctx->width * (avctx->height + 16) + 13)
60 if (avctx->get_buffer(avctx, pic) < 0) {
61 av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n");
62 return AVERROR(ENOMEM);
66 pic->pict_type = AV_PICTURE_TYPE_I;
68 for (i = 0; i < 2; i++) {
69 src += avctx->width * 16;
70 srca += avctx->width * 16;
71 y = pic->data[0] + i * pic->linesize[0];
72 u = pic->data[1] + i * pic->linesize[1];
73 v = pic->data[2] + i * pic->linesize[2];
74 a = pic->data[3] + i * pic->linesize[3];
76 for (j = 0; j < (avctx->height + 1) >> 1; j++) {
77 for (k = 0; k < (avctx->width + 1) >> 1; k++) {
80 a[2 * k ] = 0xFF - (transparent ? *srca++ : 0);
83 y[2 * k + 1] = *src++;
84 a[2 * k + 1] = 0xFF - (transparent ? *srca++ : 0);
88 y += 2 * pic->linesize[0];
89 u += 2 * pic->linesize[1];
90 v += 2 * pic->linesize[2];
91 a += 2 * pic->linesize[3];
96 *data_size = sizeof(AVFrame);
97 *(AVFrame *)data = *pic;
102 static av_cold int avui_decode_close(AVCodecContext *avctx)
104 if (avctx->coded_frame->data[0])
105 avctx->release_buffer(avctx, avctx->coded_frame);
107 av_freep(&avctx->coded_frame);
112 AVCodec ff_avui_decoder = {
114 .type = AVMEDIA_TYPE_VIDEO,
116 .init = avui_decode_init,
117 .decode = avui_decode_frame,
118 .close = avui_decode_close,
119 .capabilities = CODEC_CAP_DR1,
120 .long_name = NULL_IF_CONFIG_SMALL("AVID Meridien"),