aboutsummaryrefslogtreecommitdiff
path: root/src/decoder/endpoint_codec.h
diff options
context:
space:
mode:
authorGravatar Jeff McGlynn <jwmcglynn@google.com>2018-06-20 11:34:20 -0700
committerGravatar Jeff McGlynn <jwmcglynn@google.com>2018-06-20 11:50:22 -0700
commitb56a50064caf2a590ba43699e0074690fcd431bf (patch)
treed81c98f2d097f9b32f23cffef7afa6725a182e66 /src/decoder/endpoint_codec.h
parentce724a5f1c94f539a6bf956fc6431c37e97961a9 (diff)
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
Diffstat (limited to 'src/decoder/endpoint_codec.h')
-rw-r--r--src/decoder/endpoint_codec.h90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/decoder/endpoint_codec.h b/src/decoder/endpoint_codec.h
new file mode 100644
index 0000000..a1232d0
--- /dev/null
+++ b/src/decoder/endpoint_codec.h
@@ -0,0 +1,90 @@
+// 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_ENDPOINT_CODEC_H_
+#define ASTC_CODEC_DECODER_ENDPOINT_CODEC_H_
+
+#include "src/decoder/physical_astc_block.h"
+#include "src/decoder/types.h"
+
+#include <array>
+#include <vector>
+
+namespace astc_codec {
+
+// We use a special distinction for encode modes used to pass to the
+// EncodeColorsForMode function below. The reason is that some of the color
+// modes have sub-modes (like blue-contract) that change whether or not it is
+// useful to encode an endpoint pair using one mode versus another. To avoid
+// this problem, we approach the problem of encoding by specifying some
+// high-level encoding modes. These eventually choose one of the low level
+// ColorEndpointModes from Section C.2.14 when used in EncodeColorsForMode.
+enum class EndpointEncodingMode {
+ kDirectLuma,
+ kDirectLumaAlpha,
+ kBaseScaleRGB,
+ kBaseScaleRGBA,
+ kDirectRGB,
+ kDirectRGBA
+};
+
+// Returns the number of values in the encoded endpoint pair after encoding
+// to a specific high-level encoding mode.
+constexpr int NumValuesForEncodingMode(EndpointEncodingMode mode) {
+ return
+ mode == EndpointEncodingMode::kDirectLuma ? 2 :
+ mode == EndpointEncodingMode::kDirectLumaAlpha ? 4 :
+ mode == EndpointEncodingMode::kBaseScaleRGB ? 4 :
+ mode == EndpointEncodingMode::kBaseScaleRGBA ? 6 :
+ mode == EndpointEncodingMode::kDirectRGB ? 6 : 8;
+}
+
+// Fills |vals| with the quantized endpoint colors values defined in the ASTC
+// specification. The values are quantized to the range [0, max_value]. These
+// quantization limits can be obtained by querying the associated functions in
+// integer_sequence_codec. The returned |astc_mode| will be the ASTC mode used
+// to encode the resulting sequence.
+//
+// The |encoding_mode| is used to determine the way that we encode the values.
+// Each encoding mode is used to determine which ASTC mode best corresponds
+// to the pair of endpoints. It is a necessary hint to the encoding function
+// in order to process the endpoints. Each encoding mode gurantees a certain
+// number of values generated per endpoints.
+//
+// The return value will be true if the endpoints have been switched in order to
+// reap the most benefit from the way the hardware decodes the given mode. In
+// this case, the associated weights that interpolate this color must also be
+// switched. In other words, for each w, it should change to 64 - w.
+bool EncodeColorsForMode(
+ const RgbaColor& endpoint_low_rgba, const RgbaColor& endpoint_high_rgba,
+ int max_value, EndpointEncodingMode encoding_mode,
+ ColorEndpointMode* astc_mode, std::vector<int>* vals);
+
+// Decodes the color values quantized to the range [0, max_value] into RGBA
+// endpoints for the given mode. This function is the inverse of
+// EncodeColorsForMode -- see that function for details. This function should
+// work on all LDR endpoint modes, but no HDR modes.
+void DecodeColorsForMode(const std::vector<int>& vals,
+ int max_value, ColorEndpointMode mode,
+ RgbaColor* endpoint_low_rgba,
+ RgbaColor* endpoint_high_rgba);
+
+// Returns true if the quantized |vals| in the range [0, max_value] use the
+// 'blue_contract' modification during decoding for the given |mode|.
+bool UsesBlueContract(int max_value, ColorEndpointMode mode,
+ const std::vector<int>& vals);
+
+} // namespace astc_codec
+
+#endif // ASTC_CODEC_DECODER_ENDPOINT_CODEC_H_