Texture.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 FIF {
  10. FIF_UNKNOWN = -1,
  11. FIF_BMP = 0,
  12. FIF_ICO = 1,
  13. FIF_JPEG = 2,
  14. FIF_JNG = 3,
  15. FIF_KOALA = 4,
  16. FIF_LBM = 5,
  17. FIF_IFF = FIF_LBM,
  18. FIF_MNG = 6,
  19. FIF_PBM = 7,
  20. FIF_PBMRAW = 8,
  21. FIF_PCD = 9,
  22. FIF_PCX = 10,
  23. FIF_PGM = 11,
  24. FIF_PGMRAW = 12,
  25. FIF_PNG = 13,
  26. FIF_PPM = 14,
  27. FIF_PPMRAW = 15,
  28. FIF_RAS = 16,
  29. FIF_TARGA = 17,
  30. FIF_TIFF = 18,
  31. FIF_WBMP = 19,
  32. FIF_PSD = 20,
  33. FIF_CUT = 21,
  34. FIF_XBM = 22,
  35. FIF_XPM = 23,
  36. FIF_DDS = 24,
  37. FIF_GIF = 25,
  38. FIF_HDR = 26,
  39. FIF_FAXG3 = 27,
  40. FIF_SGI = 28,
  41. FIF_EXR = 29,
  42. FIF_J2K = 30,
  43. FIF_JP2 = 31,
  44. FIF_PFM = 32,
  45. FIF_PICT = 33,
  46. FIF_RAW = 34,
  47. FIF_WEBP = 35,
  48. FIF_MP4 = FIF_WEBP,
  49. FIF_JXR = 36
  50. };
  51. enum TextureFormat {
  52. TextureFormat_UNKNOWN = 0xFFFFFFFF,
  53. TextureFormat_ARGB8888 = 0,
  54. TextureFormat_RGB888 = 1,
  55. TextureFormat_RGB565 = 2,
  56. TextureFormat_DXT5 = 4,
  57. TextureFormat_DXT3 = 6,
  58. TextureFormat_DXT1 = 7,
  59. TextureFormat_RG88 = 8,
  60. TextureFormat_R8 = 9,
  61. TextureFormat_RG1616f = 10,
  62. TextureFormat_R16f = 11,
  63. TextureFormat_BC7 = 12,
  64. TextureFormat_RGBa1010102 = 13,
  65. TextureFormat_RGBA16161616f = 14,
  66. TextureFormat_RGB161616f = 15,
  67. /** The rest only have an FBO format name (sub_1401E53A0) */
  68. TextureFormat_R32f = 16,
  69. TextureFormat_RGBA16161616 = 17,
  70. TextureFormat_RGB161616 = 18,
  71. TextureFormat_RGBA16161616S = 19,
  72. TextureFormat_RGB161616S = 20,
  73. TextureFormat_RGBA8888S = 21,
  74. /** Not a .tex format: a depth only render target with 32 bit float depth (WE's shadow atlas, R32_TYPELESS) */
  75. TextureFormat_D32f = 100,
  76. };
  77. enum TextureFlags {
  78. TextureFlags_NoFlags = 0,
  79. TextureFlags_NoInterpolation = 1,
  80. TextureFlags_ClampUVs = 2,
  81. TextureFlags_IsGif = 4,
  82. TextureFlags_ClampUVsBorder = 8,
  83. TextureFlags_Video = 32,
  84. /** Volume texture (image filter LUTs), every mipmap carries a depth after its width and height */
  85. TextureFlags_Volume = 64,
  86. TextureFlags_AlphaChannelPriority = 524288, // Indicates RG88/R8 format where alpha is in G/R channel
  87. /** PBR masks: bit 0x100000 << i marks the sampler's i-th "components" entry as painted (metallic, roughness,
  88. * reflection, emissive for generic shaders), which turns its combo on (wallpaper64.exe 2.8.42 sub_14016C800) */
  89. TextureFlags_MaskComponents = 0xF00000,
  90. TextureFlags_All = TextureFlags_NoInterpolation | TextureFlags_ClampUVs | TextureFlags_IsGif
  91. | TextureFlags_ClampUVsBorder | TextureFlags_Video | TextureFlags_Volume | TextureFlags_AlphaChannelPriority
  92. | TextureFlags_MaskComponents,
  93. };
  94. // part of a mipmap swapped in while a user property condition holds (TEXB0004, sub_14015C8D0)
  95. struct MipmapPatch {
  96. uint32_t key = 0;
  97. uint32_t x = 0;
  98. uint32_t y = 0;
  99. uint32_t width = 0;
  100. uint32_t height = 0;
  101. /** FreeImage format of the data, -1 for raw pixels like the mipmap's own */
  102. int format = -1;
  103. std::string data {};
  104. };
  105. struct Mipmap {
  106. uint32_t width = 0;
  107. uint32_t height = 0;
  108. uint32_t depth = 1;
  109. uint32_t compression = 0;
  110. int uncompressedSize = 0;
  111. int compressedSize = 0;
  112. std::unique_ptr<char[]> compressedData = nullptr;
  113. std::unique_ptr<char[]> uncompressedData = nullptr;
  114. std::vector<MipmapPatch> patches {};
  115. std::vector<unsigned char> composedPixels {};
  116. std::shared_ptr<unsigned char> decodedPixels = nullptr;
  117. int decodedWidth = 0;
  118. int decodedHeight = 0;
  119. };
  120. struct TextureCondition {
  121. /** Only the first condition that holds within a group counts */
  122. uint32_t group = 0;
  123. uint32_t key = 0;
  124. /** Bit 0 blends the patch by its alpha, bit 1 replaces the whole mipmap with the patch's raw data */
  125. uint32_t flags = 0;
  126. std::string json {};
  127. };
  128. struct Frame {
  129. uint32_t frameNumber = 0;
  130. float frametime = 0.0f;
  131. float x = 0.0f;
  132. float y = 0.0f;
  133. float width1 = 0.0f;
  134. float width2 = 0.0f;
  135. float height1 = 0.0f;
  136. float height2 = 0.0f;
  137. };
  138. struct Texture {
  139. /** The number after TEXB / TEXS (sub_14015E580) */
  140. uint32_t containerVersion = 0;
  141. uint32_t animatedVersion = 0;
  142. uint32_t flags = TextureFlags_NoFlags;
  143. uint32_t width = 0;
  144. uint32_t height = 0;
  145. /** Texture size in memory (power of 2), as opposed to real width/height above */
  146. uint32_t textureWidth = 0;
  147. uint32_t textureHeight = 0;
  148. uint32_t depth = 1;
  149. uint32_t gifWidth = 0;
  150. uint32_t gifHeight = 0;
  151. TextureFormat format = TextureFormat_UNKNOWN;
  152. FIF freeImageFormat = FIF_UNKNOWN;
  153. bool isVideoMp4 = false;
  154. bool isAnimatedGif = false;
  155. uint32_t imageCount = 0;
  156. std::vector<TextureCondition> conditions {};
  157. std::map<uint32_t, MipmapList> images {};
  158. std::vector<FrameSharedPtr> frames {};
  159. [[nodiscard]] bool isAnimated () const { return (flags & TextureFlags_IsGif) == TextureFlags_IsGif; }
  160. };
  161. }