@woosh/meep-engine 3.8.0 → 3.10.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 (735) hide show
  1. package/build/bundle-worker-image-decoder.js +1 -1
  2. package/build/bundle-worker-terrain.js +1 -1
  3. package/package.json +3 -2
  4. package/src/avif/encode_image_source.d.ts +70 -0
  5. package/src/avif/encode_image_source.d.ts.map +1 -0
  6. package/src/avif/encode_image_source.js +117 -0
  7. package/src/avif/encoder_worker.js +15 -126
  8. package/src/avif/index.d.ts +4 -2
  9. package/src/avif/index.js +21 -2
  10. package/src/avif/native/DECISIONS.md +537 -0
  11. package/src/avif/native/NOTICE.md +61 -0
  12. package/src/avif/native/api/AvifDecoder.d.ts +67 -0
  13. package/src/avif/native/api/AvifDecoder.d.ts.map +1 -0
  14. package/src/avif/native/api/AvifDecoder.js +121 -0
  15. package/src/avif/native/api/apply_transformations.d.ts +30 -0
  16. package/src/avif/native/api/apply_transformations.d.ts.map +1 -0
  17. package/src/avif/native/api/apply_transformations.js +120 -0
  18. package/src/avif/native/api/avif_to_sampler2d.d.ts +25 -0
  19. package/src/avif/native/api/avif_to_sampler2d.d.ts.map +1 -0
  20. package/src/avif/native/api/avif_to_sampler2d.js +42 -0
  21. package/src/avif/native/api/convert_to_rgba.d.ts +54 -0
  22. package/src/avif/native/api/convert_to_rgba.d.ts.map +1 -0
  23. package/src/avif/native/api/convert_to_rgba.js +204 -0
  24. package/src/avif/native/api/decode_avif.d.ts +24 -0
  25. package/src/avif/native/api/decode_avif.d.ts.map +1 -0
  26. package/src/avif/native/api/decode_avif.js +111 -0
  27. package/src/avif/native/api/decode_image_item.d.ts +18 -0
  28. package/src/avif/native/api/decode_image_item.d.ts.map +1 -0
  29. package/src/avif/native/api/decode_image_item.js +234 -0
  30. package/src/avif/native/api/encode_avif.d.ts +73 -0
  31. package/src/avif/native/api/encode_avif.d.ts.map +1 -0
  32. package/src/avif/native/api/encode_avif.js +488 -0
  33. package/src/avif/native/api/sampler2d_to_avif.d.ts +22 -0
  34. package/src/avif/native/api/sampler2d_to_avif.d.ts.map +1 -0
  35. package/src/avif/native/api/sampler2d_to_avif.js +108 -0
  36. package/src/avif/native/av1/decode/Av1FrameContext.d.ts +286 -0
  37. package/src/avif/native/av1/decode/Av1FrameContext.d.ts.map +1 -0
  38. package/src/avif/native/av1/decode/Av1FrameContext.js +622 -0
  39. package/src/avif/native/av1/decode/block_decoded.d.ts +27 -0
  40. package/src/avif/native/av1/decode/block_decoded.d.ts.map +1 -0
  41. package/src/avif/native/av1/decode/block_decoded.js +59 -0
  42. package/src/avif/native/av1/decode/decode_av1_still.d.ts +22 -0
  43. package/src/avif/native/av1/decode/decode_av1_still.d.ts.map +1 -0
  44. package/src/avif/native/av1/decode/decode_av1_still.js +309 -0
  45. package/src/avif/native/av1/decode/decode_coefficients.d.ts +20 -0
  46. package/src/avif/native/av1/decode/decode_coefficients.d.ts.map +1 -0
  47. package/src/avif/native/av1/decode/decode_coefficients.js +259 -0
  48. package/src/avif/native/av1/decode/decode_palette.d.ts +28 -0
  49. package/src/avif/native/av1/decode/decode_palette.d.ts.map +1 -0
  50. package/src/avif/native/av1/decode/decode_palette.js +442 -0
  51. package/src/avif/native/av1/decode/decode_tile.d.ts +14 -0
  52. package/src/avif/native/av1/decode/decode_tile.d.ts.map +1 -0
  53. package/src/avif/native/av1/decode/decode_tile.js +1213 -0
  54. package/src/avif/native/av1/decode/get_scan.d.ts +16 -0
  55. package/src/avif/native/av1/decode/get_scan.d.ts.map +1 -0
  56. package/src/avif/native/av1/decode/get_scan.js +138 -0
  57. package/src/avif/native/av1/decode/read_lr.d.ts +35 -0
  58. package/src/avif/native/av1/decode/read_lr.d.ts.map +1 -0
  59. package/src/avif/native/av1/decode/read_lr.js +277 -0
  60. package/src/avif/native/av1/decode/read_transform_type.d.ts +19 -0
  61. package/src/avif/native/av1/decode/read_transform_type.d.ts.map +1 -0
  62. package/src/avif/native/av1/decode/read_transform_type.js +92 -0
  63. package/src/avif/native/av1/decode/reconstruct.d.ts +36 -0
  64. package/src/avif/native/av1/decode/reconstruct.d.ts.map +1 -0
  65. package/src/avif/native/av1/decode/reconstruct.js +241 -0
  66. package/src/avif/native/av1/decode/transform_type.d.ts +49 -0
  67. package/src/avif/native/av1/decode/transform_type.d.ts.map +1 -0
  68. package/src/avif/native/av1/decode/transform_type.js +137 -0
  69. package/src/avif/native/av1/encode/Av1BlockSnapshot.d.ts +81 -0
  70. package/src/avif/native/av1/encode/Av1BlockSnapshot.d.ts.map +1 -0
  71. package/src/avif/native/av1/encode/Av1BlockSnapshot.js +299 -0
  72. package/src/avif/native/av1/encode/Av1EncodeContext.d.ts +384 -0
  73. package/src/avif/native/av1/encode/Av1EncodeContext.d.ts.map +1 -0
  74. package/src/avif/native/av1/encode/Av1EncodeContext.js +590 -0
  75. package/src/avif/native/av1/encode/build_headers.d.ts +50 -0
  76. package/src/avif/native/av1/encode/build_headers.d.ts.map +1 -0
  77. package/src/avif/native/av1/encode/build_headers.js +359 -0
  78. package/src/avif/native/av1/encode/choose_chroma_alpha.d.ts +26 -0
  79. package/src/avif/native/av1/encode/choose_chroma_alpha.d.ts.map +1 -0
  80. package/src/avif/native/av1/encode/choose_chroma_alpha.js +90 -0
  81. package/src/avif/native/av1/encode/choose_filters.d.ts +21 -0
  82. package/src/avif/native/av1/encode/choose_filters.d.ts.map +1 -0
  83. package/src/avif/native/av1/encode/choose_filters.js +318 -0
  84. package/src/avif/native/av1/encode/choose_restoration.d.ts +35 -0
  85. package/src/avif/native/av1/encode/choose_restoration.d.ts.map +1 -0
  86. package/src/avif/native/av1/encode/choose_restoration.js +616 -0
  87. package/src/avif/native/av1/encode/decode_effort.d.ts +57 -0
  88. package/src/avif/native/av1/encode/decode_effort.d.ts.map +1 -0
  89. package/src/avif/native/av1/encode/decode_effort.js +59 -0
  90. package/src/avif/native/av1/encode/encode_av1_still.d.ts +17 -0
  91. package/src/avif/native/av1/encode/encode_av1_still.d.ts.map +1 -0
  92. package/src/avif/native/av1/encode/encode_av1_still.js +194 -0
  93. package/src/avif/native/av1/encode/encode_effort.d.ts +56 -0
  94. package/src/avif/native/av1/encode/encode_effort.d.ts.map +1 -0
  95. package/src/avif/native/av1/encode/encode_effort.js +97 -0
  96. package/src/avif/native/av1/encode/encode_tile.d.ts +26 -0
  97. package/src/avif/native/av1/encode/encode_tile.d.ts.map +1 -0
  98. package/src/avif/native/av1/encode/encode_tile.js +2331 -0
  99. package/src/avif/native/av1/encode/quantise.d.ts +51 -0
  100. package/src/avif/native/av1/encode/quantise.d.ts.map +1 -0
  101. package/src/avif/native/av1/encode/quantise.js +212 -0
  102. package/src/avif/native/av1/encode/write_coefficients.d.ts +42 -0
  103. package/src/avif/native/av1/encode/write_coefficients.d.ts.map +1 -0
  104. package/src/avif/native/av1/encode/write_coefficients.js +367 -0
  105. package/src/avif/native/av1/encode/write_lr.d.ts +33 -0
  106. package/src/avif/native/av1/encode/write_lr.d.ts.map +1 -0
  107. package/src/avif/native/av1/encode/write_lr.js +174 -0
  108. package/src/avif/native/av1/encode/write_transform_type.d.ts +21 -0
  109. package/src/avif/native/av1/encode/write_transform_type.d.ts.map +1 -0
  110. package/src/avif/native/av1/encode/write_transform_type.js +70 -0
  111. package/src/avif/native/av1/entropy/CdfContext.d.ts +167 -0
  112. package/src/avif/native/av1/entropy/CdfContext.d.ts.map +1 -0
  113. package/src/avif/native/av1/entropy/CdfContext.js +433 -0
  114. package/src/avif/native/av1/entropy/SymbolReader.d.ts +103 -0
  115. package/src/avif/native/av1/entropy/SymbolReader.d.ts.map +1 -0
  116. package/src/avif/native/av1/entropy/SymbolReader.js +317 -0
  117. package/src/avif/native/av1/entropy/SymbolWriter.d.ts +107 -0
  118. package/src/avif/native/av1/entropy/SymbolWriter.d.ts.map +1 -0
  119. package/src/avif/native/av1/entropy/SymbolWriter.js +352 -0
  120. package/src/avif/native/av1/entropy/coefficient_context.d.ts +71 -0
  121. package/src/avif/native/av1/entropy/coefficient_context.d.ts.map +1 -0
  122. package/src/avif/native/av1/entropy/coefficient_context.js +325 -0
  123. package/src/avif/native/av1/entropy/partition_cdf.d.ts +54 -0
  124. package/src/avif/native/av1/entropy/partition_cdf.d.ts.map +1 -0
  125. package/src/avif/native/av1/entropy/partition_cdf.js +98 -0
  126. package/src/avif/native/av1/entropy/symbol_cost.d.ts +37 -0
  127. package/src/avif/native/av1/entropy/symbol_cost.d.ts.map +1 -0
  128. package/src/avif/native/av1/entropy/symbol_cost.js +76 -0
  129. package/src/avif/native/av1/filter/cdef.d.ts +15 -0
  130. package/src/avif/native/av1/filter/cdef.d.ts.map +1 -0
  131. package/src/avif/native/av1/filter/cdef.js +313 -0
  132. package/src/avif/native/av1/filter/loop_filter.d.ts +14 -0
  133. package/src/avif/native/av1/filter/loop_filter.d.ts.map +1 -0
  134. package/src/avif/native/av1/filter/loop_filter.js +377 -0
  135. package/src/avif/native/av1/filter/loop_restoration.d.ts +42 -0
  136. package/src/avif/native/av1/filter/loop_restoration.d.ts.map +1 -0
  137. package/src/avif/native/av1/filter/loop_restoration.js +451 -0
  138. package/src/avif/native/av1/filter/superres.d.ts +18 -0
  139. package/src/avif/native/av1/filter/superres.d.ts.map +1 -0
  140. package/src/avif/native/av1/filter/superres.js +86 -0
  141. package/src/avif/native/av1/grain/FilmGrainState.d.ts +62 -0
  142. package/src/avif/native/av1/grain/FilmGrainState.d.ts.map +1 -0
  143. package/src/avif/native/av1/grain/FilmGrainState.js +87 -0
  144. package/src/avif/native/av1/grain/film_grain.d.ts +16 -0
  145. package/src/avif/native/av1/grain/film_grain.d.ts.map +1 -0
  146. package/src/avif/native/av1/grain/film_grain.js +623 -0
  147. package/src/avif/native/av1/obu/FrameHeader.d.ts +248 -0
  148. package/src/avif/native/av1/obu/FrameHeader.d.ts.map +1 -0
  149. package/src/avif/native/av1/obu/FrameHeader.js +381 -0
  150. package/src/avif/native/av1/obu/ObuHeader.d.ts +53 -0
  151. package/src/avif/native/av1/obu/ObuHeader.d.ts.map +1 -0
  152. package/src/avif/native/av1/obu/ObuHeader.js +62 -0
  153. package/src/avif/native/av1/obu/SequenceHeader.d.ts +157 -0
  154. package/src/avif/native/av1/obu/SequenceHeader.d.ts.map +1 -0
  155. package/src/avif/native/av1/obu/SequenceHeader.js +225 -0
  156. package/src/avif/native/av1/obu/for_each_obu.d.ts +24 -0
  157. package/src/avif/native/av1/obu/for_each_obu.d.ts.map +1 -0
  158. package/src/avif/native/av1/obu/for_each_obu.js +50 -0
  159. package/src/avif/native/av1/obu/parse_frame_header.d.ts +18 -0
  160. package/src/avif/native/av1/obu/parse_frame_header.d.ts.map +1 -0
  161. package/src/avif/native/av1/obu/parse_frame_header.js +841 -0
  162. package/src/avif/native/av1/obu/parse_obu_header.d.ts +23 -0
  163. package/src/avif/native/av1/obu/parse_obu_header.d.ts.map +1 -0
  164. package/src/avif/native/av1/obu/parse_obu_header.js +69 -0
  165. package/src/avif/native/av1/obu/parse_sequence_header.d.ts +17 -0
  166. package/src/avif/native/av1/obu/parse_sequence_header.d.ts.map +1 -0
  167. package/src/avif/native/av1/obu/parse_sequence_header.js +263 -0
  168. package/src/avif/native/av1/obu/write_frame_header.d.ts +16 -0
  169. package/src/avif/native/av1/obu/write_frame_header.d.ts.map +1 -0
  170. package/src/avif/native/av1/obu/write_frame_header.js +579 -0
  171. package/src/avif/native/av1/obu/write_sequence_header.d.ts +17 -0
  172. package/src/avif/native/av1/obu/write_sequence_header.d.ts.map +1 -0
  173. package/src/avif/native/av1/obu/write_sequence_header.js +189 -0
  174. package/src/avif/native/av1/predict/IntraPredictionState.d.ts +49 -0
  175. package/src/avif/native/av1/predict/IntraPredictionState.d.ts.map +1 -0
  176. package/src/avif/native/av1/predict/IntraPredictionState.js +58 -0
  177. package/src/avif/native/av1/predict/intra_filter_type.d.ts +17 -0
  178. package/src/avif/native/av1/predict/intra_filter_type.d.ts.map +1 -0
  179. package/src/avif/native/av1/predict/intra_filter_type.js +79 -0
  180. package/src/avif/native/av1/predict/predict_chroma_from_luma.d.ts +50 -0
  181. package/src/avif/native/av1/predict/predict_chroma_from_luma.d.ts.map +1 -0
  182. package/src/avif/native/av1/predict/predict_chroma_from_luma.js +153 -0
  183. package/src/avif/native/av1/predict/predict_intra.d.ts +42 -0
  184. package/src/avif/native/av1/predict/predict_intra.d.ts.map +1 -0
  185. package/src/avif/native/av1/predict/predict_intra.js +803 -0
  186. package/src/avif/native/av1/predict/predict_palette.d.ts +23 -0
  187. package/src/avif/native/av1/predict/predict_palette.d.ts.map +1 -0
  188. package/src/avif/native/av1/predict/predict_palette.js +36 -0
  189. package/src/avif/native/av1/tables/av1_symbols.d.ts +411 -0
  190. package/src/avif/native/av1/tables/av1_symbols.d.ts.map +1 -0
  191. package/src/avif/native/av1/tables/av1_symbols.js +419 -0
  192. package/src/avif/native/av1/tables/block_tables.d.ts +181 -0
  193. package/src/avif/native/av1/tables/block_tables.d.ts.map +1 -0
  194. package/src/avif/native/av1/tables/block_tables.js +270 -0
  195. package/src/avif/native/av1/tables/cdf_tables.d.ts +961 -0
  196. package/src/avif/native/av1/tables/cdf_tables.d.ts.map +1 -0
  197. package/src/avif/native/av1/tables/cdf_tables.js +1893 -0
  198. package/src/avif/native/av1/tables/coefficient_tables.d.ts +41 -0
  199. package/src/avif/native/av1/tables/coefficient_tables.d.ts.map +1 -0
  200. package/src/avif/native/av1/tables/coefficient_tables.js +82 -0
  201. package/src/avif/native/av1/tables/derived_block_tables.d.ts +15 -0
  202. package/src/avif/native/av1/tables/derived_block_tables.d.ts.map +1 -0
  203. package/src/avif/native/av1/tables/derived_block_tables.js +23 -0
  204. package/src/avif/native/av1/tables/filter_tables.d.ts +171 -0
  205. package/src/avif/native/av1/tables/filter_tables.d.ts.map +1 -0
  206. package/src/avif/native/av1/tables/filter_tables.js +313 -0
  207. package/src/avif/native/av1/tables/grain_tables.d.ts +11 -0
  208. package/src/avif/native/av1/tables/grain_tables.d.ts.map +1 -0
  209. package/src/avif/native/av1/tables/grain_tables.js +190 -0
  210. package/src/avif/native/av1/tables/prediction_tables.d.ts +141 -0
  211. package/src/avif/native/av1/tables/prediction_tables.d.ts.map +1 -0
  212. package/src/avif/native/av1/tables/prediction_tables.js +223 -0
  213. package/src/avif/native/av1/tables/quantizer_matrix_tables.d.ts +21 -0
  214. package/src/avif/native/av1/tables/quantizer_matrix_tables.d.ts.map +1 -0
  215. package/src/avif/native/av1/tables/quantizer_matrix_tables.js +38 -0
  216. package/src/avif/native/av1/tables/quantizer_tables.d.ts +21 -0
  217. package/src/avif/native/av1/tables/quantizer_tables.d.ts.map +1 -0
  218. package/src/avif/native/av1/tables/quantizer_tables.js +160 -0
  219. package/src/avif/native/av1/tables/scan_tables.d.ts +321 -0
  220. package/src/avif/native/av1/tables/scan_tables.d.ts.map +1 -0
  221. package/src/avif/native/av1/tables/scan_tables.js +727 -0
  222. package/src/avif/native/av1/tables/segmentation_tables.d.ts +31 -0
  223. package/src/avif/native/av1/tables/segmentation_tables.d.ts.map +1 -0
  224. package/src/avif/native/av1/tables/segmentation_tables.js +48 -0
  225. package/src/avif/native/av1/tables/transform_tables.d.ts +91 -0
  226. package/src/avif/native/av1/tables/transform_tables.d.ts.map +1 -0
  227. package/src/avif/native/av1/tables/transform_tables.js +140 -0
  228. package/src/avif/native/av1/tables/unpack_table.d.ts +33 -0
  229. package/src/avif/native/av1/tables/unpack_table.d.ts.map +1 -0
  230. package/src/avif/native/av1/tables/unpack_table.js +73 -0
  231. package/src/avif/native/av1/transform/forward_transform_2d.d.ts +61 -0
  232. package/src/avif/native/av1/transform/forward_transform_2d.d.ts.map +1 -0
  233. package/src/avif/native/av1/transform/forward_transform_2d.js +574 -0
  234. package/src/avif/native/av1/transform/inverse_transform_1d.d.ts +76 -0
  235. package/src/avif/native/av1/transform/inverse_transform_1d.d.ts.map +1 -0
  236. package/src/avif/native/av1/transform/inverse_transform_1d.js +590 -0
  237. package/src/avif/native/av1/transform/inverse_transform_2d.d.ts +46 -0
  238. package/src/avif/native/av1/transform/inverse_transform_2d.d.ts.map +1 -0
  239. package/src/avif/native/av1/transform/inverse_transform_2d.js +180 -0
  240. package/src/avif/native/av1/util/ceil_log2.d.ts +13 -0
  241. package/src/avif/native/av1/util/ceil_log2.d.ts.map +1 -0
  242. package/src/avif/native/av1/util/ceil_log2.js +18 -0
  243. package/src/avif/native/av1/util/floor_log2.d.ts +20 -0
  244. package/src/avif/native/av1/util/floor_log2.d.ts.map +1 -0
  245. package/src/avif/native/av1/util/floor_log2.js +20 -0
  246. package/src/avif/native/av1/util/round2.d.ts +22 -0
  247. package/src/avif/native/av1/util/round2.d.ts.map +1 -0
  248. package/src/avif/native/av1/util/round2.js +27 -0
  249. package/src/avif/native/av1/util/round2_signed.d.ts +14 -0
  250. package/src/avif/native/av1/util/round2_signed.d.ts.map +1 -0
  251. package/src/avif/native/av1/util/round2_signed.js +17 -0
  252. package/src/avif/native/av1/util/tile_log2.d.ts +16 -0
  253. package/src/avif/native/av1/util/tile_log2.d.ts.map +1 -0
  254. package/src/avif/native/av1/util/tile_log2.js +23 -0
  255. package/src/avif/native/bitstream/BitReader.d.ts +174 -0
  256. package/src/avif/native/bitstream/BitReader.d.ts.map +1 -0
  257. package/src/avif/native/bitstream/BitReader.js +391 -0
  258. package/src/avif/native/bitstream/BitWriter.d.ts +122 -0
  259. package/src/avif/native/bitstream/BitWriter.d.ts.map +1 -0
  260. package/src/avif/native/bitstream/BitWriter.js +351 -0
  261. package/src/avif/native/color/ColourTransform.d.ts +62 -0
  262. package/src/avif/native/color/ColourTransform.d.ts.map +1 -0
  263. package/src/avif/native/color/ColourTransform.js +189 -0
  264. package/src/avif/native/color/YuvImage.d.ts +51 -0
  265. package/src/avif/native/color/YuvImage.d.ts.map +1 -0
  266. package/src/avif/native/color/YuvImage.js +66 -0
  267. package/src/avif/native/color/clamp_sample.d.ts +18 -0
  268. package/src/avif/native/color/clamp_sample.d.ts.map +1 -0
  269. package/src/avif/native/color/clamp_sample.js +25 -0
  270. package/src/avif/native/color/linear_to_transfer.d.ts +24 -0
  271. package/src/avif/native/color/linear_to_transfer.d.ts.map +1 -0
  272. package/src/avif/native/color/linear_to_transfer.js +126 -0
  273. package/src/avif/native/color/primaries.d.ts +20 -0
  274. package/src/avif/native/color/primaries.d.ts.map +1 -0
  275. package/src/avif/native/color/primaries.js +94 -0
  276. package/src/avif/native/color/rgb_row_to_ycbcr.d.ts +20 -0
  277. package/src/avif/native/color/rgb_row_to_ycbcr.d.ts.map +1 -0
  278. package/src/avif/native/color/rgb_row_to_ycbcr.js +78 -0
  279. package/src/avif/native/color/transfer_to_linear.d.ts +49 -0
  280. package/src/avif/native/color/transfer_to_linear.d.ts.map +1 -0
  281. package/src/avif/native/color/transfer_to_linear.js +171 -0
  282. package/src/avif/native/color/upsample_chroma_row.d.ts +35 -0
  283. package/src/avif/native/color/upsample_chroma_row.d.ts.map +1 -0
  284. package/src/avif/native/color/upsample_chroma_row.js +89 -0
  285. package/src/avif/native/color/ycbcr_row_to_rgb.d.ts +23 -0
  286. package/src/avif/native/color/ycbcr_row_to_rgb.d.ts.map +1 -0
  287. package/src/avif/native/color/ycbcr_row_to_rgb.js +78 -0
  288. package/src/avif/native/heif/AvifFile.d.ts +112 -0
  289. package/src/avif/native/heif/AvifFile.d.ts.map +1 -0
  290. package/src/avif/native/heif/AvifFile.js +142 -0
  291. package/src/avif/native/heif/ItemProperty.d.ts +244 -0
  292. package/src/avif/native/heif/ItemProperty.d.ts.map +1 -0
  293. package/src/avif/native/heif/ItemProperty.js +321 -0
  294. package/src/avif/native/heif/find_item_property.d.ts +17 -0
  295. package/src/avif/native/heif/find_item_property.d.ts.map +1 -0
  296. package/src/avif/native/heif/find_item_property.js +28 -0
  297. package/src/avif/native/heif/find_item_references.d.ts +16 -0
  298. package/src/avif/native/heif/find_item_references.d.ts.map +1 -0
  299. package/src/avif/native/heif/find_item_references.js +29 -0
  300. package/src/avif/native/heif/find_items_referencing.d.ts +17 -0
  301. package/src/avif/native/heif/find_items_referencing.d.ts.map +1 -0
  302. package/src/avif/native/heif/find_items_referencing.js +36 -0
  303. package/src/avif/native/heif/parse_avif_file.d.ts +15 -0
  304. package/src/avif/native/heif/parse_avif_file.d.ts.map +1 -0
  305. package/src/avif/native/heif/parse_avif_file.js +383 -0
  306. package/src/avif/native/heif/parse_image_grid.d.ts +18 -0
  307. package/src/avif/native/heif/parse_image_grid.d.ts.map +1 -0
  308. package/src/avif/native/heif/parse_image_grid.js +48 -0
  309. package/src/avif/native/heif/parse_item_property.d.ts +18 -0
  310. package/src/avif/native/heif/parse_item_property.d.ts.map +1 -0
  311. package/src/avif/native/heif/parse_item_property.js +243 -0
  312. package/src/avif/native/heif/read_item_data.d.ts +22 -0
  313. package/src/avif/native/heif/read_item_data.d.ts.map +1 -0
  314. package/src/avif/native/heif/read_item_data.js +97 -0
  315. package/src/avif/native/heif/write_avif_file.d.ts +50 -0
  316. package/src/avif/native/heif/write_avif_file.d.ts.map +1 -0
  317. package/src/avif/native/heif/write_avif_file.js +348 -0
  318. package/src/avif/native/heif/write_item_property.d.ts +16 -0
  319. package/src/avif/native/heif/write_item_property.d.ts.map +1 -0
  320. package/src/avif/native/heif/write_item_property.js +182 -0
  321. package/src/avif/native/index.d.ts +14 -0
  322. package/src/avif/native/index.d.ts.map +1 -0
  323. package/src/avif/native/index.js +56 -0
  324. package/src/avif/native/isobmff/BoxHeader.d.ts +50 -0
  325. package/src/avif/native/isobmff/BoxHeader.d.ts.map +1 -0
  326. package/src/avif/native/isobmff/BoxHeader.js +57 -0
  327. package/src/avif/native/isobmff/BoxWriter.d.ts +118 -0
  328. package/src/avif/native/isobmff/BoxWriter.d.ts.map +1 -0
  329. package/src/avif/native/isobmff/BoxWriter.js +264 -0
  330. package/src/avif/native/isobmff/ByteCursor.d.ts +125 -0
  331. package/src/avif/native/isobmff/ByteCursor.d.ts.map +1 -0
  332. package/src/avif/native/isobmff/ByteCursor.js +298 -0
  333. package/src/avif/native/isobmff/for_each_box.d.ts +23 -0
  334. package/src/avif/native/isobmff/for_each_box.d.ts.map +1 -0
  335. package/src/avif/native/isobmff/for_each_box.js +39 -0
  336. package/src/avif/native/isobmff/read_box_header.d.ts +22 -0
  337. package/src/avif/native/isobmff/read_box_header.d.ts.map +1 -0
  338. package/src/avif/native/isobmff/read_box_header.js +59 -0
  339. package/src/avif/native/isobmff/read_full_box_header.d.ts +26 -0
  340. package/src/avif/native/isobmff/read_full_box_header.d.ts.map +1 -0
  341. package/src/avif/native/isobmff/read_full_box_header.js +33 -0
  342. package/src/avif/threaded_image_encoder.d.ts +7 -2
  343. package/src/avif/threaded_image_encoder.d.ts.map +1 -1
  344. package/src/avif/threaded_image_encoder.js +107 -21
  345. package/src/core/binary/BinaryBuffer.d.ts +40 -0
  346. package/src/core/binary/BinaryBuffer.d.ts.map +1 -1
  347. package/src/core/binary/BinaryBuffer.js +100 -0
  348. package/src/core/binary/hash/crc32.d.ts +16 -0
  349. package/src/core/binary/hash/crc32.d.ts.map +1 -0
  350. package/src/core/binary/hash/crc32.js +96 -0
  351. package/src/core/binary/utf8/utf8_decode.d.ts +21 -0
  352. package/src/core/binary/utf8/utf8_decode.d.ts.map +1 -0
  353. package/src/core/binary/utf8/utf8_decode.js +43 -0
  354. package/src/core/binary/utf8/utf8_encode_into.d.ts +20 -0
  355. package/src/core/binary/utf8/utf8_encode_into.d.ts.map +1 -0
  356. package/src/core/binary/utf8/utf8_encode_into.js +48 -0
  357. package/src/core/binary/utf8/utf8_encoded_length.d.ts +14 -0
  358. package/src/core/binary/utf8/utf8_encoded_length.d.ts.map +1 -0
  359. package/src/core/binary/utf8/utf8_encoded_length.js +36 -0
  360. package/src/core/color/COLOR_FIX_PLAN_2026_08_28.md +417 -0
  361. package/src/core/color/COLOR_REVIEW_2026_08_28.md +779 -0
  362. package/src/core/color/Color.d.ts +128 -20
  363. package/src/core/color/Color.d.ts.map +1 -1
  364. package/src/core/color/Color.js +959 -866
  365. package/src/core/color/PQ/PQ_constants.d.ts +10 -0
  366. package/src/core/color/PQ/PQ_constants.d.ts.map +1 -1
  367. package/src/core/color/PQ/PQ_constants.js +10 -0
  368. package/src/core/color/PQ/linear_to_PQ.d.ts.map +1 -1
  369. package/src/core/color/PQ/linear_to_PQ.js +6 -0
  370. package/src/core/color/REC709_PRIMARIES.d.ts +50 -0
  371. package/src/core/color/REC709_PRIMARIES.d.ts.map +1 -0
  372. package/src/core/color/REC709_PRIMARIES.js +53 -0
  373. package/src/core/color/construct/color_from_hex.d.ts +21 -0
  374. package/src/core/color/construct/color_from_hex.d.ts.map +1 -0
  375. package/src/core/color/construct/color_from_hex.js +33 -0
  376. package/src/core/color/construct/color_from_temperature.d.ts +22 -0
  377. package/src/core/color/construct/color_from_temperature.d.ts.map +1 -0
  378. package/src/core/color/construct/color_from_temperature.js +33 -0
  379. package/src/core/color/construct/color_from_uint24.d.ts +19 -0
  380. package/src/core/color/construct/color_from_uint24.d.ts.map +1 -0
  381. package/src/core/color/construct/color_from_uint24.js +26 -0
  382. package/src/core/color/construct/color_from_uint32.d.ts +20 -0
  383. package/src/core/color/construct/color_from_uint32.d.ts.map +1 -0
  384. package/src/core/color/construct/color_from_uint32.js +39 -0
  385. package/src/core/color/construct/color_gray.d.ts +17 -0
  386. package/src/core/color/construct/color_gray.d.ts.map +1 -0
  387. package/src/core/color/construct/color_gray.js +22 -0
  388. package/src/core/color/hex/hex2rgb.d.ts +1 -11
  389. package/src/core/color/hex/hex2rgb.d.ts.map +1 -1
  390. package/src/core/color/hex/hex2rgb.js +7 -24
  391. package/src/core/color/hex/hex_to_rgb.d.ts +18 -0
  392. package/src/core/color/hex/hex_to_rgb.d.ts.map +1 -0
  393. package/src/core/color/hex/hex_to_rgb.js +62 -0
  394. package/src/core/color/hex/rgb2hex.d.ts +1 -8
  395. package/src/core/color/hex/rgb2hex.d.ts.map +1 -1
  396. package/src/core/color/hex/rgb2hex.js +7 -13
  397. package/src/core/color/hex/rgb_to_hex.d.ts +9 -0
  398. package/src/core/color/hex/rgb_to_hex.d.ts.map +1 -0
  399. package/src/core/color/hex/rgb_to_hex.js +13 -0
  400. package/src/core/color/hex/rgba_to_hex.d.ts +19 -0
  401. package/src/core/color/hex/rgba_to_hex.d.ts.map +1 -0
  402. package/src/core/color/hex/rgba_to_hex.js +23 -0
  403. package/src/core/color/hsv/hsv2rgb.d.ts +1 -12
  404. package/src/core/color/hsv/hsv2rgb.d.ts.map +1 -1
  405. package/src/core/color/hsv/hsv2rgb.js +8 -21
  406. package/src/core/color/hsv/hsv2rgb_float.d.ts +1 -12
  407. package/src/core/color/hsv/hsv2rgb_float.d.ts.map +1 -1
  408. package/src/core/color/hsv/hsv2rgb_float.js +8 -56
  409. package/src/core/color/hsv/hsv_to_rgb.d.ts +13 -0
  410. package/src/core/color/hsv/hsv_to_rgb.d.ts.map +1 -0
  411. package/src/core/color/hsv/hsv_to_rgb.js +39 -0
  412. package/src/core/color/hsv/hsv_to_rgb_uint8.d.ts +13 -0
  413. package/src/core/color/hsv/hsv_to_rgb_uint8.d.ts.map +1 -0
  414. package/src/core/color/hsv/hsv_to_rgb_uint8.js +21 -0
  415. package/src/core/color/hsv/hue_to_rgb_sextant.d.ts +24 -0
  416. package/src/core/color/hsv/hue_to_rgb_sextant.d.ts.map +1 -0
  417. package/src/core/color/hsv/hue_to_rgb_sextant.js +67 -0
  418. package/src/core/color/hsv/rgb2hsv.d.ts +1 -12
  419. package/src/core/color/hsv/rgb2hsv.d.ts.map +1 -1
  420. package/src/core/color/hsv/rgb2hsv.js +7 -42
  421. package/src/core/color/hsv/rgb_to_hsv.d.ts +13 -0
  422. package/src/core/color/hsv/rgb_to_hsv.d.ts.map +1 -0
  423. package/src/core/color/hsv/rgb_to_hsv.js +42 -0
  424. package/src/core/color/hunt/hpe_to_xyz.d.ts +2 -0
  425. package/src/core/color/hunt/hpe_to_xyz.d.ts.map +1 -0
  426. package/src/core/color/hunt/hpe_to_xyz.js +4 -0
  427. package/src/core/color/hunt/xyz_to_hpe.d.ts +1 -6
  428. package/src/core/color/hunt/xyz_to_hpe.d.ts.map +1 -1
  429. package/src/core/color/hunt/xyz_to_hpe.js +12 -15
  430. package/src/core/color/illuminant/D65_spd_tabulated.d.ts.map +1 -1
  431. package/src/core/color/illuminant/D65_spd_tabulated.js +107 -104
  432. package/src/core/color/int2rgb.d.ts +1 -10
  433. package/src/core/color/int2rgb.d.ts.map +1 -1
  434. package/src/core/color/int2rgb.js +7 -12
  435. package/src/core/color/int_to_rgb.d.ts +21 -0
  436. package/src/core/color/int_to_rgb.d.ts.map +1 -0
  437. package/src/core/color/int_to_rgb.js +33 -0
  438. package/src/core/color/kelvin/kelvin_to_rgb.d.ts.map +1 -1
  439. package/src/core/color/kelvin/kelvin_to_rgb.js +22 -2
  440. package/src/core/color/kelvin/rgb_to_kelvin.d.ts +22 -2
  441. package/src/core/color/kelvin/rgb_to_kelvin.d.ts.map +1 -1
  442. package/src/core/color/kelvin/rgb_to_kelvin.js +22 -2
  443. package/src/core/color/lab/lab_to_xyz.d.ts +20 -0
  444. package/src/core/color/lab/lab_to_xyz.d.ts.map +1 -0
  445. package/src/core/color/lab/lab_to_xyz.js +69 -0
  446. package/src/core/color/oklab/gamut_clip_adaptive_l0.d.ts +34 -0
  447. package/src/core/color/oklab/gamut_clip_adaptive_l0.d.ts.map +1 -0
  448. package/src/core/color/oklab/gamut_clip_adaptive_l0.js +46 -0
  449. package/src/core/color/oklab/gamut_clip_at_l0.d.ts +33 -0
  450. package/src/core/color/oklab/gamut_clip_at_l0.d.ts.map +1 -0
  451. package/src/core/color/oklab/gamut_clip_at_l0.js +84 -0
  452. package/src/core/color/oklab/gamut_clip_preserve_chroma.d.ts +24 -0
  453. package/src/core/color/oklab/gamut_clip_preserve_chroma.d.ts.map +1 -0
  454. package/src/core/color/oklab/gamut_clip_preserve_chroma.js +37 -0
  455. package/src/core/color/oklab/gamut_clip_project_to_lcusp.d.ts +23 -0
  456. package/src/core/color/oklab/gamut_clip_project_to_lcusp.d.ts.map +1 -0
  457. package/src/core/color/oklab/gamut_clip_project_to_lcusp.js +46 -0
  458. package/src/core/color/oklab/linear_srgb_to_okhsl.d.ts +19 -0
  459. package/src/core/color/oklab/linear_srgb_to_okhsl.d.ts.map +1 -0
  460. package/src/core/color/oklab/linear_srgb_to_okhsl.js +93 -0
  461. package/src/core/color/oklab/linear_srgb_to_okhsv.d.ts +12 -4
  462. package/src/core/color/oklab/linear_srgb_to_okhsv.d.ts.map +1 -1
  463. package/src/core/color/oklab/linear_srgb_to_okhsv.js +108 -84
  464. package/src/core/color/oklab/linear_srgb_to_oklab.d.ts +13 -4
  465. package/src/core/color/oklab/linear_srgb_to_oklab.d.ts.map +1 -1
  466. package/src/core/color/oklab/linear_srgb_to_oklab.js +28 -19
  467. package/src/core/color/oklab/okhsl_chroma_bounds.d.ts +51 -0
  468. package/src/core/color/oklab/okhsl_chroma_bounds.d.ts.map +1 -0
  469. package/src/core/color/oklab/okhsl_chroma_bounds.js +128 -0
  470. package/src/core/color/oklab/okhsl_to_linear_srgb.d.ts +19 -0
  471. package/src/core/color/oklab/okhsl_to_linear_srgb.d.ts.map +1 -0
  472. package/src/core/color/oklab/okhsl_to_linear_srgb.js +85 -0
  473. package/src/core/color/oklab/oklab_to_oklch.d.ts +24 -0
  474. package/src/core/color/oklab/oklab_to_oklch.d.ts.map +1 -0
  475. package/src/core/color/oklab/oklab_to_oklch.js +35 -0
  476. package/src/core/color/oklab/oklch_to_oklab.d.ts +18 -0
  477. package/src/core/color/oklab/oklch_to_oklab.d.ts.map +1 -0
  478. package/src/core/color/oklab/oklch_to_oklab.js +26 -0
  479. package/src/core/color/oklab/toe.d.ts +12 -0
  480. package/src/core/color/oklab/toe.d.ts.map +1 -1
  481. package/src/core/color/oklab/toe.js +34 -22
  482. package/src/core/color/operations/color_add.d.ts +21 -0
  483. package/src/core/color/operations/color_add.d.ts.map +1 -0
  484. package/src/core/color/operations/color_add.js +23 -0
  485. package/src/core/color/operations/color_add_scaled.d.ts +20 -0
  486. package/src/core/color/operations/color_add_scaled.d.ts.map +1 -0
  487. package/src/core/color/operations/color_add_scaled.js +30 -0
  488. package/src/core/color/operations/color_clamp.d.ts +22 -0
  489. package/src/core/color/operations/color_clamp.d.ts.map +1 -0
  490. package/src/core/color/operations/color_clamp.js +25 -0
  491. package/src/core/color/operations/color_darken.d.ts +2 -1
  492. package/src/core/color/operations/color_darken.d.ts.map +1 -1
  493. package/src/core/color/operations/color_darken.js +25 -24
  494. package/src/core/color/operations/color_desaturate.d.ts +2 -1
  495. package/src/core/color/operations/color_desaturate.d.ts.map +1 -1
  496. package/src/core/color/operations/color_desaturate.js +25 -24
  497. package/src/core/color/operations/color_get_hsl.d.ts +18 -0
  498. package/src/core/color/operations/color_get_hsl.d.ts.map +1 -0
  499. package/src/core/color/operations/color_get_hsl.js +60 -0
  500. package/src/core/color/operations/color_is_in_gamut.d.ts +20 -0
  501. package/src/core/color/operations/color_is_in_gamut.d.ts.map +1 -0
  502. package/src/core/color/operations/color_is_in_gamut.js +30 -0
  503. package/src/core/color/operations/color_lerp.d.ts +12 -3
  504. package/src/core/color/operations/color_lerp.d.ts.map +1 -1
  505. package/src/core/color/operations/color_lerp.js +55 -46
  506. package/src/core/color/operations/color_lighten.d.ts +9 -5
  507. package/src/core/color/operations/color_lighten.d.ts.map +1 -1
  508. package/src/core/color/operations/color_lighten.js +29 -24
  509. package/src/core/color/operations/color_mix_okhsv_channel.d.ts +24 -0
  510. package/src/core/color/operations/color_mix_okhsv_channel.d.ts.map +1 -0
  511. package/src/core/color/operations/color_mix_okhsv_channel.js +48 -0
  512. package/src/core/color/operations/color_multiply_rgb.d.ts +21 -0
  513. package/src/core/color/operations/color_multiply_rgb.d.ts.map +1 -0
  514. package/src/core/color/operations/color_multiply_rgb.js +26 -0
  515. package/src/core/color/operations/color_saturate.d.ts +9 -5
  516. package/src/core/color/operations/color_saturate.d.ts.map +1 -1
  517. package/src/core/color/operations/color_saturate.js +29 -24
  518. package/src/core/color/operations/color_scale_okhsv_channel.d.ts +1 -1
  519. package/src/core/color/operations/color_scale_okhsv_channel.d.ts.map +1 -1
  520. package/src/core/color/operations/color_scale_okhsv_channel.js +58 -45
  521. package/src/core/color/operations/color_srgb_apply.d.ts +28 -0
  522. package/src/core/color/operations/color_srgb_apply.d.ts.map +1 -0
  523. package/src/core/color/operations/color_srgb_apply.js +40 -0
  524. package/src/core/color/operations/color_sub.d.ts +16 -0
  525. package/src/core/color/operations/color_sub.d.ts.map +1 -0
  526. package/src/core/color/operations/color_sub.js +18 -0
  527. package/src/core/color/parse_color.d.ts +10 -1
  528. package/src/core/color/parse_color.d.ts.map +1 -1
  529. package/src/core/color/parse_color.js +100 -84
  530. package/src/core/color/parse_color_normalized.d.ts +24 -0
  531. package/src/core/color/parse_color_normalized.d.ts.map +1 -0
  532. package/src/core/color/parse_color_normalized.js +38 -0
  533. package/src/core/color/rgb2uint24.d.ts +1 -8
  534. package/src/core/color/rgb2uint24.d.ts.map +1 -1
  535. package/src/core/color/rgb2uint24.js +7 -20
  536. package/src/core/color/rgb2uint32.d.ts +1 -9
  537. package/src/core/color/rgb2uint32.d.ts.map +1 -1
  538. package/src/core/color/rgb2uint32.js +7 -18
  539. package/src/core/color/rgb_to_luminance.d.ts +14 -5
  540. package/src/core/color/rgb_to_luminance.d.ts.map +1 -1
  541. package/src/core/color/rgb_to_luminance.js +24 -13
  542. package/src/core/color/rgb_to_uint24.d.ts +9 -0
  543. package/src/core/color/rgb_to_uint24.d.ts.map +1 -0
  544. package/src/core/color/rgb_to_uint24.js +20 -0
  545. package/src/core/color/rgb_to_uint32.d.ts +10 -0
  546. package/src/core/color/rgb_to_uint32.d.ts.map +1 -0
  547. package/src/core/color/rgb_to_uint32.js +21 -0
  548. package/src/core/color/sRGB/linear_to_sRGB.d.ts +7 -0
  549. package/src/core/color/sRGB/linear_to_sRGB.d.ts.map +1 -1
  550. package/src/core/color/sRGB/linear_to_sRGB.js +39 -32
  551. package/src/core/color/xyz/hpe_to_xyz.d.ts +24 -0
  552. package/src/core/color/xyz/hpe_to_xyz.d.ts.map +1 -0
  553. package/src/core/color/xyz/hpe_to_xyz.js +39 -0
  554. package/src/core/color/xyz/rgb_to_xyz.d.ts +17 -2
  555. package/src/core/color/xyz/rgb_to_xyz.d.ts.map +1 -1
  556. package/src/core/color/xyz/rgb_to_xyz.js +44 -18
  557. package/src/core/color/xyz/xyz_cmf_tabulated.d.ts.map +1 -1
  558. package/src/core/color/xyz/xyz_cmf_tabulated.js +217 -211
  559. package/src/core/color/xyz/xyz_cmf_wyman.d.ts +4 -0
  560. package/src/core/color/xyz/xyz_cmf_wyman.d.ts.map +1 -1
  561. package/src/core/color/xyz/xyz_cmf_wyman.js +74 -65
  562. package/src/core/color/xyz/xyz_to_hpe.d.ts +18 -0
  563. package/src/core/color/xyz/xyz_to_hpe.d.ts.map +1 -0
  564. package/src/core/color/xyz/xyz_to_hpe.js +33 -0
  565. package/src/core/color/xyz/xyz_to_rgb.d.ts +17 -2
  566. package/src/core/color/xyz/xyz_to_rgb.d.ts.map +1 -1
  567. package/src/core/color/xyz/xyz_to_rgb.js +39 -16
  568. package/src/core/color/ycxcz/xyz_to_ycxcz.d.ts +7 -2
  569. package/src/core/color/ycxcz/xyz_to_ycxcz.d.ts.map +1 -1
  570. package/src/core/color/ycxcz/xyz_to_ycxcz.js +33 -28
  571. package/src/core/events/signal/Signal.js +820 -820
  572. package/src/core/math/clamp_index.d.ts +18 -0
  573. package/src/core/math/clamp_index.d.ts.map +1 -0
  574. package/src/core/math/clamp_index.js +23 -0
  575. package/src/engine/asset/loaders/image/IMAGE_CODEC_REVIEW_2026_08_28.md +803 -0
  576. package/src/engine/asset/loaders/image/jpeg/JpegFrame.d.ts +5 -3
  577. package/src/engine/asset/loaders/image/jpeg/JpegFrame.d.ts.map +1 -1
  578. package/src/engine/asset/loaders/image/jpeg/JpegFrame.js +5 -3
  579. package/src/engine/asset/loaders/image/jpeg/JpegFrameComponent.d.ts +2 -1
  580. package/src/engine/asset/loaders/image/jpeg/JpegFrameComponent.d.ts.map +1 -1
  581. package/src/engine/asset/loaders/image/jpeg/JpegFrameComponent.js +2 -1
  582. package/src/engine/asset/loaders/image/jpeg/JpegImage.d.ts +17 -0
  583. package/src/engine/asset/loaders/image/jpeg/JpegImage.d.ts.map +1 -1
  584. package/src/engine/asset/loaders/image/jpeg/JpegImage.js +197 -157
  585. package/src/engine/asset/loaders/image/jpeg/idct8x8_float.d.ts +0 -1
  586. package/src/engine/asset/loaders/image/jpeg/idct8x8_float.d.ts.map +1 -1
  587. package/src/engine/asset/loaders/image/jpeg/idct8x8_float.js +0 -1
  588. package/src/engine/asset/loaders/image/jpeg/jpeg_component_row.d.ts +28 -0
  589. package/src/engine/asset/loaders/image/jpeg/jpeg_component_row.d.ts.map +1 -0
  590. package/src/engine/asset/loaders/image/jpeg/jpeg_component_row.js +31 -0
  591. package/src/engine/asset/loaders/image/png/PNG.d.ts +3 -18
  592. package/src/engine/asset/loaders/image/png/PNG.d.ts.map +1 -1
  593. package/src/engine/asset/loaders/image/png/PNG.js +3 -139
  594. package/src/engine/asset/loaders/image/png/PNGReader.d.ts +16 -16
  595. package/src/engine/asset/loaders/image/png/PNGReader.d.ts.map +1 -1
  596. package/src/engine/asset/loaders/image/png/PNGReader.js +143 -160
  597. package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_iTXt.js +3 -3
  598. package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_zTXt.js +3 -3
  599. package/src/engine/asset/loaders/image/png/crc32.d.ts +1 -15
  600. package/src/engine/asset/loaders/image/png/crc32.d.ts.map +1 -1
  601. package/src/engine/asset/loaders/image/png/crc32.js +5 -89
  602. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterNone.d.ts +12 -10
  603. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterNone.d.ts.map +1 -1
  604. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterNone.js +20 -45
  605. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterSub.d.ts +2 -1
  606. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterSub.d.ts.map +1 -1
  607. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterSub.js +2 -0
  608. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterUp.d.ts +2 -1
  609. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterUp.d.ts.map +1 -1
  610. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterUp.js +2 -0
  611. package/src/engine/asset/loaders/image/png/filter/png_unfilter.d.ts +22 -0
  612. package/src/engine/asset/loaders/image/png/filter/png_unfilter.d.ts.map +1 -0
  613. package/src/engine/asset/loaders/image/png/filter/png_unfilter.js +68 -0
  614. package/src/engine/asset/loaders/image/png/png_inflate.d.ts +20 -0
  615. package/src/engine/asset/loaders/image/png/png_inflate.d.ts.map +1 -0
  616. package/src/engine/asset/loaders/image/png/png_inflate.js +85 -0
  617. package/src/engine/asset/loaders/image/png/png_unpack_samples.d.ts +22 -0
  618. package/src/engine/asset/loaders/image/png/png_unpack_samples.d.ts.map +1 -0
  619. package/src/engine/asset/loaders/image/png/png_unpack_samples.js +38 -0
  620. package/src/engine/graphics/ecs/sprite/SpriteSystemPE.d.ts.map +1 -1
  621. package/src/engine/graphics/ecs/sprite/SpriteSystemPE.js +135 -132
  622. package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.d.ts +16 -3
  623. package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.d.ts.map +1 -1
  624. package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +1157 -1149
  625. package/src/engine/graphics/render/frame_graph/FrameGraph.js +900 -900
  626. package/src/engine/physics/ecs/PhysicsSystem.d.ts +72 -81
  627. package/src/engine/physics/ecs/PhysicsSystem.d.ts.map +1 -1
  628. package/src/engine/physics/ecs/PhysicsSystem.js +86 -77
  629. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  630. package/src/shade/device/IMMEDIATE_DATA_PLAN_2026_08_28.md +451 -0
  631. package/src/shade/device/timing/GPU_PROFILER_PROPOSAL_2026_08_28.md +625 -0
  632. package/src/shade/renderer/postprocess/nss/NSS.d.ts +1 -1
  633. package/src/shade/renderer/rasterize/native/oit/shader_oit_blend.d.ts.map +1 -1
  634. package/src/shade/renderer/rasterize/native/oit/shader_oit_blend.js +5 -4
  635. package/src/shade/renderer/scene/serialization/decode_image_source_hdr.d.ts +14 -3
  636. package/src/shade/renderer/scene/serialization/decode_image_source_hdr.d.ts.map +1 -1
  637. package/src/shade/renderer/scene/serialization/decode_image_source_hdr.js +50 -51
  638. package/src/shade/renderer/scene/serialization/deserialize_scene.d.ts.map +1 -1
  639. package/src/shade/renderer/scene/serialization/deserialize_scene.js +531 -521
  640. package/src/shade/renderer/scene/serialization/write_image_source.d.ts.map +1 -1
  641. package/src/shade/renderer/scene/serialization/write_image_source.js +6 -4
  642. package/src/shade/renderer/shader/chunk/color/chunk_rgb_to_luminance.d.ts.map +1 -1
  643. package/src/shade/renderer/shader/chunk/color/chunk_rgb_to_luminance.js +34 -32
  644. package/src/shade/renderer/shader/chunk/color/iCtCp/chunk_eotf_st2084.d.ts +31 -0
  645. package/src/shade/renderer/shader/chunk/color/iCtCp/chunk_eotf_st2084.d.ts.map +1 -1
  646. package/src/shade/renderer/shader/chunk/color/iCtCp/chunk_eotf_st2084.js +62 -31
  647. package/src/shade/renderer/shader/chunk/color/iCtCp/chunk_inverse_eotf_st2084.d.ts +10 -0
  648. package/src/shade/renderer/shader/chunk/color/iCtCp/chunk_inverse_eotf_st2084.d.ts.map +1 -1
  649. package/src/shade/renderer/shader/chunk/color/iCtCp/chunk_inverse_eotf_st2084.js +32 -22
  650. package/src/shade/renderer/shader/chunk/color/sRGB/chunk_sRGBTransferOETF.d.ts.map +1 -1
  651. package/src/shade/renderer/shader/chunk/color/sRGB/chunk_sRGBTransferOETF.js +22 -21
  652. package/src/shade/renderer/shader/chunk/color/tonemap/gt7/chunk_tonemap_gt7.d.ts +6 -0
  653. package/src/shade/renderer/shader/chunk/color/tonemap/gt7/chunk_tonemap_gt7.d.ts.map +1 -1
  654. package/src/shade/renderer/shader/chunk/color/tonemap/gt7/chunk_tonemap_gt7.js +110 -104
  655. package/src/shade/renderer/shader/chunk/color/xyz/chunk_rgb_to_xyz.d.ts.map +1 -1
  656. package/src/shade/renderer/shader/chunk/color/xyz/chunk_rgb_to_xyz.js +23 -21
  657. package/src/shade/renderer/shader/chunk/math/chunk_magnitude_floor.d.ts +9 -0
  658. package/src/shade/renderer/shader/chunk/math/chunk_magnitude_floor.d.ts.map +1 -0
  659. package/src/shade/renderer/shader/chunk/math/chunk_magnitude_floor.js +16 -0
  660. package/src/shade/renderer/shader/chunk/math/complex/chunk_complex_magnitude_floor.d.ts +10 -0
  661. package/src/shade/renderer/shader/chunk/math/complex/chunk_complex_magnitude_floor.d.ts.map +1 -0
  662. package/src/shade/renderer/shader/chunk/math/complex/chunk_complex_magnitude_floor.js +17 -0
  663. package/src/shade/renderer/shader/chunk/math/complex/chunk_complex_solve_cubic_blinn.d.ts.map +1 -1
  664. package/src/shade/renderer/shader/chunk/math/complex/chunk_complex_solve_cubic_blinn.js +7 -1
  665. package/src/shade/renderer/shader/chunk/math/complex/chunk_complex_square_root.d.ts.map +1 -1
  666. package/src/shade/renderer/shader/chunk/math/complex/chunk_complex_square_root.js +9 -3
  667. package/src/shade/renderer/shader/chunk/math/polynomial/chunk_solve_cubic.d.ts.map +1 -1
  668. package/src/shade/renderer/shader/chunk/math/polynomial/chunk_solve_cubic.js +13 -7
  669. package/src/shade/renderer/shader/chunk/math/polynomial/chunk_solve_cubic_blinn_smallest.d.ts.map +1 -1
  670. package/src/shade/renderer/shader/chunk/math/polynomial/chunk_solve_cubic_blinn_smallest.js +13 -4
  671. package/src/shade/renderer/shader/chunk/math/polynomial/chunk_solve_quadratic.d.ts.map +1 -1
  672. package/src/shade/renderer/shader/chunk/math/polynomial/chunk_solve_quadratic.js +20 -13
  673. package/src/shade/renderer/shader/chunk/math/polynomial/chunk_solve_quartic_neumark.d.ts.map +1 -1
  674. package/src/shade/renderer/shader/chunk/math/polynomial/chunk_solve_quartic_neumark.js +8 -4
  675. package/src/shade/renderer/shader/chunk/mboit/NOTES.md +35 -1
  676. package/src/shade/renderer/shader/chunk/mboit/moments/geometric/chunk_compute_transmittance_from_2_trigonometric_moments.d.ts.map +1 -1
  677. package/src/shade/renderer/shader/chunk/mboit/moments/geometric/chunk_compute_transmittance_from_2_trigonometric_moments.js +18 -5
  678. package/src/shade/renderer/shader/chunk/mboit/moments/geometric/chunk_compute_transmittance_from_3_trigonometric_moments.d.ts.map +1 -1
  679. package/src/shade/renderer/shader/chunk/mboit/moments/geometric/chunk_compute_transmittance_from_3_trigonometric_moments.js +21 -8
  680. package/src/shade/renderer/shader/chunk/mboit/moments/geometric/chunk_compute_transmittance_from_4_trigonometric_moments.d.ts.map +1 -1
  681. package/src/shade/renderer/shader/chunk/mboit/moments/geometric/chunk_compute_transmittance_from_4_trigonometric_moments.js +25 -12
  682. package/src/shade/renderer/shader/chunk/mboit/moments/geometric/chunk_generate_trigonometric_moments_4.d.ts +6 -2
  683. package/src/shade/renderer/shader/chunk/mboit/moments/geometric/chunk_generate_trigonometric_moments_4.d.ts.map +1 -1
  684. package/src/shade/renderer/shader/chunk/mboit/moments/geometric/chunk_generate_trigonometric_moments_4.js +42 -35
  685. package/src/shade/renderer/shader/chunk/mboit/moments/power/chunk_compute_transmittance_from_4_power_moments.d.ts.map +1 -1
  686. package/src/shade/renderer/shader/chunk/mboit/moments/power/chunk_compute_transmittance_from_4_power_moments.js +18 -5
  687. package/src/shade/renderer/shader/chunk/mboit/moments/power/chunk_compute_transmittance_from_6_power_moments.d.ts.map +1 -1
  688. package/src/shade/renderer/shader/chunk/mboit/moments/power/chunk_compute_transmittance_from_6_power_moments.js +24 -9
  689. package/src/shade/renderer/shader/chunk/mboit/moments/power/chunk_compute_transmittance_from_8_power_moments.d.ts.map +1 -1
  690. package/src/shade/renderer/shader/chunk/mboit/moments/power/chunk_compute_transmittance_from_8_power_moments.js +29 -13
  691. package/src/shade/renderer/shader/chunk/mboit/moments/power/chunk_generate_power_moments_4.d.ts +12 -0
  692. package/src/shade/renderer/shader/chunk/mboit/moments/power/chunk_generate_power_moments_4.d.ts.map +1 -1
  693. package/src/shade/renderer/shader/chunk/mboit/moments/power/chunk_generate_power_moments_4.js +38 -48
  694. package/src/view/elements/ColorPickerView.js +296 -296
  695. package/src/avif/codec/dec/Readme.md +0 -14
  696. package/src/avif/codec/dec/avif_dec.cpp +0 -234
  697. package/src/avif/codec/dec/avif_dec.d.ts +0 -3
  698. package/src/avif/codec/dec/avif_dec.d.ts.map +0 -1
  699. package/src/avif/codec/dec/avif_dec.js +0 -16
  700. package/src/avif/codec/dec/avif_dec.wasm +0 -0
  701. package/src/avif/codec/enc/README.md +0 -37
  702. package/src/avif/codec/enc/avif_enc.cpp +0 -216
  703. package/src/avif/codec/enc/avif_enc.d.ts +0 -3
  704. package/src/avif/codec/enc/avif_enc.d.ts.map +0 -1
  705. package/src/avif/codec/enc/avif_enc.js +0 -6144
  706. package/src/avif/codec/enc/avif_enc.wasm +0 -0
  707. package/src/avif/codec/enc/avif_enc_mt.d.ts +0 -3
  708. package/src/avif/codec/enc/avif_enc_mt.d.ts.map +0 -1
  709. package/src/avif/codec/enc/avif_enc_mt.js +0 -6811
  710. package/src/avif/codec/enc/avif_enc_mt.wasm +0 -0
  711. package/src/avif/codec/enc/avif_enc_mt.worker.d.mts +0 -2
  712. package/src/avif/codec/enc/avif_enc_mt.worker.d.mts.map +0 -1
  713. package/src/avif/codec/enc/avif_enc_mt.worker.d.ts +0 -11
  714. package/src/avif/codec/enc/avif_enc_mt.worker.d.ts.map +0 -1
  715. package/src/avif/codec/enc/avif_enc_mt.worker.js +0 -171
  716. package/src/avif/codec/enc/avif_enc_mt.worker.mjs +0 -1
  717. package/src/avif/decode.d.ts +0 -3
  718. package/src/avif/decode.d.ts.map +0 -1
  719. package/src/avif/decode.js +0 -42
  720. package/src/avif/encode.d.ts +0 -3
  721. package/src/avif/encode.d.ts.map +0 -1
  722. package/src/avif/encode.js +0 -75
  723. package/src/avif/meta.d.ts +0 -24
  724. package/src/avif/meta.d.ts.map +0 -1
  725. package/src/avif/meta.js +0 -23
  726. package/src/avif/tsconfig.tsbuildinfo +0 -1
  727. package/src/avif/utils.d.ts +0 -17
  728. package/src/avif/utils.d.ts.map +0 -1
  729. package/src/avif/utils.js +0 -31
  730. package/src/engine/asset/loaders/image/jpeg/idct8x8_fixed.d.ts +0 -23
  731. package/src/engine/asset/loaders/image/jpeg/idct8x8_fixed.d.ts.map +0 -1
  732. package/src/engine/asset/loaders/image/jpeg/idct8x8_fixed.js +0 -214
  733. package/src/engine/asset/loaders/image/png/inflate.d.ts +0 -7
  734. package/src/engine/asset/loaders/image/png/inflate.d.ts.map +0 -1
  735. package/src/engine/asset/loaders/image/png/inflate.js +0 -20
@@ -1,866 +1,959 @@
1
- import { assert } from "../assert.js";
2
- import { float_to_uint8 } from "../binary/float_to_uint8.js";
3
- import { uint8_to_float } from "../binary/uint8_to_float.js";
4
- import Signal from "../events/signal/Signal.js";
5
- import { lerp } from "../math/lerp.js";
6
- import { max2 } from "../math/max2.js";
7
- import { min2 } from "../math/min2.js";
8
- import { min3 } from "../math/min3.js";
9
- import { rgb2hex } from "./hex/rgb2hex.js";
10
-
11
- import { hsv2rgb_float } from "./hsv/hsv2rgb_float.js";
12
- import { rgb2hsv } from "./hsv/rgb2hsv.js";
13
- import { parse_color } from "./parse_color.js";
14
- import { rgb2uint24 } from "./rgb2uint24.js";
15
- import { rgb2uint32 } from "./rgb2uint32.js";
16
- import { rgb_to_luminance } from "./rgb_to_luminance.js";
17
- import { linear_to_sRGB } from "./sRGB/linear_to_sRGB.js";
18
- import { sRGB_to_linear } from "./sRGB/sRGB_to_linear.js";
19
-
20
- /**
21
- * Representation color and transparency (RGBA).
22
- *
23
- * @example
24
- * const red = new Color(1,0,0);
25
- *
26
- * @extends {Array.<number>}
27
- * @class
28
- */
29
- export class Color {
30
- /**
31
- *
32
- * @param {number} [r=0] Red from 0 to 1 for SDR
33
- * @param {number} [g=0] Green from 0 to 1 for SDR
34
- * @param {number} [b=0] Blue from 0 to 1 for SDR
35
- * @param {number} [a=1] Alpha from 0 to 1 (transparency)
36
- */
37
- constructor(r = 0, g = 0, b = 0, a = 1) {
38
- assert.isNumber(r, 'r');
39
- assert.isNumber(g, 'g');
40
- assert.isNumber(b, 'b');
41
- assert.isNumber(a, 'a');
42
-
43
- /**
44
- * Red channel
45
- * Value from 0 to 1 for SDR
46
- * @type {number}
47
- */
48
- this.r = r;
49
- /**
50
- * Green channel
51
- * Value from 0 to 1 for SDR
52
- * @type {number}
53
- */
54
- this.g = g;
55
- /**
56
- * Blue channel
57
- * Value from 0 to 1 for SDR
58
- * @type {number}
59
- */
60
- this.b = b;
61
-
62
- /**
63
- * Alpha channel (transparency)
64
- * Value from 0 to 1
65
- * @type {number}
66
- */
67
- this.a = a;
68
-
69
- /**
70
- * @readonly
71
- * @type {Signal<number,number,number,number, number,number,number,number>}
72
- */
73
- this.onChanged = new Signal();
74
- }
75
-
76
- /**
77
- *
78
- * @returns {number}
79
- */
80
- get 0() {
81
- return this.r;
82
- }
83
-
84
- /**
85
- *
86
- * @param {number} v
87
- */
88
- set 0(v) {
89
- this.r = v;
90
- }
91
-
92
- /**
93
- *
94
- * @returns {number}
95
- */
96
- get 1() {
97
- return this.g;
98
- }
99
-
100
- /**
101
- *
102
- * @param {number} v
103
- */
104
- set 1(v) {
105
- this.g = v;
106
- }
107
-
108
- /**
109
- *
110
- * @returns {number}
111
- */
112
- get 2() {
113
- return this.b;
114
- }
115
-
116
- /**
117
- *
118
- * @param {number} v
119
- */
120
- set 2(v) {
121
- this.b = v;
122
- }
123
-
124
- /**
125
- *
126
- * @returns {number}
127
- */
128
- get 3() {
129
- return this.a;
130
- }
131
-
132
- /**
133
- *
134
- * @param {number} v
135
- */
136
- set 3(v) {
137
- this.a = v;
138
- }
139
-
140
- // XYZW accessors
141
-
142
- /**
143
- *
144
- * @returns {number}
145
- */
146
- get x() {
147
- return this.r;
148
- }
149
-
150
- /**
151
- *
152
- * @param {number} v
153
- */
154
- set x(v) {
155
- this.r = v;
156
- }
157
-
158
- /**
159
- *
160
- * @returns {number}
161
- */
162
- get y() {
163
- return this.g;
164
- }
165
-
166
- /**
167
- *
168
- * @param {number} v
169
- */
170
- set y(v) {
171
- this.g = v;
172
- }
173
-
174
- /**
175
- *
176
- * @returns {number}
177
- */
178
- get z() {
179
- return this.b;
180
- }
181
-
182
- /**
183
- *
184
- * @param {number} v
185
- */
186
- set z(v) {
187
- this.b = v;
188
- }
189
-
190
- /**
191
- *
192
- * @returns {number}
193
- */
194
- get w() {
195
- return this.a;
196
- }
197
-
198
- /**
199
- *
200
- * @param {number} v
201
- */
202
- set w(v) {
203
- this.a = v;
204
- }
205
-
206
- /**
207
- * Pretending to be an array
208
- * @return {number}
209
- */
210
- get length() {
211
- return 4;
212
- }
213
-
214
- /**
215
- *
216
- * @param {number} r
217
- * @param {number} g
218
- * @param {number} b
219
- */
220
- setRGB(r, g, b) {
221
-
222
- this.set(r, g, b, this.a);
223
- }
224
-
225
- /**
226
- *
227
- * @param {number} r in range of 0..255
228
- * @param {number} g in range of 0..255
229
- * @param {number} b in range of 0..255
230
- */
231
- setRGBUint8(r, g, b) {
232
- this.setRGB(
233
- uint8_to_float(r),
234
- uint8_to_float(g),
235
- uint8_to_float(b),
236
- )
237
- }
238
-
239
- /**
240
- * set alpha
241
- * @param {number} a
242
- */
243
- setA(a) {
244
- this.set(this.r, this.g, this.b, a);
245
- }
246
-
247
- /**
248
- *
249
- * @param {number} r
250
- * @param {number} g
251
- * @param {number} b
252
- * @param {number} a
253
- * @returns {this}
254
- */
255
- set(r, g, b, a = 1.0) {
256
- assert.isNumber(r, 'r');
257
- assert.isNumber(g, 'g');
258
- assert.isNumber(b, 'b');
259
- assert.isNumber(a, 'a');
260
-
261
- assert.notNaN(r, 'r');
262
- assert.notNaN(g, 'g');
263
- assert.notNaN(b, 'b');
264
- assert.notNaN(a, 'a');
265
-
266
- assert.isFinite(r, 'r');
267
- assert.isFinite(g, 'g');
268
- assert.isFinite(b, 'b');
269
- assert.isFinite(a, 'a');
270
-
271
- // remember old values
272
- const _r = this.r;
273
- const _g = this.g;
274
- const _b = this.b;
275
- const _a = this.a;
276
-
277
- if (
278
- _r === r
279
- && _g === g
280
- && _b === b
281
- && _a === a
282
- ) {
283
- // no change
284
- return this;
285
- }
286
-
287
- // set new values
288
- this.r = r;
289
- this.g = g;
290
- this.b = b;
291
- this.a = a;
292
-
293
- this.onChanged.send8(r, g, b, a, _r, _g, _b, _a);
294
-
295
- return this;
296
- }
297
-
298
- /**
299
- * Hue Saturation Lightness
300
- * @param {number} h 0..1 (hue rotation compressed to normal 0 to 1 range where 1 represents 360deg)
301
- * @param {number} s 0..1
302
- * @param {number} l 0..1
303
- */
304
- setHSL(h, s, l) {
305
- // pull hue into 0..1 range
306
- let _h = h % 1;
307
-
308
- if (_h < 0) {
309
- // move into positive range
310
- _h = _h + Math.ceil(Math.abs(_h));
311
- }
312
-
313
- const k_r = (_h * 12) % 12;
314
- const k_g = (8 + _h * 12) % 12;
315
- const k_b = (4 + _h * 12) % 12;
316
-
317
- const a = s * min2(l, 1 - l);
318
-
319
- const r = l - a * max2(-1, min3(k_r - 3, 9 - k_r, 1));
320
- const g = l - a * max2(-1, min3(k_g - 3, 9 - k_g, 1));
321
- const b = l - a * max2(-1, min3(k_b - 3, 9 - k_b, 1));
322
-
323
- this.setRGB(r, g, b);
324
- }
325
-
326
- /**
327
- * Hue Chroma Luma
328
- * @param {number} h Hue
329
- * @param {number} c Chroma
330
- * @param {number} l Luma
331
- */
332
- setHCL(h, c, l) {
333
- // pull hue into 0..1 range
334
- let _h = h % 1;
335
-
336
- if (_h < 0) {
337
- // move into positive range
338
- _h = _h + Math.ceil(Math.abs(_h));
339
- }
340
-
341
- const h_face = _h * 6;
342
-
343
- const x = c * (1 - Math.abs(h_face % 2 - 1));
344
-
345
- let r, g, b;
346
-
347
- // map to RGB
348
- switch (Math.floor(h_face)) {
349
- case 0:
350
- r = c;
351
- g = x;
352
- b = 0;
353
- break;
354
- case 1:
355
- r = x;
356
- g = c;
357
- b = 0;
358
- break;
359
- case 2:
360
- r = 0;
361
- g = c;
362
- b = x;
363
- break;
364
- case 3:
365
- r = 0;
366
- g = x;
367
- b = c;
368
- break;
369
- case 4:
370
- r = x;
371
- g = 0;
372
- b = c;
373
- break;
374
- case 5:
375
- r = c;
376
- g = 0;
377
- b = x;
378
- }
379
-
380
- const m = l - (0.3 * r + 0.59 * g + 0.11 * b);
381
-
382
- this.setRGB(r + m, g + m, b + m);
383
- }
384
-
385
- /**
386
- * NOTE: I'm not sure if the implementation is correct, based on wikipedia article
387
- * Hue Saturation Intensity
388
- * @param {number} h 0..1 (hue rotation compressed to normal 0 to 1 range where 1 represents 360deg)
389
- * @param {number} s 0..1
390
- * @param {number} i 0..1
391
- * @see https://en.wikipedia.org/wiki/HSL_and_HSV
392
- */
393
- setHSI(h, s, i) {
394
- // pull hue into 0..1 range
395
- let _h = h % 1;
396
-
397
- if (_h < 0) {
398
- // move into positive range
399
- _h = _h + Math.ceil(Math.abs(_h));
400
- }
401
-
402
- const h_face = _h * 6;
403
-
404
- const z = 1 - Math.abs(h_face % 2 - 1);
405
-
406
- const c = (3 * i * s) / (1 + z);
407
-
408
- const x = c * z;
409
-
410
- let r, g, b;
411
- // map to RGB
412
- switch (Math.floor(h_face)) {
413
- case 0:
414
- r = c;
415
- g = x;
416
- b = 0;
417
- break;
418
- case 1:
419
- r = x;
420
- g = c;
421
- b = 0;
422
- break;
423
- case 2:
424
- r = 0;
425
- g = c;
426
- b = x;
427
- break;
428
- case 3:
429
- r = 0;
430
- g = x;
431
- b = c;
432
- break;
433
- case 4:
434
- r = x;
435
- g = 0;
436
- b = c;
437
- break;
438
- case 5:
439
- r = c;
440
- g = 0;
441
- b = x;
442
- }
443
-
444
- const m = i * (1 - s);
445
-
446
- this.setRGB(r + m, g + m, b + m);
447
- }
448
-
449
- /**
450
- * Hue Saturation Value
451
- * @param {number} h 0..1
452
- * @param {number} s 0..1
453
- * @param {number} v 0..1
454
- */
455
- setHSV(h, s, v) {
456
- const { r, g, b } = hsv2rgb_float(h, s, v);
457
-
458
- this.setRGB(r, g, b);
459
- }
460
-
461
- /**
462
- *
463
- * @return {number}
464
- */
465
- computeLuminance() {
466
- return rgb_to_luminance(this.r, this.g, this.b);
467
- }
468
-
469
- getHSV() {
470
- return rgb2hsv(
471
- this.r,
472
- this.g,
473
- this.b
474
- );
475
- }
476
-
477
- /**
478
- * Encodes RGB to uint24
479
- * @returns {number}
480
- */
481
- toUint() {
482
- return rgb2uint24(this.r, this.g, this.b);
483
- }
484
-
485
- /**
486
- * Encodes RGBA to uint32
487
- * @returns {number}
488
- */
489
- toUint32() {
490
- return rgb2uint32(this.r, this.g, this.b, this.a);
491
- }
492
-
493
- /**
494
- *
495
- * @param {number} value
496
- */
497
- fromUint(value) {
498
- assert.isNonNegativeInteger(value, 'value');
499
-
500
- const r = value >> 16;
501
- const g = (value >> 8) & 0xFF;
502
- const b = (value) & 0xFF;
503
-
504
- this.setRGBUint8(r, g, b);
505
- }
506
-
507
- /**
508
- * Returns color in CSS hex color format
509
- * @example #FF0000
510
- * @returns {string}
511
- */
512
- toHex() {
513
- return '#' + rgb2hex(
514
- float_to_uint8(this.r),
515
- float_to_uint8(this.g),
516
- float_to_uint8(this.b)
517
- );
518
- }
519
-
520
- /**
521
- *
522
- * @returns {string}
523
- */
524
- toCssRGBAString() {
525
- return `rgba(${float_to_uint8(this.r)},${float_to_uint8(this.g)},${float_to_uint8(this.b)},${this.a})`;
526
- }
527
-
528
- /**
529
- *
530
- * @param {Color} other
531
- */
532
- equals(other) {
533
- return this.r === other.r
534
- && this.g === other.g
535
- && this.b === other.b
536
- && this.a === other.a;
537
- }
538
-
539
- /**
540
- *
541
- * @param {Color} other
542
- */
543
- copy(other) {
544
- this.set(other.r, other.g, other.b, other.a);
545
- }
546
-
547
- /**
548
- *
549
- * @returns {Color}
550
- */
551
- clone() {
552
- const result = new Color();
553
-
554
- result.copy(this);
555
-
556
- return result;
557
- }
558
-
559
- /**
560
- *
561
- * @returns {number}
562
- */
563
- hash() {
564
- return this.toUint();
565
- }
566
-
567
- fromJSON({ r, g, b, a = 1 }) {
568
- this.set(r, g, b, a);
569
- }
570
-
571
- toJSON() {
572
- return {
573
- r: this.r,
574
- g: this.g,
575
- b: this.b,
576
- a: this.a
577
- };
578
- }
579
-
580
- toString() {
581
- return `Color{r:${this.r},g:${this.g},b:${this.b},a:${this.a}}`
582
- }
583
-
584
- * [Symbol.iterator]() {
585
-
586
- yield this.r;
587
- yield this.g;
588
- yield this.b;
589
- yield this.a;
590
-
591
- }
592
-
593
- /**
594
- *
595
- * @param {number[]} [destination] where to write the output, if not provided a new array will be created
596
- * @param {number} [destination_offset]
597
- * @returns {number[]} [g,g,b,a], same object as input destination (if provided)
598
- */
599
- toArray(destination = [], destination_offset = 0) {
600
- destination[destination_offset] = this.r;
601
- destination[destination_offset + 1] = this.g;
602
- destination[destination_offset + 2] = this.b;
603
- destination[destination_offset + 3] = this.a;
604
-
605
- return destination;
606
- }
607
-
608
- /**
609
- * Can be either RGB or RGBA, in case of 3 element array, A(alpha) channel will be se to 1
610
- * @param {number[]|Float32Array} source
611
- * @param {number} [offset]
612
- * @returns {Color}
613
- */
614
- fromArray(source, offset = 0) {
615
- const r = source[offset + 0];
616
- const g = source[offset + 1];
617
- const b = source[offset + 2];
618
- const a = source[offset + 3] ?? 1;
619
-
620
- return this.set(r, g, b, a);
621
- }
622
-
623
- /**
624
- *
625
- * @param {number[]|Float32Array} source
626
- * @param {number} [offset]
627
- * @returns {Color}
628
- */
629
- static fromArray(source, offset) {
630
- const r = new Color();
631
-
632
- r.fromArray(source, offset);
633
-
634
- return r;
635
- }
636
-
637
-
638
- /**
639
- * @deprecated please use your own {@link BinaryClassSerializationAdapter}
640
- * @param {BinaryBuffer} buffer
641
- */
642
- toBinaryBuffer(buffer) {
643
- buffer.writeFloat32(this.r);
644
- buffer.writeFloat32(this.g);
645
- buffer.writeFloat32(this.b);
646
- buffer.writeFloat32(this.a);
647
- }
648
-
649
- /**
650
- * @deprecated please use your own {@link BinaryClassSerializationAdapter}
651
- * @param {BinaryBuffer} buffer
652
- */
653
- fromBinaryBuffer(buffer) {
654
- const r = buffer.readFloat32();
655
- const g = buffer.readFloat32();
656
- const b = buffer.readFloat32();
657
- const a = buffer.readFloat32();
658
-
659
- this.set(r, g, b, a);
660
- }
661
-
662
- /**
663
- * @param {string|number} str CSS-style string
664
- * @returns {void}
665
- */
666
- parse(str) {
667
- const c = parse_color(str);
668
-
669
- if (typeof c[3] === "number") {
670
- this.a = c[3];
671
- } else {
672
- this.a = 1;
673
- }
674
-
675
- this.setRGB(c[0] / 255, c[1] / 255, c[2] / 255);
676
- }
677
-
678
- /**
679
- *
680
- * @param {Color} a
681
- * @param {Color} b
682
- * @param {number} f
683
- * @returns {this}
684
- */
685
- lerpColors(a, b, f) {
686
- assert.defined(a, 'a');
687
- assert.defined(b, 'b');
688
-
689
- const _r = lerp(a.r, b.r, f);
690
- const _g = lerp(a.g, b.g, f);
691
- const _b = lerp(a.b, b.b, f);
692
- const _a = lerp(a.a, b.a, f);
693
-
694
- return this.set(_r, _g, _b, _a);
695
- }
696
-
697
- /**
698
- * Multiply every component by a scalar value
699
- * @param {number} x
700
- * @returns {this}
701
- */
702
- multiplyScalar(x) {
703
- assert.isNumber(x, 'x');
704
- assert.notNaN(x, 'x');
705
-
706
- const r = this.r * x;
707
- const g = this.g * x;
708
- const b = this.b * x;
709
- const a = this.a * x;
710
-
711
- return this.set(r, g, b, a);
712
- }
713
-
714
- /**
715
- * Component-wise vector multiplication
716
- * @param {Color} other
717
- * @returns {this}
718
- */
719
- multiply(other) {
720
- assert.defined(other, 'other');
721
- assert.isObject(other, 'other');
722
- assert.equal(other.isColor, true, 'other.isColor !== true');
723
-
724
- const r = this.r * other.r;
725
- const g = this.g * other.g;
726
- const b = this.b * other.b;
727
- const a = this.a * other.a;
728
-
729
- this.set(r, g, b, a);
730
-
731
- return this;
732
- }
733
-
734
- /**
735
- *
736
- * @param {number} r
737
- * @param {number} g
738
- * @param {number} b
739
- * @returns {Color}
740
- */
741
- static fromRGB(r, g, b) {
742
- return new Color(r, g, b);
743
- }
744
-
745
- /**
746
- *
747
- * @param {number} h
748
- * @param {number} s
749
- * @param {number} v
750
- * @return {Color}
751
- */
752
- static fromHSV(h, s, v) {
753
- const color = new Color();
754
-
755
- color.setHSV(h, s, v);
756
-
757
- return color;
758
- }
759
-
760
-
761
- /**
762
- * Create a color for numeric or string representation. Supports most CSS color representations.
763
- * @example
764
- * Color.parse("#FF00FF");
765
- * Color.parse(0xFF00FF);
766
- * Color.parse("rgb(255, 0, 255)");
767
- * Color.parse("rgba(255, 0, 255, 0.5)");
768
- * Color.parse("hsv(0.5, 1, 0.3)");
769
- *
770
- * @param {string|number} value
771
- * @return {Color}
772
- * @throws Error if format could not be parsed
773
- */
774
- static parse(value) {
775
- const r = new Color();
776
-
777
- r.parse(value);
778
-
779
- return r;
780
- }
781
-
782
- /**
783
- *
784
- * @param {Color} input
785
- * @param {Color} [output]
786
- * @returns {Color}
787
- */
788
- static from_linear_to_sRGB(input, output = new Color()) {
789
-
790
- linear_to_sRGB(output, 0, input, 0);
791
-
792
- return output;
793
- }
794
-
795
- /**
796
- *
797
- * @param {Color} input
798
- * @param {Color} [output]
799
- * @returns {Color}
800
- */
801
- static from_sRGB_to_linear(input, output = new Color()) {
802
- sRGB_to_linear(output, 0, input, 0);
803
-
804
- return output;
805
- }
806
- }
807
-
808
- /**
809
- * @readonly
810
- * @type {boolean}
811
- */
812
- Color.prototype.isColor = true;
813
-
814
- /**
815
- * @readonly
816
- * @type {Readonly<Color>}
817
- */
818
- Color.red = Object.freeze(new Color(1, 0, 0));
819
-
820
- /**
821
- * @readonly
822
- * @type {Readonly<Color>}
823
- */
824
- Color.green = Object.freeze(new Color(0, 1, 0));
825
-
826
- /**
827
- * @readonly
828
- * @type {Readonly<Color>}
829
- */
830
- Color.blue = Object.freeze(new Color(0, 0, 1));
831
-
832
- /**
833
- * @readonly
834
- * @type {Readonly<Color>}
835
- */
836
- Color.yellow = Object.freeze(new Color(1, 1, 0));
837
-
838
- /**
839
- * @readonly
840
- * @type {Readonly<Color>}
841
- */
842
- Color.cyan = Object.freeze(new Color(0, 1, 1));
843
-
844
- /**
845
- * @readonly
846
- * @type {Readonly<Color>}
847
- */
848
- Color.magenta = Object.freeze(new Color(1, 0, 1));
849
-
850
- /**
851
- * @readonly
852
- * @type {Readonly<Color>}
853
- */
854
- Color.white = Object.freeze(new Color(1, 1, 1));
855
-
856
- /**
857
- * @readonly
858
- * @type {Readonly<Color>}
859
- */
860
- Color.black = Object.freeze(new Color(0, 0, 0));
861
-
862
- /**
863
- * @readonly
864
- * @type {Readonly<Color>}
865
- */
866
- Color.transparent = Object.freeze(new Color(0, 0, 0, 0));
1
+ import { assert } from "../assert.js";
2
+ import { float_to_uint8 } from "../binary/float_to_uint8.js";
3
+ import { uint8_to_float } from "../binary/uint8_to_float.js";
4
+ import Signal from "../events/signal/Signal.js";
5
+ import { lerp } from "../math/lerp.js";
6
+ import { max2 } from "../math/max2.js";
7
+ import { min2 } from "../math/min2.js";
8
+ import { euclidean_modulo } from "../math/euclidean_modulo.js";
9
+ import { min3 } from "../math/min3.js";
10
+ import { rgb_to_hex } from "./hex/rgb_to_hex.js";
11
+
12
+ import { hsv_to_rgb } from "./hsv/hsv_to_rgb.js";
13
+ import { hue_to_rgb_sextant } from "./hsv/hue_to_rgb_sextant.js";
14
+ import { rgb_to_hsv } from "./hsv/rgb_to_hsv.js";
15
+ import { parse_color_normalized } from "./parse_color_normalized.js";
16
+ import { int_to_rgb } from "./int_to_rgb.js";
17
+ import { rgb_to_uint24 } from "./rgb_to_uint24.js";
18
+ import { rgb_to_uint32 } from "./rgb_to_uint32.js";
19
+ import { rgb_to_luminance } from "./rgb_to_luminance.js";
20
+ import { linear_to_sRGB } from "./sRGB/linear_to_sRGB.js";
21
+ import { sRGB_to_linear } from "./sRGB/sRGB_to_linear.js";
22
+
23
+ /**
24
+ * Scratch triple for the sRGB transfer statics.
25
+ *
26
+ * The transfer functions write three channels positionally; writing them straight into a `Color` would go
27
+ * through the numeric index setters and bypass `set()`, so the result is staged here first.
28
+ *
29
+ * @type {number[]}
30
+ */
31
+ const transfer_scratch = [0, 0, 0];
32
+
33
+ /**
34
+ * Scratch quad for {@link Color#parse}.
35
+ * @type {number[]}
36
+ */
37
+ const parse_scratch = [0, 0, 0, 0];
38
+
39
+ /**
40
+ * Scratch triple for the cylindrical setters, which build a colour before offsetting it.
41
+ * @type {number[]}
42
+ */
43
+ const sextant_scratch = [0, 0, 0];
44
+
45
+ /**
46
+ * Representation color and transparency (RGBA).
47
+ *
48
+ * ## Colour space
49
+ *
50
+ * `Color` is **space-agnostic**. It is four floats and a change signal; it holds whatever the caller put in
51
+ * it and carries no record of which transfer function or primaries that was. There is deliberately no space
52
+ * tag, enum, or brand — this is a low-level container used on per-particle and per-vertex paths, and the
53
+ * contract lives in the *functions* that operate on a `Color` rather than in the object.
54
+ *
55
+ * That contract is worth knowing, because the two halves of the package disagree by default:
56
+ *
57
+ * - {@link Color#parse}, {@link Color#toHex} and {@link Color#toCssRGBAString} speak **encoded** sRGB, since
58
+ * that is what CSS and hex literals are.
59
+ * - Everything in `operations/` (`color_lighten`, `color_darken`, `color_lerp`, …) and
60
+ * {@link Color#computeLuminance} expect **linear** values.
61
+ *
62
+ * So `color_lighten(Color.parse('#808080'))` is wrong, quietly. Convert with
63
+ * {@link Color.from_sRGB_to_linear} first, or use the `color_srgb_*` wrappers in `operations/`, which do it
64
+ * for you.
65
+ *
66
+ * ## Range
67
+ *
68
+ * Values are 0 to 1 for SDR, but nothing enforces that: {@link Color#set} accepts any finite number so that
69
+ * HDR content and out-of-gamut intermediates work. The cost of that tolerance is that a channel which has
70
+ * gone wrong is usually still a perfectly finite number, so no assert will catch it for you.
71
+ *
72
+ * ## Notifications
73
+ *
74
+ * {@link Color#set} and everything routed through it fire `onChanged`. The numeric index setters do not —
75
+ * see the note on `set 0`.
76
+ *
77
+ * @example
78
+ * const red = new Color(1,0,0);
79
+ *
80
+ * @class
81
+ */
82
+ export class Color {
83
+ /**
84
+ *
85
+ * @param {number} [r=0] Red from 0 to 1 for SDR
86
+ * @param {number} [g=0] Green from 0 to 1 for SDR
87
+ * @param {number} [b=0] Blue from 0 to 1 for SDR
88
+ * @param {number} [a=1] Alpha from 0 to 1 (transparency)
89
+ */
90
+ constructor(r = 0, g = 0, b = 0, a = 1) {
91
+ assert.isNumber(r, 'r');
92
+ assert.isNumber(g, 'g');
93
+ assert.isNumber(b, 'b');
94
+ assert.isNumber(a, 'a');
95
+
96
+ /**
97
+ * Red channel
98
+ * Value from 0 to 1 for SDR
99
+ * @type {number}
100
+ */
101
+ this.r = r;
102
+ /**
103
+ * Green channel
104
+ * Value from 0 to 1 for SDR
105
+ * @type {number}
106
+ */
107
+ this.g = g;
108
+ /**
109
+ * Blue channel
110
+ * Value from 0 to 1 for SDR
111
+ * @type {number}
112
+ */
113
+ this.b = b;
114
+
115
+ /**
116
+ * Alpha channel (transparency)
117
+ * Value from 0 to 1
118
+ * @type {number}
119
+ */
120
+ this.a = a;
121
+
122
+ // `onChanged` is deliberately NOT allocated here; see the getter.
123
+ }
124
+
125
+ /**
126
+ * Lazily allocated backing for {@link Color#onChanged}.
127
+ *
128
+ * A private field rather than a property, for two reasons. It stays out of `Object.keys`, `JSON.stringify`
129
+ * and the spread operator, so a `Color` still looks like four numbers to anything enumerating it. And
130
+ * private fields are not affected by `Object.freeze`, so the frozen constants (`Color.red` and friends) can
131
+ * still allocate one on first access instead of throwing.
132
+ *
133
+ * @type {Signal<number,number,number,number, number,number,number,number>|null}
134
+ */
135
+ #onChanged = null;
136
+
137
+ /**
138
+ * Fires whenever {@link Color#set} changes any channel, with the new four values followed by the old four.
139
+ *
140
+ * Allocated on first access rather than in the constructor. Every `Color` used to pay for a `Signal`
141
+ * whether or not anything subscribed — measured at 4x the construction cost — and `Color` is a low-level
142
+ * type used on per-particle and per-vertex paths where most instances never have a listener.
143
+ *
144
+ * This is a getter, but it behaves as the plain property it replaced: reading it always yields the same
145
+ * `Signal` for a given `Color`.
146
+ *
147
+ * @readonly
148
+ * @returns {Signal<number,number,number,number, number,number,number,number>}
149
+ */
150
+ get onChanged() {
151
+ let signal = this.#onChanged;
152
+
153
+ if (signal === null) {
154
+ signal = this.#onChanged = new Signal();
155
+ }
156
+
157
+ return signal;
158
+ }
159
+
160
+ /**
161
+ *
162
+ * @returns {number}
163
+ */
164
+ get 0() {
165
+ return this.r;
166
+ }
167
+
168
+ /**
169
+ * NOTE: the numeric index setters write the field directly, so they bypass {@link Color#set} — no
170
+ * equality check and, more importantly, no `onChanged` notification. Writing a `Color` positionally
171
+ * (by handing it to a function that takes an `(output, output_offset)` pair, for instance) is
172
+ * therefore an *unobserved* mutation. Prefer `set()` whenever the target may have listeners.
173
+ *
174
+ * @param {number} v
175
+ */
176
+ set 0(v) {
177
+ this.r = v;
178
+ }
179
+
180
+ /**
181
+ *
182
+ * @returns {number}
183
+ */
184
+ get 1() {
185
+ return this.g;
186
+ }
187
+
188
+ /**
189
+ *
190
+ * @param {number} v
191
+ */
192
+ set 1(v) {
193
+ this.g = v;
194
+ }
195
+
196
+ /**
197
+ *
198
+ * @returns {number}
199
+ */
200
+ get 2() {
201
+ return this.b;
202
+ }
203
+
204
+ /**
205
+ *
206
+ * @param {number} v
207
+ */
208
+ set 2(v) {
209
+ this.b = v;
210
+ }
211
+
212
+ /**
213
+ *
214
+ * @returns {number}
215
+ */
216
+ get 3() {
217
+ return this.a;
218
+ }
219
+
220
+ /**
221
+ *
222
+ * @param {number} v
223
+ */
224
+ set 3(v) {
225
+ this.a = v;
226
+ }
227
+
228
+ // XYZW accessors
229
+
230
+ /**
231
+ *
232
+ * @returns {number}
233
+ */
234
+ get x() {
235
+ return this.r;
236
+ }
237
+
238
+ /**
239
+ *
240
+ * @param {number} v
241
+ */
242
+ set x(v) {
243
+ this.r = v;
244
+ }
245
+
246
+ /**
247
+ *
248
+ * @returns {number}
249
+ */
250
+ get y() {
251
+ return this.g;
252
+ }
253
+
254
+ /**
255
+ *
256
+ * @param {number} v
257
+ */
258
+ set y(v) {
259
+ this.g = v;
260
+ }
261
+
262
+ /**
263
+ *
264
+ * @returns {number}
265
+ */
266
+ get z() {
267
+ return this.b;
268
+ }
269
+
270
+ /**
271
+ *
272
+ * @param {number} v
273
+ */
274
+ set z(v) {
275
+ this.b = v;
276
+ }
277
+
278
+ /**
279
+ *
280
+ * @returns {number}
281
+ */
282
+ get w() {
283
+ return this.a;
284
+ }
285
+
286
+ /**
287
+ *
288
+ * @param {number} v
289
+ */
290
+ set w(v) {
291
+ this.a = v;
292
+ }
293
+
294
+ /**
295
+ * Pretending to be an array
296
+ * @return {number}
297
+ */
298
+ get length() {
299
+ return 4;
300
+ }
301
+
302
+ /**
303
+ *
304
+ * @param {number} r
305
+ * @param {number} g
306
+ * @param {number} b
307
+ */
308
+ setRGB(r, g, b) {
309
+
310
+ this.set(r, g, b, this.a);
311
+ }
312
+
313
+ /**
314
+ *
315
+ * @param {number} r in range of 0..255
316
+ * @param {number} g in range of 0..255
317
+ * @param {number} b in range of 0..255
318
+ */
319
+ setRGBUint8(r, g, b) {
320
+ this.setRGB(
321
+ uint8_to_float(r),
322
+ uint8_to_float(g),
323
+ uint8_to_float(b),
324
+ )
325
+ }
326
+
327
+ /**
328
+ * set alpha
329
+ * @param {number} a
330
+ */
331
+ setA(a) {
332
+ this.set(this.r, this.g, this.b, a);
333
+ }
334
+
335
+ /**
336
+ *
337
+ * @param {number} r
338
+ * @param {number} g
339
+ * @param {number} b
340
+ * @param {number} a
341
+ * @returns {this}
342
+ */
343
+ set(r, g, b, a = 1.0) {
344
+ assert.isNumber(r, 'r');
345
+ assert.isNumber(g, 'g');
346
+ assert.isNumber(b, 'b');
347
+ assert.isNumber(a, 'a');
348
+
349
+ assert.notNaN(r, 'r');
350
+ assert.notNaN(g, 'g');
351
+ assert.notNaN(b, 'b');
352
+ assert.notNaN(a, 'a');
353
+
354
+ assert.isFinite(r, 'r');
355
+ assert.isFinite(g, 'g');
356
+ assert.isFinite(b, 'b');
357
+ assert.isFinite(a, 'a');
358
+
359
+ // remember old values
360
+ const _r = this.r;
361
+ const _g = this.g;
362
+ const _b = this.b;
363
+ const _a = this.a;
364
+
365
+ if (
366
+ _r === r
367
+ && _g === g
368
+ && _b === b
369
+ && _a === a
370
+ ) {
371
+ // no change
372
+ return this;
373
+ }
374
+
375
+ // set new values
376
+ this.r = r;
377
+ this.g = g;
378
+ this.b = b;
379
+ this.a = a;
380
+
381
+ // read the field directly rather than through the getter, so that a `Color` nobody listens to never
382
+ // allocates a Signal just by being written to
383
+ const signal = this.#onChanged;
384
+
385
+ if (signal !== null) {
386
+ signal.send8(r, g, b, a, _r, _g, _b, _a);
387
+ }
388
+
389
+ return this;
390
+ }
391
+
392
+ /**
393
+ * Hue Saturation Lightness
394
+ * @param {number} h 0..1 (hue rotation compressed to normal 0 to 1 range where 1 represents 360deg)
395
+ * @param {number} s 0..1
396
+ * @param {number} l 0..1
397
+ */
398
+ setHSL(h, s, l) {
399
+ // pull hue into 0..1 range
400
+ const _h = euclidean_modulo(h, 1);
401
+
402
+ const k_r = (_h * 12) % 12;
403
+ const k_g = (8 + _h * 12) % 12;
404
+ const k_b = (4 + _h * 12) % 12;
405
+
406
+ const a = s * min2(l, 1 - l);
407
+
408
+ const r = l - a * max2(-1, min3(k_r - 3, 9 - k_r, 1));
409
+ const g = l - a * max2(-1, min3(k_g - 3, 9 - k_g, 1));
410
+ const b = l - a * max2(-1, min3(k_b - 3, 9 - k_b, 1));
411
+
412
+ this.setRGB(r, g, b);
413
+ }
414
+
415
+ /**
416
+ * Hue Chroma Luma.
417
+ *
418
+ * **Unbounded — the caller clamps.** The result is exact by construction: the written colour has chroma
419
+ * exactly `c` and Rec.601 luma exactly `l`. Not every `(h, c, l)` triple names a point inside the RGB
420
+ * cube, though, so a saturated one lands outside it — `setHCL(0, 1, 0.5)` gives `(1.2, 0.2, 0.2)`, which
421
+ * is the honest answer rather than an error. Clamping here would silently move the hue, and `Color` is a
422
+ * space-agnostic container that already tolerates out-of-range values for HDR, so gamut mapping belongs
423
+ * to the caller. Use `color_clamp` / `color_is_in_gamut` if you need the colour displayable.
424
+ *
425
+ * Contrast {@link Color#setHSL} and {@link Color#setHSV}, which cannot leave the cube for any input.
426
+ *
427
+ * @param {number} h Hue, 0..1 (1 represents 360deg); values outside the range wrap
428
+ * @param {number} c Chroma
429
+ * @param {number} l Luma (Rec.601 weighted)
430
+ */
431
+ setHCL(h, c, l) {
432
+ // pull hue into 0..1 range
433
+ const _h = euclidean_modulo(h, 1);
434
+
435
+ const h_face = _h * 6;
436
+
437
+ const x = c * (1 - Math.abs(h_face % 2 - 1));
438
+
439
+ hue_to_rgb_sextant(sextant_scratch, h_face, c, x);
440
+
441
+ const r = sextant_scratch[0];
442
+ const g = sextant_scratch[1];
443
+ const b = sextant_scratch[2];
444
+
445
+ const m = l - (0.3 * r + 0.59 * g + 0.11 * b);
446
+
447
+ this.setRGB(r + m, g + m, b + m);
448
+ }
449
+
450
+ /**
451
+ * Hue Saturation Intensity.
452
+ *
453
+ * Verified against the definition rather than against a table: the written colour satisfies both HSI
454
+ * invariants exactly — its intensity `(r + g + b) / 3` is `i`, and its saturation `1 - min(r,g,b) / i` is
455
+ * `s`. That settles the author's earlier note about not being sure the implementation was right; it is.
456
+ *
457
+ * **Unbounded — the caller clamps**, same as {@link Color#setHCL}. `setHSI(0, 1, 0.5)` gives
458
+ * `(1.5, 0, 0)`, and that is correct: intensity 0.5 at full saturation on a pure hue *requires* a red of
459
+ * 1.5, because the mean of the three channels has to come to 0.5. The triple is outside the RGB cube, so
460
+ * the colour is too.
461
+ *
462
+ * @param {number} h 0..1 (hue rotation compressed to normal 0 to 1 range where 1 represents 360deg); values outside the range wrap
463
+ * @param {number} s 0..1
464
+ * @param {number} i 0..1
465
+ * @see https://en.wikipedia.org/wiki/HSL_and_HSV
466
+ */
467
+ setHSI(h, s, i) {
468
+ // pull hue into 0..1 range
469
+ const _h = euclidean_modulo(h, 1);
470
+
471
+ const h_face = _h * 6;
472
+
473
+ const z = 1 - Math.abs(h_face % 2 - 1);
474
+
475
+ const c = (3 * i * s) / (1 + z);
476
+
477
+ const x = c * z;
478
+
479
+ hue_to_rgb_sextant(sextant_scratch, h_face, c, x);
480
+
481
+ const r = sextant_scratch[0];
482
+ const g = sextant_scratch[1];
483
+ const b = sextant_scratch[2];
484
+
485
+ const m = i * (1 - s);
486
+
487
+ this.setRGB(r + m, g + m, b + m);
488
+ }
489
+
490
+ /**
491
+ * Hue Saturation Value
492
+ * @param {number} h 0..1
493
+ * @param {number} s 0..1
494
+ * @param {number} v 0..1
495
+ */
496
+ setHSV(h, s, v) {
497
+ const { r, g, b } = hsv_to_rgb(h, s, v);
498
+
499
+ this.setRGB(r, g, b);
500
+ }
501
+
502
+ /**
503
+ *
504
+ * @return {number}
505
+ */
506
+ computeLuminance() {
507
+ return rgb_to_luminance(this.r, this.g, this.b);
508
+ }
509
+
510
+ getHSV() {
511
+ return rgb_to_hsv(
512
+ this.r,
513
+ this.g,
514
+ this.b
515
+ );
516
+ }
517
+
518
+ /**
519
+ * Encodes RGB to uint24
520
+ * @returns {number}
521
+ */
522
+ toUint() {
523
+ return rgb_to_uint24(this.r, this.g, this.b);
524
+ }
525
+
526
+ /**
527
+ * Encodes RGBA to uint32
528
+ * @returns {number}
529
+ */
530
+ toUint32() {
531
+ return rgb_to_uint32(this.r, this.g, this.b, this.a);
532
+ }
533
+
534
+ /**
535
+ * Decodes a 24-bit `0xRRGGBB` value. Alpha is left untouched.
536
+ *
537
+ * @param {number} value 24-bit `0xRRGGBB`
538
+ */
539
+ fromUint(value) {
540
+ assert.isNonNegativeInteger(value, 'value');
541
+
542
+ // unpacked by int_to_rgb rather than inline: this used to be one of three copies with three different
543
+ // masking behaviours, which is how a 32-bit input came to leak its high byte into red as a negative
544
+ // number and fail several frames away inside `uint8_to_float`
545
+ const { r, g, b } = int_to_rgb(value);
546
+
547
+ this.setRGBUint8(r, g, b);
548
+ }
549
+
550
+ /**
551
+ * Returns color in CSS hex color format.
552
+ *
553
+ * Produces **encoded** sRGB, because that is what a hex literal means. If this `Color` holds linear
554
+ * values, encode it with {@link Color.from_linear_to_sRGB} first or the result will read far too dark.
555
+ *
556
+ * Alpha is dropped — the three-channel `#RRGGBB` form is the only one written.
557
+ *
558
+ * @example #FF0000
559
+ * @returns {string}
560
+ */
561
+ toHex() {
562
+ return '#' + rgb_to_hex(
563
+ float_to_uint8(this.r),
564
+ float_to_uint8(this.g),
565
+ float_to_uint8(this.b)
566
+ );
567
+ }
568
+
569
+ /**
570
+ * Returns color in CSS `rgba()` format.
571
+ *
572
+ * Produces **encoded** sRGB, same as {@link Color#toHex}.
573
+ *
574
+ * @returns {string}
575
+ */
576
+ toCssRGBAString() {
577
+ return `rgba(${float_to_uint8(this.r)},${float_to_uint8(this.g)},${float_to_uint8(this.b)},${this.a})`;
578
+ }
579
+
580
+ /**
581
+ *
582
+ * @param {Color} other
583
+ */
584
+ equals(other) {
585
+ return this.r === other.r
586
+ && this.g === other.g
587
+ && this.b === other.b
588
+ && this.a === other.a;
589
+ }
590
+
591
+ /**
592
+ *
593
+ * @param {Color} other
594
+ */
595
+ copy(other) {
596
+ this.set(other.r, other.g, other.b, other.a);
597
+ }
598
+
599
+ /**
600
+ *
601
+ * @returns {Color}
602
+ */
603
+ clone() {
604
+ const result = new Color();
605
+
606
+ result.copy(this);
607
+
608
+ return result;
609
+ }
610
+
611
+ /**
612
+ * Hashes all four channels.
613
+ *
614
+ * Via {@link Color#toUint32} rather than {@link Color#toUint}, so that alpha participates — {@link
615
+ * Color#equals} compares four channels, so hashing three made colours differing only in alpha collide.
616
+ * The `equals => same hash` contract held either way; this just stops the collision.
617
+ *
618
+ * @returns {number}
619
+ */
620
+ hash() {
621
+ return this.toUint32();
622
+ }
623
+
624
+ fromJSON({ r, g, b, a = 1 }) {
625
+ this.set(r, g, b, a);
626
+ }
627
+
628
+ toJSON() {
629
+ return {
630
+ r: this.r,
631
+ g: this.g,
632
+ b: this.b,
633
+ a: this.a
634
+ };
635
+ }
636
+
637
+ toString() {
638
+ return `Color{r:${this.r},g:${this.g},b:${this.b},a:${this.a}}`
639
+ }
640
+
641
+ * [Symbol.iterator]() {
642
+
643
+ yield this.r;
644
+ yield this.g;
645
+ yield this.b;
646
+ yield this.a;
647
+
648
+ }
649
+
650
+ /**
651
+ *
652
+ * @param {number[]} [destination] where to write the output, if not provided a new array will be created
653
+ * @param {number} [destination_offset]
654
+ * @returns {number[]} [g,g,b,a], same object as input destination (if provided)
655
+ */
656
+ toArray(destination = [], destination_offset = 0) {
657
+ destination[destination_offset] = this.r;
658
+ destination[destination_offset + 1] = this.g;
659
+ destination[destination_offset + 2] = this.b;
660
+ destination[destination_offset + 3] = this.a;
661
+
662
+ return destination;
663
+ }
664
+
665
+ /**
666
+ * Can be either RGB or RGBA, in case of 3 element array, A(alpha) channel will be se to 1
667
+ * @param {number[]|Float32Array} source
668
+ * @param {number} [offset]
669
+ * @returns {Color}
670
+ */
671
+ fromArray(source, offset = 0) {
672
+ const r = source[offset + 0];
673
+ const g = source[offset + 1];
674
+ const b = source[offset + 2];
675
+ const a = source[offset + 3] ?? 1;
676
+
677
+ return this.set(r, g, b, a);
678
+ }
679
+
680
+ /**
681
+ *
682
+ * @param {number[]|Float32Array} source
683
+ * @param {number} [offset]
684
+ * @returns {Color}
685
+ */
686
+ static fromArray(source, offset) {
687
+ const r = new Color();
688
+
689
+ r.fromArray(source, offset);
690
+
691
+ return r;
692
+ }
693
+
694
+
695
+ /**
696
+ * @deprecated please use your own {@link BinaryClassSerializationAdapter}
697
+ * @param {BinaryBuffer} buffer
698
+ */
699
+ toBinaryBuffer(buffer) {
700
+ buffer.writeFloat32(this.r);
701
+ buffer.writeFloat32(this.g);
702
+ buffer.writeFloat32(this.b);
703
+ buffer.writeFloat32(this.a);
704
+ }
705
+
706
+ /**
707
+ * @deprecated please use your own {@link BinaryClassSerializationAdapter}
708
+ * @param {BinaryBuffer} buffer
709
+ */
710
+ fromBinaryBuffer(buffer) {
711
+ const r = buffer.readFloat32();
712
+ const g = buffer.readFloat32();
713
+ const b = buffer.readFloat32();
714
+ const a = buffer.readFloat32();
715
+
716
+ this.set(r, g, b, a);
717
+ }
718
+
719
+ /**
720
+ * Reads a CSS colour literal into this `Color`.
721
+ *
722
+ * The result holds **encoded** sRGB — CSS values are encoded by definition. Convert with
723
+ * {@link Color.from_sRGB_to_linear} before handing it to anything in `operations/`, or to
724
+ * {@link Color#computeLuminance}, all of which expect linear input.
725
+ *
726
+ * @param {string|number} str CSS-style string, or a 24-bit `0xRRGGBB` integer
727
+ * @returns {void}
728
+ * @throws Error if the value cannot be parsed
729
+ */
730
+ parse(str) {
731
+ // via parse_color_normalized rather than parse_color: the byte-to-float conversion is knowledge about
732
+ // parse_color's mixed return units, and it belongs on that side of the boundary rather than here
733
+ parse_color_normalized(parse_scratch, str);
734
+
735
+ this.set(parse_scratch[0], parse_scratch[1], parse_scratch[2], parse_scratch[3]);
736
+ }
737
+
738
+ /**
739
+ * Per-channel linear interpolation between two other colours, written into this one.
740
+ *
741
+ * Interpolates the raw channels, which is the right thing when a colour is being treated as a vector, and
742
+ * is space-agnostic in the sense that it does whatever linear algebra you asked for in whatever space the
743
+ * inputs happened to be in. It is *not* perceptual: `color_lerp` converts to OkHSV and takes the shortest
744
+ * hue arc instead, and the two give substantially different results at mid-`f`.
745
+ *
746
+ * @param {Color} a
747
+ * @param {Color} b
748
+ * @param {number} f
749
+ * @returns {this}
750
+ *
751
+ * @see color_lerp for the perceptual alternative
752
+ */
753
+ lerpColors(a, b, f) {
754
+ assert.defined(a, 'a');
755
+ assert.defined(b, 'b');
756
+
757
+ const _r = lerp(a.r, b.r, f);
758
+ const _g = lerp(a.g, b.g, f);
759
+ const _b = lerp(a.b, b.b, f);
760
+ const _a = lerp(a.a, b.a, f);
761
+
762
+ return this.set(_r, _g, _b, _a);
763
+ }
764
+
765
+ /**
766
+ * Multiply every component by a scalar value.
767
+ *
768
+ * **Alpha is scaled too** — this is a 4-vector multiply, not an exposure control. That is rarely what a
769
+ * caller reaching for "multiply a colour" wants, so it is called out here rather than left to be
770
+ * discovered: `multiplyScalar(0.5)` halves transparency along with brightness. Use `color_multiply_rgb`
771
+ * when the intent is exposure or tint.
772
+ *
773
+ * @param {number} x
774
+ * @returns {this}
775
+ */
776
+ multiplyScalar(x) {
777
+ assert.isNumber(x, 'x');
778
+ assert.notNaN(x, 'x');
779
+
780
+ const r = this.r * x;
781
+ const g = this.g * x;
782
+ const b = this.b * x;
783
+ const a = this.a * x;
784
+
785
+ return this.set(r, g, b, a);
786
+ }
787
+
788
+ /**
789
+ * Component-wise vector multiplication.
790
+ *
791
+ * **Alpha is multiplied too**, same as {@link Color#multiplyScalar} — see the note there.
792
+ *
793
+ * @param {Color} other
794
+ * @returns {this}
795
+ */
796
+ multiply(other) {
797
+ assert.defined(other, 'other');
798
+ assert.isObject(other, 'other');
799
+ assert.equal(other.isColor, true, 'other.isColor !== true');
800
+
801
+ const r = this.r * other.r;
802
+ const g = this.g * other.g;
803
+ const b = this.b * other.b;
804
+ const a = this.a * other.a;
805
+
806
+ this.set(r, g, b, a);
807
+
808
+ return this;
809
+ }
810
+
811
+ /**
812
+ *
813
+ * @param {number} r
814
+ * @param {number} g
815
+ * @param {number} b
816
+ * @returns {Color}
817
+ */
818
+ static fromRGB(r, g, b) {
819
+ return new Color(r, g, b);
820
+ }
821
+
822
+ /**
823
+ *
824
+ * @param {number} h
825
+ * @param {number} s
826
+ * @param {number} v
827
+ * @return {Color}
828
+ */
829
+ static fromHSV(h, s, v) {
830
+ const color = new Color();
831
+
832
+ color.setHSV(h, s, v);
833
+
834
+ return color;
835
+ }
836
+
837
+
838
+ /**
839
+ * Create a color for numeric or string representation. Supports most CSS color representations.
840
+ * @example
841
+ * Color.parse("#FF00FF");
842
+ * Color.parse(0xFF00FF);
843
+ * Color.parse("rgb(255, 0, 255)");
844
+ * Color.parse("rgba(255, 0, 255, 0.5)");
845
+ * Color.parse("hsv(0.5, 1, 0.3)");
846
+ *
847
+ * The result holds **encoded** sRGB; see {@link Color#parse}.
848
+ *
849
+ * @param {string|number} value
850
+ * @return {Color}
851
+ * @throws Error if format could not be parsed
852
+ */
853
+ static parse(value) {
854
+ const r = new Color();
855
+
856
+ r.parse(value);
857
+
858
+ return r;
859
+ }
860
+
861
+ /**
862
+ * Encode a linear colour to sRGB.
863
+ *
864
+ * Alpha is carried across unchanged; the transfer function applies to the three colour channels only.
865
+ *
866
+ * @param {Color} input **linear** sRGB
867
+ * @param {Color} [output] may be `input`
868
+ * @returns {Color} `output`, holding **encoded** sRGB
869
+ */
870
+ static from_linear_to_sRGB(input, output = new Color()) {
871
+
872
+ linear_to_sRGB(transfer_scratch, 0, input, 0);
873
+
874
+ // via set() rather than the positional setters, so that `onChanged` observers of an existing
875
+ // `output` are notified. see the note on the numeric index setters.
876
+ output.set(transfer_scratch[0], transfer_scratch[1], transfer_scratch[2], input.a);
877
+
878
+ return output;
879
+ }
880
+
881
+ /**
882
+ * Decode an sRGB colour to linear.
883
+ *
884
+ * Alpha is carried across unchanged; the transfer function applies to the three colour channels only.
885
+ *
886
+ * @param {Color} input **encoded** sRGB
887
+ * @param {Color} [output] may be `input`
888
+ * @returns {Color} `output`, holding **linear** sRGB
889
+ */
890
+ static from_sRGB_to_linear(input, output = new Color()) {
891
+
892
+ sRGB_to_linear(transfer_scratch, 0, input, 0);
893
+
894
+ // see the note in from_linear_to_sRGB on why this goes through set()
895
+ output.set(transfer_scratch[0], transfer_scratch[1], transfer_scratch[2], input.a);
896
+
897
+ return output;
898
+ }
899
+ }
900
+
901
+ /**
902
+ * @readonly
903
+ * @type {boolean}
904
+ */
905
+ Color.prototype.isColor = true;
906
+
907
+ /**
908
+ * @readonly
909
+ * @type {Readonly<Color>}
910
+ */
911
+ Color.red = Object.freeze(new Color(1, 0, 0));
912
+
913
+ /**
914
+ * @readonly
915
+ * @type {Readonly<Color>}
916
+ */
917
+ Color.green = Object.freeze(new Color(0, 1, 0));
918
+
919
+ /**
920
+ * @readonly
921
+ * @type {Readonly<Color>}
922
+ */
923
+ Color.blue = Object.freeze(new Color(0, 0, 1));
924
+
925
+ /**
926
+ * @readonly
927
+ * @type {Readonly<Color>}
928
+ */
929
+ Color.yellow = Object.freeze(new Color(1, 1, 0));
930
+
931
+ /**
932
+ * @readonly
933
+ * @type {Readonly<Color>}
934
+ */
935
+ Color.cyan = Object.freeze(new Color(0, 1, 1));
936
+
937
+ /**
938
+ * @readonly
939
+ * @type {Readonly<Color>}
940
+ */
941
+ Color.magenta = Object.freeze(new Color(1, 0, 1));
942
+
943
+ /**
944
+ * @readonly
945
+ * @type {Readonly<Color>}
946
+ */
947
+ Color.white = Object.freeze(new Color(1, 1, 1));
948
+
949
+ /**
950
+ * @readonly
951
+ * @type {Readonly<Color>}
952
+ */
953
+ Color.black = Object.freeze(new Color(0, 0, 0));
954
+
955
+ /**
956
+ * @readonly
957
+ * @type {Readonly<Color>}
958
+ */
959
+ Color.transparent = Object.freeze(new Color(0, 0, 0, 0));