Revision 04331882 libavcodec/vp3.c

View differences:

libavcodec/vp3.c
277 277
     * macroblock is coded. */
278 278
    unsigned char *macroblock_coded;
279 279

  
280
    int first_coded_y_fragment;
281
    int first_coded_c_fragment;
282
    int last_coded_y_fragment;
283
    int last_coded_c_fragment;
284

  
280 285
} Vp3DecodeContext;
281 286

  
282 287
/************************************************************************
......
1197 1202
    /* figure out which fragments are coded; iterate through each
1198 1203
     * superblock (all planes) */
1199 1204
    s->coded_fragment_list_index = 0;
1205
    s->first_coded_y_fragment = s->first_coded_c_fragment = 0;
1206
    s->last_coded_y_fragment = s->last_coded_c_fragment = -1;
1200 1207
    memset(s->macroblock_coded, 0, s->macroblock_count);
1201 1208
    for (i = 0; i < s->superblock_count; i++) {
1202 1209

  
......
1225 1232
                        /* mode will be decoded in the next phase */
1226 1233
                        s->all_fragments[current_fragment].coding_method = 
1227 1234
                            MODE_INTER_NO_MV;
1228
                        s->coded_fragment_list[s->coded_fragment_list_index++] = 
1235
                        s->coded_fragment_list[s->coded_fragment_list_index] = 
1229 1236
                            current_fragment;
1237
                        if ((current_fragment >= s->u_fragment_start) &&
1238
                            (s->last_coded_y_fragment == -1)) {
1239
                            s->first_coded_c_fragment = s->coded_fragment_list_index;
1240
                            s->last_coded_y_fragment = s->first_coded_c_fragment - 1;
1241
                        }
1242
                        s->coded_fragment_list_index++;
1230 1243
                        s->macroblock_coded[s->all_fragments[current_fragment].macroblock] = 1;
1231 1244
                        debug_block_coding("      superblock %d is partially coded, fragment %d is coded\n",
1232 1245
                            i, current_fragment);
......
1246 1259
                     * coding will be determined in next step */
1247 1260
                    s->all_fragments[current_fragment].coding_method = 
1248 1261
                        MODE_INTER_NO_MV;
1249
                    s->coded_fragment_list[s->coded_fragment_list_index++] = 
1262
                    s->coded_fragment_list[s->coded_fragment_list_index] = 
1250 1263
                        current_fragment;
1264
                    if ((current_fragment >= s->u_fragment_start) &&
1265
                        (s->last_coded_y_fragment == -1)) {
1266
                        s->first_coded_c_fragment = s->coded_fragment_list_index;
1267
                        s->last_coded_y_fragment = s->first_coded_c_fragment - 1;
1268
                    }
1269
                    s->coded_fragment_list_index++;
1251 1270
                    s->macroblock_coded[s->all_fragments[current_fragment].macroblock] = 1;
1252 1271
                    debug_block_coding("      superblock %d is fully coded, fragment %d is coded\n",
1253 1272
                        i, current_fragment);
......
1255 1274
            }
1256 1275
        }
1257 1276
    }
1277

  
1278
    if (s->first_coded_c_fragment == 0)
1279
        /* no C fragments coded */
1280
        s->last_coded_y_fragment = s->coded_fragment_list_index - 1;
1281
    else
1282
        s->last_coded_c_fragment = s->coded_fragment_list_index - 1;
1283
    debug_block_coding("    %d total coded fragments, y: %d -> %d, c: %d -> %d\n",
1284
        s->coded_fragment_list_index,
1285
        s->first_coded_y_fragment,
1286
        s->last_coded_y_fragment,
1287
        s->first_coded_c_fragment,
1288
        s->last_coded_c_fragment);
1258 1289
}
1259 1290

  
1260 1291
/*
......
1565 1596
    DCTELEM coeff;
1566 1597
    Vp3Fragment *fragment;
1567 1598

  
1568
    for (i = first_fragment; i < last_fragment; i++) {
1599
    for (i = first_fragment; i <= last_fragment; i++) {
1569 1600

  
1570 1601
        fragment = &s->all_fragments[s->coded_fragment_list[i]];
1571 1602
        if (fragment->coeff_count > coeff_index)
......
1610 1641
    int ac_c_table;
1611 1642
    int residual_eob_run = 0;
1612 1643

  
1613
    /* for the binary search */
1614
    int left, middle, right, found;
1615
    /* this indicates the first fragment of the color plane data */
1616
    int plane_split = 0;
1617

  
1618
    debug_vp3("  vp3: unpacking DCT coefficients\n");
1619

  
1620
    /* find the plane split (the first color plane fragment) using a binary 
1621
     * search; test the boundaries first */
1622
    if (s->coded_fragment_list_index == 0)
1623
        return;
1624
    if (s->u_fragment_start <= s->coded_fragment_list[0])
1625
        plane_split = 0;  /* this means no Y fragments */
1626
    else if (s->coded_fragment_list[s->coded_fragment_list_index - 1] >
1627
        s->u_fragment_start) {
1628

  
1629
        left = 0;
1630
        right = s->coded_fragment_list_index - 1;
1631
        found = 0;
1632
        do {
1633
            middle = (left + right + 1) / 2;
1634
            if ((s->coded_fragment_list[middle] >= s->u_fragment_start) &&
1635
                (s->coded_fragment_list[middle - 1] < s->u_fragment_start))
1636
                found = 1;
1637
            else if (s->coded_fragment_list[middle] < s->u_fragment_start)
1638
                left = middle;
1639
            else
1640
                right = middle;
1641
        } while (!found);
1642

  
1643
        plane_split = middle;
1644
    }
1645

  
1646
    debug_vp3("  plane split @ index %d (fragment %d)\n", plane_split,
1647
        s->coded_fragment_list[plane_split]);
1648

  
1649 1644
    /* fetch the DC table indices */
1650 1645
    dc_y_table = get_bits(gb, 4);
1651 1646
    dc_c_table = get_bits(gb, 4);
......
1654 1649
    debug_vp3("  vp3: unpacking Y plane DC coefficients using table %d\n",
1655 1650
        dc_y_table);
1656 1651
    residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_y_table], 0, 
1657
        0, plane_split, residual_eob_run);
1652
        s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run);
1658 1653

  
1659 1654
    /* unpack the C plane DC coefficients */
1660 1655
    debug_vp3("  vp3: unpacking C plane DC coefficients using table %d\n",
1661 1656
        dc_c_table);
1662 1657
    residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_c_table], 0,
1663
        plane_split, s->coded_fragment_list_index, residual_eob_run);
1658
        s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run);
1664 1659

  
1665 1660
    /* fetch the AC table indices */
1666 1661
    ac_y_table = get_bits(gb, 4);
......
1672 1667
        debug_vp3("  vp3: unpacking level %d Y plane AC coefficients using table %d\n",
1673 1668
            i, ac_y_table);
1674 1669
        residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_1[ac_y_table], i, 
1675
            0, plane_split, residual_eob_run);
1670
            s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run);
1676 1671

  
1677 1672
        debug_vp3("  vp3: unpacking level %d C plane AC coefficients using table %d\n",
1678 1673
            i, ac_c_table);
1679 1674
        residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_1[ac_c_table], i, 
1680
            plane_split, s->coded_fragment_list_index, residual_eob_run);
1675
            s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run);
1681 1676
    }
1682 1677

  
1683 1678
    /* unpack the group 2 AC coefficients (coeffs 6-14) */
......
1686 1681
        debug_vp3("  vp3: unpacking level %d Y plane AC coefficients using table %d\n",
1687 1682
            i, ac_y_table);
1688 1683
        residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_2[ac_y_table], i, 
1689
            0, plane_split, residual_eob_run);
1684
            s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run);
1690 1685

  
1691 1686
        debug_vp3("  vp3: unpacking level %d C plane AC coefficients using table %d\n",
1692 1687
            i, ac_c_table);
1693 1688
        residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_2[ac_c_table], i, 
1694
            plane_split, s->coded_fragment_list_index, residual_eob_run);
1689
            s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run);
1695 1690
    }
1696 1691

  
1697 1692
    /* unpack the group 3 AC coefficients (coeffs 15-27) */
......
1700 1695
        debug_vp3("  vp3: unpacking level %d Y plane AC coefficients using table %d\n",
1701 1696
            i, ac_y_table);
1702 1697
        residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_3[ac_y_table], i, 
1703
            0, plane_split, residual_eob_run);
1698
            s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run);
1704 1699

  
1705 1700
        debug_vp3("  vp3: unpacking level %d C plane AC coefficients using table %d\n",
1706 1701
            i, ac_c_table);
1707 1702
        residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_3[ac_c_table], i, 
1708
            plane_split, s->coded_fragment_list_index, residual_eob_run);
1703
            s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run);
1709 1704
    }
1710 1705

  
1711 1706
    /* unpack the group 4 AC coefficients (coeffs 28-63) */
......
1714 1709
        debug_vp3("  vp3: unpacking level %d Y plane AC coefficients using table %d\n",
1715 1710
            i, ac_y_table);
1716 1711
        residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_4[ac_y_table], i, 
1717
            0, plane_split, residual_eob_run);
1712
            s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run);
1718 1713

  
1719 1714
        debug_vp3("  vp3: unpacking level %d C plane AC coefficients using table %d\n",
1720 1715
            i, ac_c_table);
1721 1716
        residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_4[ac_c_table], i, 
1722
            plane_split, s->coded_fragment_list_index, residual_eob_run);
1717
            s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run);
1723 1718
    }
1724 1719
}
1725 1720

  

Also available in: Unified diff