EtcFileHeader.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. #pragma once
  17. #include "EtcFile.h"
  18. #include <stdio.h>
  19. #include <inttypes.h>
  20. namespace Etc
  21. {
  22. class Image;
  23. class FileHeader
  24. {
  25. public:
  26. virtual void Write(FILE *a_pfile) = 0;
  27. File GetFile();
  28. virtual ~FileHeader(void) {}
  29. protected:
  30. File *m_pfile;
  31. };
  32. // ----------------------------------------------------------------------------------------------------
  33. //
  34. class FileHeader_Pkm : public FileHeader
  35. {
  36. public:
  37. FileHeader_Pkm(File *a_pfile);
  38. virtual void Write(FILE *a_pfile);
  39. virtual ~FileHeader_Pkm(void) {}
  40. private:
  41. typedef struct
  42. {
  43. char m_acMagicNumber[4];
  44. char m_acVersion[2];
  45. unsigned char m_ucDataType_msb; // e.g. ETC1_RGB_NO_MIPMAPS
  46. unsigned char m_ucDataType_lsb;
  47. unsigned char m_ucExtendedWidth_msb; // padded to 4x4 blocks
  48. unsigned char m_ucExtendedWidth_lsb;
  49. unsigned char m_ucExtendedHeight_msb; // padded to 4x4 blocks
  50. unsigned char m_ucExtendedHeight_lsb;
  51. unsigned char m_ucOriginalWidth_msb;
  52. unsigned char m_ucOriginalWidth_lsb;
  53. unsigned char m_ucOriginalHeight_msb;
  54. unsigned char m_ucOriginalHeight_lsb;
  55. } Data;
  56. Data m_data;
  57. };
  58. // ----------------------------------------------------------------------------------------------------
  59. //
  60. class FileHeader_Ktx : public FileHeader
  61. {
  62. public:
  63. typedef struct
  64. {
  65. uint32_t u32KeyAndValueByteSize;
  66. } KeyValuePair;
  67. typedef struct
  68. {
  69. uint8_t m_au8Identifier[12];
  70. uint32_t m_u32Endianness;
  71. uint32_t m_u32GlType;
  72. uint32_t m_u32GlTypeSize;
  73. uint32_t m_u32GlFormat;
  74. uint32_t m_u32GlInternalFormat;
  75. uint32_t m_u32GlBaseInternalFormat;
  76. uint32_t m_u32PixelWidth;
  77. uint32_t m_u32PixelHeight;
  78. uint32_t m_u32PixelDepth;
  79. uint32_t m_u32NumberOfArrayElements;
  80. uint32_t m_u32NumberOfFaces;
  81. uint32_t m_u32NumberOfMipmapLevels;
  82. uint32_t m_u32BytesOfKeyValueData;
  83. } Data;
  84. enum class InternalFormat
  85. {
  86. ETC1_RGB8 = 0x8D64,
  87. ETC1_ALPHA8 = ETC1_RGB8,
  88. //
  89. ETC2_R11 = 0x9270,
  90. ETC2_SIGNED_R11 = 0x9271,
  91. ETC2_RG11 = 0x9272,
  92. ETC2_SIGNED_RG11 = 0x9273,
  93. ETC2_RGB8 = 0x9274,
  94. ETC2_SRGB8 = 0x9275,
  95. ETC2_RGB8A1 = 0x9276,
  96. ETC2_SRGB8_PUNCHTHROUGH_ALPHA1 = 0x9277,
  97. ETC2_RGBA8 = 0x9278
  98. };
  99. enum class BaseInternalFormat
  100. {
  101. ETC2_R11 = 0x1903,
  102. ETC2_RG11 = 0x8227,
  103. ETC1_RGB8 = 0x1907,
  104. ETC1_ALPHA8 = ETC1_RGB8,
  105. //
  106. ETC2_RGB8 = 0x1907,
  107. ETC2_RGB8A1 = 0x1908,
  108. ETC2_RGBA8 = 0x1908,
  109. };
  110. FileHeader_Ktx(File *a_pfile);
  111. virtual void Write(FILE *a_pfile);
  112. virtual ~FileHeader_Ktx(void) {}
  113. void AddKeyAndValue(KeyValuePair *a_pkeyvaluepair);
  114. Data* GetData();
  115. private:
  116. Data m_data;
  117. KeyValuePair *m_pkeyvaluepair;
  118. uint32_t m_u32Images;
  119. uint32_t m_u32KeyValuePairs;
  120. };
  121. } // namespace Etc