Texture.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #pragma once
  2. #include <cstdint>
  3. #include <map>
  4. #include <memory>
  5. #include <string>
  6. #include <vector>
  7. #include "Types.h"
  8. namespace WallpaperEngine::Data::Assets {
  9. enum ContainerVersion {
  10. ContainerVersion_UNKNOWN = 0,
  11. ContainerVersion_TEXB0001 = 1,
  12. ContainerVersion_TEXB0002 = 2,
  13. ContainerVersion_TEXB0003 = 3,
  14. ContainerVersion_TEXB0004 = 4,
  15. };
  16. enum AnimatedVersion {
  17. AnimatedVersion_UNKNOWN = 0,
  18. AnimatedVersion_TEXS0002 = 2,
  19. AnimatedVersion_TEXS0003 = 3,
  20. };
  21. enum FIF {
  22. FIF_UNKNOWN = -1,
  23. FIF_BMP = 0,
  24. FIF_ICO = 1,
  25. FIF_JPEG = 2,
  26. FIF_JNG = 3,
  27. FIF_KOALA = 4,
  28. FIF_LBM = 5,
  29. FIF_IFF = FIF_LBM,
  30. FIF_MNG = 6,
  31. FIF_PBM = 7,
  32. FIF_PBMRAW = 8,
  33. FIF_PCD = 9,
  34. FIF_PCX = 10,
  35. FIF_PGM = 11,
  36. FIF_PGMRAW = 12,
  37. FIF_PNG = 13,
  38. FIF_PPM = 14,
  39. FIF_PPMRAW = 15,
  40. FIF_RAS = 16,
  41. FIF_TARGA = 17,
  42. FIF_TIFF = 18,
  43. FIF_WBMP = 19,
  44. FIF_PSD = 20,
  45. FIF_CUT = 21,
  46. FIF_XBM = 22,
  47. FIF_XPM = 23,
  48. FIF_DDS = 24,
  49. FIF_GIF = 25,
  50. FIF_HDR = 26,
  51. FIF_FAXG3 = 27,
  52. FIF_SGI = 28,
  53. FIF_EXR = 29,
  54. FIF_J2K = 30,
  55. FIF_JP2 = 31,
  56. FIF_PFM = 32,
  57. FIF_PICT = 33,
  58. FIF_RAW = 34,
  59. FIF_WEBP = 35,
  60. FIF_MP4 = FIF_WEBP,
  61. FIF_JXR = 36
  62. };
  63. enum TextureFormat {
  64. TextureFormat_UNKNOWN = 0xFFFFFFFF,
  65. TextureFormat_ARGB8888 = 0,
  66. TextureFormat_RGB888 = 1,
  67. TextureFormat_RGB565 = 2,
  68. TextureFormat_DXT5 = 4,
  69. TextureFormat_DXT3 = 6,
  70. TextureFormat_DXT1 = 7,
  71. TextureFormat_RG88 = 8,
  72. TextureFormat_R8 = 9,
  73. TextureFormat_RG1616f = 10,
  74. TextureFormat_R16f = 11,
  75. TextureFormat_BC7 = 12,
  76. TextureFormat_RGBa1010102 = 13,
  77. TextureFormat_RGBA16161616f = 14,
  78. TextureFormat_RGB161616f = 15,
  79. };
  80. enum TextureFlags {
  81. TextureFlags_NoFlags = 0,
  82. TextureFlags_NoInterpolation = 1,
  83. TextureFlags_ClampUVs = 2,
  84. TextureFlags_IsGif = 4,
  85. TextureFlags_ClampUVsBorder = 8,
  86. TextureFlags_AlphaChannelPriority = 524288, // Indicates RG88/R8 format where alpha is in G/R channel
  87. TextureFlags_All = TextureFlags_NoInterpolation | TextureFlags_ClampUVs | TextureFlags_IsGif
  88. | TextureFlags_ClampUVsBorder | TextureFlags_AlphaChannelPriority,
  89. };
  90. struct Mipmap {
  91. /** Width of the mipmap */
  92. uint32_t width = 0;
  93. /** Height of the mipmap */
  94. uint32_t height = 0;
  95. /** If the mipmap data is compressed */
  96. uint32_t compression = 0;
  97. /** Uncompressed size of the mipmap */
  98. int uncompressedSize = 0;
  99. /** Compress size of the mipmap */
  100. int compressedSize = 0;
  101. /** Pointer to the compressed data */
  102. std::unique_ptr<char[]> compressedData = nullptr;
  103. /** Pointer to the uncompressed data */
  104. std::unique_ptr<char[]> uncompressedData = nullptr;
  105. /** JSON data */
  106. std::string json {};
  107. };
  108. struct Frame {
  109. /** The image index of this frame */
  110. uint32_t frameNumber = 0;
  111. /** The amount of time this frame spends being displayed */
  112. float frametime = 0.0f;
  113. /** The x position of the frame in the texture */
  114. float x = 0.0f;
  115. /** The y position of the frame in the texture */
  116. float y = 0.0f;
  117. /** The width of the frame in the texture */
  118. float width1 = 0.0f;
  119. float width2 = 0.0f;
  120. /** The height of the frame in the texture */
  121. float height1 = 0.0f;
  122. float height2 = 0.0f;
  123. };
  124. struct Texture {
  125. /** The version of the texture container */
  126. ContainerVersion containerVersion = ContainerVersion_UNKNOWN;
  127. /** The version of the animated data */
  128. AnimatedVersion animatedVersion = AnimatedVersion_UNKNOWN;
  129. /** Flags with extra texture information @see TextureFlags */
  130. uint32_t flags = TextureFlags_NoFlags;
  131. /** Real width of the texture */
  132. uint32_t width = 0;
  133. /** Real height of the texture */
  134. uint32_t height = 0;
  135. /** Texture width in memory (power of 2) */
  136. uint32_t textureWidth = 0;
  137. /** Texture height in memory (power of 2) */
  138. uint32_t textureHeight = 0;
  139. /** Gif width */
  140. uint32_t gifWidth = 0;
  141. /** Gif height */
  142. uint32_t gifHeight = 0;
  143. /** Texture data format */
  144. TextureFormat format = TextureFormat_UNKNOWN;
  145. /** Free Image format */
  146. FIF freeImageFormat = FIF_UNKNOWN;
  147. /** Indicates if we have an MP4 video */
  148. bool isVideoMp4 = false;
  149. /** The amount of images in the texture file */
  150. uint32_t imageCount = 0;
  151. /** List of mipmaps */
  152. std::map<uint32_t, MipmapList> images {};
  153. /** List of animation frames */
  154. std::vector<FrameSharedPtr> frames {};
  155. /** Spritesheet grid data (from .tex-json metadata) */
  156. uint32_t spritesheetCols = 0;
  157. uint32_t spritesheetRows = 0;
  158. uint32_t spritesheetFrames = 0;
  159. float spritesheetDuration = 0.0f;
  160. [[nodiscard]] bool isAnimated () const { return (flags & TextureFlags_IsGif) == TextureFlags_IsGif; }
  161. [[nodiscard]] bool hasSpritesheet () const { return spritesheetFrames > 0; }
  162. };
  163. }