Revision ea676144

View differences:

libavcodec/vp3.c
206 206
     * index. */
207 207
    int *superblock_fragments;
208 208

  
209
    /* This table contains macroblock_count * 6 entries. Each set of 6
210
     * numbers corresponds to the fragment indexes 0..5 which comprise
211
     * the macroblock (4 Y fragments and 2 C fragments). */
212
    int *macroblock_fragments;
213 209
    /* This is an array that indicates how a particular macroblock
214 210
     * is coded. */
215 211
    unsigned char *macroblock_coding;
......
353 349
    /* initialize the macroblock <-> fragment mapping */
354 350
    current_fragment = 0;
355 351
    current_macroblock = 0;
356
    mapping_index = 0;
357 352
    for (i = 0; i < s->fragment_height; i += 2) {
358 353

  
359 354
        for (j = 0; j < s->fragment_width; j += 2) {
360 355

  
361 356
            s->all_fragments[current_fragment].macroblock = current_macroblock;
362
            s->macroblock_fragments[mapping_index++] = current_fragment;
363 357

  
364 358
            if (j + 1 < s->fragment_width) {
365 359
                s->all_fragments[current_fragment + 1].macroblock = current_macroblock;
366
                s->macroblock_fragments[mapping_index++] = current_fragment + 1;
367
            } else
368
                s->macroblock_fragments[mapping_index++] = -1;
360
            }
369 361

  
370 362
            if (i + 1 < s->fragment_height) {
371 363
                s->all_fragments[current_fragment + s->fragment_width].macroblock =
372 364
                    current_macroblock;
373
                s->macroblock_fragments[mapping_index++] =
374
                    current_fragment + s->fragment_width;
375
            } else
376
                s->macroblock_fragments[mapping_index++] = -1;
365
            }
377 366

  
378 367
            if ((j + 1 < s->fragment_width) && (i + 1 < s->fragment_height)) {
379 368
                s->all_fragments[current_fragment + s->fragment_width + 1].macroblock =
380 369
                    current_macroblock;
381
                s->macroblock_fragments[mapping_index++] =
382
                    current_fragment + s->fragment_width + 1;
383
            } else
384
                s->macroblock_fragments[mapping_index++] = -1;
370
            }
385 371

  
386 372
            /* C planes */
387 373
            c_fragment = s->fragment_start[1] +
388 374
                (i * s->fragment_width / 4) + (j / 2);
389 375
            s->all_fragments[c_fragment].macroblock = s->macroblock_count;
390
            s->macroblock_fragments[mapping_index++] = c_fragment;
391 376

  
392 377
            c_fragment = s->fragment_start[2] +
393 378
                (i * s->fragment_width / 4) + (j / 2);
394 379
            s->all_fragments[c_fragment].macroblock = s->macroblock_count;
395
            s->macroblock_fragments[mapping_index++] = c_fragment;
396 380

  
397 381
            if (j + 2 <= s->fragment_width)
398 382
                current_fragment += 2;
......
742 726
                    (s->macroblock_coding[current_macroblock] == MODE_COPY))
743 727
                    continue;
744 728

  
729
#define BLOCK_X (2*mb_x + (k&1))
730
#define BLOCK_Y (2*mb_y + (k>>1))
731

  
745 732
                /* mode 7 means get 3 bits for each coding mode */
746 733
                if (scheme == 7)
747 734
                    coding_mode = get_bits(gb, 3);
......
753 740
                        [get_vlc2(gb, s->mode_code_vlc.table, 3, 3)];
754 741

  
755 742
                s->macroblock_coding[current_macroblock] = coding_mode;
756
                for (k = 0; k < 6; k++) {
743
                for (k = 0; k < 4; k++) {
757 744
                    current_fragment =
758
                        s->macroblock_fragments[current_macroblock * 6 + k];
759
                    if (current_fragment == -1)
760
                        continue;
761
                    if (current_fragment >= s->fragment_count) {
762
                        av_log(s->avctx, AV_LOG_ERROR, "  vp3:unpack_modes(): bad fragment number (%d >= %d)\n",
763
                            current_fragment, s->fragment_count);
764
                        return 1;
765
                    }
745
                        BLOCK_Y*s->fragment_width + BLOCK_X;
746
                    if (s->all_fragments[current_fragment].coding_method !=
747
                        MODE_COPY)
748
                        s->all_fragments[current_fragment].coding_method =
749
                            coding_mode;
750
                }
751
                for (k = 0; k < 2; k++) {
752
                    current_fragment = s->fragment_start[k+1] +
753
                        mb_y*(s->fragment_width>>1) + mb_x;
766 754
                    if (s->all_fragments[current_fragment].coding_method !=
767 755
                        MODE_COPY)
768 756
                        s->all_fragments[current_fragment].coding_method =
......
816 804
                (s->macroblock_coding[current_macroblock] == MODE_COPY))
817 805
                continue;
818 806

  
819
            current_fragment = s->macroblock_fragments[current_macroblock * 6];
820
            if (current_fragment >= s->fragment_count) {
821
                av_log(s->avctx, AV_LOG_ERROR, "  vp3:unpack_vectors(): bad fragment number (%d >= %d\n",
822
                    current_fragment, s->fragment_count);
823
                return 1;
824
            }
825 807
            switch (s->macroblock_coding[current_macroblock]) {
826 808

  
827 809
            case MODE_INTER_PLUS_MV:
......
854 836
                 * Y fragment, then average for the C fragment vectors */
855 837
                motion_x[4] = motion_y[4] = 0;
856 838
                for (k = 0; k < 4; k++) {
839
                    current_fragment = BLOCK_Y*s->fragment_width + BLOCK_X;
857 840
                    for (l = 0; l < s->coded_fragment_list_index; l++)
858
                        if (s->coded_fragment_list[l] == s->macroblock_fragments[6*current_macroblock + k])
841
                        if (s->coded_fragment_list[l] == current_fragment)
859 842
                            break;
860 843
                    if (l < s->coded_fragment_list_index) {
861 844
                        if (coding_mode == 0) {
......
913 896
            }
914 897

  
915 898
            /* assign the motion vectors to the correct fragments */
916
            for (k = 0; k < 6; k++) {
899
            for (k = 0; k < 4; k++) {
917 900
                current_fragment =
918
                    s->macroblock_fragments[current_macroblock * 6 + k];
919
                if (current_fragment == -1)
920
                    continue;
921
                if (current_fragment >= s->fragment_count) {
922
                    av_log(s->avctx, AV_LOG_ERROR, "  vp3:unpack_vectors(): bad fragment number (%d >= %d)\n",
923
                        current_fragment, s->fragment_count);
924
                    return 1;
925
                }
901
                    BLOCK_Y*s->fragment_width + BLOCK_X;
926 902
                if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) {
927 903
                    s->all_fragments[current_fragment].motion_x = motion_x[k];
928 904
                    s->all_fragments[current_fragment].motion_y = motion_y[k];
......
931 907
                    s->all_fragments[current_fragment].motion_y = motion_y[0];
932 908
                }
933 909
            }
910
            for (k = 0; k < 2; k++) {
911
                current_fragment = s->fragment_start[k+1] +
912
                    mb_y*(s->fragment_width>>1) + mb_x;
913
                if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) {
914
                    s->all_fragments[current_fragment].motion_x = motion_x[k+4];
915
                    s->all_fragments[current_fragment].motion_y = motion_y[k+4];
916
                } else {
917
                    s->all_fragments[current_fragment].motion_x = motion_x[0];
918
                    s->all_fragments[current_fragment].motion_y = motion_y[0];
919
                }
920
            }
934 921
        }
935 922
        }
936 923
    }
......
1441 1428
    int motion_halfpel_index;
1442 1429
    uint8_t *motion_source;
1443 1430
    int plane;
1444
    int current_macroblock_entry = slice * s->macroblock_width * 6;
1445 1431

  
1446 1432
    if (slice >= s->macroblock_height)
1447 1433
        return;
......
1455 1441
        int plane_height      = s->height >> !!plane;
1456 1442
        int y =        slice *  FRAGMENT_PIXELS << !plane ;
1457 1443
        int slice_height = y + (FRAGMENT_PIXELS << !plane);
1458
        int i = s->macroblock_fragments[current_macroblock_entry + plane + 3*!!plane];
1444
        int i = s->fragment_start[plane] + (y>>3)*(s->fragment_width>>!!plane);
1459 1445

  
1460 1446
        if (!s->flipped_image) stride = -stride;
1461 1447

  
......
1781 1767

  
1782 1768
    /* work out the block mapping tables */
1783 1769
    s->superblock_fragments = av_malloc(s->superblock_count * 16 * sizeof(int));
1784
    s->macroblock_fragments = av_malloc(s->macroblock_count * 6 * sizeof(int));
1785 1770
    s->macroblock_coding = av_malloc(s->macroblock_count + 1);
1786
    if (!s->superblock_fragments ||
1787
        !s->macroblock_fragments || !s->macroblock_coding) {
1771
    if (!s->superblock_fragments || !s->macroblock_coding) {
1788 1772
        vp3_decode_end(avctx);
1789 1773
        return -1;
1790 1774
    }
......
1981 1965
    av_free(s->coded_fragment_list);
1982 1966
    av_free(s->fast_fragment_list);
1983 1967
    av_free(s->superblock_fragments);
1984
    av_free(s->macroblock_fragments);
1985 1968
    av_free(s->macroblock_coding);
1986 1969

  
1987 1970
    for (i = 0; i < 16; i++) {

Also available in: Unified diff