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_ASTC_TYPES_H_
16 #define ASTC_CODEC_DECODER_ASTC_TYPES_H_
17
18 #include <array>
19 #include <string>
20 #include <utility>
21
22 namespace astc_codec {
23
24 // The color endpoint mode determines how the values encoded in the ASTC block
25 // are interpreted in order to create the RGBA values for the given endpoint
26 // pair. The order of this enum is required to match the ASTC specification in
27 // Section C.2.14.
28 enum class ColorEndpointMode {
29 kLDRLumaDirect = 0,
30 kLDRLumaBaseOffset,
31 kHDRLumaLargeRange,
32 kHDRLumaSmallRange,
33 kLDRLumaAlphaDirect,
34 kLDRLumaAlphaBaseOffset,
35 kLDRRGBBaseScale,
36 kHDRRGBBaseScale,
37 kLDRRGBDirect,
38 kLDRRGBBaseOffset,
39 kLDRRGBBaseScaleTwoA,
40 kHDRRGBDirect,
41 kLDRRGBADirect,
42 kLDRRGBABaseOffset,
43 kHDRRGBDirectLDRAlpha,
44 kHDRRGBDirectHDRAlpha,
45
46 // The total number of color endpoints defined by the ASTC specification.
47 // This isn't a specific endpoint mode and its sole purpose is to be used
48 // as a constant number.
49 kNumColorEndpointModes
50 };
51
52 // Returns the class for the given mode as defined in Section C.2.11.
EndpointModeClass(ColorEndpointMode mode)53 constexpr int EndpointModeClass(ColorEndpointMode mode) {
54 return static_cast<int>(mode) / 4;
55 }
56
57 // Returns the number of encoded color values for the given endpoint mode. The
58 // number of encoded color values and their range determines the size of the
59 // color data in a physical ASTC block. This information is taken from
60 // Section C.2.17 of the ASTC specification.
NumColorValuesForEndpointMode(ColorEndpointMode mode)61 constexpr int NumColorValuesForEndpointMode(ColorEndpointMode mode) {
62 return (EndpointModeClass(mode) + 1) * 2;
63 }
64
65 // We define a number of convenience types here that give more logical meaning
66 // throughout the ASTC utilities.
67 using RgbColor = std::array<int, 3>;
68 using RgbaColor = std::array<int, 4>;
69 using Endpoint = RgbaColor;
70 using EndpointPair = std::pair<Endpoint, Endpoint>;
71
72 } // namespace astc_codec
73
74 #endif // ASTC_CODEC_DECODER_ASTC_TYPES_H_
75