comparison vp3.c @ 10647:0139a62827ce libavcodec

Various VP3 optimizations. Faster checks in reverse_dc_prediction. Simplified deblocking checks. Check transform==15 first, since it's more common than 13.
author darkshikari
date Sun, 06 Dec 2009 12:48:09 +0000
parents 972b17631531
children b5644bcfff48
comparison
equal deleted inserted replaced
10646:bb14c1586891 10647:0139a62827ce
1231 * the frame. Much of this function is adapted directly from the original 1231 * the frame. Much of this function is adapted directly from the original
1232 * VP3 source code. 1232 * VP3 source code.
1233 */ 1233 */
1234 #define COMPATIBLE_FRAME(x) \ 1234 #define COMPATIBLE_FRAME(x) \
1235 (compatible_frame[s->all_fragments[x].coding_method] == current_frame_type) 1235 (compatible_frame[s->all_fragments[x].coding_method] == current_frame_type)
1236 #define FRAME_CODED(x) (s->all_fragments[x].coding_method != MODE_COPY)
1237 #define DC_COEFF(u) (s->coeffs[u].index ? 0 : s->coeffs[u].coeff) //FIXME do somethin to simplify this 1236 #define DC_COEFF(u) (s->coeffs[u].index ? 0 : s->coeffs[u].coeff) //FIXME do somethin to simplify this
1238 1237
1239 static void reverse_dc_prediction(Vp3DecodeContext *s, 1238 static void reverse_dc_prediction(Vp3DecodeContext *s,
1240 int first_fragment, 1239 int first_fragment,
1241 int fragment_width, 1240 int fragment_width,
1288 * prediction. For example, INTRA is the only mode in this table to 1287 * prediction. For example, INTRA is the only mode in this table to
1289 * have a frame number of 0. That means INTRA blocks can only predict 1288 * have a frame number of 0. That means INTRA blocks can only predict
1290 * from other INTRA blocks. There are 2 golden frame coding types; 1289 * from other INTRA blocks. There are 2 golden frame coding types;
1291 * blocks encoding in these modes can only predict from other blocks 1290 * blocks encoding in these modes can only predict from other blocks
1292 * that were encoded with these 1 of these 2 modes. */ 1291 * that were encoded with these 1 of these 2 modes. */
1293 static const unsigned char compatible_frame[8] = { 1292 static const unsigned char compatible_frame[9] = {
1294 1, /* MODE_INTER_NO_MV */ 1293 1, /* MODE_INTER_NO_MV */
1295 0, /* MODE_INTRA */ 1294 0, /* MODE_INTRA */
1296 1, /* MODE_INTER_PLUS_MV */ 1295 1, /* MODE_INTER_PLUS_MV */
1297 1, /* MODE_INTER_LAST_MV */ 1296 1, /* MODE_INTER_LAST_MV */
1298 1, /* MODE_INTER_PRIOR_MV */ 1297 1, /* MODE_INTER_PRIOR_MV */
1299 2, /* MODE_USING_GOLDEN */ 1298 2, /* MODE_USING_GOLDEN */
1300 2, /* MODE_GOLDEN_MV */ 1299 2, /* MODE_GOLDEN_MV */
1301 1 /* MODE_INTER_FOUR_MV */ 1300 1, /* MODE_INTER_FOUR_MV */
1301 3 /* MODE_COPY */
1302 }; 1302 };
1303 int current_frame_type; 1303 int current_frame_type;
1304 1304
1305 /* there is a last DC predictor for each of the 3 frame types */ 1305 /* there is a last DC predictor for each of the 3 frame types */
1306 short last_dc[3]; 1306 short last_dc[3];
1324 1324
1325 transform= 0; 1325 transform= 0;
1326 if(x){ 1326 if(x){
1327 l= i-1; 1327 l= i-1;
1328 vl = DC_COEFF(l); 1328 vl = DC_COEFF(l);
1329 if(FRAME_CODED(l) && COMPATIBLE_FRAME(l)) 1329 if(COMPATIBLE_FRAME(l))
1330 transform |= PL; 1330 transform |= PL;
1331 } 1331 }
1332 if(y){ 1332 if(y){
1333 u= i-fragment_width; 1333 u= i-fragment_width;
1334 vu = DC_COEFF(u); 1334 vu = DC_COEFF(u);
1335 if(FRAME_CODED(u) && COMPATIBLE_FRAME(u)) 1335 if(COMPATIBLE_FRAME(u))
1336 transform |= PU; 1336 transform |= PU;
1337 if(x){ 1337 if(x){
1338 ul= i-fragment_width-1; 1338 ul= i-fragment_width-1;
1339 vul = DC_COEFF(ul); 1339 vul = DC_COEFF(ul);
1340 if(FRAME_CODED(ul) && COMPATIBLE_FRAME(ul)) 1340 if(COMPATIBLE_FRAME(ul))
1341 transform |= PUL; 1341 transform |= PUL;
1342 } 1342 }
1343 if(x + 1 < fragment_width){ 1343 if(x + 1 < fragment_width){
1344 ur= i-fragment_width+1; 1344 ur= i-fragment_width+1;
1345 vur = DC_COEFF(ur); 1345 vur = DC_COEFF(ur);
1346 if(FRAME_CODED(ur) && COMPATIBLE_FRAME(ur)) 1346 if(COMPATIBLE_FRAME(ur))
1347 transform |= PUR; 1347 transform |= PUR;
1348 } 1348 }
1349 } 1349 }
1350 1350
1351 if (transform == 0) { 1351 if (transform == 0) {
1364 1364
1365 predicted_dc /= 128; 1365 predicted_dc /= 128;
1366 1366
1367 /* check for outranging on the [ul u l] and 1367 /* check for outranging on the [ul u l] and
1368 * [ul u ur l] predictors */ 1368 * [ul u ur l] predictors */
1369 if ((transform == 13) || (transform == 15)) { 1369 if ((transform == 15) || (transform == 13)) {
1370 if (FFABS(predicted_dc - vu) > 128) 1370 if (FFABS(predicted_dc - vu) > 128)
1371 predicted_dc = vu; 1371 predicted_dc = vu;
1372 else if (FFABS(predicted_dc - vl) > 128) 1372 else if (FFABS(predicted_dc - vl) > 128)
1373 predicted_dc = vl; 1373 predicted_dc = vl;
1374 else if (FFABS(predicted_dc - vul) > 128) 1374 else if (FFABS(predicted_dc - vul) > 128)
1639 if (!s->flipped_image) stride = -stride; 1639 if (!s->flipped_image) stride = -stride;
1640 1640
1641 for (y = 0; y < height; y++) { 1641 for (y = 0; y < height; y++) {
1642 1642
1643 for (x = 0; x < width; x++) { 1643 for (x = 0; x < width; x++) {
1644 /* do not perform left edge filter for left columns frags */ 1644 /* This code basically just deblocks on the edges of coded blocks.
1645 if ((x > 0) && 1645 * However, it has to be much more complicated because of the
1646 (s->all_fragments[fragment].coding_method != MODE_COPY)) { 1646 * braindamaged deblock ordering used in VP3/Theora. Order matters
1647 s->dsp.vp3_h_loop_filter( 1647 * because some pixels get filtered twice. */
1648 plane_data + s->all_fragments[fragment].first_pixel, 1648 if( s->all_fragments[fragment].coding_method != MODE_COPY )
1649 stride, bounding_values); 1649 {
1650 } 1650 /* do not perform left edge filter for left columns frags */
1651 1651 if (x > 0) {
1652 /* do not perform top edge filter for top row fragments */ 1652 s->dsp.vp3_h_loop_filter(
1653 if ((y > 0) && 1653 plane_data + s->all_fragments[fragment].first_pixel,
1654 (s->all_fragments[fragment].coding_method != MODE_COPY)) { 1654 stride, bounding_values);
1655 s->dsp.vp3_v_loop_filter( 1655 }
1656 plane_data + s->all_fragments[fragment].first_pixel, 1656
1657 stride, bounding_values); 1657 /* do not perform top edge filter for top row fragments */
1658 } 1658 if (y > 0) {
1659 1659 s->dsp.vp3_v_loop_filter(
1660 /* do not perform right edge filter for right column 1660 plane_data + s->all_fragments[fragment].first_pixel,
1661 * fragments or if right fragment neighbor is also coded 1661 stride, bounding_values);
1662 * in this frame (it will be filtered in next iteration) */ 1662 }
1663 if ((x < width - 1) && 1663
1664 (s->all_fragments[fragment].coding_method != MODE_COPY) && 1664 /* do not perform right edge filter for right column
1665 (s->all_fragments[fragment + 1].coding_method == MODE_COPY)) { 1665 * fragments or if right fragment neighbor is also coded
1666 s->dsp.vp3_h_loop_filter( 1666 * in this frame (it will be filtered in next iteration) */
1667 plane_data + s->all_fragments[fragment + 1].first_pixel, 1667 if ((x < width - 1) &&
1668 stride, bounding_values); 1668 (s->all_fragments[fragment + 1].coding_method == MODE_COPY)) {
1669 } 1669 s->dsp.vp3_h_loop_filter(
1670 1670 plane_data + s->all_fragments[fragment + 1].first_pixel,
1671 /* do not perform bottom edge filter for bottom row 1671 stride, bounding_values);
1672 * fragments or if bottom fragment neighbor is also coded 1672 }
1673 * in this frame (it will be filtered in the next row) */ 1673
1674 if ((y < height - 1) && 1674 /* do not perform bottom edge filter for bottom row
1675 (s->all_fragments[fragment].coding_method != MODE_COPY) && 1675 * fragments or if bottom fragment neighbor is also coded
1676 (s->all_fragments[fragment + width].coding_method == MODE_COPY)) { 1676 * in this frame (it will be filtered in the next row) */
1677 s->dsp.vp3_v_loop_filter( 1677 if ((y < height - 1) &&
1678 plane_data + s->all_fragments[fragment + width].first_pixel, 1678 (s->all_fragments[fragment + width].coding_method == MODE_COPY)) {
1679 stride, bounding_values); 1679 s->dsp.vp3_v_loop_filter(
1680 plane_data + s->all_fragments[fragment + width].first_pixel,
1681 stride, bounding_values);
1682 }
1680 } 1683 }
1681 1684
1682 fragment++; 1685 fragment++;
1683 } 1686 }
1684 } 1687 }