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;
53
if ( avctx->codec_tag == MKTAG('0', '1', '2', 'v')
54
&& avpkt->size % avctx->height == 0
55
&& avpkt->size / avctx->height * 3 >= width * 8)
56
stride = avpkt->size / avctx->height;
58
if (avpkt->size < avctx->height * stride) {
59
av_log(avctx, AV_LOG_ERROR, "Packet too small: %d instead of %d\n",
60
avpkt->size, avctx->height * stride);
61
return AVERROR_INVALIDDATA;
64
if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
67
pic->pict_type = AV_PICTURE_TYPE_I;
70
y = (uint16_t *)pic->data[0];
71
u = (uint16_t *)pic->data[1];
72
v = (uint16_t *)pic->data[2];
73
line_end = avpkt->data + stride;
75
while (line++ < avctx->height) {
77
uint32_t t = AV_RL32(src);
79
*u++ = t << 6 & 0xFFC0;
80
*y++ = t >> 4 & 0xFFC0;
81
*v++ = t >> 14 & 0xFFC0;
83
if (src >= line_end - 1) {
87
y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
88
u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
89
v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
95
*y++ = t << 6 & 0xFFC0;
96
*u++ = t >> 4 & 0xFFC0;
97
*y++ = t >> 14 & 0xFFC0;
98
if (src >= line_end - 2) {
104
y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
105
u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
106
v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
112
*v++ = t << 6 & 0xFFC0;
113
*y++ = t >> 4 & 0xFFC0;
114
*u++ = t >> 14 & 0xFFC0;
116
if (src >= line_end - 1) {
120
y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
121
u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
122
v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
128
*y++ = t << 6 & 0xFFC0;
129
*v++ = t >> 4 & 0xFFC0;
130
*y++ = t >> 14 & 0xFFC0;
132
if (src >= line_end - 2) {
138
y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
139
u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
140
v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
151
AVCodec ff_zero12v_decoder = {
153
.long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
154
.type = AVMEDIA_TYPE_VIDEO,
155
.id = AV_CODEC_ID_012V,
156
.init = zero12v_decode_init,
157
.decode = zero12v_decode_frame,
158
.capabilities = CODEC_CAP_DR1,