1 // Copyright 2018 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef ASTC_CODEC_DECODER_QUANTIZATION_H_ 16 #define ASTC_CODEC_DECODER_QUANTIZATION_H_ 17 18 //////////////////////////////////////////////////////////////////////////////// 19 // 20 // ASTC Quantization procedures. 21 // 22 // The values stored in ASTC blocks tend to be stored in a range much more 23 // restricted than the logical range used. For example, sometimes weights are 24 // stored in the range from [0, 3] but are used in the range [0, 64]. The 25 // process of translating a value to or from this range is known as quantization 26 // and dequantization. The ranges to which these values can be (de)quantized 27 // are defined by ISERange[Begin|End]() in integer_sequence_codec.h 28 29 namespace astc_codec { 30 31 // The minimum possible range for a pair of endpoints. If endpoints are 32 // quantized to something smaller than this, then it would constitute an 33 // illegal ASTC encoding. 34 constexpr int kEndpointRangeMinValue = 5; 35 36 // The maximum possible range for a weight value. If weights are quantized to 37 // something larger than this, then it would constitute an illegal ASTC 38 // encoding. 39 constexpr int kWeightRangeMaxValue = 31; 40 41 // Quantizes a value in the range [0, 255] to [0, |range|]. The quantized values 42 // have no correlation to the input values, and there should be no implicit 43 // assumptions made about their ordering. Valid values of |range_max_value| are 44 // in the interval [5, 255] 45 int QuantizeCEValueToRange(int value, int range_max_value); 46 47 // Unquantizes a value in the range [0, |range|] to [0, 255]. Performs the 48 // inverse procedure of QuantizeValueToRange. Valid values of |range_max_value| 49 // are in the interval [5, 255] 50 int UnquantizeCEValueFromRange(int value, int range_max_value); 51 52 // Quantizes a weight in the range [0, 64] to [0, |range_max_value|]. The 53 // quantized values have no correlation to the input values, and there should 54 // be no implicit assumptions made about their ordering. Valid values of 55 // |range_max_value| are in the interval [1, 31] 56 int QuantizeWeightToRange(int weight, int range_max_value); 57 58 // Unquantizes a weight in the range [0, |range_max_value|] to [0, 64]. Performs 59 // the inverse procedure of QuantizeWeightToRange. Valid values of 60 // |range_max_value| are in the interval [1, 31] 61 int UnquantizeWeightFromRange(int weight, int range_max_value); 62 63 } // namespace astc_codec 64 65 #endif // ASTC_CODEC_DECODER_QUANTIZATION_H_ 66