2 * Copyright (C) 2009 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of Libav.
6 * Libav is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * Libav is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Libav; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "libavutil/bswap.h"
24 #include "libavutil/internal.h"
25 #include "libavutil/mem.h"
27 static av_cold int decode_init(AVCodecContext *avctx)
29 if (avctx->width & 1) {
30 av_log(avctx, AV_LOG_ERROR, "v210x needs even width\n");
31 return AVERROR(EINVAL);
33 avctx->pix_fmt = AV_PIX_FMT_YUV422P16;
34 avctx->bits_per_raw_sample = 10;
36 avctx->coded_frame= avcodec_alloc_frame();
41 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
44 const uint32_t *src = (const uint32_t *)avpkt->data;
45 AVFrame *pic = avctx->coded_frame;
46 int width = avctx->width;
48 uint16_t *ydst, *udst, *vdst, *yend;
52 avctx->release_buffer(avctx, pic);
54 if (avpkt->size < avctx->width * avctx->height * 8 / 3) {
55 av_log(avctx, AV_LOG_ERROR, "Packet too small\n");
56 return AVERROR_INVALIDDATA;
59 if (avpkt->size > avctx->width * avctx->height * 8 / 3) {
60 av_log_ask_for_sample(avctx, "Probably padded data\n");
64 if ((ret = ff_get_buffer(avctx, pic)) < 0)
67 ydst = (uint16_t *)pic->data[0];
68 udst = (uint16_t *)pic->data[1];
69 vdst = (uint16_t *)pic->data[2];
71 pic->pict_type = AV_PICTURE_TYPE_I;
75 uint32_t v = av_be2ne32(*src++);
76 *udst++ = (v >> 16) & 0xFFC0;
77 *ydst++ = (v >> 6 ) & 0xFFC0;
78 *vdst++ = (v << 4 ) & 0xFFC0;
80 v = av_be2ne32(*src++);
81 *ydst++ = (v >> 16) & 0xFFC0;
84 ydst += pic->linesize[0] / 2 - width;
85 udst += pic->linesize[1] / 2 - width / 2;
86 vdst += pic->linesize[2] / 2 - width / 2;
88 if (++y >= avctx->height)
92 *udst++ = (v >> 6 ) & 0xFFC0;
93 *ydst++ = (v << 4 ) & 0xFFC0;
95 v = av_be2ne32(*src++);
96 *vdst++ = (v >> 16) & 0xFFC0;
97 *ydst++ = (v >> 6 ) & 0xFFC0;
100 ydst += pic->linesize[0] / 2 - width;
101 udst += pic->linesize[1] / 2 - width / 2;
102 vdst += pic->linesize[2] / 2 - width / 2;
104 if (++y >= avctx->height)
108 *udst++ = (v << 4 ) & 0xFFC0;
110 v = av_be2ne32(*src++);
111 *ydst++ = (v >> 16) & 0xFFC0;
112 *vdst++ = (v >> 6 ) & 0xFFC0;
113 *ydst++ = (v << 4 ) & 0xFFC0;
115 ydst += pic->linesize[0] / 2 - width;
116 udst += pic->linesize[1] / 2 - width / 2;
117 vdst += pic->linesize[2] / 2 - width / 2;
119 if (++y >= avctx->height)
125 *(AVFrame*)data= *avctx->coded_frame;
130 static av_cold int decode_close(AVCodecContext *avctx)
132 AVFrame *pic = avctx->coded_frame;
134 avctx->release_buffer(avctx, pic);
135 av_freep(&avctx->coded_frame);
140 AVCodec ff_v210x_decoder = {
142 .type = AVMEDIA_TYPE_VIDEO,
143 .id = AV_CODEC_ID_V210X,
145 .close = decode_close,
146 .decode = decode_frame,
147 .capabilities = CODEC_CAP_DR1,
148 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),