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 #include "libavutil/intreadwrite.h"
27 static av_cold int zero12v_decode_init(AVCodecContext *avctx)
29 avctx->pix_fmt = AV_PIX_FMT_YUV422P16;
30 avctx->bits_per_raw_sample = 10;
32 if (avctx->codec_tag == MKTAG('a', '1', '2', 'v'))
33 avpriv_request_sample(avctx, "transparency");
38 static int zero12v_decode_frame(AVCodecContext *avctx, void *data,
39 int *got_frame, AVPacket *avpkt)
42 const int width = avctx->width;
45 const uint8_t *line_end, *src = avpkt->data;
46 int stride = avctx->width * 8 / 3;
49 av_log(avctx, AV_LOG_ERROR, "Width 1 not supported.\n");
50 return AVERROR_INVALIDDATA;
52 if (avpkt->size < avctx->height * stride) {
53 av_log(avctx, AV_LOG_ERROR, "Packet too small: %d instead of %d\n",
54 avpkt->size, avctx->height * stride);
55 return AVERROR_INVALIDDATA;
58 if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
61 pic->pict_type = AV_PICTURE_TYPE_I;
64 y = (uint16_t *)pic->data[0];
65 u = (uint16_t *)pic->data[1];
66 v = (uint16_t *)pic->data[2];
67 line_end = avpkt->data + stride;
69 while (line++ < avctx->height) {
71 uint32_t t = AV_RL32(src);
73 *u++ = t << 6 & 0xFFC0;
74 *y++ = t >> 4 & 0xFFC0;
75 *v++ = t >> 14 & 0xFFC0;
77 if (src >= line_end - 1) {
81 y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
82 u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
83 v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
89 *y++ = t << 6 & 0xFFC0;
90 *u++ = t >> 4 & 0xFFC0;
91 *y++ = t >> 14 & 0xFFC0;
92 if (src >= line_end - 2) {
98 y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
99 u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
100 v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
106 *v++ = t << 6 & 0xFFC0;
107 *y++ = t >> 4 & 0xFFC0;
108 *u++ = t >> 14 & 0xFFC0;
110 if (src >= line_end - 1) {
114 y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
115 u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
116 v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
122 *y++ = t << 6 & 0xFFC0;
123 *v++ = t >> 4 & 0xFFC0;
124 *y++ = t >> 14 & 0xFFC0;
126 if (src >= line_end - 2) {
132 y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
133 u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
134 v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
145 AVCodec ff_zero12v_decoder = {
147 .type = AVMEDIA_TYPE_VIDEO,
148 .id = AV_CODEC_ID_012V,
149 .init = zero12v_decode_init,
150 .decode = zero12v_decode_frame,
151 .capabilities = CODEC_CAP_DR1,
152 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),