@carbonenginejs/runtime-resource 0.1.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (329) hide show
  1. package/FORMAT-PROVENANCE.md +155 -135
  2. package/LICENSE +21 -21
  3. package/NOTICE +29 -29
  4. package/README.md +548 -241
  5. package/dist/CjsMotherLode.js +1271 -56
  6. package/dist/CjsMotherLode.js.map +1 -1
  7. package/dist/CjsResMan.js +3005 -740
  8. package/dist/CjsResMan.js.map +1 -1
  9. package/dist/CjsResManQueue.js +214 -214
  10. package/dist/CjsResource.js +566 -366
  11. package/dist/CjsResource.js.map +1 -1
  12. package/dist/CjsResourceSource.js +59 -59
  13. package/dist/_virtual/_rollupPluginBabelHelpers.js +153 -153
  14. package/dist/format/CjsBlueReader.js +269 -0
  15. package/dist/format/CjsBlueReader.js.map +1 -0
  16. package/dist/format/CjsFormat.js +192 -178
  17. package/dist/format/CjsFormat.js.map +1 -1
  18. package/dist/format/CjsReader.js +18 -0
  19. package/dist/format/CjsReader.js.map +1 -0
  20. package/dist/format/CjsResourceProbe.js +277 -269
  21. package/dist/format/CjsResourceProbe.js.map +1 -1
  22. package/dist/format/payloadContract.js +173 -173
  23. package/dist/formats/black/CjsBlackFormat.js +278 -272
  24. package/dist/formats/black/CjsBlackFormat.js.map +1 -1
  25. package/dist/formats/black/core/CjsBlackBinaryReader.js +153 -153
  26. package/dist/formats/black/core/CjsBlackPropertyReaders.js +382 -382
  27. package/dist/formats/black/core/CjsBlackReader.js +639 -760
  28. package/dist/formats/black/core/CjsBlackReader.js.map +1 -1
  29. package/dist/formats/black/core/CjsBlackSchemaRegistry.js +433 -433
  30. package/dist/formats/black/core/black-schema-v1-2026-07-11.json.js +4 -4
  31. package/dist/formats/black/core/blackConstants.js +7 -7
  32. package/dist/formats/black/core/blackDefinitions.js +10 -10
  33. package/dist/formats/black/core/blackEnums.js +6 -6
  34. package/dist/formats/black/core/blackSchema.js +3 -3
  35. package/dist/formats/black/core/blackVersion.js +22 -22
  36. package/dist/formats/black/core/helpers.js +182 -182
  37. package/dist/formats/black/core/schema.js +4 -4
  38. package/dist/formats/black/index.js +2 -2
  39. package/dist/formats/bnk/CjsBnkFormat.js +238 -245
  40. package/dist/formats/bnk/CjsBnkFormat.js.map +1 -1
  41. package/dist/formats/bnk/core/graph.js +140 -0
  42. package/dist/formats/bnk/core/graph.js.map +1 -0
  43. package/dist/formats/bnk/core/helpers.js +409 -354
  44. package/dist/formats/bnk/core/helpers.js.map +1 -1
  45. package/dist/formats/bnk/core/musicNodes.js +521 -0
  46. package/dist/formats/bnk/core/musicNodes.js.map +1 -0
  47. package/dist/formats/bnk/core/soundbanksInfo.js +246 -246
  48. package/dist/formats/bnk/index.js +2 -3
  49. package/dist/formats/bnk/index.js.map +1 -1
  50. package/dist/formats/cmf/CjsCmfFormat.js +497 -491
  51. package/dist/formats/cmf/CjsCmfFormat.js.map +1 -1
  52. package/dist/formats/cmf/core/binary.js +118 -118
  53. package/dist/formats/cmf/core/buffers.js +233 -233
  54. package/dist/formats/cmf/core/constants.js +47 -47
  55. package/dist/formats/cmf/core/gr2Anim.js +453 -453
  56. package/dist/formats/cmf/core/helpers.js +287 -287
  57. package/dist/formats/cmf/core/pack.js +276 -276
  58. package/dist/formats/cmf/core/schema.js +364 -364
  59. package/dist/formats/cmf/core/shared.js +268 -268
  60. package/dist/formats/cmf/core/writer.js +517 -517
  61. package/dist/formats/cmf/index.js +2 -2
  62. package/dist/formats/dds/CjsDdsFormat.js +193 -187
  63. package/dist/formats/dds/CjsDdsFormat.js.map +1 -1
  64. package/dist/formats/dds/core/bc6h.js +288 -0
  65. package/dist/formats/dds/core/bc6h.js.map +1 -0
  66. package/dist/formats/dds/core/bc7.js +251 -0
  67. package/dist/formats/dds/core/bc7.js.map +1 -0
  68. package/dist/formats/dds/core/helpers.js +815 -812
  69. package/dist/formats/dds/core/helpers.js.map +1 -1
  70. package/dist/formats/dds/index.js +2 -2
  71. package/dist/formats/fbx/CjsFbxFormat.js +266 -260
  72. package/dist/formats/fbx/CjsFbxFormat.js.map +1 -1
  73. package/dist/formats/fbx/core/helpers.js +3901 -3901
  74. package/dist/formats/fbx/index.js +2 -2
  75. package/dist/formats/flac/CjsFlacFormat.js +87 -81
  76. package/dist/formats/flac/CjsFlacFormat.js.map +1 -1
  77. package/dist/formats/flac/core/helpers.js +295 -295
  78. package/dist/formats/flac/index.js +2 -2
  79. package/dist/formats/gif/CjsGifFormat.js +87 -81
  80. package/dist/formats/gif/CjsGifFormat.js.map +1 -1
  81. package/dist/formats/gif/core/helpers.js +360 -360
  82. package/dist/formats/gif/index.js +2 -2
  83. package/dist/formats/gltf/CjsGltfFormat.js +290 -284
  84. package/dist/formats/gltf/CjsGltfFormat.js.map +1 -1
  85. package/dist/formats/gltf/core/helpers.js +292 -292
  86. package/dist/formats/gltf/core/json.js +79 -79
  87. package/dist/formats/gltf/core/parser.js +666 -666
  88. package/dist/formats/gltf/core/targets.js +163 -163
  89. package/dist/formats/gltf/index.js +2 -2
  90. package/dist/formats/index.js +23 -23
  91. package/dist/formats/jpeg/CjsJpegFormat.js +206 -200
  92. package/dist/formats/jpeg/CjsJpegFormat.js.map +1 -1
  93. package/dist/formats/jpeg/core/helpers.js +350 -350
  94. package/dist/formats/jpeg/core/jpeg.js +377 -377
  95. package/dist/formats/jpeg/index.js +2 -2
  96. package/dist/formats/mp3/CjsMp3Format.js +192 -186
  97. package/dist/formats/mp3/CjsMp3Format.js.map +1 -1
  98. package/dist/formats/mp3/core/helpers.js +338 -338
  99. package/dist/formats/mp3/index.js +2 -2
  100. package/dist/formats/mp4/CjsMp4Format.js +191 -185
  101. package/dist/formats/mp4/CjsMp4Format.js.map +1 -1
  102. package/dist/formats/mp4/core/helpers.js +449 -449
  103. package/dist/formats/mp4/index.js +2 -2
  104. package/dist/formats/obj/CjsObjFormat.js +253 -247
  105. package/dist/formats/obj/CjsObjFormat.js.map +1 -1
  106. package/dist/formats/obj/core/helpers.js +573 -573
  107. package/dist/formats/obj/core/json.js +64 -64
  108. package/dist/formats/obj/core/parser.js +321 -321
  109. package/dist/formats/obj/index.js +2 -2
  110. package/dist/formats/ogg/CjsOggFormat.js +88 -82
  111. package/dist/formats/ogg/CjsOggFormat.js.map +1 -1
  112. package/dist/formats/ogg/core/helpers.js +387 -387
  113. package/dist/formats/ogg/core/imdct.js +178 -178
  114. package/dist/formats/ogg/core/vorbis.js +999 -999
  115. package/dist/formats/ogg/index.js +2 -2
  116. package/dist/formats/png/CjsPngFormat.js +195 -189
  117. package/dist/formats/png/CjsPngFormat.js.map +1 -1
  118. package/dist/formats/png/core/helpers.js +583 -583
  119. package/dist/formats/png/index.js +2 -2
  120. package/dist/formats/red/CjsRedFormat.js +261 -247
  121. package/dist/formats/red/CjsRedFormat.js.map +1 -1
  122. package/dist/formats/red/core/CjsRedReader.js +194 -201
  123. package/dist/formats/red/core/CjsRedReader.js.map +1 -1
  124. package/dist/formats/red/core/blackDefinitions.js +3 -3
  125. package/dist/formats/red/core/helpers.js +139 -136
  126. package/dist/formats/red/core/helpers.js.map +1 -1
  127. package/dist/formats/red/core/redGraph.js +68 -68
  128. package/dist/formats/red/core/schema.js +4 -4
  129. package/dist/formats/red/index.js +2 -2
  130. package/dist/formats/stl/CjsStlFormat.js +365 -304
  131. package/dist/formats/stl/CjsStlFormat.js.map +1 -1
  132. package/dist/formats/stl/core/helpers.js +261 -257
  133. package/dist/formats/stl/core/helpers.js.map +1 -1
  134. package/dist/formats/stl/core/json.js +51 -51
  135. package/dist/formats/stl/core/stl.js +629 -544
  136. package/dist/formats/stl/core/stl.js.map +1 -1
  137. package/dist/formats/stl/core/targets.js +163 -163
  138. package/dist/formats/stl/index.js +2 -2
  139. package/dist/formats/tga/CjsTgaFormat.js +192 -186
  140. package/dist/formats/tga/CjsTgaFormat.js.map +1 -1
  141. package/dist/formats/tga/core/helpers.js +446 -446
  142. package/dist/formats/tga/index.js +2 -2
  143. package/dist/formats/wav/CjsWavFormat.js +192 -186
  144. package/dist/formats/wav/CjsWavFormat.js.map +1 -1
  145. package/dist/formats/wav/core/helpers.js +328 -328
  146. package/dist/formats/wav/index.js +2 -2
  147. package/dist/formats/webm/CjsWebmFormat.js +191 -185
  148. package/dist/formats/webm/CjsWebmFormat.js.map +1 -1
  149. package/dist/formats/webm/core/helpers.js +537 -537
  150. package/dist/formats/webm/index.js +2 -2
  151. package/dist/formats/webp/CjsWebpFormat.js +86 -80
  152. package/dist/formats/webp/CjsWebpFormat.js.map +1 -1
  153. package/dist/formats/webp/core/helpers.js +214 -214
  154. package/dist/formats/webp/index.js +2 -2
  155. package/dist/formats/wem/CjsWemFormat.js +241 -197
  156. package/dist/formats/wem/CjsWemFormat.js.map +1 -1
  157. package/dist/formats/wem/core/bitStream.js +259 -259
  158. package/dist/formats/wem/core/codebookLibrary.js +164 -164
  159. package/dist/formats/wem/core/helpers.js +417 -336
  160. package/dist/formats/wem/core/helpers.js.map +1 -1
  161. package/dist/formats/wem/core/packedCodebooksAotuv603.js +30 -30
  162. package/dist/formats/wem/core/ptadpcm.js +77 -0
  163. package/dist/formats/wem/core/ptadpcm.js.map +1 -0
  164. package/dist/formats/wem/core/resolve.js +121 -0
  165. package/dist/formats/wem/core/resolve.js.map +1 -0
  166. package/dist/formats/wem/core/wemToOgg.js +485 -485
  167. package/dist/formats/wem/index.js +2 -2
  168. package/dist/formats/yaml/CjsYamlFormat.js +83 -77
  169. package/dist/formats/yaml/CjsYamlFormat.js.map +1 -1
  170. package/dist/formats/yaml/core/CjsYamlReader.js +305 -304
  171. package/dist/formats/yaml/core/CjsYamlReader.js.map +1 -1
  172. package/dist/formats/yaml/core/helpers.js +160 -160
  173. package/dist/formats/yaml/index.js +2 -2
  174. package/dist/index.js +48 -52
  175. package/dist/index.js.map +1 -1
  176. package/dist/resourcePath.js +18 -18
  177. package/dist/resourceStates.js +9 -9
  178. package/dist/{generated/resources → resources}/AudioGeometryResData.js +47 -47
  179. package/dist/resources/AudioGeometryResData.js.map +1 -0
  180. package/dist/{generated/resources → resources}/GStateBindingCallbackData.js +31 -31
  181. package/dist/resources/GStateBindingCallbackData.js.map +1 -0
  182. package/dist/{generated/resources → resources}/MeshDecalData.js +37 -37
  183. package/dist/resources/MeshDecalData.js.map +1 -0
  184. package/dist/{generated/resources → resources}/MeshDecalLodData.js +34 -34
  185. package/dist/resources/MeshDecalLodData.js.map +1 -0
  186. package/dist/resources/Tr2EffectRes.js +71 -71
  187. package/dist/resources/Tr2GrannyIntersectionResult.js +60 -0
  188. package/dist/resources/Tr2GrannyIntersectionResult.js.map +1 -0
  189. package/dist/resources/Tr2GrannyStateRes.js +44 -44
  190. package/dist/resources/Tr2ImageRes.js +114 -114
  191. package/dist/resources/Tr2LightProfileRes.js +40 -40
  192. package/dist/{generated/resources → resources}/Tr2MaterialArea.js +34 -34
  193. package/dist/resources/Tr2MaterialArea.js.map +1 -0
  194. package/dist/{generated/resources → resources}/Tr2MaterialMesh.js +31 -31
  195. package/dist/resources/Tr2MaterialMesh.js.map +1 -0
  196. package/dist/{generated/resources → resources}/Tr2MaterialRes.js +34 -34
  197. package/dist/resources/Tr2MaterialRes.js.map +1 -0
  198. package/dist/{generated/resources → resources}/Tr2ShaderPermutation.js +43 -43
  199. package/dist/resources/Tr2ShaderPermutation.js.map +1 -0
  200. package/dist/{generated/resources → resources}/Tr2TextureLodManager.js +100 -60
  201. package/dist/resources/Tr2TextureLodManager.js.map +1 -0
  202. package/dist/{generated/resources → resources}/Tr2TextureLodUpdateRequest.js +37 -37
  203. package/dist/resources/Tr2TextureLodUpdateRequest.js.map +1 -0
  204. package/dist/{generated/resources → resources}/Tr2TexturePackChannel.js +37 -37
  205. package/dist/resources/Tr2TexturePackChannel.js.map +1 -0
  206. package/dist/resources/Tr2TexturePipeline.js +68 -0
  207. package/dist/resources/Tr2TexturePipeline.js.map +1 -0
  208. package/dist/{generated/resources → resources}/Tr2TexturePipelineParams.js +34 -34
  209. package/dist/resources/Tr2TexturePipelineParams.js.map +1 -0
  210. package/dist/{generated/resources → resources}/Tr2TexturePipelineStepCompress.js +40 -40
  211. package/dist/resources/Tr2TexturePipelineStepCompress.js.map +1 -0
  212. package/dist/{generated/resources → resources}/Tr2TexturePipelineStepLimitSize.js +34 -34
  213. package/dist/resources/Tr2TexturePipelineStepLimitSize.js.map +1 -0
  214. package/dist/{generated/resources → resources}/Tr2TexturePipelineStepLoad.js +31 -31
  215. package/dist/resources/Tr2TexturePipelineStepLoad.js.map +1 -0
  216. package/dist/{generated/resources → resources}/Tr2TexturePipelineStepPack.js +43 -43
  217. package/dist/resources/Tr2TexturePipelineStepPack.js.map +1 -0
  218. package/dist/resources/TriGeometryRes.js +239 -216
  219. package/dist/resources/TriGeometryRes.js.map +1 -1
  220. package/dist/{generated/resources → resources}/TriGeometryResAreaData.js +59 -59
  221. package/dist/resources/TriGeometryResAreaData.js.map +1 -0
  222. package/dist/{generated/resources → resources}/TriGeometryResJointData.js +38 -38
  223. package/dist/resources/TriGeometryResJointData.js.map +1 -0
  224. package/dist/{generated/resources → resources}/TriGeometryResLodData.js +88 -88
  225. package/dist/resources/TriGeometryResLodData.js.map +1 -0
  226. package/dist/{generated/resources → resources}/TriGeometryResMeshData.js +63 -63
  227. package/dist/resources/TriGeometryResMeshData.js.map +1 -0
  228. package/dist/{generated/resources → resources}/TriGeometryResSkeletonData.js +34 -34
  229. package/dist/resources/TriGeometryResSkeletonData.js.map +1 -0
  230. package/dist/resources/TriGrannyRes.js +43 -43
  231. package/dist/{generated/resources → resources}/TriJointBinding.js +38 -38
  232. package/dist/resources/TriJointBinding.js.map +1 -0
  233. package/dist/{generated/resources → resources}/TriMorphTargetGeometryConstants.js +46 -46
  234. package/dist/resources/TriMorphTargetGeometryConstants.js.map +1 -0
  235. package/dist/{generated/resources → resources}/TriRtGeometryConstants.js +88 -88
  236. package/dist/resources/TriRtGeometryConstants.js.map +1 -0
  237. package/dist/resources/TriTextureRes.js +304 -304
  238. package/dist/{generated/resources → resources}/enums.js +18 -18
  239. package/dist/resources/enums.js.map +1 -0
  240. package/dist/resources/resourceBoundary.js +47 -47
  241. package/dist/resources/texturePipelineBehavior.js +320 -0
  242. package/dist/resources/texturePipelineBehavior.js.map +1 -0
  243. package/dist/texture/CjsTextureArrayRes.js +406 -406
  244. package/dist/texture/CjsTextureParameterProxy.js +133 -133
  245. package/format-notices/black/LICENSE +21 -21
  246. package/format-notices/black/NOTICE +47 -47
  247. package/format-notices/bnk/LICENSE +21 -21
  248. package/format-notices/bnk/NOTICE +20 -17
  249. package/format-notices/cmf/LICENSE +21 -21
  250. package/format-notices/cmf/NOTICE +36 -36
  251. package/format-notices/dds/LICENSE +21 -21
  252. package/format-notices/dds/NOTICE +14 -14
  253. package/format-notices/fbx/LICENSE +21 -21
  254. package/format-notices/fbx/NOTICE +14 -14
  255. package/format-notices/flac/LICENSE +21 -21
  256. package/format-notices/flac/NOTICE +14 -14
  257. package/format-notices/gif/LICENSE +21 -21
  258. package/format-notices/gif/NOTICE +14 -14
  259. package/format-notices/gltf/LICENSE +21 -21
  260. package/format-notices/gltf/NOTICE +27 -27
  261. package/format-notices/jpeg/LICENSE +21 -21
  262. package/format-notices/jpeg/NOTICE +14 -14
  263. package/format-notices/mp3/LICENSE +21 -21
  264. package/format-notices/mp3/NOTICE +14 -14
  265. package/format-notices/mp4/LICENSE +21 -21
  266. package/format-notices/mp4/NOTICE +14 -14
  267. package/format-notices/obj/LICENSE +21 -21
  268. package/format-notices/obj/NOTICE +26 -26
  269. package/format-notices/ogg/LICENSE +21 -21
  270. package/format-notices/ogg/NOTICE +28 -28
  271. package/format-notices/png/LICENSE +21 -21
  272. package/format-notices/png/NOTICE +14 -14
  273. package/format-notices/red/LICENSE +21 -21
  274. package/format-notices/red/NOTICE +31 -31
  275. package/format-notices/stl/LICENSE +21 -21
  276. package/format-notices/stl/NOTICE +21 -21
  277. package/format-notices/tga/LICENSE +21 -21
  278. package/format-notices/tga/NOTICE +14 -14
  279. package/format-notices/wav/LICENSE +21 -21
  280. package/format-notices/wav/NOTICE +14 -14
  281. package/format-notices/webm/LICENSE +21 -21
  282. package/format-notices/webm/NOTICE +14 -14
  283. package/format-notices/webp/LICENSE +21 -21
  284. package/format-notices/webp/NOTICE +14 -14
  285. package/format-notices/wem/LICENSE +57 -57
  286. package/format-notices/wem/NOTICE +33 -33
  287. package/format-notices/yaml/LICENSE +21 -21
  288. package/format-notices/yaml/NOTICE +44 -44
  289. package/package.json +51 -51
  290. package/resource-lifecycle.md +679 -487
  291. package/dist/generated/resources/AudioGeometryResData.js.map +0 -1
  292. package/dist/generated/resources/CmfVertexReader.js +0 -46
  293. package/dist/generated/resources/CmfVertexReader.js.map +0 -1
  294. package/dist/generated/resources/GStateBindingCallbackData.js.map +0 -1
  295. package/dist/generated/resources/MeshDecalData.js.map +0 -1
  296. package/dist/generated/resources/MeshDecalLodData.js.map +0 -1
  297. package/dist/generated/resources/Tr2AsyncSave.js +0 -46
  298. package/dist/generated/resources/Tr2AsyncSave.js.map +0 -1
  299. package/dist/generated/resources/Tr2CmfContents.js +0 -37
  300. package/dist/generated/resources/Tr2CmfContents.js.map +0 -1
  301. package/dist/generated/resources/Tr2GrannyIntersectionResult.js +0 -58
  302. package/dist/generated/resources/Tr2GrannyIntersectionResult.js.map +0 -1
  303. package/dist/generated/resources/Tr2LoadPrepareFence.js +0 -37
  304. package/dist/generated/resources/Tr2LoadPrepareFence.js.map +0 -1
  305. package/dist/generated/resources/Tr2MaterialArea.js.map +0 -1
  306. package/dist/generated/resources/Tr2MaterialMesh.js.map +0 -1
  307. package/dist/generated/resources/Tr2MaterialRes.js.map +0 -1
  308. package/dist/generated/resources/Tr2ShaderPermutation.js.map +0 -1
  309. package/dist/generated/resources/Tr2TextureLodManager.js.map +0 -1
  310. package/dist/generated/resources/Tr2TextureLodUpdateRequest.js.map +0 -1
  311. package/dist/generated/resources/Tr2TexturePackChannel.js.map +0 -1
  312. package/dist/generated/resources/Tr2TexturePipeline.js +0 -44
  313. package/dist/generated/resources/Tr2TexturePipeline.js.map +0 -1
  314. package/dist/generated/resources/Tr2TexturePipelineParams.js.map +0 -1
  315. package/dist/generated/resources/Tr2TexturePipelineStepCompress.js.map +0 -1
  316. package/dist/generated/resources/Tr2TexturePipelineStepLimitSize.js.map +0 -1
  317. package/dist/generated/resources/Tr2TexturePipelineStepLoad.js.map +0 -1
  318. package/dist/generated/resources/Tr2TexturePipelineStepPack.js.map +0 -1
  319. package/dist/generated/resources/TriGeometryResAreaData.js.map +0 -1
  320. package/dist/generated/resources/TriGeometryResJointData.js.map +0 -1
  321. package/dist/generated/resources/TriGeometryResLodData.js.map +0 -1
  322. package/dist/generated/resources/TriGeometryResMeshData.js.map +0 -1
  323. package/dist/generated/resources/TriGeometryResSkeletonData.js.map +0 -1
  324. package/dist/generated/resources/TriJointBinding.js.map +0 -1
  325. package/dist/generated/resources/TriMorphTargetGeometryConstants.js.map +0 -1
  326. package/dist/generated/resources/TriRtGeometryConstants.js.map +0 -1
  327. package/dist/generated/resources/enums.js.map +0 -1
  328. package/dist/generated/resources/index.js +0 -32
  329. package/dist/generated/resources/index.js.map +0 -1
@@ -0,0 +1,288 @@
1
+ // BC6H is a little-endian 128-bit block format. MODE_LAYOUTS describes the
2
+ // fixed endpoint bit assignments from the Khronos Data Format Specification,
3
+ // section 20.2. The decoder and its numeric pipeline are CarbonEngineJS code.
4
+
5
+ const MODE_LAYOUTS = Object.freeze(["M0 M1 GY4 BY4 BZ4 RW0 RW1 RW2 RW3 RW4 RW5 RW6 RW7 RW8 RW9 GW0 GW1 GW2 GW3 GW4 GW5 GW6 GW7 GW8 GW9 BW0 BW1 BW2 BW3 BW4 BW5 BW6 BW7 BW8 BW9 RX0 RX1 RX2 RX3 RX4 GZ4 GY0 GY1 GY2 GY3 GX0 GX1 GX2 GX3 GX4 BZ0 GZ0 GZ1 GZ2 GZ3 BX0 BX1 BX2 BX3 BX4 BZ1 BY0 BY1 BY2 BY3 RY0 RY1 RY2 RY3 RY4 BZ2 RZ0 R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W4 GW5 GW6 GW7 GW8 GW9 BW0 BW1 BW2 BW3 BW4 BW5 BW6 BW7 BW8 BW9 RX0 RX1 RX2 RX3 RW15 RW14 RW13 RW12 RW11 RW10 GX0 GX1 GX2 GX3 GW15 GW14 GW13 GW12 GW11 GW10 BX0 BX1 BX2 BX3 BW15 BW14 BW13 BW12 BW11 BW10 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0"]);
6
+ const MODES = Object.freeze([{
7
+ code: 0x00,
8
+ subsets: 2,
9
+ transformed: true,
10
+ indexBits: 3,
11
+ endpointBits: 10,
12
+ deltaBits: [5, 5, 5]
13
+ }, {
14
+ code: 0x01,
15
+ subsets: 2,
16
+ transformed: true,
17
+ indexBits: 3,
18
+ endpointBits: 7,
19
+ deltaBits: [6, 6, 6]
20
+ }, {
21
+ code: 0x02,
22
+ subsets: 2,
23
+ transformed: true,
24
+ indexBits: 3,
25
+ endpointBits: 11,
26
+ deltaBits: [5, 4, 4]
27
+ }, {
28
+ code: 0x06,
29
+ subsets: 2,
30
+ transformed: true,
31
+ indexBits: 3,
32
+ endpointBits: 11,
33
+ deltaBits: [4, 5, 4]
34
+ }, {
35
+ code: 0x0a,
36
+ subsets: 2,
37
+ transformed: true,
38
+ indexBits: 3,
39
+ endpointBits: 11,
40
+ deltaBits: [4, 4, 5]
41
+ }, {
42
+ code: 0x0e,
43
+ subsets: 2,
44
+ transformed: true,
45
+ indexBits: 3,
46
+ endpointBits: 9,
47
+ deltaBits: [5, 5, 5]
48
+ }, {
49
+ code: 0x12,
50
+ subsets: 2,
51
+ transformed: true,
52
+ indexBits: 3,
53
+ endpointBits: 8,
54
+ deltaBits: [6, 5, 5]
55
+ }, {
56
+ code: 0x16,
57
+ subsets: 2,
58
+ transformed: true,
59
+ indexBits: 3,
60
+ endpointBits: 8,
61
+ deltaBits: [5, 6, 5]
62
+ }, {
63
+ code: 0x1a,
64
+ subsets: 2,
65
+ transformed: true,
66
+ indexBits: 3,
67
+ endpointBits: 8,
68
+ deltaBits: [5, 5, 6]
69
+ }, {
70
+ code: 0x1e,
71
+ subsets: 2,
72
+ transformed: false,
73
+ indexBits: 3,
74
+ endpointBits: 6,
75
+ deltaBits: [6, 6, 6]
76
+ }, {
77
+ code: 0x03,
78
+ subsets: 1,
79
+ transformed: false,
80
+ indexBits: 4,
81
+ endpointBits: 10,
82
+ deltaBits: [10, 10, 10]
83
+ }, {
84
+ code: 0x07,
85
+ subsets: 1,
86
+ transformed: true,
87
+ indexBits: 4,
88
+ endpointBits: 11,
89
+ deltaBits: [9, 9, 9]
90
+ }, {
91
+ code: 0x0b,
92
+ subsets: 1,
93
+ transformed: true,
94
+ indexBits: 4,
95
+ endpointBits: 12,
96
+ deltaBits: [8, 8, 8]
97
+ }, {
98
+ code: 0x0f,
99
+ subsets: 1,
100
+ transformed: true,
101
+ indexBits: 4,
102
+ endpointBits: 16,
103
+ deltaBits: [4, 4, 4]
104
+ }]);
105
+ const MODE_BY_CODE = new Int8Array(32).fill(-1);
106
+ for (let index = 0; index < MODES.length; index++) MODE_BY_CODE[MODES[index].code] = index;
107
+ const FIELD_CHANNEL = Object.freeze({
108
+ R: 0,
109
+ G: 1,
110
+ B: 2
111
+ });
112
+ const FIELD_ENDPOINT = Object.freeze({
113
+ W: 0,
114
+ X: 1,
115
+ Y: 2,
116
+ Z: 3
117
+ });
118
+ const DESCRIPTORS = MODE_LAYOUTS.map(layout => layout.split(" ").map(token => {
119
+ const match = /^([A-Z]+)(\d+)$/u.exec(token);
120
+ const field = match[1];
121
+ const bit = Number(match[2]);
122
+ if (field === "M" || field === "NA") return null;
123
+ if (field === "D") return {
124
+ shape: true,
125
+ bit
126
+ };
127
+ return {
128
+ endpoint: FIELD_ENDPOINT[field[1]],
129
+ channel: FIELD_CHANNEL[field[0]],
130
+ bit
131
+ };
132
+ }));
133
+ const WEIGHTS_3 = new Uint8Array([0, 9, 18, 27, 37, 46, 55, 64]);
134
+ const WEIGHTS_4 = new Uint8Array([0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64]);
135
+
136
+ // One bit per texel in y-major order. BC6H uses the first 32 two-subset
137
+ // partitions shared with BC7.
138
+ const PARTITIONS_2 = new Uint16Array([0xcccc, 0x8888, 0xeeee, 0xecc8, 0xc880, 0xfeec, 0xfec8, 0xec80, 0xc800, 0xffec, 0xfe80, 0xe800, 0xffe8, 0xff00, 0xfff0, 0xf000, 0xf710, 0x008e, 0x7100, 0x08ce, 0x008c, 0x7310, 0x3100, 0x8cce, 0x088c, 0x3110, 0x6666, 0x366c, 0x17e8, 0x0ff0, 0x718e, 0x399c]);
139
+ const ANCHOR_2 = new Uint8Array([15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 2, 8, 2, 2, 8, 8, 15, 2, 8, 2, 2, 8, 8, 2, 2]);
140
+ function decodeBc6h(source, width, height, rowPitch = Math.ceil(width / 4) * 16, signed = false) {
141
+ const rgba = new Float32Array(width * height * 4);
142
+ const blockRows = Math.ceil(height / 4);
143
+ const blockColumns = Math.ceil(width / 4);
144
+ for (let blockY = 0; blockY < blockRows; blockY++) {
145
+ for (let blockX = 0; blockX < blockColumns; blockX++) {
146
+ const blockOffset = blockY * rowPitch + blockX * 16;
147
+ const pixels = decodeBc6hBlock(source.subarray(blockOffset, blockOffset + 16), signed);
148
+ copyBlock(pixels, rgba, width, height, blockX, blockY);
149
+ }
150
+ }
151
+ return rgba;
152
+ }
153
+ function decodeBc6hBlock(block, signed = false) {
154
+ if (block.byteLength < 16) throw new RangeError("BC6H block must contain 16 bytes");
155
+ const lowMode = readBits(block, 0, 2);
156
+ const modeCode = lowMode < 2 ? lowMode : readBits(block, 0, 5);
157
+ const modeIndex = MODE_BY_CODE[modeCode];
158
+ if (modeIndex < 0) return opaqueBlackBlock();
159
+ const mode = MODES[modeIndex];
160
+ const descriptor = DESCRIPTORS[modeIndex];
161
+ const headerBits = mode.subsets === 2 ? 82 : 65;
162
+ const endpoints = Array.from({
163
+ length: 4
164
+ }, () => [0, 0, 0]);
165
+ let shape = 0;
166
+ for (let sourceBit = 0; sourceBit < headerBits; sourceBit++) {
167
+ if (!readBit(block, sourceBit)) continue;
168
+ const target = descriptor[sourceBit];
169
+ if (!target) continue;
170
+ if (target.shape) {
171
+ shape |= 1 << target.bit;
172
+ } else {
173
+ endpoints[target.endpoint][target.channel] |= 1 << target.bit;
174
+ }
175
+ }
176
+ prepareEndpoints(endpoints, mode, signed);
177
+ const output = new Float32Array(16 * 4);
178
+ const weights = mode.indexBits === 3 ? WEIGHTS_3 : WEIGHTS_4;
179
+ const partition = mode.subsets === 2 ? PARTITIONS_2[shape] : 0;
180
+ const anchor = mode.subsets === 2 ? ANCHOR_2[shape] : -1;
181
+ let sourceBit = headerBits;
182
+ for (let pixel = 0; pixel < 16; pixel++) {
183
+ const isAnchor = pixel === 0 || pixel === anchor;
184
+ const indexBits = mode.indexBits - (isAnchor ? 1 : 0);
185
+ const colorIndex = readBits(block, sourceBit, indexBits);
186
+ sourceBit += indexBits;
187
+ const subset = mode.subsets === 2 ? partition >>> pixel & 1 : 0;
188
+ const endpoint0 = endpoints[subset * 2];
189
+ const endpoint1 = endpoints[subset * 2 + 1];
190
+ const weight = weights[colorIndex];
191
+ const outputOffset = pixel * 4;
192
+ for (let channel = 0; channel < 3; channel++) {
193
+ const value0 = unquantize(endpoint0[channel], mode.endpointBits, signed);
194
+ const value1 = unquantize(endpoint1[channel], mode.endpointBits, signed);
195
+ const interpolated = value0 * (64 - weight) + value1 * weight + 32 >> 6;
196
+ output[outputOffset + channel] = halfToFloat(finishHalf(interpolated, signed));
197
+ }
198
+ output[outputOffset + 3] = 1;
199
+ }
200
+ return output;
201
+ }
202
+ function prepareEndpoints(endpoints, mode, signed) {
203
+ if (signed) {
204
+ for (let channel = 0; channel < 3; channel++) {
205
+ endpoints[0][channel] = signExtend(endpoints[0][channel], mode.endpointBits);
206
+ }
207
+ }
208
+ if (signed || mode.transformed) {
209
+ for (let endpoint = 1; endpoint < mode.subsets * 2; endpoint++) {
210
+ for (let channel = 0; channel < 3; channel++) {
211
+ endpoints[endpoint][channel] = signExtend(endpoints[endpoint][channel], mode.deltaBits[channel]);
212
+ }
213
+ }
214
+ }
215
+ if (!mode.transformed) return;
216
+ const mask = (1 << mode.endpointBits) - 1;
217
+ for (let endpoint = 1; endpoint < mode.subsets * 2; endpoint++) {
218
+ for (let channel = 0; channel < 3; channel++) {
219
+ let value = endpoints[0][channel] + endpoints[endpoint][channel] & mask;
220
+ if (signed) value = signExtend(value, mode.endpointBits);
221
+ endpoints[endpoint][channel] = value;
222
+ }
223
+ }
224
+ }
225
+ function unquantize(component, bits, signed) {
226
+ if (signed) {
227
+ if (bits >= 16) return component;
228
+ const negative = component < 0;
229
+ const magnitude = negative ? -component : component;
230
+ const maximum = (1 << bits - 1) - 1;
231
+ const value = magnitude === 0 ? 0 : magnitude >= maximum ? 0x7fff : (magnitude << 15) + 0x4000 >> bits - 1;
232
+ return negative ? -value : value;
233
+ }
234
+ if (bits >= 15) return component;
235
+ if (component === 0) return 0;
236
+ if (component === (1 << bits) - 1) return 0xffff;
237
+ return (component << 16) + 0x8000 >> bits;
238
+ }
239
+ function finishHalf(component, signed) {
240
+ if (signed) {
241
+ const magnitude = component < 0 ? -(-component * 31 >> 5) : component * 31 >> 5;
242
+ return magnitude < 0 ? 0x8000 | -magnitude : magnitude;
243
+ }
244
+ return component * 31 >> 6;
245
+ }
246
+ function signExtend(value, bits) {
247
+ return value << 32 - bits >> 32 - bits;
248
+ }
249
+ function readBit(source, bit) {
250
+ return source[bit >>> 3] >>> (bit & 7) & 1;
251
+ }
252
+ function readBits(source, start, count) {
253
+ let value = 0;
254
+ for (let bit = 0; bit < count; bit++) value |= readBit(source, start + bit) << bit;
255
+ return value;
256
+ }
257
+ function halfToFloat(value) {
258
+ const sign = value & 0x8000 ? -1 : 1;
259
+ const exponent = value >>> 10 & 0x1f;
260
+ const mantissa = value & 0x03ff;
261
+ if (exponent === 0) return sign * Math.pow(2, -14) * (mantissa / 1024);
262
+ if (exponent === 0x1f) return mantissa === 0 ? sign * Infinity : NaN;
263
+ return sign * Math.pow(2, exponent - 15) * (1 + mantissa / 1024);
264
+ }
265
+ function opaqueBlackBlock() {
266
+ const output = new Float32Array(16 * 4);
267
+ for (let pixel = 0; pixel < 16; pixel++) output[pixel * 4 + 3] = 1;
268
+ return output;
269
+ }
270
+ function copyBlock(block, output, width, height, blockX, blockY) {
271
+ for (let y = 0; y < 4; y++) {
272
+ const outputY = blockY * 4 + y;
273
+ if (outputY >= height) continue;
274
+ for (let x = 0; x < 4; x++) {
275
+ const outputX = blockX * 4 + x;
276
+ if (outputX >= width) continue;
277
+ const sourceOffset = (y * 4 + x) * 4;
278
+ const outputOffset = (outputY * width + outputX) * 4;
279
+ output[outputOffset] = block[sourceOffset];
280
+ output[outputOffset + 1] = block[sourceOffset + 1];
281
+ output[outputOffset + 2] = block[sourceOffset + 2];
282
+ output[outputOffset + 3] = block[sourceOffset + 3];
283
+ }
284
+ }
285
+ }
286
+
287
+ export { decodeBc6h, decodeBc6hBlock };
288
+ //# sourceMappingURL=bc6h.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bc6h.js","sources":["../../../../../src/formats/dds/core/bc6h.js"],"sourcesContent":["// BC6H is a little-endian 128-bit block format. MODE_LAYOUTS describes the\n// fixed endpoint bit assignments from the Khronos Data Format Specification,\n// section 20.2. The decoder and its numeric pipeline are CarbonEngineJS code.\n\nconst MODE_LAYOUTS = Object.freeze([\n \"M0 M1 GY4 BY4 BZ4 RW0 RW1 RW2 RW3 RW4 RW5 RW6 RW7 RW8 RW9 GW0 GW1 GW2 GW3 GW4 GW5 GW6 GW7 GW8 GW9 BW0 BW1 BW2 BW3 BW4 BW5 BW6 BW7 BW8 BW9 RX0 RX1 RX2 RX3 RX4 GZ4 GY0 GY1 GY2 GY3 GX0 GX1 GX2 GX3 GX4 BZ0 G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0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0\",\n \"M0 M1 M2 M3 M4 RW0 RW1 RW2 RW3 RW4 RW5 RW6 RW7 RW8 RW9 GW0 GW1 GW2 GW3 GW4 GW5 GW6 GW7 GW8 GW9 BW0 BW1 BW2 BW3 BW4 BW5 BW6 BW7 BW8 BW9 RX0 RX1 RX2 RX3 RW15 RW14 RW13 RW12 RW11 RW10 GX0 GX1 GX2 GX3 GW15 GW14 GW13 GW12 GW11 GW10 BX0 BX1 BX2 BX3 BW15 BW14 BW13 BW12 BW11 BW10 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0 NA0\"\n]);\n\nconst MODES = Object.freeze([\n { code: 0x00, subsets: 2, transformed: true, indexBits: 3, endpointBits: 10, deltaBits: [ 5, 5, 5 ] },\n { code: 0x01, subsets: 2, transformed: true, indexBits: 3, endpointBits: 7, deltaBits: [ 6, 6, 6 ] },\n { code: 0x02, subsets: 2, transformed: true, indexBits: 3, endpointBits: 11, deltaBits: [ 5, 4, 4 ] },\n { code: 0x06, subsets: 2, transformed: true, indexBits: 3, endpointBits: 11, deltaBits: [ 4, 5, 4 ] },\n { code: 0x0a, subsets: 2, transformed: true, indexBits: 3, endpointBits: 11, deltaBits: [ 4, 4, 5 ] },\n { code: 0x0e, subsets: 2, transformed: true, indexBits: 3, endpointBits: 9, deltaBits: [ 5, 5, 5 ] },\n { code: 0x12, subsets: 2, transformed: true, indexBits: 3, endpointBits: 8, deltaBits: [ 6, 5, 5 ] },\n { code: 0x16, subsets: 2, transformed: true, indexBits: 3, endpointBits: 8, deltaBits: [ 5, 6, 5 ] },\n { code: 0x1a, subsets: 2, transformed: true, indexBits: 3, endpointBits: 8, deltaBits: [ 5, 5, 6 ] },\n { code: 0x1e, subsets: 2, transformed: false, indexBits: 3, endpointBits: 6, deltaBits: [ 6, 6, 6 ] },\n { code: 0x03, subsets: 1, transformed: false, indexBits: 4, endpointBits: 10, deltaBits: [ 10, 10, 10 ] },\n { code: 0x07, subsets: 1, transformed: true, indexBits: 4, endpointBits: 11, deltaBits: [ 9, 9, 9 ] },\n { code: 0x0b, subsets: 1, transformed: true, indexBits: 4, endpointBits: 12, deltaBits: [ 8, 8, 8 ] },\n { code: 0x0f, subsets: 1, transformed: true, indexBits: 4, endpointBits: 16, deltaBits: [ 4, 4, 4 ] }\n]);\n\nconst MODE_BY_CODE = new Int8Array(32).fill(-1);\nfor (let index = 0; index < MODES.length; index++) MODE_BY_CODE[MODES[index].code] = index;\n\nconst FIELD_CHANNEL = Object.freeze({ R: 0, G: 1, B: 2 });\nconst FIELD_ENDPOINT = Object.freeze({ W: 0, X: 1, Y: 2, Z: 3 });\nconst DESCRIPTORS = MODE_LAYOUTS.map((layout) => layout.split(\" \").map((token) =>\n{\n const match = /^([A-Z]+)(\\d+)$/u.exec(token);\n const field = match[1];\n const bit = Number(match[2]);\n if (field === \"M\" || field === \"NA\") return null;\n if (field === \"D\") return { shape: true, bit };\n return {\n endpoint: FIELD_ENDPOINT[field[1]],\n channel: FIELD_CHANNEL[field[0]],\n bit\n };\n}));\n\nconst WEIGHTS_3 = new Uint8Array([ 0, 9, 18, 27, 37, 46, 55, 64 ]);\nconst WEIGHTS_4 = new Uint8Array([ 0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64 ]);\n\n// One bit per texel in y-major order. BC6H uses the first 32 two-subset\n// partitions shared with BC7.\nconst PARTITIONS_2 = new Uint16Array([\n 0xcccc, 0x8888, 0xeeee, 0xecc8, 0xc880, 0xfeec, 0xfec8, 0xec80,\n 0xc800, 0xffec, 0xfe80, 0xe800, 0xffe8, 0xff00, 0xfff0, 0xf000,\n 0xf710, 0x008e, 0x7100, 0x08ce, 0x008c, 0x7310, 0x3100, 0x8cce,\n 0x088c, 0x3110, 0x6666, 0x366c, 0x17e8, 0x0ff0, 0x718e, 0x399c\n]);\n\nconst ANCHOR_2 = new Uint8Array([\n 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,\n 15, 2, 8, 2, 2, 8, 8, 15, 2, 8, 2, 2, 8, 8, 2, 2\n]);\n\nexport function decodeBc6h(source, width, height, rowPitch = Math.ceil(width / 4) * 16, signed = false)\n{\n const rgba = new Float32Array(width * height * 4);\n const blockRows = Math.ceil(height / 4);\n const blockColumns = Math.ceil(width / 4);\n\n for (let blockY = 0; blockY < blockRows; blockY++)\n {\n for (let blockX = 0; blockX < blockColumns; blockX++)\n {\n const blockOffset = blockY * rowPitch + blockX * 16;\n const pixels = decodeBc6hBlock(source.subarray(blockOffset, blockOffset + 16), signed);\n copyBlock(pixels, rgba, width, height, blockX, blockY);\n }\n }\n\n return rgba;\n}\n\nexport function decodeBc6hBlock(block, signed = false)\n{\n if (block.byteLength < 16) throw new RangeError(\"BC6H block must contain 16 bytes\");\n\n const lowMode = readBits(block, 0, 2);\n const modeCode = lowMode < 2 ? lowMode : readBits(block, 0, 5);\n const modeIndex = MODE_BY_CODE[modeCode];\n if (modeIndex < 0) return opaqueBlackBlock();\n\n const mode = MODES[modeIndex];\n const descriptor = DESCRIPTORS[modeIndex];\n const headerBits = mode.subsets === 2 ? 82 : 65;\n const endpoints = Array.from({ length: 4 }, () => [ 0, 0, 0 ]);\n let shape = 0;\n\n for (let sourceBit = 0; sourceBit < headerBits; sourceBit++)\n {\n if (!readBit(block, sourceBit)) continue;\n const target = descriptor[sourceBit];\n if (!target) continue;\n if (target.shape)\n {\n shape |= 1 << target.bit;\n }\n else\n {\n endpoints[target.endpoint][target.channel] |= 1 << target.bit;\n }\n }\n\n prepareEndpoints(endpoints, mode, signed);\n\n const output = new Float32Array(16 * 4);\n const weights = mode.indexBits === 3 ? WEIGHTS_3 : WEIGHTS_4;\n const partition = mode.subsets === 2 ? PARTITIONS_2[shape] : 0;\n const anchor = mode.subsets === 2 ? ANCHOR_2[shape] : -1;\n let sourceBit = headerBits;\n\n for (let pixel = 0; pixel < 16; pixel++)\n {\n const isAnchor = pixel === 0 || pixel === anchor;\n const indexBits = mode.indexBits - (isAnchor ? 1 : 0);\n const colorIndex = readBits(block, sourceBit, indexBits);\n sourceBit += indexBits;\n\n const subset = mode.subsets === 2 ? ((partition >>> pixel) & 1) : 0;\n const endpoint0 = endpoints[subset * 2];\n const endpoint1 = endpoints[subset * 2 + 1];\n const weight = weights[colorIndex];\n const outputOffset = pixel * 4;\n\n for (let channel = 0; channel < 3; channel++)\n {\n const value0 = unquantize(endpoint0[channel], mode.endpointBits, signed);\n const value1 = unquantize(endpoint1[channel], mode.endpointBits, signed);\n const interpolated = (value0 * (64 - weight) + value1 * weight + 32) >> 6;\n output[outputOffset + channel] = halfToFloat(finishHalf(interpolated, signed));\n }\n output[outputOffset + 3] = 1;\n }\n\n return output;\n}\n\nfunction prepareEndpoints(endpoints, mode, signed)\n{\n if (signed)\n {\n for (let channel = 0; channel < 3; channel++)\n {\n endpoints[0][channel] = signExtend(endpoints[0][channel], mode.endpointBits);\n }\n }\n\n if (signed || mode.transformed)\n {\n for (let endpoint = 1; endpoint < mode.subsets * 2; endpoint++)\n {\n for (let channel = 0; channel < 3; channel++)\n {\n endpoints[endpoint][channel] = signExtend(endpoints[endpoint][channel], mode.deltaBits[channel]);\n }\n }\n }\n\n if (!mode.transformed) return;\n\n const mask = (1 << mode.endpointBits) - 1;\n for (let endpoint = 1; endpoint < mode.subsets * 2; endpoint++)\n {\n for (let channel = 0; channel < 3; channel++)\n {\n let value = (endpoints[0][channel] + endpoints[endpoint][channel]) & mask;\n if (signed) value = signExtend(value, mode.endpointBits);\n endpoints[endpoint][channel] = value;\n }\n }\n}\n\nfunction unquantize(component, bits, signed)\n{\n if (signed)\n {\n if (bits >= 16) return component;\n const negative = component < 0;\n const magnitude = negative ? -component : component;\n const maximum = (1 << (bits - 1)) - 1;\n const value = magnitude === 0\n ? 0\n : magnitude >= maximum\n ? 0x7fff\n : ((magnitude << 15) + 0x4000) >> (bits - 1);\n return negative ? -value : value;\n }\n\n if (bits >= 15) return component;\n if (component === 0) return 0;\n if (component === (1 << bits) - 1) return 0xffff;\n return ((component << 16) + 0x8000) >> bits;\n}\n\nfunction finishHalf(component, signed)\n{\n if (signed)\n {\n const magnitude = component < 0\n ? -(((-component) * 31) >> 5)\n : (component * 31) >> 5;\n return magnitude < 0 ? 0x8000 | -magnitude : magnitude;\n }\n return (component * 31) >> 6;\n}\n\nfunction signExtend(value, bits)\n{\n return (value << (32 - bits)) >> (32 - bits);\n}\n\nfunction readBit(source, bit)\n{\n return (source[bit >>> 3] >>> (bit & 7)) & 1;\n}\n\nfunction readBits(source, start, count)\n{\n let value = 0;\n for (let bit = 0; bit < count; bit++) value |= readBit(source, start + bit) << bit;\n return value;\n}\n\nfunction halfToFloat(value)\n{\n const sign = value & 0x8000 ? -1 : 1;\n const exponent = (value >>> 10) & 0x1f;\n const mantissa = value & 0x03ff;\n if (exponent === 0) return sign * Math.pow(2, -14) * (mantissa / 1024);\n if (exponent === 0x1f) return mantissa === 0 ? sign * Infinity : NaN;\n return sign * Math.pow(2, exponent - 15) * (1 + mantissa / 1024);\n}\n\nfunction opaqueBlackBlock()\n{\n const output = new Float32Array(16 * 4);\n for (let pixel = 0; pixel < 16; pixel++) output[pixel * 4 + 3] = 1;\n return output;\n}\n\nfunction copyBlock(block, output, width, height, blockX, blockY)\n{\n for (let y = 0; y < 4; y++)\n {\n const outputY = blockY * 4 + y;\n if (outputY >= height) continue;\n for (let x = 0; x < 4; x++)\n {\n const outputX = blockX * 4 + x;\n if (outputX >= width) continue;\n const sourceOffset = (y * 4 + x) * 4;\n const outputOffset = (outputY * width + outputX) * 4;\n output[outputOffset] = block[sourceOffset];\n output[outputOffset + 1] = block[sourceOffset + 1];\n output[outputOffset + 2] = block[sourceOffset + 2];\n output[outputOffset + 3] = block[sourceOffset + 3];\n }\n }\n}\n"],"names":["MODE_LAYOUTS","Object","freeze","MODES","code","subsets","transformed","indexBits","endpointBits","deltaBits","MODE_BY_CODE","Int8Array","fill","index","length","FIELD_CHANNEL","R","G","B","FIELD_ENDPOINT","W","X","Y","Z","DESCRIPTORS","map","layout","split","token","match","exec","field","bit","Number","shape","endpoint","channel","WEIGHTS_3","Uint8Array","WEIGHTS_4","PARTITIONS_2","Uint16Array","ANCHOR_2","decodeBc6h","source","width","height","rowPitch","Math","ceil","signed","rgba","Float32Array","blockRows","blockColumns","blockY","blockX","blockOffset","pixels","decodeBc6hBlock","subarray","copyBlock","block","byteLength","RangeError","lowMode","readBits","modeCode","modeIndex","opaqueBlackBlock","mode","descriptor","headerBits","endpoints","Array","from","sourceBit","readBit","target","prepareEndpoints","output","weights","partition","anchor","pixel","isAnchor","colorIndex","subset","endpoint0","endpoint1","weight","outputOffset","value0","unquantize","value1","interpolated","halfToFloat","finishHalf","signExtend","mask","value","component","bits","negative","magnitude","maximum","start","count","sign","exponent","mantissa","pow","Infinity","NaN","y","outputY","x","outputX","sourceOffset"],"mappings":"AAAA;AACA;AACA;;AAEA,MAAMA,YAAY,GAAGC,MAAM,CAACC,MAAM,CAAC,CAC/B,kUAAkU,EAClU,kUAAkU,EAClU,kUAAkU,EAClU,kUAAkU,EAClU,kUAAkU,EAClU,+TAA+T,EAC/T,+TAA+T,EAC/T,+TAA+T,EAC/T,+TAA+T,EAC/T,+TAA+T,EAC/T,oUAAoU,EACpU,uUAAuU,EACvU,0UAA0U,EAC1U,sVAAsV,CACzV,CAAC;AAEF,MAAMC,KAAK,GAAGF,MAAM,CAACC,MAAM,CAAC,CACxB;AAAEE,EAAAA,IAAI,EAAE,IAAI;AAAEC,EAAAA,OAAO,EAAE,CAAC;AAAEC,EAAAA,WAAW,EAAE,IAAI;AAAEC,EAAAA,SAAS,EAAE,CAAC;AAAEC,EAAAA,YAAY,EAAE,EAAE;AAAEC,EAAAA,SAAS,EAAE,CAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAAG,CAAC,EACrG;AAAEL,EAAAA,IAAI,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AY,GAAG,CAACJ,CAAC,GAAG,CAAC,GAAGE,CAAC,IAAI,CAAC;MACpC,MAAMzB,YAAY,GAAG,CAACwB,OAAO,GAAGtE,KAAK,GAAGwE,OAAO,IAAI,CAAC;AACpDrC,MAAAA,MAAM,CAACW,YAAY,CAAC,GAAG7B,KAAK,CAACwD,YAAY,CAAC;MAC1CtC,MAAM,CAACW,YAAY,GAAG,CAAC,CAAC,GAAG7B,KAAK,CAACwD,YAAY,GAAG,CAAC,CAAC;MAClDtC,MAAM,CAACW,YAAY,GAAG,CAAC,CAAC,GAAG7B,KAAK,CAACwD,YAAY,GAAG,CAAC,CAAC;MAClDtC,MAAM,CAACW,YAAY,GAAG,CAAC,CAAC,GAAG7B,KAAK,CAACwD,YAAY,GAAG,CAAC,CAAC;AACtD,IAAA;AACJ,EAAA;AACJ;;;;"}
@@ -0,0 +1,251 @@
1
+ // BC7 is defined as a little-endian 128-bit block format. The mode and
2
+ // partition constants below are the fixed tables from the Khronos Data Format
3
+ // Specification, section 20.1. The decoder itself is CarbonEngineJS code.
4
+
5
+ const MODE = Object.freeze([{
6
+ subsets: 3,
7
+ partitionBits: 4,
8
+ rotationBits: 0,
9
+ selectionBits: 0,
10
+ colorBits: 4,
11
+ alphaBits: 0,
12
+ endpointPBits: 1,
13
+ sharedPBits: 0,
14
+ indexBits: 3,
15
+ secondaryIndexBits: 0
16
+ }, {
17
+ subsets: 2,
18
+ partitionBits: 6,
19
+ rotationBits: 0,
20
+ selectionBits: 0,
21
+ colorBits: 6,
22
+ alphaBits: 0,
23
+ endpointPBits: 0,
24
+ sharedPBits: 1,
25
+ indexBits: 3,
26
+ secondaryIndexBits: 0
27
+ }, {
28
+ subsets: 3,
29
+ partitionBits: 6,
30
+ rotationBits: 0,
31
+ selectionBits: 0,
32
+ colorBits: 5,
33
+ alphaBits: 0,
34
+ endpointPBits: 0,
35
+ sharedPBits: 0,
36
+ indexBits: 2,
37
+ secondaryIndexBits: 0
38
+ }, {
39
+ subsets: 2,
40
+ partitionBits: 6,
41
+ rotationBits: 0,
42
+ selectionBits: 0,
43
+ colorBits: 7,
44
+ alphaBits: 0,
45
+ endpointPBits: 1,
46
+ sharedPBits: 0,
47
+ indexBits: 2,
48
+ secondaryIndexBits: 0
49
+ }, {
50
+ subsets: 1,
51
+ partitionBits: 0,
52
+ rotationBits: 2,
53
+ selectionBits: 1,
54
+ colorBits: 5,
55
+ alphaBits: 6,
56
+ endpointPBits: 0,
57
+ sharedPBits: 0,
58
+ indexBits: 2,
59
+ secondaryIndexBits: 3
60
+ }, {
61
+ subsets: 1,
62
+ partitionBits: 0,
63
+ rotationBits: 2,
64
+ selectionBits: 0,
65
+ colorBits: 7,
66
+ alphaBits: 8,
67
+ endpointPBits: 0,
68
+ sharedPBits: 0,
69
+ indexBits: 2,
70
+ secondaryIndexBits: 2
71
+ }, {
72
+ subsets: 1,
73
+ partitionBits: 0,
74
+ rotationBits: 0,
75
+ selectionBits: 0,
76
+ colorBits: 7,
77
+ alphaBits: 7,
78
+ endpointPBits: 1,
79
+ sharedPBits: 0,
80
+ indexBits: 4,
81
+ secondaryIndexBits: 0
82
+ }, {
83
+ subsets: 2,
84
+ partitionBits: 6,
85
+ rotationBits: 0,
86
+ selectionBits: 0,
87
+ colorBits: 5,
88
+ alphaBits: 5,
89
+ endpointPBits: 1,
90
+ sharedPBits: 0,
91
+ indexBits: 2,
92
+ secondaryIndexBits: 0
93
+ }]);
94
+ const WEIGHTS = Object.freeze({
95
+ 2: new Uint8Array([0, 21, 43, 64]),
96
+ 3: new Uint8Array([0, 9, 18, 27, 37, 46, 55, 64]),
97
+ 4: new Uint8Array([0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64])
98
+ });
99
+
100
+ // One bit per texel, in y-major order.
101
+ const PARTITIONS_2 = new Uint16Array([0xcccc, 0x8888, 0xeeee, 0xecc8, 0xc880, 0xfeec, 0xfec8, 0xec80, 0xc800, 0xffec, 0xfe80, 0xe800, 0xffe8, 0xff00, 0xfff0, 0xf000, 0xf710, 0x008e, 0x7100, 0x08ce, 0x008c, 0x7310, 0x3100, 0x8cce, 0x088c, 0x3110, 0x6666, 0x366c, 0x17e8, 0x0ff0, 0x718e, 0x399c, 0xaaaa, 0xf0f0, 0x5a5a, 0x33cc, 0x3c3c, 0x55aa, 0x9696, 0xa55a, 0x73ce, 0x13c8, 0x324c, 0x3bdc, 0x6996, 0xc33c, 0x9966, 0x0660, 0x0272, 0x04e4, 0x4e40, 0x2720, 0xc936, 0x936c, 0x39c6, 0x639c, 0x9336, 0x9cc6, 0x817e, 0xe718, 0xccf0, 0x0fcc, 0x7744, 0xee22]);
102
+
103
+ // Two bits per texel, in y-major order.
104
+ const PARTITIONS_3 = new Uint32Array([0xaa685050, 0x6a5a5040, 0x5a5a4200, 0x5450a0a8, 0xa5a50000, 0xa0a05050, 0x5555a0a0, 0x5a5a5050, 0xaa550000, 0xaa555500, 0xaaaa5500, 0x90909090, 0x94949494, 0xa4a4a4a4, 0xa9a59450, 0x2a0a4250, 0xa5945040, 0x0a425054, 0xa5a5a500, 0x55a0a0a0, 0xa8a85454, 0x6a6a4040, 0xa4a45000, 0x1a1a0500, 0x0050a4a4, 0xaaa59090, 0x14696914, 0x69691400, 0xa08585a0, 0xaa821414, 0x50a4a450, 0x6a5a0200, 0xa9a58000, 0x5090a0a8, 0xa8a09050, 0x24242424, 0x00aa5500, 0x24924924, 0x24499224, 0x50a50a50, 0x500aa550, 0xaaaa4444, 0x66660000, 0xa5a0a5a0, 0x50a050a0, 0x69286928, 0x44aaaa44, 0x66666600, 0xaa444444, 0x54a854a8, 0x95809580, 0x96969600, 0xa85454a8, 0x80959580, 0xaa141414, 0x96960000, 0xaaaa1414, 0xa05050a0, 0xa0a5a5a0, 0x96000000, 0x40804080, 0xa9a8a9a8, 0xaaaaaa44, 0x2a4a5254]);
105
+ const ANCHOR_2 = new Uint8Array([15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 2, 8, 2, 2, 8, 8, 15, 2, 8, 2, 2, 8, 8, 2, 2, 15, 15, 6, 8, 2, 8, 15, 15, 2, 8, 2, 2, 2, 15, 15, 6, 6, 2, 6, 8, 15, 15, 2, 2, 15, 15, 15, 15, 15, 2, 2, 15]);
106
+ const ANCHOR_3_SECOND = new Uint8Array([3, 3, 15, 15, 8, 3, 15, 15, 8, 8, 6, 6, 6, 5, 3, 3, 3, 3, 8, 15, 3, 3, 6, 10, 5, 8, 8, 6, 8, 5, 15, 15, 8, 15, 3, 5, 6, 10, 8, 15, 15, 3, 15, 5, 15, 15, 15, 15, 3, 15, 5, 5, 5, 8, 5, 10, 5, 10, 8, 13, 15, 12, 3, 3]);
107
+ const ANCHOR_3_THIRD = new Uint8Array([15, 8, 8, 3, 15, 15, 3, 8, 15, 15, 15, 15, 15, 15, 15, 8, 15, 8, 15, 3, 15, 8, 15, 8, 3, 15, 6, 10, 15, 15, 10, 8, 15, 3, 15, 10, 10, 8, 9, 10, 6, 15, 8, 15, 3, 6, 6, 8, 15, 3, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 3, 15, 15, 8]);
108
+ function decodeBc7(source, width, height, rowPitch = Math.ceil(width / 4) * 16) {
109
+ const rgba = new Uint8Array(width * height * 4);
110
+ const blockRows = Math.ceil(height / 4);
111
+ const blockColumns = Math.ceil(width / 4);
112
+ for (let blockY = 0; blockY < blockRows; blockY++) {
113
+ for (let blockX = 0; blockX < blockColumns; blockX++) {
114
+ const blockOffset = blockY * rowPitch + blockX * 16;
115
+ const pixels = decodeBc7Block(source.subarray(blockOffset, blockOffset + 16));
116
+ copyBlock(pixels, rgba, width, height, blockX, blockY);
117
+ }
118
+ }
119
+ return rgba;
120
+ }
121
+ function decodeBc7Block(block) {
122
+ if (block.byteLength < 16) throw new RangeError("BC7 block must contain 16 bytes");
123
+ if (block[0] === 0) return new Uint8Array(16 * 4);
124
+ const reader = new BitReader(block);
125
+ let mode = 0;
126
+ while (mode < 8 && reader.read(1) === 0) mode++;
127
+ if (mode === 8) return new Uint8Array(16 * 4);
128
+ const info = MODE[mode];
129
+ const partition = reader.read(info.partitionBits);
130
+ const rotation = reader.read(info.rotationBits);
131
+ const selection = reader.read(info.selectionBits);
132
+ const endpointCount = info.subsets * 2;
133
+ const endpoints = Array.from({
134
+ length: endpointCount
135
+ }, () => [0, 0, 0, 255]);
136
+ for (let channel = 0; channel < 3; channel++) {
137
+ for (let endpoint = 0; endpoint < endpointCount; endpoint++) {
138
+ endpoints[endpoint][channel] = reader.read(info.colorBits);
139
+ }
140
+ }
141
+ if (info.alphaBits) {
142
+ for (let endpoint = 0; endpoint < endpointCount; endpoint++) {
143
+ endpoints[endpoint][3] = reader.read(info.alphaBits);
144
+ }
145
+ }
146
+ const pBits = new Uint8Array(endpointCount);
147
+ if (info.endpointPBits) {
148
+ for (let endpoint = 0; endpoint < endpointCount; endpoint++) pBits[endpoint] = reader.read(1);
149
+ } else if (info.sharedPBits) {
150
+ for (let subset = 0; subset < info.subsets; subset++) {
151
+ const pBit = reader.read(1);
152
+ pBits[subset * 2] = pBit;
153
+ pBits[subset * 2 + 1] = pBit;
154
+ }
155
+ }
156
+ const colorPrecision = info.colorBits + (info.endpointPBits || info.sharedPBits ? 1 : 0);
157
+ const alphaPrecision = info.alphaBits + (info.alphaBits && (info.endpointPBits || info.sharedPBits) ? 1 : 0);
158
+ for (let endpoint = 0; endpoint < endpointCount; endpoint++) {
159
+ for (let channel = 0; channel < 3; channel++) {
160
+ const value = info.endpointPBits || info.sharedPBits ? endpoints[endpoint][channel] << 1 | pBits[endpoint] : endpoints[endpoint][channel];
161
+ endpoints[endpoint][channel] = expandEndpoint(value, colorPrecision);
162
+ }
163
+ if (info.alphaBits) {
164
+ const value = info.endpointPBits || info.sharedPBits ? endpoints[endpoint][3] << 1 | pBits[endpoint] : endpoints[endpoint][3];
165
+ endpoints[endpoint][3] = expandEndpoint(value, alphaPrecision);
166
+ }
167
+ }
168
+ const primary = readIndices(reader, info.indexBits, info.subsets, partition);
169
+ const secondary = info.secondaryIndexBits ? readIndices(reader, info.secondaryIndexBits, info.subsets, partition) : primary;
170
+ const colorUsesSecondary = info.selectionBits && selection === 1;
171
+ const alphaUsesSecondary = info.secondaryIndexBits && (!info.selectionBits || selection === 0);
172
+ const colorIndices = colorUsesSecondary ? secondary : primary;
173
+ const alphaIndices = alphaUsesSecondary ? secondary : primary;
174
+ const colorIndexBits = colorUsesSecondary ? info.secondaryIndexBits : info.indexBits;
175
+ const alphaIndexBits = alphaUsesSecondary ? info.secondaryIndexBits : info.indexBits;
176
+ const pixels = new Uint8Array(16 * 4);
177
+ for (let pixel = 0; pixel < 16; pixel++) {
178
+ const subset = getSubset(info.subsets, partition, pixel);
179
+ const first = endpoints[subset * 2];
180
+ const second = endpoints[subset * 2 + 1];
181
+ const output = pixel * 4;
182
+ for (let channel = 0; channel < 3; channel++) {
183
+ pixels[output + channel] = interpolate(first[channel], second[channel], colorIndices[pixel], colorIndexBits);
184
+ }
185
+ pixels[output + 3] = interpolate(first[3], second[3], alphaIndices[pixel], alphaIndexBits);
186
+ if (rotation) {
187
+ const channel = rotation - 1;
188
+ const value = pixels[output + channel];
189
+ pixels[output + channel] = pixels[output + 3];
190
+ pixels[output + 3] = value;
191
+ }
192
+ }
193
+ return pixels;
194
+ }
195
+ function readIndices(reader, bitCount, subsets, partition) {
196
+ const indices = new Uint8Array(16);
197
+ for (let pixel = 0; pixel < 16; pixel++) {
198
+ const subset = getSubset(subsets, partition, pixel);
199
+ const isAnchor = pixel === getAnchor(subsets, partition, subset);
200
+ indices[pixel] = reader.read(bitCount - (isAnchor ? 1 : 0));
201
+ }
202
+ return indices;
203
+ }
204
+ function getSubset(subsets, partition, pixel) {
205
+ if (subsets === 1) return 0;
206
+ if (subsets === 2) return PARTITIONS_2[partition] >>> pixel & 1;
207
+ return PARTITIONS_3[partition] >>> pixel * 2 & 3;
208
+ }
209
+ function getAnchor(subsets, partition, subset) {
210
+ if (subset === 0) return 0;
211
+ if (subsets === 2) return ANCHOR_2[partition];
212
+ return subset === 1 ? ANCHOR_3_SECOND[partition] : ANCHOR_3_THIRD[partition];
213
+ }
214
+ function expandEndpoint(value, bitCount) {
215
+ if (bitCount === 8) return value;
216
+ return value << 8 - bitCount | value >>> 2 * bitCount - 8;
217
+ }
218
+ function interpolate(first, second, index, bitCount) {
219
+ const weight = WEIGHTS[bitCount][index];
220
+ return (64 - weight) * first + weight * second + 32 >>> 6;
221
+ }
222
+ function copyBlock(block, output, width, height, blockX, blockY) {
223
+ for (let y = 0; y < 4; y++) {
224
+ const outputY = blockY * 4 + y;
225
+ if (outputY >= height) continue;
226
+ for (let x = 0; x < 4; x++) {
227
+ const outputX = blockX * 4 + x;
228
+ if (outputX >= width) continue;
229
+ const sourceOffset = (y * 4 + x) * 4;
230
+ output.set(block.subarray(sourceOffset, sourceOffset + 4), (outputY * width + outputX) * 4);
231
+ }
232
+ }
233
+ }
234
+ class BitReader {
235
+ constructor(bytes) {
236
+ this.bytes = bytes;
237
+ this.offset = 0;
238
+ }
239
+ read(bitCount) {
240
+ let value = 0;
241
+ for (let bit = 0; bit < bitCount; bit++) {
242
+ if (this.offset >= 128) throw new RangeError("BC7 block bitstream exceeds 128 bits");
243
+ value |= (this.bytes[this.offset >>> 3] >>> (this.offset & 7) & 1) << bit;
244
+ this.offset++;
245
+ }
246
+ return value;
247
+ }
248
+ }
249
+
250
+ export { decodeBc7, decodeBc7Block };
251
+ //# sourceMappingURL=bc7.js.map