comparison mpegvideo.c @ 200:6ab301aaa652 libavcodec

(commit by michael) dequantizers skip trailing zeros msmpeg4 non-intra decoder has its dequantizer "build in" now
author arpi_esp
date Sun, 13 Jan 2002 04:59:37 +0000
parents 82ba367b1827
children 994aa8623443
comparison
equal deleted inserted replaced
199:0f1dba8fc617 200:6ab301aaa652
65 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 65 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
66 }; 66 };
67 67
68 /* default motion estimation */ 68 /* default motion estimation */
69 int motion_estimation_method = ME_LOG; 69 int motion_estimation_method = ME_LOG;
70
71 extern UINT8 zigzag_end[64];
70 72
71 /* XXX: should use variable shift ? */ 73 /* XXX: should use variable shift ? */
72 #define QMAT_SHIFT_MMX 19 74 #define QMAT_SHIFT_MMX 19
73 #define QMAT_SHIFT 25 75 #define QMAT_SHIFT 25
74 76
672 static inline void add_dct(MpegEncContext *s, 674 static inline void add_dct(MpegEncContext *s,
673 DCTELEM *block, int i, UINT8 *dest, int line_size) 675 DCTELEM *block, int i, UINT8 *dest, int line_size)
674 { 676 {
675 if (s->block_last_index[i] >= 0) { 677 if (s->block_last_index[i] >= 0) {
676 if (!s->mpeg2) 678 if (!s->mpeg2)
677 s->dct_unquantize(s, block, i, s->qscale); 679 if(s->encoding || s->avctx==NULL || s->avctx->codec->id!=CODEC_ID_MSMPEG4)
680 s->dct_unquantize(s, block, i, s->qscale);
678 ff_idct (block); 681 ff_idct (block);
679 add_pixels_clamped(block, dest, line_size); 682 add_pixels_clamped(block, dest, line_size);
680 } 683 }
681 } 684 }
682 685
1204 } 1207 }
1205 1208
1206 static void dct_unquantize_mpeg1_c(MpegEncContext *s, 1209 static void dct_unquantize_mpeg1_c(MpegEncContext *s,
1207 DCTELEM *block, int n, int qscale) 1210 DCTELEM *block, int n, int qscale)
1208 { 1211 {
1209 int i, level; 1212 int i, level, nCoeffs;
1210 const UINT16 *quant_matrix; 1213 const UINT16 *quant_matrix;
1211 1214
1215 if(s->alternate_scan) nCoeffs= 64;
1216 else nCoeffs= s->block_last_index[n]+1;
1217
1212 if (s->mb_intra) { 1218 if (s->mb_intra) {
1213 if (n < 4) 1219 if (n < 4)
1214 block[0] = block[0] * s->y_dc_scale; 1220 block[0] = block[0] * s->y_dc_scale;
1215 else 1221 else
1216 block[0] = block[0] * s->c_dc_scale; 1222 block[0] = block[0] * s->c_dc_scale;
1217 /* XXX: only mpeg1 */ 1223 /* XXX: only mpeg1 */
1218 quant_matrix = s->intra_matrix; 1224 quant_matrix = s->intra_matrix;
1219 for(i=1;i<64;i++) { 1225 for(i=1;i<nCoeffs;i++) {
1220 level = block[i]; 1226 int j= zigzag_direct[i];
1227 level = block[j];
1221 if (level) { 1228 if (level) {
1222 if (level < 0) { 1229 if (level < 0) {
1223 level = -level; 1230 level = -level;
1224 level = (int)(level * qscale * quant_matrix[i]) >> 3; 1231 level = (int)(level * qscale * quant_matrix[j]) >> 3;
1225 level = (level - 1) | 1; 1232 level = (level - 1) | 1;
1226 level = -level; 1233 level = -level;
1227 } else { 1234 } else {
1228 level = (int)(level * qscale * quant_matrix[i]) >> 3; 1235 level = (int)(level * qscale * quant_matrix[j]) >> 3;
1229 level = (level - 1) | 1; 1236 level = (level - 1) | 1;
1230 } 1237 }
1231 #ifdef PARANOID 1238 #ifdef PARANOID
1232 if (level < -2048 || level > 2047) 1239 if (level < -2048 || level > 2047)
1233 fprintf(stderr, "unquant error %d %d\n", i, level); 1240 fprintf(stderr, "unquant error %d %d\n", i, level);
1234 #endif 1241 #endif
1235 block[i] = level; 1242 block[j] = level;
1236 } 1243 }
1237 } 1244 }
1238 } else { 1245 } else {
1239 i = 0; 1246 i = 0;
1240 quant_matrix = s->non_intra_matrix; 1247 quant_matrix = s->non_intra_matrix;
1241 for(;i<64;i++) { 1248 for(i=1;i<nCoeffs;i++) {
1242 level = block[i]; 1249 int j= zigzag_direct[i];
1250 level = block[j];
1243 if (level) { 1251 if (level) {
1244 if (level < 0) { 1252 if (level < 0) {
1245 level = -level; 1253 level = -level;
1246 level = (((level << 1) + 1) * qscale * 1254 level = (((level << 1) + 1) * qscale *
1247 ((int) (quant_matrix[i]))) >> 4; 1255 ((int) (quant_matrix[j]))) >> 4;
1248 level = (level - 1) | 1; 1256 level = (level - 1) | 1;
1249 level = -level; 1257 level = -level;
1250 } else { 1258 } else {
1251 level = (((level << 1) + 1) * qscale * 1259 level = (((level << 1) + 1) * qscale *
1252 ((int) (quant_matrix[i]))) >> 4; 1260 ((int) (quant_matrix[j]))) >> 4;
1253 level = (level - 1) | 1; 1261 level = (level - 1) | 1;
1254 } 1262 }
1255 #ifdef PARANOID 1263 #ifdef PARANOID
1256 if (level < -2048 || level > 2047) 1264 if (level < -2048 || level > 2047)
1257 fprintf(stderr, "unquant error %d %d\n", i, level); 1265 fprintf(stderr, "unquant error %d %d\n", i, level);
1258 #endif 1266 #endif
1259 block[i] = level; 1267 block[j] = level;
1260 } 1268 }
1261 } 1269 }
1262 } 1270 }
1263 } 1271 }
1264 1272
1265 static void dct_unquantize_h263_c(MpegEncContext *s, 1273 static void dct_unquantize_h263_c(MpegEncContext *s,
1266 DCTELEM *block, int n, int qscale) 1274 DCTELEM *block, int n, int qscale)
1267 { 1275 {
1268 int i, level, qmul, qadd; 1276 int i, level, qmul, qadd;
1277 int nCoeffs;
1269 1278
1270 if (s->mb_intra) { 1279 if (s->mb_intra) {
1271 if (n < 4) 1280 if (n < 4)
1272 block[0] = block[0] * s->y_dc_scale; 1281 block[0] = block[0] * s->y_dc_scale;
1273 else 1282 else
1274 block[0] = block[0] * s->c_dc_scale; 1283 block[0] = block[0] * s->c_dc_scale;
1275 i = 1; 1284 i = 1;
1285 nCoeffs= 64; //does not allways use zigzag table
1276 } else { 1286 } else {
1277 i = 0; 1287 i = 0;
1288 nCoeffs= zigzag_end[ s->block_last_index[n] ];
1278 } 1289 }
1279 1290
1280 qmul = s->qscale << 1; 1291 qmul = s->qscale << 1;
1281 qadd = (s->qscale - 1) | 1; 1292 qadd = (s->qscale - 1) | 1;
1282 1293
1283 for(;i<64;i++) { 1294 for(;i<nCoeffs;i++) {
1284 level = block[i]; 1295 level = block[i];
1285 if (level) { 1296 if (level) {
1286 if (level < 0) { 1297 if (level < 0) {
1287 level = level * qmul - qadd; 1298 level = level * qmul - qadd;
1288 } else { 1299 } else {