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 avctx
->pix_fmt
= PIX_FMT_YUV422P16
;
31 avctx
->bits_per_raw_sample
= 10;
33 avctx
->coded_frame
= avcodec_alloc_frame();
38 static int decode_frame(AVCodecContext
*avctx
, void *data
, int *data_size
, AVPacket
*avpkt
)
41 int width
= avctx
->width
;
42 AVFrame
*pic
= avctx
->coded_frame
;
43 const uint32_t *src
= (const uint32_t *)avpkt
->data
;
44 uint16_t *ydst
, *udst
, *vdst
, *yend
;
47 avctx
->release_buffer(avctx
, pic
);
49 if(avpkt
->size
< avctx
->width
* avctx
->height
* 8 / 3){
50 av_log(avctx
, AV_LOG_ERROR
, "Packet too small\n");
54 if(avpkt
->size
> avctx
->width
* avctx
->height
* 8 / 3){
55 av_log(avctx
, AV_LOG_ERROR
, "Probably padded data, need sample!\n");
59 if(avctx
->get_buffer(avctx
, pic
) < 0)
62 ydst
= (uint16_t *)pic
->data
[0];
63 udst
= (uint16_t *)pic
->data
[1];
64 vdst
= (uint16_t *)pic
->data
[2];
66 pic
->pict_type
= FF_I_TYPE
;
70 uint32_t v
= be2me_32(*src
++);
71 *udst
++= (v
>>16) & 0xFFC0;
72 *ydst
++= (v
>>6 ) & 0xFFC0;
73 *vdst
++= (v
<<4 ) & 0xFFC0;
76 *ydst
++= (v
>>16) & 0xFFC0;
79 ydst
+= pic
->linesize
[0]/2 - width
;
80 udst
+= pic
->linesize
[1]/2 - width
/2;
81 vdst
+= pic
->linesize
[2]/2 - width
/2;
83 if(++y
>= avctx
->height
)
87 *udst
++= (v
>>6 ) & 0xFFC0;
88 *ydst
++= (v
<<4 ) & 0xFFC0;
91 *vdst
++= (v
>>16) & 0xFFC0;
92 *ydst
++= (v
>>6 ) & 0xFFC0;
95 ydst
+= pic
->linesize
[0]/2 - width
;
96 udst
+= pic
->linesize
[1]/2 - width
/2;
97 vdst
+= pic
->linesize
[2]/2 - width
/2;
99 if(++y
>= avctx
->height
)
103 *udst
++= (v
<<4 ) & 0xFFC0;
106 *ydst
++= (v
>>16) & 0xFFC0;
107 *vdst
++= (v
>>6 ) & 0xFFC0;
108 *ydst
++= (v
<<4 ) & 0xFFC0;
110 ydst
+= pic
->linesize
[0]/2 - width
;
111 udst
+= pic
->linesize
[1]/2 - width
/2;
112 vdst
+= pic
->linesize
[2]/2 - width
/2;
114 if(++y
>= avctx
->height
)
119 *data_size
=sizeof(AVFrame
);
120 *(AVFrame
*)data
= *avctx
->coded_frame
;
125 static av_cold
int decode_close(AVCodecContext
*avctx
)
127 AVFrame
*pic
= avctx
->coded_frame
;
129 avctx
->release_buffer(avctx
, pic
);
130 av_freep(&avctx
->coded_frame
);
135 AVCodec v210x_decoder
= {