3 * Copyright (c) 2012 Carl Eugen Hoyos
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 static av_cold int v408_decode_init(AVCodecContext *avctx)
26 avctx->pix_fmt = AV_PIX_FMT_YUVA444P;
28 avctx->coded_frame = avcodec_alloc_frame();
30 if (!avctx->coded_frame) {
31 av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
32 return AVERROR(ENOMEM);
38 static int v408_decode_frame(AVCodecContext *avctx, void *data,
39 int *data_size, AVPacket *avpkt)
41 AVFrame *pic = avctx->coded_frame;
42 const uint8_t *src = avpkt->data;
43 uint8_t *y, *u, *v, *a;
47 avctx->release_buffer(avctx, pic);
49 if (avpkt->size < 4 * avctx->height * avctx->width) {
50 av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n");
51 return AVERROR(EINVAL);
56 if (avctx->get_buffer(avctx, pic) < 0) {
57 av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n");
58 return AVERROR(ENOMEM);
62 pic->pict_type = AV_PICTURE_TYPE_I;
69 for (i = 0; i < avctx->height; i++) {
70 for (j = 0; j < avctx->width; j++) {
71 if (avctx->codec_id==AV_CODEC_ID_AYUV) {
84 y += pic->linesize[0];
85 u += pic->linesize[1];
86 v += pic->linesize[2];
87 a += pic->linesize[3];
90 *data_size = sizeof(AVFrame);
91 *(AVFrame *)data = *pic;
96 static av_cold int v408_decode_close(AVCodecContext *avctx)
98 if (avctx->coded_frame->data[0])
99 avctx->release_buffer(avctx, avctx->coded_frame);
101 av_freep(&avctx->coded_frame);
106 #if CONFIG_AYUV_DECODER
107 AVCodec ff_ayuv_decoder = {
109 .type = AVMEDIA_TYPE_VIDEO,
110 .id = AV_CODEC_ID_AYUV,
111 .init = v408_decode_init,
112 .decode = v408_decode_frame,
113 .close = v408_decode_close,
114 .capabilities = CODEC_CAP_DR1,
115 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed MS 4:4:4:4"),
118 #if CONFIG_V408_DECODER
119 AVCodec ff_v408_decoder = {
121 .type = AVMEDIA_TYPE_VIDEO,
122 .id = AV_CODEC_ID_V408,
123 .init = v408_decode_init,
124 .decode = v408_decode_frame,
125 .close = v408_decode_close,
126 .capabilities = CODEC_CAP_DR1,
127 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed QT 4:4:4:4"),