1/* -*- tab-width: 4; -*- */
2/* vi: set sw=2 ts=4 expandtab textwidth=70: */
3
4/*
5 * Copyright 2019-2020 The Khronos Group Inc.
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
9/**
10 * @internal
11 * @file basisu_sgd.h
12 * @~English
13 *
14 * @brief Declare global data for Basis LZ supercompression with ETC1S.
15 *
16 * These functions are private and should not be used outside the library.
17 */
18
19#ifndef _BASIS_SGD_H_
20#define _BASIS_SGD_H_
21
22#include <stdint.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28// This must be the same value as cSliceDescFlagsFrameIsIFrame so we can just
29// invert the bit when passing back & forth. As FrameIsIFrame is within
30// a C namespace it can't easily be accessed from a c header.
31enum bu_image_flags__bits_e { eBUImageIsPframe = 0x02 };
32
33typedef uint32_t buFlags;
34
35typedef struct ktxBasisLzGlobalHeader {
36 uint16_t endpointCount;
37 uint16_t selectorCount;
38 uint32_t endpointsByteLength;
39 uint32_t selectorsByteLength;
40 uint32_t tablesByteLength;
41 uint32_t extendedByteLength;
42} ktxBasisLzGlobalHeader;
43
44// This header is followed by imageCount "slice" descriptions.
45
46// 1, or 2 slices per image (i.e. layer, face & slice).
47// These offsets are relative to start of a mip level as given by the
48// main levelIndex.
49typedef struct ktxBasisLzEtc1sImageDesc {
50 buFlags imageFlags;
51 uint32_t rgbSliceByteOffset;
52 uint32_t rgbSliceByteLength;
53 uint32_t alphaSliceByteOffset;
54 uint32_t alphaSliceByteLength;
55} ktxBasisLzEtc1sImageDesc;
56
57#define BGD_ETC1S_IMAGE_DESCS(bgd) \
58 reinterpret_cast<ktxBasisLzEtc1sImageDesc*>(bgd + sizeof(ktxBasisLzGlobalHeader))
59
60// The are followed in the global data by these ...
61// uint8_t[endpointsByteLength] endpointsData;
62// uint8_t[selectorsByteLength] selectorsData;
63// uint8_t[tablesByteLength] tablesData;
64
65#define BGD_ENDPOINTS_ADDR(bgd, imageCount) \
66 (bgd + sizeof(ktxBasisLzGlobalHeader) + sizeof(ktxBasisLzEtc1sImageDesc) * imageCount)
67
68#define BGD_SELECTORS_ADDR(bgd, bgdh, imageCount) (BGD_ENDPOINTS_ADDR(bgd, imageCount) + bgdh.endpointsByteLength)
69
70#define BGD_TABLES_ADDR(bgd, bgdh, imageCount) (BGD_SELECTORS_ADDR(bgd, bgdh, imageCount) + bgdh.selectorsByteLength)
71
72#define BGD_EXTENDED_ADDR(bgd, bgdh, imageCount) (BGD_TABLES_ADDR(bgd, bgdh, imageCount) + bgdh.tablesByteLength)
73
74// Just because this is a convenient place to put it for basis_{en,trans}code.
75enum alpha_content_e {
76 eNone,
77 eAlpha,
78 eGreen
79};
80
81#ifdef __cplusplus
82}
83#endif
84
85#endif /* _BASIS_SGD_H_ */
86