comparison mdec.c @ 2967:ef2149182f1c libavcodec

COSMETICS: Remove all trailing whitespace.
author diego
date Sat, 17 Dec 2005 18:14:38 +0000
parents 89b92f0800ab
children 0b546eab515d
comparison
equal deleted inserted replaced
2966:564788471dd4 2967:ef2149182f1c
16 * License along with this library; if not, write to the Free Software 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 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * 18 *
19 * based upon code from Sebastian Jedruszkiewicz <elf@frogger.rules.pl> 19 * based upon code from Sebastian Jedruszkiewicz <elf@frogger.rules.pl>
20 */ 20 */
21 21
22 /** 22 /**
23 * @file mdec.c 23 * @file mdec.c
24 * PSX MDEC codec. 24 * PSX MDEC codec.
25 * This is very similar to intra only MPEG1. 25 * This is very similar to intra only MPEG1.
26 */ 26 */
27 27
28 #include "avcodec.h" 28 #include "avcodec.h"
29 #include "dsputil.h" 29 #include "dsputil.h"
30 #include "mpegvideo.h" 30 #include "mpegvideo.h"
31 31
32 //#undef NDEBUG 32 //#undef NDEBUG
72 if (diff >= 0xffff) 72 if (diff >= 0xffff)
73 return -1; 73 return -1;
74 a->last_dc[component]+= diff; 74 a->last_dc[component]+= diff;
75 block[0] = a->last_dc[component]<<3; 75 block[0] = a->last_dc[component]<<3;
76 } 76 }
77 77
78 i = 0; 78 i = 0;
79 { 79 {
80 OPEN_READER(re, &a->gb); 80 OPEN_READER(re, &a->gb);
81 /* now quantify & encode AC coefs */ 81 /* now quantify & encode AC coefs */
82 for(;;) { 82 for(;;) {
83 UPDATE_CACHE(re, &a->gb); 83 UPDATE_CACHE(re, &a->gb);
84 GET_RL_VLC(level, run, re, &a->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); 84 GET_RL_VLC(level, run, re, &a->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
85 85
86 if(level == 127){ 86 if(level == 127){
87 break; 87 break;
88 } else if(level != 0) { 88 } else if(level != 0) {
89 i += run; 89 i += run;
90 j = scantable[i]; 90 j = scantable[i];
125 static inline int decode_mb(MDECContext *a, DCTELEM block[6][64]){ 125 static inline int decode_mb(MDECContext *a, DCTELEM block[6][64]){
126 int i; 126 int i;
127 const int block_index[6]= {5,4,0,1,2,3}; 127 const int block_index[6]= {5,4,0,1,2,3};
128 128
129 a->dsp.clear_blocks(block[0]); 129 a->dsp.clear_blocks(block[0]);
130 130
131 for(i=0; i<6; i++){ 131 for(i=0; i<6; i++){
132 if( mdec_decode_block_intra(a, block[ block_index[i] ], block_index[i]) < 0) 132 if( mdec_decode_block_intra(a, block[ block_index[i] ], block_index[i]) < 0)
133 return -1; 133 return -1;
134 } 134 }
135 return 0; 135 return 0;
136 } 136 }
137 137
138 static inline void idct_put(MDECContext *a, int mb_x, int mb_y){ 138 static inline void idct_put(MDECContext *a, int mb_x, int mb_y){
139 DCTELEM (*block)[64]= a->block; 139 DCTELEM (*block)[64]= a->block;
140 int linesize= a->picture.linesize[0]; 140 int linesize= a->picture.linesize[0];
141 141
142 uint8_t *dest_y = a->picture.data[0] + (mb_y * 16* linesize ) + mb_x * 16; 142 uint8_t *dest_y = a->picture.data[0] + (mb_y * 16* linesize ) + mb_x * 16;
143 uint8_t *dest_cb = a->picture.data[1] + (mb_y * 8 * a->picture.linesize[1]) + mb_x * 8; 143 uint8_t *dest_cb = a->picture.data[1] + (mb_y * 8 * a->picture.linesize[1]) + mb_x * 8;
144 uint8_t *dest_cr = a->picture.data[2] + (mb_y * 8 * a->picture.linesize[2]) + mb_x * 8; 144 uint8_t *dest_cr = a->picture.data[2] + (mb_y * 8 * a->picture.linesize[2]) + mb_x * 8;
145 145
146 a->dsp.idct_put(dest_y , linesize, block[0]); 146 a->dsp.idct_put(dest_y , linesize, block[0]);
152 a->dsp.idct_put(dest_cb, a->picture.linesize[1], block[4]); 152 a->dsp.idct_put(dest_cb, a->picture.linesize[1], block[4]);
153 a->dsp.idct_put(dest_cr, a->picture.linesize[2], block[5]); 153 a->dsp.idct_put(dest_cr, a->picture.linesize[2], block[5]);
154 } 154 }
155 } 155 }
156 156
157 static int decode_frame(AVCodecContext *avctx, 157 static int decode_frame(AVCodecContext *avctx,
158 void *data, int *data_size, 158 void *data, int *data_size,
159 uint8_t *buf, int buf_size) 159 uint8_t *buf, int buf_size)
160 { 160 {
161 MDECContext * const a = avctx->priv_data; 161 MDECContext * const a = avctx->priv_data;
162 AVFrame *picture = data; 162 AVFrame *picture = data;
181 for(i=0; i<buf_size; i+=2){ 181 for(i=0; i<buf_size; i+=2){
182 a->bitstream_buffer[i] = buf[i+1]; 182 a->bitstream_buffer[i] = buf[i+1];
183 a->bitstream_buffer[i+1]= buf[i ]; 183 a->bitstream_buffer[i+1]= buf[i ];
184 } 184 }
185 init_get_bits(&a->gb, a->bitstream_buffer, buf_size*8); 185 init_get_bits(&a->gb, a->bitstream_buffer, buf_size*8);
186 186
187 /* skip over 4 preamble bytes in stream (typically 0xXX 0xXX 0x00 0x38) */ 187 /* skip over 4 preamble bytes in stream (typically 0xXX 0xXX 0x00 0x38) */
188 skip_bits(&a->gb, 32); 188 skip_bits(&a->gb, 32);
189 189
190 a->qscale= get_bits(&a->gb, 16); 190 a->qscale= get_bits(&a->gb, 16);
191 a->version= get_bits(&a->gb, 16); 191 a->version= get_bits(&a->gb, 16);
192 192
193 // printf("qscale:%d (0x%X), version:%d (0x%X)\n", a->qscale, a->qscale, a->version, a->version); 193 // printf("qscale:%d (0x%X), version:%d (0x%X)\n", a->qscale, a->qscale, a->version, a->version);
194 194
195 for(a->mb_x=0; a->mb_x<a->mb_width; a->mb_x++){ 195 for(a->mb_x=0; a->mb_x<a->mb_width; a->mb_x++){
196 for(a->mb_y=0; a->mb_y<a->mb_height; a->mb_y++){ 196 for(a->mb_y=0; a->mb_y<a->mb_height; a->mb_y++){
197 if( decode_mb(a, a->block) <0) 197 if( decode_mb(a, a->block) <0)
198 return -1; 198 return -1;
199 199
200 idct_put(a, a->mb_x, a->mb_y); 200 idct_put(a, a->mb_x, a->mb_y);
201 } 201 }
202 } 202 }
203 203
204 // p->quality= (32 + a->inv_qscale/2)/a->inv_qscale; 204 // p->quality= (32 + a->inv_qscale/2)/a->inv_qscale;
205 // memset(p->qscale_table, p->quality, p->qstride*a->mb_height); 205 // memset(p->qscale_table, p->quality, p->qstride*a->mb_height);
206 206
207 *picture= *(AVFrame*)&a->picture; 207 *picture= *(AVFrame*)&a->picture;
208 *data_size = sizeof(AVPicture); 208 *data_size = sizeof(AVPicture);
209 209
210 emms_c(); 210 emms_c();
211 211
212 return (get_bits_count(&a->gb)+31)/32*4; 212 return (get_bits_count(&a->gb)+31)/32*4;
213 } 213 }
214 214
215 static void mdec_common_init(AVCodecContext *avctx){ 215 static void mdec_common_init(AVCodecContext *avctx){
216 MDECContext * const a = avctx->priv_data; 216 MDECContext * const a = avctx->priv_data;
225 } 225 }
226 226
227 static int decode_init(AVCodecContext *avctx){ 227 static int decode_init(AVCodecContext *avctx){
228 MDECContext * const a = avctx->priv_data; 228 MDECContext * const a = avctx->priv_data;
229 AVFrame *p= (AVFrame*)&a->picture; 229 AVFrame *p= (AVFrame*)&a->picture;
230 230
231 mdec_common_init(avctx); 231 mdec_common_init(avctx);
232 init_vlcs(); 232 init_vlcs();
233 ff_init_scantable(a->dsp.idct_permutation, &a->scantable, ff_zigzag_direct); 233 ff_init_scantable(a->dsp.idct_permutation, &a->scantable, ff_zigzag_direct);
234 /* 234 /*
235 for(i=0; i<64; i++){ 235 for(i=0; i<64; i++){
248 MDECContext * const a = avctx->priv_data; 248 MDECContext * const a = avctx->priv_data;
249 249
250 av_freep(&a->bitstream_buffer); 250 av_freep(&a->bitstream_buffer);
251 av_freep(&a->picture.qscale_table); 251 av_freep(&a->picture.qscale_table);
252 a->bitstream_buffer_size=0; 252 a->bitstream_buffer_size=0;
253 253
254 return 0; 254 return 0;
255 } 255 }
256 256
257 AVCodec mdec_decoder = { 257 AVCodec mdec_decoder = {
258 "mdec", 258 "mdec",