Debian Codegraph @

third_party/etc2comp/EtcTool/EtcFileHeader.h

raw
1 /*
2 * Copyright 2015 The Etc2Comp Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #pragma once
18
19 #include "EtcFile.h"
20 #include <stdio.h>
21 #include <inttypes.h>
22
23 namespace Etc
24 {
25
26 class Image;
27
28 class FileHeader
29 {
30 public:
31
32 virtual void Write(FILE *a_pfile) = 0;
33 File GetFile();
34 virtual ~FileHeader(void) {}
35 protected:
36
37 File *m_pfile;
38 };
39
40 // ----------------------------------------------------------------------------------------------------
41 //
42 class FileHeader_Pkm : public FileHeader
43 {
44 public:
45
46 FileHeader_Pkm(File *a_pfile);
47
48 virtual void Write(FILE *a_pfile);
49 virtual ~FileHeader_Pkm(void) {}
50 private:
51
52 typedef struct
53 {
54 char m_acMagicNumber[4];
55 char m_acVersion[2];
56 unsigned char m_ucDataType_msb; // e.g. ETC1_RGB_NO_MIPMAPS
57 unsigned char m_ucDataType_lsb;
58 unsigned char m_ucExtendedWidth_msb; // padded to 4x4 blocks
59 unsigned char m_ucExtendedWidth_lsb;
60 unsigned char m_ucExtendedHeight_msb; // padded to 4x4 blocks
61 unsigned char m_ucExtendedHeight_lsb;
62 unsigned char m_ucOriginalWidth_msb;
63 unsigned char m_ucOriginalWidth_lsb;
64 unsigned char m_ucOriginalHeight_msb;
65 unsigned char m_ucOriginalHeight_lsb;
66 } Data;
67
68 Data m_data;
69 };
70
71 // ----------------------------------------------------------------------------------------------------
72 //
73 class FileHeader_Ktx : public FileHeader
74 {
75 public:
76
77 typedef struct
78 {
79 uint32_t u32KeyAndValueByteSize;
80 } KeyValuePair;
81
82 typedef struct
83 {
84 uint8_t m_au8Identifier[12];
85 uint32_t m_u32Endianness;
86 uint32_t m_u32GlType;
87 uint32_t m_u32GlTypeSize;
88 uint32_t m_u32GlFormat;
89 uint32_t m_u32GlInternalFormat;
90 uint32_t m_u32GlBaseInternalFormat;
91 uint32_t m_u32PixelWidth;
92 uint32_t m_u32PixelHeight;
93 uint32_t m_u32PixelDepth;
94 uint32_t m_u32NumberOfArrayElements;
95 uint32_t m_u32NumberOfFaces;
96 uint32_t m_u32NumberOfMipmapLevels;
97 uint32_t m_u32BytesOfKeyValueData;
98 } Data;
99
100 enum class InternalFormat
101 {
102 ETC1_RGB8 = 0x8D64,
103 ETC1_ALPHA8 = ETC1_RGB8,
104 //
105 ETC2_R11 = 0x9270,
106 ETC2_SIGNED_R11 = 0x9271,
107 ETC2_RG11 = 0x9272,
108 ETC2_SIGNED_RG11 = 0x9273,
109 ETC2_RGB8 = 0x9274,
110 ETC2_SRGB8 = 0x9275,
111 ETC2_RGB8A1 = 0x9276,
112 ETC2_SRGB8_PUNCHTHROUGH_ALPHA1 = 0x9277,
113 ETC2_RGBA8 = 0x9278
114 };
115
116 enum class BaseInternalFormat
117 {
118 ETC2_R11 = 0x1903,
119 ETC2_RG11 = 0x8227,
120 ETC1_RGB8 = 0x1907,
121 ETC1_ALPHA8 = ETC1_RGB8,
122 //
123 ETC2_RGB8 = 0x1907,
124 ETC2_RGB8A1 = 0x1908,
125 ETC2_RGBA8 = 0x1908,
126 };
127
128 FileHeader_Ktx(File *a_pfile);
129
130 virtual void Write(FILE *a_pfile);
131 virtual ~FileHeader_Ktx(void) {}
132
133 void AddKeyAndValue(KeyValuePair *a_pkeyvaluepair);
134
135 Data* GetData();
136
137 private:
138
139 Data m_data;
140 KeyValuePair *m_pkeyvaluepair;
141
142 uint32_t m_u32Images;
143 uint32_t m_u32KeyValuePairs;
144 };
145
146 } // namespace Etc