44 * This software incorporates material from third parties. See NOTICE.txt for details.
55 *--------------------------------------------------------------------------------------------*/
66
7+ use wide:: u32x8;
8+
79use crate :: consts:: * ;
810use crate :: helpers:: * ;
911
@@ -13,7 +15,9 @@ pub struct QuantizationTables {
1315 quantization_table : [ u16 ; 64 ] ,
1416 quantization_table_transposed : [ u16 ; 64 ] ,
1517
16- quantization_table_transposed_recip : [ u32 ; 64 ] ,
18+ quantization_table_transposed_recip_vert : u32x8 ,
19+ quantization_table_transposed_recip_horiz : u32x8 ,
20+
1721 // Values for discrimination between "regular" and "noise" part of
1822 // edge AC coefficients, used in `read/write_edge_coefficient`.
1923 // Calculated using approximate maximal magnitudes
@@ -33,7 +37,8 @@ impl QuantizationTables {
3337 quantization_table : [ 0 ; 64 ] ,
3438 quantization_table_transposed : [ 0 ; 64 ] ,
3539 min_noise_threshold : [ 0 ; 14 ] ,
36- quantization_table_transposed_recip : [ 0 ; 64 ] ,
40+ quantization_table_transposed_recip_vert : u32x8:: default ( ) ,
41+ quantization_table_transposed_recip_horiz : u32x8:: default ( ) ,
3742 } ;
3843
3944 for pixel_row in 0 ..8 {
@@ -44,10 +49,18 @@ impl QuantizationTables {
4449
4550 retval. quantization_table [ coord] = q;
4651 retval. quantization_table_transposed [ coord_tr] = q;
47- retval. quantization_table_transposed_recip [ coord_tr] = QuantizationTables :: recip ( q) ;
4852 }
4953 }
5054
55+ for i in 0 ..8 {
56+ retval
57+ . quantization_table_transposed_recip_horiz
58+ . as_array_mut ( ) [ i] = Self :: recip ( retval. quantization_table [ i] ) ;
59+ retval
60+ . quantization_table_transposed_recip_vert
61+ . as_array_mut ( ) [ i] = Self :: recip ( retval. quantization_table_transposed [ i] ) ;
62+ }
63+
5164 for i in 0 ..14 {
5265 let coord = if i < 7 { i + 1 } else { ( i - 6 ) * 8 } ;
5366 if retval. quantization_table [ coord] < 9 {
@@ -78,18 +91,12 @@ impl QuantizationTables {
7891 return retval;
7992 }
8093
81- pub fn div_quantization_table_transposed_recip ( & self , v : u32 , index : usize ) -> u32 {
82- // no need to round negative towards zero since this is unsigened division
83- let result = ( ( u64:: from ( v) * u64:: from ( self . quantization_table_transposed_recip [ index] ) )
84- >> 31 + 13 ) as u32 ;
85-
86- debug_assert_eq ! (
87- result,
88- ( v / ( u32 :: from( self . quantization_table_transposed[ index] ) ) / ( 1 << 13 ) ) ,
89- "right shift"
90- ) ;
91-
92- result
94+ pub fn quantization_table_transposed_recip < const HORIZONTAL : bool > ( & self ) -> u32x8 {
95+ if HORIZONTAL {
96+ self . quantization_table_transposed_recip_horiz
97+ } else {
98+ self . quantization_table_transposed_recip_vert
99+ }
93100 }
94101
95102 pub fn get_quantization_table ( & self ) -> & [ u16 ; 64 ] {
0 commit comments