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
23 #include "libavutil/bswap.h"
24 #include "libavutil/internal.h"
25 #include "libavutil/mem.h"
27 static av_cold int decode_init(AVCodecContext *avctx)
30 av_log(avctx, AV_LOG_ERROR, "v210x needs even width\n");
33 avctx->pix_fmt = AV_PIX_FMT_YUV422P16;
34 avctx->bits_per_raw_sample= 10;
36 avctx->coded_frame= avcodec_alloc_frame();
37 if (!avctx->coded_frame)
38 return AVERROR(ENOMEM);
43 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
47 int width= avctx->width;
48 AVFrame *pic= avctx->coded_frame;
49 const uint32_t *src= (const uint32_t *)avpkt->data;
50 uint16_t *ydst, *udst, *vdst, *yend;
53 avctx->release_buffer(avctx, pic);
55 if(avpkt->size < avctx->width * avctx->height * 8 / 3){
56 av_log(avctx, AV_LOG_ERROR, "Packet too small\n");
60 if(avpkt->size > avctx->width * avctx->height * 8 / 3){
61 av_log_ask_for_sample(avctx, "Probably padded data\n");
65 if(ff_get_buffer(avctx, pic) < 0)
68 ydst= (uint16_t *)pic->data[0];
69 udst= (uint16_t *)pic->data[1];
70 vdst= (uint16_t *)pic->data[2];
72 pic->pict_type= AV_PICTURE_TYPE_I;
76 uint32_t v= av_be2ne32(*src++);
77 *udst++= (v>>16) & 0xFFC0;
78 *ydst++= (v>>6 ) & 0xFFC0;
79 *vdst++= (v<<4 ) & 0xFFC0;
81 v= av_be2ne32(*src++);
82 *ydst++= (v>>16) & 0xFFC0;
85 ydst+= pic->linesize[0]/2 - width;
86 udst+= pic->linesize[1]/2 - width/2;
87 vdst+= pic->linesize[2]/2 - width/2;
89 if(++y >= avctx->height)
93 *udst++= (v>>6 ) & 0xFFC0;
94 *ydst++= (v<<4 ) & 0xFFC0;
96 v= av_be2ne32(*src++);
97 *vdst++= (v>>16) & 0xFFC0;
98 *ydst++= (v>>6 ) & 0xFFC0;
101 ydst+= pic->linesize[0]/2 - width;
102 udst+= pic->linesize[1]/2 - width/2;
103 vdst+= pic->linesize[2]/2 - width/2;
105 if(++y >= avctx->height)
109 *udst++= (v<<4 ) & 0xFFC0;
111 v= av_be2ne32(*src++);
112 *ydst++= (v>>16) & 0xFFC0;
113 *vdst++= (v>>6 ) & 0xFFC0;
114 *ydst++= (v<<4 ) & 0xFFC0;
116 ydst+= pic->linesize[0]/2 - width;
117 udst+= pic->linesize[1]/2 - width/2;
118 vdst+= pic->linesize[2]/2 - width/2;
120 if(++y >= avctx->height)
126 *(AVFrame*)data= *avctx->coded_frame;
131 static av_cold int decode_close(AVCodecContext *avctx)
133 AVFrame *pic = avctx->coded_frame;
135 avctx->release_buffer(avctx, pic);
136 av_freep(&avctx->coded_frame);
141 AVCodec ff_v210x_decoder = {
143 .type = AVMEDIA_TYPE_VIDEO,
144 .id = AV_CODEC_ID_V210X,
146 .close = decode_close,
147 .decode = decode_frame,
148 .capabilities = CODEC_CAP_DR1,
149 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),