@@ -17,12 +17,46 @@ void free_quantizer_decoder(uint8_t* component_value) {
1717 return ;
1818}
1919
20+
21+ void build_hop_cache () {
22+ int h ;
23+ const int hop_min = 1 , hop_max = 255 - 1 ;
24+ const float maxr = MAX_R , minr = MIN_R , range = RANGE ;
25+ double rpos , rneg ;
26+
27+ for (int hop0 = 0 ;hop0 <=255 ;hop0 ++ ) {
28+ for (int hop1 = MIN_H1 ; hop1 <=MAX_H1 ;hop1 ++ ) {
29+
30+ rpos = min (maxr ,pow (range * ((255 - hop0 )/hop1 ),1.0f /3.0f ));
31+ rpos = max (minr ,rpos );
32+
33+ rneg = min (maxr ,pow (range * (hop0 /hop1 ),1.0f /3.0f ));
34+ rneg = max (minr ,rneg );
35+
36+ h = (int )(hop0 - hop1 * rneg * rneg * rneg );
37+ h = min (hop_max ,h );
38+ h = max (h ,hop_min );
39+ cache_hops [hop0 ][hop1 - 4 ][0 ] = (uint8_t )h ;//(hop0-hop1*rneg*rneg*rneg);
40+
41+ h = (int )(hop0 - hop1 * rneg * rneg );
42+ h = min (hop_max ,h );
43+ h = max (h ,hop_min );
44+ cache_hops [hop0 ][hop1 - 4 ][1 ] = (uint8_t )h ;//(hop0-hop1*rneg*rneg);
45+
46+ h = (int )(hop0 - hop1 * rneg );
47+ h = min (hop_max ,h );
48+ h = max (h ,hop_min );
49+ cache_hops [hop0 ][hop1 - 4 ][2 ] = (uint8_t )h ;//(hop0-hop1*rneg);
50+
51+ }
52+ }
53+
54+ }
2055void decode_line_quantizer (uint8_t * hops , uint8_t * component_value , int hops_lenght ) {
2156
2257 char gradient = 0 ;
2358 unsigned char h1 = START_H1 , hop0 ;
2459 bool last_small_hop = true, small_hop ;
25- double positive_ratio , negative_ratio ;
2660 uint8_t current_hop ;
2761
2862 for (int x = 0 ; x < hops_lenght ; x ++ ) {
@@ -40,8 +74,6 @@ void decode_line_quantizer(uint8_t * hops, uint8_t * component_value, int hops_l
4074 hop0 += gradient ;
4175 #endif
4276
43- calculate_ranges (hop0 , h1 , & positive_ratio , & negative_ratio );
44-
4577 switch (current_hop )
4678 {
4779 case HOP_0 :
@@ -51,38 +83,39 @@ void decode_line_quantizer(uint8_t * hops, uint8_t * component_value, int hops_l
5183 component_value [x ] = hop0 + h1 ;
5284 break ;
5385 case HOP_P2 :
54- component_value [x ] = hop0 + ( int ) ceil ( h1 * positive_ratio ) ;
86+ component_value [x ] = 255 - cache_hops [ 255 - hop0 ][ h1 - 4 ][ 2 ] ;
5587 break ;
5688 case HOP_P3 :
57- component_value [x ] = hop0 + ( int ) ceil ( h1 * positive_ratio * positive_ratio ) ;
89+ component_value [x ] = 255 - cache_hops [ 255 - hop0 ][ h1 - 4 ][ 1 ] ;
5890 break ;
5991 case HOP_P4 :
6092 #ifdef IS_MAX_HOPS
6193 component_value [x ] = 255 ;
6294 #else
63- component_value [x ] = hop0 + ( int ) ceil ( h1 * positive_ratio * positive_ratio * positive_ratio ) ;
95+ component_value [x ] = 255 - cache_hops [ 255 - hop0 ][ h1 - 4 ][ 0 ] ;
6496 #endif
6597 break ;
6698 case HOP_N1 :
6799 component_value [x ] = hop0 - h1 ;
68100 break ;
69101 case HOP_N2 :
70- component_value [x ] = hop0 - ( int ) ceil ( h1 * negative_ratio ) ;
102+ component_value [x ] = cache_hops [ hop0 ][ h1 - 4 ][ 2 ] ;
71103 break ;
72104 case HOP_N3 :
73- component_value [x ] = hop0 - ( int ) ceil ( h1 * negative_ratio * negative_ratio ) ;
105+ component_value [x ] = cache_hops [ hop0 ][ h1 - 4 ][ 1 ] ;
74106 break ;
75107 case HOP_N4 :
76108 #ifdef IS_MAX_HOPS
77109 component_value [x ] = 0 ;
78110 #else
79- component_value [x ] = hop0 - ( int ) ceil ( h1 * negative_ratio * negative_ratio * negative_ratio ) ;
111+ component_value [x ] = cache_hops [ hop0 ][ h1 - 4 ][ 0 ] ;
80112 #endif
81113 break ;
82114 default :
83115 printf ("ERROR: Unexpected symbol were found." );
84116 break ;
85117 }
118+
86119 small_hop = is_small_hop (current_hop );
87120 h1 = adapt_h1 (h1 , small_hop , last_small_hop );
88121 #ifdef IS_GRADIENT
0 commit comments