Typo in softfloat_reciprocal comment.
[FFMpeg-mirror/lagarith.git] / libavcodec / v210x.c
blob549a157f418b990e371f43856776bb1865e00add
1 /*
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
21 #include "avcodec.h"
22 #include "libavutil/bswap.h"
24 static av_cold int decode_init(AVCodecContext *avctx)
26 if(avctx->width & 1){
27 av_log(avctx, AV_LOG_ERROR, "v210x needs even width\n");
28 return -1;
30 avctx->pix_fmt = PIX_FMT_YUV422P16;
31 avctx->bits_per_raw_sample= 10;
33 avctx->coded_frame= avcodec_alloc_frame();
35 return 0;
38 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
40 int y=0;
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;
46 if(pic->data[0])
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");
51 return -1;
54 if(avpkt->size > avctx->width * avctx->height * 8 / 3){
55 av_log(avctx, AV_LOG_ERROR, "Probably padded data, need sample!\n");
58 pic->reference= 0;
59 if(avctx->get_buffer(avctx, pic) < 0)
60 return -1;
62 ydst= (uint16_t *)pic->data[0];
63 udst= (uint16_t *)pic->data[1];
64 vdst= (uint16_t *)pic->data[2];
65 yend= ydst + width;
66 pic->pict_type= FF_I_TYPE;
67 pic->key_frame= 1;
69 for(;;){
70 uint32_t v= be2me_32(*src++);
71 *udst++= (v>>16) & 0xFFC0;
72 *ydst++= (v>>6 ) & 0xFFC0;
73 *vdst++= (v<<4 ) & 0xFFC0;
75 v= be2me_32(*src++);
76 *ydst++= (v>>16) & 0xFFC0;
78 if(ydst >= yend){
79 ydst+= pic->linesize[0]/2 - width;
80 udst+= pic->linesize[1]/2 - width/2;
81 vdst+= pic->linesize[2]/2 - width/2;
82 yend= ydst + width;
83 if(++y >= avctx->height)
84 break;
87 *udst++= (v>>6 ) & 0xFFC0;
88 *ydst++= (v<<4 ) & 0xFFC0;
90 v= be2me_32(*src++);
91 *vdst++= (v>>16) & 0xFFC0;
92 *ydst++= (v>>6 ) & 0xFFC0;
94 if(ydst >= yend){
95 ydst+= pic->linesize[0]/2 - width;
96 udst+= pic->linesize[1]/2 - width/2;
97 vdst+= pic->linesize[2]/2 - width/2;
98 yend= ydst + width;
99 if(++y >= avctx->height)
100 break;
103 *udst++= (v<<4 ) & 0xFFC0;
105 v= be2me_32(*src++);
106 *ydst++= (v>>16) & 0xFFC0;
107 *vdst++= (v>>6 ) & 0xFFC0;
108 *ydst++= (v<<4 ) & 0xFFC0;
109 if(ydst >= yend){
110 ydst+= pic->linesize[0]/2 - width;
111 udst+= pic->linesize[1]/2 - width/2;
112 vdst+= pic->linesize[2]/2 - width/2;
113 yend= ydst + width;
114 if(++y >= avctx->height)
115 break;
119 *data_size=sizeof(AVFrame);
120 *(AVFrame*)data= *avctx->coded_frame;
122 return avpkt->size;
125 static av_cold int decode_close(AVCodecContext *avctx)
127 AVFrame *pic = avctx->coded_frame;
128 if (pic->data[0])
129 avctx->release_buffer(avctx, pic);
130 av_freep(&avctx->coded_frame);
132 return 0;
135 AVCodec v210x_decoder = {
136 "v210x",
137 CODEC_TYPE_VIDEO,
138 CODEC_ID_V210X,
140 decode_init,
141 NULL,
142 decode_close,
143 decode_frame,
144 CODEC_CAP_DR1,