From b56a50064caf2a590ba43699e0074690fcd431bf Mon Sep 17 00:00:00 2001 From: Jeff McGlynn Date: Wed, 20 Jun 2018 11:34:20 -0700 Subject: Initial version of astc-codec for open source release Contains an implementation of an ASTC decoder that is able to pass the dEQP ASTC LDR tests. astc-codec has no external dependencies for the main library, only for test code, and is licensed under the Apache license. Components: include/ - Public API that can decode ASTC LDR data into a RGBA UNORM8 buffer. src/base/ - Base library with common functionality not directly related to ASTC decoding. Contains a uint128 implementation, BitStream for reading/writing bits with a primitive (or uint128 type), Optional implementation (to not take a dependency on C++17), and more. src/decoder/ - Internal implementation of the ASTC decoder. src/base/test/, src/decoder/test/ - Unit tests (and a fuzzing test) for the astc decoder. src/decoder/testdata/ - Sample ASTC images and golden image results for testing. src/decoder/tools/ - A tool to inspect contents of an ASTC file. third_party/ - Third party libraries, only used for tests. Change-Id: Ia98e5a7dc847daa3d3a48c5e62d94b8fb1cb98bd --- src/decoder/quantization.h | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/decoder/quantization.h (limited to 'src/decoder/quantization.h') diff --git a/src/decoder/quantization.h b/src/decoder/quantization.h new file mode 100644 index 0000000..5f7239f --- /dev/null +++ b/src/decoder/quantization.h @@ -0,0 +1,65 @@ +// Copyright 2018 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef ASTC_CODEC_DECODER_QUANTIZATION_H_ +#define ASTC_CODEC_DECODER_QUANTIZATION_H_ + +//////////////////////////////////////////////////////////////////////////////// +// +// ASTC Quantization procedures. +// +// The values stored in ASTC blocks tend to be stored in a range much more +// restricted than the logical range used. For example, sometimes weights are +// stored in the range from [0, 3] but are used in the range [0, 64]. The +// process of translating a value to or from this range is known as quantization +// and dequantization. The ranges to which these values can be (de)quantized +// are defined by ISERange[Begin|End]() in integer_sequence_codec.h + +namespace astc_codec { + +// The minimum possible range for a pair of endpoints. If endpoints are +// quantized to something smaller than this, then it would constitute an +// illegal ASTC encoding. +constexpr int kEndpointRangeMinValue = 5; + +// The maximum possible range for a weight value. If weights are quantized to +// something larger than this, then it would constitute an illegal ASTC +// encoding. +constexpr int kWeightRangeMaxValue = 31; + +// Quantizes a value in the range [0, 255] to [0, |range|]. The quantized values +// have no correlation to the input values, and there should be no implicit +// assumptions made about their ordering. Valid values of |range_max_value| are +// in the interval [5, 255] +int QuantizeCEValueToRange(int value, int range_max_value); + +// Unquantizes a value in the range [0, |range|] to [0, 255]. Performs the +// inverse procedure of QuantizeValueToRange. Valid values of |range_max_value| +// are in the interval [5, 255] +int UnquantizeCEValueFromRange(int value, int range_max_value); + +// Quantizes a weight in the range [0, 64] to [0, |range_max_value|]. The +// quantized values have no correlation to the input values, and there should +// be no implicit assumptions made about their ordering. Valid values of +// |range_max_value| are in the interval [1, 31] +int QuantizeWeightToRange(int weight, int range_max_value); + +// Unquantizes a weight in the range [0, |range_max_value|] to [0, 64]. Performs +// the inverse procedure of QuantizeWeightToRange. Valid values of +// |range_max_value| are in the interval [1, 31] +int UnquantizeWeightFromRange(int weight, int range_max_value); + +} // namespace astc_codec + +#endif // ASTC_CODEC_DECODER_QUANTIZATION_H_ -- cgit v1.2.3