2 * Copyright (C) 2009 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of FFmpeg.
6 * FFmpeg 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 * FFmpeg 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 FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "libavutil/bswap.h"
23 #include "libavutil/internal.h"
24 #include "libavutil/mem.h"
26 static av_cold int decode_init(AVCodecContext *avctx)
29 av_log(avctx, AV_LOG_ERROR, "v210x needs even width\n");
32 avctx->pix_fmt = AV_PIX_FMT_YUV422P16;
33 avctx->bits_per_raw_sample= 10;
35 avctx->coded_frame= avcodec_alloc_frame();
36 if (!avctx->coded_frame)
37 return AVERROR(ENOMEM);
42 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
45 int width= avctx->width;
46 AVFrame *pic= avctx->coded_frame;
47 const uint32_t *src= (const uint32_t *)avpkt->data;
48 uint16_t *ydst, *udst, *vdst, *yend;
51 avctx->release_buffer(avctx, pic);
53 if(avpkt->size < avctx->width * avctx->height * 8 / 3){
54 av_log(avctx, AV_LOG_ERROR, "Packet too small\n");
58 if(avpkt->size > avctx->width * avctx->height * 8 / 3){
59 av_log_ask_for_sample(avctx, "Probably padded data\n");
63 if(avctx->get_buffer(avctx, pic) < 0)
66 ydst= (uint16_t *)pic->data[0];
67 udst= (uint16_t *)pic->data[1];
68 vdst= (uint16_t *)pic->data[2];
70 pic->pict_type= AV_PICTURE_TYPE_I;
74 uint32_t v= av_be2ne32(*src++);
75 *udst++= (v>>16) & 0xFFC0;
76 *ydst++= (v>>6 ) & 0xFFC0;
77 *vdst++= (v<<4 ) & 0xFFC0;
79 v= av_be2ne32(*src++);
80 *ydst++= (v>>16) & 0xFFC0;
83 ydst+= pic->linesize[0]/2 - width;
84 udst+= pic->linesize[1]/2 - width/2;
85 vdst+= pic->linesize[2]/2 - width/2;
87 if(++y >= avctx->height)
91 *udst++= (v>>6 ) & 0xFFC0;
92 *ydst++= (v<<4 ) & 0xFFC0;
94 v= av_be2ne32(*src++);
95 *vdst++= (v>>16) & 0xFFC0;
96 *ydst++= (v>>6 ) & 0xFFC0;
99 ydst+= pic->linesize[0]/2 - width;
100 udst+= pic->linesize[1]/2 - width/2;
101 vdst+= pic->linesize[2]/2 - width/2;
103 if(++y >= avctx->height)
107 *udst++= (v<<4 ) & 0xFFC0;
109 v= av_be2ne32(*src++);
110 *ydst++= (v>>16) & 0xFFC0;
111 *vdst++= (v>>6 ) & 0xFFC0;
112 *ydst++= (v<<4 ) & 0xFFC0;
114 ydst+= pic->linesize[0]/2 - width;
115 udst+= pic->linesize[1]/2 - width/2;
116 vdst+= pic->linesize[2]/2 - width/2;
118 if(++y >= avctx->height)
123 *data_size=sizeof(AVFrame);
124 *(AVFrame*)data= *avctx->coded_frame;
129 static av_cold int decode_close(AVCodecContext *avctx)
131 AVFrame *pic = avctx->coded_frame;
133 avctx->release_buffer(avctx, pic);
134 av_freep(&avctx->coded_frame);
139 AVCodec ff_v210x_decoder = {
141 .type = AVMEDIA_TYPE_VIDEO,
142 .id = AV_CODEC_ID_V210X,
144 .close = decode_close,
145 .decode = decode_frame,
146 .capabilities = CODEC_CAP_DR1,
147 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),