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"
24 static av_cold int decode_init(AVCodecContext *avctx)
27 av_log(avctx, AV_LOG_ERROR, "v210x needs even width\n");
30 if(avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0)
32 avctx->pix_fmt = PIX_FMT_YUV422P16;
33 avctx->bits_per_raw_sample= 10;
35 avctx->coded_frame= avcodec_alloc_frame();
40 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
43 int width= avctx->width;
44 AVFrame *pic= avctx->coded_frame;
45 const uint32_t *src= (const uint32_t *)avpkt->data;
46 uint16_t *ydst, *udst, *vdst, *yend;
49 avctx->release_buffer(avctx, pic);
51 if(avpkt->size < avctx->width * avctx->height * 8 / 3){
52 av_log(avctx, AV_LOG_ERROR, "Packet too small\n");
56 if(avpkt->size > avctx->width * avctx->height * 8 / 3){
57 av_log(avctx, AV_LOG_ERROR, "Probably padded data, need sample!\n");
61 if(avctx->get_buffer(avctx, pic) < 0)
64 ydst= (uint16_t *)pic->data[0];
65 udst= (uint16_t *)pic->data[1];
66 vdst= (uint16_t *)pic->data[2];
68 pic->pict_type= FF_I_TYPE;
72 uint32_t v= be2me_32(*src++);
73 *udst++= (v>>16) & 0xFFC0;
74 *ydst++= (v>>6 ) & 0xFFC0;
75 *vdst++= (v<<4 ) & 0xFFC0;
78 *ydst++= (v>>16) & 0xFFC0;
81 ydst+= pic->linesize[0]/2 - width;
82 udst+= pic->linesize[1]/2 - width/2;
83 vdst+= pic->linesize[2]/2 - width/2;
85 if(++y >= avctx->height)
89 *udst++= (v>>6 ) & 0xFFC0;
90 *ydst++= (v<<4 ) & 0xFFC0;
93 *vdst++= (v>>16) & 0xFFC0;
94 *ydst++= (v>>6 ) & 0xFFC0;
97 ydst+= pic->linesize[0]/2 - width;
98 udst+= pic->linesize[1]/2 - width/2;
99 vdst+= pic->linesize[2]/2 - width/2;
101 if(++y >= avctx->height)
105 *udst++= (v<<4 ) & 0xFFC0;
108 *ydst++= (v>>16) & 0xFFC0;
109 *vdst++= (v>>6 ) & 0xFFC0;
110 *ydst++= (v<<4 ) & 0xFFC0;
112 ydst+= pic->linesize[0]/2 - width;
113 udst+= pic->linesize[1]/2 - width/2;
114 vdst+= pic->linesize[2]/2 - width/2;
116 if(++y >= avctx->height)
121 *data_size=sizeof(AVFrame);
122 *(AVFrame*)data= *avctx->coded_frame;
127 AVCodec v210x_decoder = {