• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ASTC_CODEC_H_
16 #define ASTC_CODEC_ASTC_CODEC_H_
17 
18 #include <cstddef>
19 #include <cstdint>
20 
21 namespace astc_codec {
22 
23 // These are the valid ASTC footprints according to the specification in
24 // Section C.2.7.
25 enum class FootprintType {
26   k4x4,
27   k5x4,
28   k5x5,
29   k6x5,
30   k6x6,
31   k8x5,
32   k8x6,
33   k10x5,
34   k10x6,
35   k8x8,
36   k10x8,
37   k10x10,
38   k12x10,
39   k12x12,
40 
41   kCount
42 };
43 
44 // Decompresses ASTC LDR image data to a RGBA32 buffer.
45 //
46 // Supports formats defined in the KHR_texture_compression_astc_ldr spec and
47 // returns UNORM8 values.  sRGB is not supported, and should be implemented
48 // by the caller.
49 //
50 // |astc_data| - Compressed ASTC image buffer, must be at least |astc_data_size|
51 //               bytes long.
52 // |astc_data_size| - The size of |astc_data|, in bytes.
53 // |width| - Image width, in pixels.
54 // |height| - Image height, in pixels.
55 // |footprint| - The ASTC footprint (block size) of the compressed image buffer.
56 // |out_buffer| - Pointer to a buffer where the decompressed image will be
57 //                stored, must be at least |out_buffer_size| bytes long.
58 // |out_buffer_size| - The size of |out_buffer|, in bytes, at least
59 //                     height*out_buffer_stride. If this is too small, this
60 //                     function will return false and no data will be
61 //                     decompressed.
62 // |out_buffer_stride| - The stride that should be used to store rows of the
63 //                       decoded image, must be at least 4*width bytes.
64 //
65 // Returns true if the decompression succeeded, or false if decompression
66 // failed, or if the astc_data_size was too small for the given width, height,
67 // and footprint, or if out_buffer_size is too small.
68 bool ASTCDecompressToRGBA(const uint8_t* astc_data, size_t astc_data_size,
69                           size_t width, size_t height, FootprintType footprint,
70                           uint8_t* out_buffer, size_t out_buffer_size,
71                           size_t out_buffer_stride);
72 
73 }  // namespace astc_codec
74 
75 #endif  // ASTC_CODEC_ASTC_CODEC_H_
76