Mercurial > libavcodec.hg
comparison vcr1.c @ 1374:f9b088451fb3 libavcodec
ATI VCR1 decoder
author | michaelni |
---|---|
date | Thu, 24 Jul 2003 12:18:46 +0000 |
parents | |
children | c93d893f6d2b |
comparison
equal
deleted
inserted
replaced
1373:b47a402bbe7f | 1374:f9b088451fb3 |
---|---|
1 /* | |
2 * ATI VCR1 codec | |
3 * Copyright (c) 2003 Michael Niedermayer | |
4 * | |
5 * This library is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2 of the License, or (at your option) any later version. | |
9 * | |
10 * This library is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Lesser General Public | |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 */ | |
19 | |
20 /** | |
21 * @file vcr1.c | |
22 * ati vcr1 codec. | |
23 */ | |
24 | |
25 #include "avcodec.h" | |
26 #include "mpegvideo.h" | |
27 | |
28 //#undef NDEBUG | |
29 //#include <assert.h> | |
30 | |
31 typedef struct VCR1Context{ | |
32 AVCodecContext *avctx; | |
33 AVFrame picture; | |
34 int delta[16]; | |
35 int offset[4]; | |
36 } VCR1Context; | |
37 | |
38 static int decode_frame(AVCodecContext *avctx, | |
39 void *data, int *data_size, | |
40 uint8_t *buf, int buf_size) | |
41 { | |
42 VCR1Context * const a = avctx->priv_data; | |
43 AVFrame *picture = data; | |
44 AVFrame * const p= (AVFrame*)&a->picture; | |
45 uint8_t *bytestream= buf; | |
46 int i, x, y; | |
47 | |
48 *data_size = 0; | |
49 | |
50 /* special case for last picture */ | |
51 if (buf_size == 0) { | |
52 return 0; | |
53 } | |
54 | |
55 if(p->data[0]) | |
56 avctx->release_buffer(avctx, p); | |
57 | |
58 p->reference= 0; | |
59 if(avctx->get_buffer(avctx, p) < 0){ | |
60 fprintf(stderr, "get_buffer() failed\n"); | |
61 return -1; | |
62 } | |
63 p->pict_type= I_TYPE; | |
64 p->key_frame= 1; | |
65 | |
66 for(i=0; i<16; i++){ | |
67 a->delta[i]= *(bytestream++); | |
68 bytestream++; | |
69 } | |
70 | |
71 for(y=0; y<avctx->height; y++){ | |
72 int offset; | |
73 uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ]; | |
74 | |
75 if((y&3) == 0){ | |
76 uint8_t *cb= &a->picture.data[1][ (y>>2)*a->picture.linesize[1] ]; | |
77 uint8_t *cr= &a->picture.data[2][ (y>>2)*a->picture.linesize[2] ]; | |
78 | |
79 for(i=0; i<4; i++) | |
80 a->offset[i]= *(bytestream++); | |
81 | |
82 offset= a->offset[0]; | |
83 for(x=0; x<avctx->width; x+=4){ | |
84 luma[0]=( offset += a->delta[ bytestream[2]&0xF ]); | |
85 luma[1]=( offset += a->delta[ bytestream[2]>>4 ]); | |
86 luma[2]=( offset += a->delta[ bytestream[0]&0xF ]); | |
87 luma[3]=( offset += a->delta[ bytestream[0]>>4 ]); | |
88 luma += 4; | |
89 | |
90 *(cb++) = bytestream[1]; | |
91 *(cr++) = bytestream[3]; | |
92 | |
93 bytestream+= 4; | |
94 } | |
95 }else{ | |
96 offset= a->offset[y&3]; | |
97 | |
98 for(x=0; x<avctx->width; x+=8){ | |
99 luma[0]=( offset += a->delta[ bytestream[2]&0xF ]); | |
100 luma[1]=( offset += a->delta[ bytestream[2]>>4 ]); | |
101 luma[2]=( offset += a->delta[ bytestream[3]&0xF ]); | |
102 luma[3]=( offset += a->delta[ bytestream[3]>>4 ]); | |
103 luma[4]=( offset += a->delta[ bytestream[0]&0xF ]); | |
104 luma[5]=( offset += a->delta[ bytestream[0]>>4 ]); | |
105 luma[6]=( offset += a->delta[ bytestream[1]&0xF ]); | |
106 luma[7]=( offset += a->delta[ bytestream[1]>>4 ]); | |
107 luma += 8; | |
108 bytestream+= 4; | |
109 } | |
110 } | |
111 } | |
112 | |
113 *picture= *(AVFrame*)&a->picture; | |
114 *data_size = sizeof(AVPicture); | |
115 | |
116 emms_c(); | |
117 | |
118 return buf_size; | |
119 } | |
120 | |
121 #if 0 | |
122 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ | |
123 VCR1Context * const a = avctx->priv_data; | |
124 AVFrame *pict = data; | |
125 AVFrame * const p= (AVFrame*)&a->picture; | |
126 int size; | |
127 int mb_x, mb_y; | |
128 | |
129 *p = *pict; | |
130 p->pict_type= I_TYPE; | |
131 p->key_frame= 1; | |
132 | |
133 emms_c(); | |
134 | |
135 align_put_bits(&a->pb); | |
136 while(get_bit_count(&a->pb)&31) | |
137 put_bits(&a->pb, 8, 0); | |
138 | |
139 size= get_bit_count(&a->pb)/32; | |
140 | |
141 return size*4; | |
142 } | |
143 #endif | |
144 | |
145 static void common_init(AVCodecContext *avctx){ | |
146 VCR1Context * const a = avctx->priv_data; | |
147 | |
148 avctx->coded_frame= (AVFrame*)&a->picture; | |
149 a->avctx= avctx; | |
150 } | |
151 | |
152 static int decode_init(AVCodecContext *avctx){ | |
153 VCR1Context * const a = avctx->priv_data; | |
154 AVFrame *p= (AVFrame*)&a->picture; | |
155 int i; | |
156 | |
157 common_init(avctx); | |
158 | |
159 avctx->pix_fmt= PIX_FMT_YUV410P; | |
160 | |
161 return 0; | |
162 } | |
163 | |
164 static int encode_init(AVCodecContext *avctx){ | |
165 VCR1Context * const a = avctx->priv_data; | |
166 int i; | |
167 | |
168 common_init(avctx); | |
169 | |
170 return 0; | |
171 } | |
172 | |
173 static int decode_end(AVCodecContext *avctx){ | |
174 VCR1Context * const a = avctx->priv_data; | |
175 | |
176 avcodec_default_free_buffers(avctx); | |
177 | |
178 return 0; | |
179 } | |
180 | |
181 AVCodec vcr1_decoder = { | |
182 "vcr1", | |
183 CODEC_TYPE_VIDEO, | |
184 CODEC_ID_VCR1, | |
185 sizeof(VCR1Context), | |
186 decode_init, | |
187 NULL, | |
188 decode_end, | |
189 decode_frame, | |
190 CODEC_CAP_DR1, | |
191 }; | |
192 #if 0 | |
193 #ifdef CONFIG_ENCODERS | |
194 | |
195 AVCodec vcr1_encoder = { | |
196 "vcr1", | |
197 CODEC_TYPE_VIDEO, | |
198 CODEC_ID_VCR1, | |
199 sizeof(VCR1Context), | |
200 encode_init, | |
201 encode_frame, | |
202 //encode_end, | |
203 }; | |
204 | |
205 #endif //CONFIG_ENCODERS | |
206 #endif |