Revision badaf88e libavcodec/mpegvideo.c

View differences:

libavcodec/mpegvideo.c
68 68
/* default motion estimation */
69 69
int motion_estimation_method = ME_LOG;
70 70

  
71
extern UINT8 zigzag_end[64];
72

  
71 73
/* XXX: should use variable shift ? */
72 74
#define QMAT_SHIFT_MMX 19
73 75
#define QMAT_SHIFT 25
......
674 676
{
675 677
    if (s->block_last_index[i] >= 0) {
676 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 681
        ff_idct (block);
679 682
        add_pixels_clamped(block, dest, line_size);
680 683
    }
......
1206 1209
static void dct_unquantize_mpeg1_c(MpegEncContext *s, 
1207 1210
                                   DCTELEM *block, int n, int qscale)
1208 1211
{
1209
    int i, level;
1212
    int i, level, nCoeffs;
1210 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 1218
    if (s->mb_intra) {
1213 1219
        if (n < 4) 
1214 1220
            block[0] = block[0] * s->y_dc_scale;
......
1216 1222
            block[0] = block[0] * s->c_dc_scale;
1217 1223
        /* XXX: only mpeg1 */
1218 1224
        quant_matrix = s->intra_matrix;
1219
        for(i=1;i<64;i++) {
1220
            level = block[i];
1225
        for(i=1;i<nCoeffs;i++) {
1226
            int j= zigzag_direct[i];
1227
            level = block[j];
1221 1228
            if (level) {
1222 1229
                if (level < 0) {
1223 1230
                    level = -level;
1224
                    level = (int)(level * qscale * quant_matrix[i]) >> 3;
1231
                    level = (int)(level * qscale * quant_matrix[j]) >> 3;
1225 1232
                    level = (level - 1) | 1;
1226 1233
                    level = -level;
1227 1234
                } else {
1228
                    level = (int)(level * qscale * quant_matrix[i]) >> 3;
1235
                    level = (int)(level * qscale * quant_matrix[j]) >> 3;
1229 1236
                    level = (level - 1) | 1;
1230 1237
                }
1231 1238
#ifdef PARANOID
1232 1239
                if (level < -2048 || level > 2047)
1233 1240
                    fprintf(stderr, "unquant error %d %d\n", i, level);
1234 1241
#endif
1235
                block[i] = level;
1242
                block[j] = level;
1236 1243
            }
1237 1244
        }
1238 1245
    } else {
1239 1246
        i = 0;
1240 1247
        quant_matrix = s->non_intra_matrix;
1241
        for(;i<64;i++) {
1242
            level = block[i];
1248
        for(i=1;i<nCoeffs;i++) {
1249
            int j= zigzag_direct[i];
1250
            level = block[j];
1243 1251
            if (level) {
1244 1252
                if (level < 0) {
1245 1253
                    level = -level;
1246 1254
                    level = (((level << 1) + 1) * qscale *
1247
                             ((int) (quant_matrix[i]))) >> 4;
1255
                             ((int) (quant_matrix[j]))) >> 4;
1248 1256
                    level = (level - 1) | 1;
1249 1257
                    level = -level;
1250 1258
                } else {
1251 1259
                    level = (((level << 1) + 1) * qscale *
1252
                             ((int) (quant_matrix[i]))) >> 4;
1260
                             ((int) (quant_matrix[j]))) >> 4;
1253 1261
                    level = (level - 1) | 1;
1254 1262
                }
1255 1263
#ifdef PARANOID
1256 1264
                if (level < -2048 || level > 2047)
1257 1265
                    fprintf(stderr, "unquant error %d %d\n", i, level);
1258 1266
#endif
1259
                block[i] = level;
1267
                block[j] = level;
1260 1268
            }
1261 1269
        }
1262 1270
    }
......
1266 1274
                                  DCTELEM *block, int n, int qscale)
1267 1275
{
1268 1276
    int i, level, qmul, qadd;
1277
    int nCoeffs;
1269 1278

  
1270 1279
    if (s->mb_intra) {
1271 1280
        if (n < 4) 
......
1273 1282
        else
1274 1283
            block[0] = block[0] * s->c_dc_scale;
1275 1284
        i = 1;
1285
        nCoeffs= 64; //does not allways use zigzag table 
1276 1286
    } else {
1277 1287
        i = 0;
1288
        nCoeffs= zigzag_end[ s->block_last_index[n] ];
1278 1289
    }
1279 1290

  
1280 1291
    qmul = s->qscale << 1;
1281 1292
    qadd = (s->qscale - 1) | 1;
1282 1293

  
1283
    for(;i<64;i++) {
1294
    for(;i<nCoeffs;i++) {
1284 1295
        level = block[i];
1285 1296
        if (level) {
1286 1297
            if (level < 0) {

Also available in: Unified diff