Mercurial > libavcodec.hg
comparison vp3.c @ 3498:4b040103da35 libavcodec
simplify
author | michael |
---|---|
date | Wed, 19 Jul 2006 20:57:44 +0000 |
parents | 3a7844f83df4 |
children | 28e8b0fe4f3e |
comparison
equal
deleted
inserted
replaced
3497:3a7844f83df4 | 3498:4b040103da35 |
---|---|
254 int fragment_height; | 254 int fragment_height; |
255 | 255 |
256 Vp3Fragment *all_fragments; | 256 Vp3Fragment *all_fragments; |
257 Coeff *coeffs; | 257 Coeff *coeffs; |
258 Coeff *next_coeff; | 258 Coeff *next_coeff; |
259 int u_fragment_start; | 259 int fragment_start[3]; |
260 int v_fragment_start; | |
261 | 260 |
262 ScanTable scantable; | 261 ScanTable scantable; |
263 | 262 |
264 /* tables */ | 263 /* tables */ |
265 uint16_t coded_dc_scale_factor[64]; | 264 uint16_t coded_dc_scale_factor[64]; |
455 superblock_row_inc = 3 * (s->fragment_width / 2) - | 454 superblock_row_inc = 3 * (s->fragment_width / 2) - |
456 (s->c_superblock_width * 4 - s->fragment_width / 2); | 455 (s->c_superblock_width * 4 - s->fragment_width / 2); |
457 hilbert = hilbert_walk_c; | 456 hilbert = hilbert_walk_c; |
458 | 457 |
459 /* the first operation for this variable is to advance by 1 */ | 458 /* the first operation for this variable is to advance by 1 */ |
460 current_fragment = s->u_fragment_start - 1; | 459 current_fragment = s->fragment_start[1] - 1; |
461 | 460 |
462 } else if (i == s->v_superblock_start) { | 461 } else if (i == s->v_superblock_start) { |
463 | 462 |
464 /* start of V superblocks */ | 463 /* start of V superblocks */ |
465 right_edge = s->fragment_width / 2; | 464 right_edge = s->fragment_width / 2; |
469 superblock_row_inc = 3 * (s->fragment_width / 2) - | 468 superblock_row_inc = 3 * (s->fragment_width / 2) - |
470 (s->c_superblock_width * 4 - s->fragment_width / 2); | 469 (s->c_superblock_width * 4 - s->fragment_width / 2); |
471 hilbert = hilbert_walk_c; | 470 hilbert = hilbert_walk_c; |
472 | 471 |
473 /* the first operation for this variable is to advance by 1 */ | 472 /* the first operation for this variable is to advance by 1 */ |
474 current_fragment = s->v_fragment_start - 1; | 473 current_fragment = s->fragment_start[2] - 1; |
475 | 474 |
476 } | 475 } |
477 | 476 |
478 if (current_width >= right_edge - 1) { | 477 if (current_width >= right_edge - 1) { |
479 /* reset width and move to next superblock row */ | 478 /* reset width and move to next superblock row */ |
591 debug_init("%d ", current_fragment + s->fragment_width + 1); | 590 debug_init("%d ", current_fragment + s->fragment_width + 1); |
592 } else | 591 } else |
593 s->macroblock_fragments[mapping_index++] = -1; | 592 s->macroblock_fragments[mapping_index++] = -1; |
594 | 593 |
595 /* C planes */ | 594 /* C planes */ |
596 c_fragment = s->u_fragment_start + | 595 c_fragment = s->fragment_start[1] + |
597 (i * s->fragment_width / 4) + (j / 2); | 596 (i * s->fragment_width / 4) + (j / 2); |
598 s->all_fragments[c_fragment].macroblock = s->macroblock_count; | 597 s->all_fragments[c_fragment].macroblock = s->macroblock_count; |
599 s->macroblock_fragments[mapping_index++] = c_fragment; | 598 s->macroblock_fragments[mapping_index++] = c_fragment; |
600 debug_init("%d ", c_fragment); | 599 debug_init("%d ", c_fragment); |
601 | 600 |
602 c_fragment = s->v_fragment_start + | 601 c_fragment = s->fragment_start[2] + |
603 (i * s->fragment_width / 4) + (j / 2); | 602 (i * s->fragment_width / 4) + (j / 2); |
604 s->all_fragments[c_fragment].macroblock = s->macroblock_count; | 603 s->all_fragments[c_fragment].macroblock = s->macroblock_count; |
605 s->macroblock_fragments[mapping_index++] = c_fragment; | 604 s->macroblock_fragments[mapping_index++] = c_fragment; |
606 debug_init("%d ", c_fragment); | 605 debug_init("%d ", c_fragment); |
607 | 606 |
845 s->all_fragments[current_fragment].coding_method = | 844 s->all_fragments[current_fragment].coding_method = |
846 MODE_INTER_NO_MV; | 845 MODE_INTER_NO_MV; |
847 s->all_fragments[current_fragment].next_coeff= s->coeffs + current_fragment; | 846 s->all_fragments[current_fragment].next_coeff= s->coeffs + current_fragment; |
848 s->coded_fragment_list[s->coded_fragment_list_index] = | 847 s->coded_fragment_list[s->coded_fragment_list_index] = |
849 current_fragment; | 848 current_fragment; |
850 if ((current_fragment >= s->u_fragment_start) && | 849 if ((current_fragment >= s->fragment_start[1]) && |
851 (s->last_coded_y_fragment == -1) && | 850 (s->last_coded_y_fragment == -1) && |
852 (!first_c_fragment_seen)) { | 851 (!first_c_fragment_seen)) { |
853 s->first_coded_c_fragment = s->coded_fragment_list_index; | 852 s->first_coded_c_fragment = s->coded_fragment_list_index; |
854 s->last_coded_y_fragment = s->first_coded_c_fragment - 1; | 853 s->last_coded_y_fragment = s->first_coded_c_fragment - 1; |
855 first_c_fragment_seen = 1; | 854 first_c_fragment_seen = 1; |
873 s->all_fragments[current_fragment].coding_method = | 872 s->all_fragments[current_fragment].coding_method = |
874 MODE_INTER_NO_MV; | 873 MODE_INTER_NO_MV; |
875 s->all_fragments[current_fragment].next_coeff= s->coeffs + current_fragment; | 874 s->all_fragments[current_fragment].next_coeff= s->coeffs + current_fragment; |
876 s->coded_fragment_list[s->coded_fragment_list_index] = | 875 s->coded_fragment_list[s->coded_fragment_list_index] = |
877 current_fragment; | 876 current_fragment; |
878 if ((current_fragment >= s->u_fragment_start) && | 877 if ((current_fragment >= s->fragment_start[1]) && |
879 (s->last_coded_y_fragment == -1) && | 878 (s->last_coded_y_fragment == -1) && |
880 (!first_c_fragment_seen)) { | 879 (!first_c_fragment_seen)) { |
881 s->first_coded_c_fragment = s->coded_fragment_list_index; | 880 s->first_coded_c_fragment = s->coded_fragment_list_index; |
882 s->last_coded_y_fragment = s->first_coded_c_fragment - 1; | 881 s->last_coded_y_fragment = s->first_coded_c_fragment - 1; |
883 first_c_fragment_seen = 1; | 882 first_c_fragment_seen = 1; |
1642 * Perform the final rendering for a particular slice of data. | 1641 * Perform the final rendering for a particular slice of data. |
1643 * The slice number ranges from 0..(macroblock_height - 1). | 1642 * The slice number ranges from 0..(macroblock_height - 1). |
1644 */ | 1643 */ |
1645 static void render_slice(Vp3DecodeContext *s, int slice) | 1644 static void render_slice(Vp3DecodeContext *s, int slice) |
1646 { | 1645 { |
1647 int x, y; | 1646 int x; |
1648 int m, n; | 1647 int m, n; |
1649 int i; /* indicates current fragment */ | |
1650 int16_t *dequantizer; | 1648 int16_t *dequantizer; |
1651 DECLARE_ALIGNED_16(DCTELEM, block[64]); | 1649 DECLARE_ALIGNED_16(DCTELEM, block[64]); |
1652 unsigned char *output_plane; | |
1653 unsigned char *last_plane; | |
1654 unsigned char *golden_plane; | |
1655 int stride; | |
1656 int motion_x = 0xdeadbeef, motion_y = 0xdeadbeef; | 1650 int motion_x = 0xdeadbeef, motion_y = 0xdeadbeef; |
1657 int upper_motion_limit, lower_motion_limit; | |
1658 int motion_halfpel_index; | 1651 int motion_halfpel_index; |
1659 uint8_t *motion_source; | 1652 uint8_t *motion_source; |
1660 int plane; | 1653 int plane; |
1661 int plane_width; | |
1662 int plane_height; | |
1663 int slice_height; | |
1664 int current_macroblock_entry = slice * s->macroblock_width * 6; | 1654 int current_macroblock_entry = slice * s->macroblock_width * 6; |
1665 int fragment_width; | |
1666 | 1655 |
1667 if (slice >= s->macroblock_height) | 1656 if (slice >= s->macroblock_height) |
1668 return; | 1657 return; |
1669 | 1658 |
1670 for (plane = 0; plane < 3; plane++) { | 1659 for (plane = 0; plane < 3; plane++) { |
1671 | 1660 uint8_t *output_plane = s->current_frame.data [plane]; |
1672 /* set up plane-specific parameters */ | 1661 uint8_t * last_plane = s-> last_frame.data [plane]; |
1673 if (plane == 0) { | 1662 uint8_t *golden_plane = s-> golden_frame.data [plane]; |
1674 output_plane = s->current_frame.data[0]; | 1663 int stride = s->current_frame.linesize[plane]; |
1675 last_plane = s->last_frame.data[0]; | 1664 int plane_width = s->width >> !!plane; |
1676 golden_plane = s->golden_frame.data[0]; | 1665 int plane_height = s->height >> !!plane; |
1677 stride = s->current_frame.linesize[0]; | 1666 int y = slice * FRAGMENT_PIXELS << !plane ; |
1678 if (!s->flipped_image) stride = -stride; | 1667 int slice_height = y + (FRAGMENT_PIXELS << !plane); |
1679 upper_motion_limit = 7 * s->current_frame.linesize[0]; | 1668 int i = s->macroblock_fragments[current_macroblock_entry + plane + 3*!!plane]; |
1680 lower_motion_limit = s->height * s->current_frame.linesize[0] + s->width - 8; | 1669 |
1681 y = slice * FRAGMENT_PIXELS * 2; | 1670 if (!s->flipped_image) stride = -stride; |
1682 plane_width = s->width; | 1671 |
1683 plane_height = s->height; | |
1684 slice_height = y + FRAGMENT_PIXELS * 2; | |
1685 i = s->macroblock_fragments[current_macroblock_entry + 0]; | |
1686 } else if (plane == 1) { | |
1687 output_plane = s->current_frame.data[1]; | |
1688 last_plane = s->last_frame.data[1]; | |
1689 golden_plane = s->golden_frame.data[1]; | |
1690 stride = s->current_frame.linesize[1]; | |
1691 if (!s->flipped_image) stride = -stride; | |
1692 upper_motion_limit = 7 * s->current_frame.linesize[1]; | |
1693 lower_motion_limit = (s->height / 2) * s->current_frame.linesize[1] + (s->width / 2) - 8; | |
1694 y = slice * FRAGMENT_PIXELS; | |
1695 plane_width = s->width / 2; | |
1696 plane_height = s->height / 2; | |
1697 slice_height = y + FRAGMENT_PIXELS; | |
1698 i = s->macroblock_fragments[current_macroblock_entry + 4]; | |
1699 } else { | |
1700 output_plane = s->current_frame.data[2]; | |
1701 last_plane = s->last_frame.data[2]; | |
1702 golden_plane = s->golden_frame.data[2]; | |
1703 stride = s->current_frame.linesize[2]; | |
1704 if (!s->flipped_image) stride = -stride; | |
1705 upper_motion_limit = 7 * s->current_frame.linesize[2]; | |
1706 lower_motion_limit = (s->height / 2) * s->current_frame.linesize[2] + (s->width / 2) - 8; | |
1707 y = slice * FRAGMENT_PIXELS; | |
1708 plane_width = s->width / 2; | |
1709 plane_height = s->height / 2; | |
1710 slice_height = y + FRAGMENT_PIXELS; | |
1711 i = s->macroblock_fragments[current_macroblock_entry + 5]; | |
1712 } | |
1713 fragment_width = plane_width / FRAGMENT_PIXELS; | |
1714 | 1672 |
1715 if(ABS(stride) > 2048) | 1673 if(ABS(stride) > 2048) |
1716 return; //various tables are fixed size | 1674 return; //various tables are fixed size |
1717 | 1675 |
1718 /* for each fragment row in the slice (both of them)... */ | 1676 /* for each fragment row in the slice (both of them)... */ |
1936 } | 1894 } |
1937 } | 1895 } |
1938 | 1896 |
1939 static void apply_loop_filter(Vp3DecodeContext *s) | 1897 static void apply_loop_filter(Vp3DecodeContext *s) |
1940 { | 1898 { |
1941 int x, y, plane; | 1899 int plane; |
1942 int width, height; | 1900 int x, y; |
1943 int fragment; | |
1944 int stride; | |
1945 unsigned char *plane_data; | |
1946 int *bounding_values= s->bounding_values_array+127; | 1901 int *bounding_values= s->bounding_values_array+127; |
1947 | 1902 |
1948 #if 0 | 1903 #if 0 |
1949 int bounding_values_array[256]; | 1904 int bounding_values_array[256]; |
1950 int filter_limit; | 1905 int filter_limit; |
1965 bounding_values[x + filter_limit] = filter_limit - x; | 1920 bounding_values[x + filter_limit] = filter_limit - x; |
1966 } | 1921 } |
1967 #endif | 1922 #endif |
1968 | 1923 |
1969 for (plane = 0; plane < 3; plane++) { | 1924 for (plane = 0; plane < 3; plane++) { |
1970 | 1925 int width = s->fragment_width >> !!plane; |
1971 if (plane == 0) { | 1926 int height = s->fragment_height >> !!plane; |
1972 /* Y plane parameters */ | 1927 int fragment = s->fragment_start [plane]; |
1973 fragment = 0; | 1928 int stride = s->current_frame.linesize[plane]; |
1974 width = s->fragment_width; | 1929 uint8_t *plane_data = s->current_frame.data [plane]; |
1975 height = s->fragment_height; | |
1976 stride = s->current_frame.linesize[0]; | |
1977 plane_data = s->current_frame.data[0]; | |
1978 } else if (plane == 1) { | |
1979 /* U plane parameters */ | |
1980 fragment = s->u_fragment_start; | |
1981 width = s->fragment_width / 2; | |
1982 height = s->fragment_height / 2; | |
1983 stride = s->current_frame.linesize[1]; | |
1984 plane_data = s->current_frame.data[1]; | |
1985 } else { | |
1986 /* V plane parameters */ | |
1987 fragment = s->v_fragment_start; | |
1988 width = s->fragment_width / 2; | |
1989 height = s->fragment_height / 2; | |
1990 stride = s->current_frame.linesize[2]; | |
1991 plane_data = s->current_frame.data[2]; | |
1992 } | |
1993 if (!s->flipped_image) stride = -stride; | 1930 if (!s->flipped_image) stride = -stride; |
1994 | 1931 |
1995 for (y = 0; y < height; y++) { | 1932 for (y = 0; y < height; y++) { |
1996 | 1933 |
1997 for (x = 0; x < width; x++) { | 1934 for (x = 0; x < width; x++) { |
2064 i-1, s->all_fragments[i-1].first_pixel); | 2001 i-1, s->all_fragments[i-1].first_pixel); |
2065 } | 2002 } |
2066 } | 2003 } |
2067 | 2004 |
2068 /* U plane */ | 2005 /* U plane */ |
2069 i = s->u_fragment_start; | 2006 i = s->fragment_start[1]; |
2070 for (y = s->fragment_height / 2; y > 0; y--) { | 2007 for (y = s->fragment_height / 2; y > 0; y--) { |
2071 for (x = 0; x < s->fragment_width / 2; x++) { | 2008 for (x = 0; x < s->fragment_width / 2; x++) { |
2072 s->all_fragments[i++].first_pixel = | 2009 s->all_fragments[i++].first_pixel = |
2073 s->golden_frame.linesize[1] * y * FRAGMENT_PIXELS - | 2010 s->golden_frame.linesize[1] * y * FRAGMENT_PIXELS - |
2074 s->golden_frame.linesize[1] + | 2011 s->golden_frame.linesize[1] + |
2077 i-1, s->all_fragments[i-1].first_pixel); | 2014 i-1, s->all_fragments[i-1].first_pixel); |
2078 } | 2015 } |
2079 } | 2016 } |
2080 | 2017 |
2081 /* V plane */ | 2018 /* V plane */ |
2082 i = s->v_fragment_start; | 2019 i = s->fragment_start[2]; |
2083 for (y = s->fragment_height / 2; y > 0; y--) { | 2020 for (y = s->fragment_height / 2; y > 0; y--) { |
2084 for (x = 0; x < s->fragment_width / 2; x++) { | 2021 for (x = 0; x < s->fragment_width / 2; x++) { |
2085 s->all_fragments[i++].first_pixel = | 2022 s->all_fragments[i++].first_pixel = |
2086 s->golden_frame.linesize[2] * y * FRAGMENT_PIXELS - | 2023 s->golden_frame.linesize[2] * y * FRAGMENT_PIXELS - |
2087 s->golden_frame.linesize[2] + | 2024 s->golden_frame.linesize[2] + |
2111 i-1, s->all_fragments[i-1].first_pixel); | 2048 i-1, s->all_fragments[i-1].first_pixel); |
2112 } | 2049 } |
2113 } | 2050 } |
2114 | 2051 |
2115 /* U plane */ | 2052 /* U plane */ |
2116 i = s->u_fragment_start; | 2053 i = s->fragment_start[1]; |
2117 for (y = 1; y <= s->fragment_height / 2; y++) { | 2054 for (y = 1; y <= s->fragment_height / 2; y++) { |
2118 for (x = 0; x < s->fragment_width / 2; x++) { | 2055 for (x = 0; x < s->fragment_width / 2; x++) { |
2119 s->all_fragments[i++].first_pixel = | 2056 s->all_fragments[i++].first_pixel = |
2120 s->golden_frame.linesize[1] * y * FRAGMENT_PIXELS - | 2057 s->golden_frame.linesize[1] * y * FRAGMENT_PIXELS - |
2121 s->golden_frame.linesize[1] + | 2058 s->golden_frame.linesize[1] + |
2124 i-1, s->all_fragments[i-1].first_pixel); | 2061 i-1, s->all_fragments[i-1].first_pixel); |
2125 } | 2062 } |
2126 } | 2063 } |
2127 | 2064 |
2128 /* V plane */ | 2065 /* V plane */ |
2129 i = s->v_fragment_start; | 2066 i = s->fragment_start[2]; |
2130 for (y = 1; y <= s->fragment_height / 2; y++) { | 2067 for (y = 1; y <= s->fragment_height / 2; y++) { |
2131 for (x = 0; x < s->fragment_width / 2; x++) { | 2068 for (x = 0; x < s->fragment_width / 2; x++) { |
2132 s->all_fragments[i++].first_pixel = | 2069 s->all_fragments[i++].first_pixel = |
2133 s->golden_frame.linesize[2] * y * FRAGMENT_PIXELS - | 2070 s->golden_frame.linesize[2] * y * FRAGMENT_PIXELS - |
2134 s->golden_frame.linesize[2] + | 2071 s->golden_frame.linesize[2] + |
2194 s->fragment_width = s->width / FRAGMENT_PIXELS; | 2131 s->fragment_width = s->width / FRAGMENT_PIXELS; |
2195 s->fragment_height = s->height / FRAGMENT_PIXELS; | 2132 s->fragment_height = s->height / FRAGMENT_PIXELS; |
2196 | 2133 |
2197 /* fragment count covers all 8x8 blocks for all 3 planes */ | 2134 /* fragment count covers all 8x8 blocks for all 3 planes */ |
2198 s->fragment_count = s->fragment_width * s->fragment_height * 3 / 2; | 2135 s->fragment_count = s->fragment_width * s->fragment_height * 3 / 2; |
2199 s->u_fragment_start = s->fragment_width * s->fragment_height; | 2136 s->fragment_start[1] = s->fragment_width * s->fragment_height; |
2200 s->v_fragment_start = s->fragment_width * s->fragment_height * 5 / 4; | 2137 s->fragment_start[2] = s->fragment_width * s->fragment_height * 5 / 4; |
2201 | 2138 |
2202 debug_init(" Y plane: %d x %d\n", s->width, s->height); | 2139 debug_init(" Y plane: %d x %d\n", s->width, s->height); |
2203 debug_init(" C plane: %d x %d\n", c_width, c_height); | 2140 debug_init(" C plane: %d x %d\n", c_width, c_height); |
2204 debug_init(" Y superblocks: %d x %d, %d total\n", | 2141 debug_init(" Y superblocks: %d x %d, %d total\n", |
2205 s->y_superblock_width, s->y_superblock_height, y_superblock_count); | 2142 s->y_superblock_width, s->y_superblock_height, y_superblock_count); |
2211 s->macroblock_width, s->macroblock_height, s->macroblock_count); | 2148 s->macroblock_width, s->macroblock_height, s->macroblock_count); |
2212 debug_init(" %d fragments, %d x %d, u starts @ %d, v starts @ %d\n", | 2149 debug_init(" %d fragments, %d x %d, u starts @ %d, v starts @ %d\n", |
2213 s->fragment_count, | 2150 s->fragment_count, |
2214 s->fragment_width, | 2151 s->fragment_width, |
2215 s->fragment_height, | 2152 s->fragment_height, |
2216 s->u_fragment_start, | 2153 s->fragment_start[1], |
2217 s->v_fragment_start); | 2154 s->fragment_start[2]); |
2218 | 2155 |
2219 s->all_fragments = av_malloc(s->fragment_count * sizeof(Vp3Fragment)); | 2156 s->all_fragments = av_malloc(s->fragment_count * sizeof(Vp3Fragment)); |
2220 s->coeffs = av_malloc(s->fragment_count * sizeof(Coeff) * 65); | 2157 s->coeffs = av_malloc(s->fragment_count * sizeof(Coeff) * 65); |
2221 s->coded_fragment_list = av_malloc(s->fragment_count * sizeof(int)); | 2158 s->coded_fragment_list = av_malloc(s->fragment_count * sizeof(int)); |
2222 s->pixel_addresses_inited = 0; | 2159 s->pixel_addresses_inited = 0; |
2499 STOP_TIMER("unpack_dct_coeffs")} | 2436 STOP_TIMER("unpack_dct_coeffs")} |
2500 {START_TIMER | 2437 {START_TIMER |
2501 | 2438 |
2502 reverse_dc_prediction(s, 0, s->fragment_width, s->fragment_height); | 2439 reverse_dc_prediction(s, 0, s->fragment_width, s->fragment_height); |
2503 if ((avctx->flags & CODEC_FLAG_GRAY) == 0) { | 2440 if ((avctx->flags & CODEC_FLAG_GRAY) == 0) { |
2504 reverse_dc_prediction(s, s->u_fragment_start, | 2441 reverse_dc_prediction(s, s->fragment_start[1], |
2505 s->fragment_width / 2, s->fragment_height / 2); | 2442 s->fragment_width / 2, s->fragment_height / 2); |
2506 reverse_dc_prediction(s, s->v_fragment_start, | 2443 reverse_dc_prediction(s, s->fragment_start[2], |
2507 s->fragment_width / 2, s->fragment_height / 2); | 2444 s->fragment_width / 2, s->fragment_height / 2); |
2508 } | 2445 } |
2509 STOP_TIMER("reverse_dc_prediction")} | 2446 STOP_TIMER("reverse_dc_prediction")} |
2510 {START_TIMER | 2447 {START_TIMER |
2511 | 2448 |