@nice2dev/ui-graphics 1.3.15 → 1.3.17

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 (294) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/animation/AnimatedPerson.js +470 -143
  3. package/dist/cjs/animation/AnimationEditor.js +289 -101
  4. package/dist/cjs/animation/Audience.js +83 -61
  5. package/dist/cjs/animation/BodyRenderer.js +69 -28
  6. package/dist/cjs/animation/animationHelper.js +281 -288
  7. package/dist/cjs/animation/characterTypes.js +200 -203
  8. package/dist/cjs/animation/choreoDSL.js +205 -219
  9. package/dist/cjs/animation/choreography.js +4 -32
  10. package/dist/cjs/animation/karaokeIntegration.js +68 -77
  11. package/dist/cjs/animation/lottieExport.js +108 -114
  12. package/dist/cjs/animation/motionPath.js +225 -248
  13. package/dist/cjs/animation/physics.js +227 -254
  14. package/dist/cjs/animation/rig/RigPlayer.js +53 -56
  15. package/dist/cjs/animation/rig/RiggedBody.js +71 -26
  16. package/dist/cjs/animation/rig/choreoRigBridge.js +72 -77
  17. package/dist/cjs/animation/rig/ik.js +13 -18
  18. package/dist/cjs/animation/rig/poseOps.js +34 -41
  19. package/dist/cjs/animation/rig/presets.js +64 -72
  20. package/dist/cjs/animation/rig/rigMath.js +25 -32
  21. package/dist/cjs/animation/rig/rigTypes.js +59 -63
  22. package/dist/cjs/animation/shapes/arms.js +31 -13
  23. package/dist/cjs/animation/shapes/eyes.js +129 -47
  24. package/dist/cjs/animation/shapes/hair.js +72 -45
  25. package/dist/cjs/animation/shapes/heads.js +131 -57
  26. package/dist/cjs/animation/shapes/headwear.js +47 -38
  27. package/dist/cjs/animation/shapes/legs.js +31 -13
  28. package/dist/cjs/animation/shapes/mouths.js +120 -44
  29. package/dist/cjs/animation/shapes/noses.js +80 -25
  30. package/dist/cjs/animation/shapes/outfits.js +101 -39
  31. package/dist/cjs/animation/shapes/torsos.js +15 -11
  32. package/dist/cjs/animation/spineExport.js +103 -121
  33. package/dist/cjs/core/LocalUI.js +108 -43
  34. package/dist/cjs/core/NiceBrushEngine.js +758 -552
  35. package/dist/cjs/core/collaboration.js +249 -251
  36. package/dist/cjs/core/colorBlindness.js +100 -115
  37. package/dist/cjs/core/dragDrop.js +155 -158
  38. package/dist/cjs/core/editorAsk.js +51 -41
  39. package/dist/cjs/core/fixes.js +140 -171
  40. package/dist/cjs/core/gridGuides.js +166 -201
  41. package/dist/cjs/core/historyVisual.js +156 -135
  42. package/dist/cjs/core/i18n.js +13 -14
  43. package/dist/cjs/core/integrations.js +238 -249
  44. package/dist/cjs/core/minimap.js +149 -151
  45. package/dist/cjs/core/plugins.js +98 -113
  46. package/dist/cjs/core/rtl.js +71 -83
  47. package/dist/cjs/core/shortcuts.js +196 -225
  48. package/dist/cjs/core/theme.js +142 -149
  49. package/dist/cjs/core/yjsCollaboration.js +232 -293
  50. package/dist/cjs/design/design-tools.js +12 -22
  51. package/dist/cjs/font/NiceFontEditor.js +877 -316
  52. package/dist/cjs/font/fontFormatUtils.js +388 -448
  53. package/dist/cjs/game/GameAsset2dEditor.js +1201 -392
  54. package/dist/cjs/game/GameAsset2dEditor.module.css.js +146 -5
  55. package/dist/cjs/game/gameAssetTypes.js +7 -16
  56. package/dist/cjs/game/gameAssetUtils.js +390 -413
  57. package/dist/cjs/game/useGameAssetEditor.js +820 -763
  58. package/dist/cjs/index.js +81 -84
  59. package/dist/cjs/nice2dev-ui-graphics.css +1 -1
  60. package/dist/cjs/node_modules/lib0/array.js +8 -70
  61. package/dist/cjs/node_modules/lib0/binary.js +3 -20
  62. package/dist/cjs/node_modules/lib0/broadcastchannel.js +24 -86
  63. package/dist/cjs/node_modules/lib0/buffer.js +15 -82
  64. package/dist/cjs/node_modules/lib0/conditions.js +3 -16
  65. package/dist/cjs/node_modules/lib0/decoding.js +108 -287
  66. package/dist/cjs/node_modules/lib0/dom.js +14 -44
  67. package/dist/cjs/node_modules/lib0/encoding.js +68 -418
  68. package/dist/cjs/node_modules/lib0/environment.js +26 -92
  69. package/dist/cjs/node_modules/lib0/error.js +5 -29
  70. package/dist/cjs/node_modules/lib0/function.js +27 -66
  71. package/dist/cjs/node_modules/lib0/iterator.js +8 -33
  72. package/dist/cjs/node_modules/lib0/logging.common.js +12 -22
  73. package/dist/cjs/node_modules/lib0/logging.js +32 -71
  74. package/dist/cjs/node_modules/lib0/map.js +16 -86
  75. package/dist/cjs/node_modules/lib0/math.js +3 -32
  76. package/dist/cjs/node_modules/lib0/number.js +4 -15
  77. package/dist/cjs/node_modules/lib0/object.js +14 -88
  78. package/dist/cjs/node_modules/lib0/observable.js +38 -78
  79. package/dist/cjs/node_modules/lib0/pair.js +3 -20
  80. package/dist/cjs/node_modules/lib0/prng.js +8 -77
  81. package/dist/cjs/node_modules/lib0/promise.js +6 -30
  82. package/dist/cjs/node_modules/lib0/random.js +8 -23
  83. package/dist/cjs/node_modules/lib0/schema.js +313 -687
  84. package/dist/cjs/node_modules/lib0/set.js +3 -10
  85. package/dist/cjs/node_modules/lib0/storage.js +20 -55
  86. package/dist/cjs/node_modules/lib0/string.js +17 -72
  87. package/dist/cjs/node_modules/lib0/symbol.js +2 -12
  88. package/dist/cjs/node_modules/lib0/time.js +2 -15
  89. package/dist/cjs/node_modules/lib0/trait/equality.js +3 -28
  90. package/dist/cjs/node_modules/lib0/url.js +4 -18
  91. package/dist/cjs/node_modules/lib0/webcrypto.js +2 -5
  92. package/dist/cjs/node_modules/y-protocols/auth.js +5 -19
  93. package/dist/cjs/node_modules/y-protocols/awareness.js +53 -116
  94. package/dist/cjs/node_modules/y-protocols/sync.js +16 -103
  95. package/dist/cjs/node_modules/y-websocket/src/y-websocket.js +77 -219
  96. package/dist/cjs/node_modules/yjs/dist/yjs.js +2128 -4868
  97. package/dist/cjs/photo/FilterThumb.js +37 -25
  98. package/dist/cjs/photo/NiceAITools.js +679 -467
  99. package/dist/cjs/photo/PhotoEditor.js +34 -20
  100. package/dist/cjs/photo/PhotoEditor.module.css.js +296 -5
  101. package/dist/cjs/photo/PhotoEditorCanvas.js +250 -91
  102. package/dist/cjs/photo/PhotoEditorLeftPanel.js +1086 -224
  103. package/dist/cjs/photo/PhotoEditorToolbar.js +135 -19
  104. package/dist/cjs/photo/photoEditorActions.js +89 -72
  105. package/dist/cjs/photo/photoEditorTypes.js +29 -32
  106. package/dist/cjs/photo/photoFilters.js +959 -985
  107. package/dist/cjs/photo/photoOverlays.js +899 -945
  108. package/dist/cjs/photo/photoSelection.js +427 -499
  109. package/dist/cjs/photo/usePhotoEditor.js +739 -741
  110. package/dist/cjs/pixel/HSVPicker.js +191 -175
  111. package/dist/cjs/pixel/PixelEditor.js +159 -48
  112. package/dist/cjs/pixel/PixelEditor.module.css.js +209 -5
  113. package/dist/cjs/pixel/PixelEditorCanvas.js +29 -16
  114. package/dist/cjs/pixel/PixelEditorMenuBar.js +160 -162
  115. package/dist/cjs/pixel/PixelEditorRightPanel.js +377 -45
  116. package/dist/cjs/pixel/PixelEditorStatusBar.js +47 -20
  117. package/dist/cjs/pixel/PixelEditorTimeline.js +106 -23
  118. package/dist/cjs/pixel/PixelEditorToolbar.js +99 -21
  119. package/dist/cjs/pixel/SpriteGeneratorPanel.js +483 -303
  120. package/dist/cjs/pixel/animalGeneratorPresets.js +776 -601
  121. package/dist/cjs/pixel/asepriteFormat.js +511 -560
  122. package/dist/cjs/pixel/buildingGeneratorPresets.js +693 -520
  123. package/dist/cjs/pixel/characterGeneratorPresets.js +644 -544
  124. package/dist/cjs/pixel/pixel-pro.js +52 -63
  125. package/dist/cjs/pixel/pixelEditorExports.js +388 -428
  126. package/dist/cjs/pixel/pixelEditorTypes.js +91 -108
  127. package/dist/cjs/pixel/pixelEditorUtils.js +519 -561
  128. package/dist/cjs/pixel/spriteGeneratorCore.js +206 -257
  129. package/dist/cjs/pixel/usePixelEditor.js +1321 -1343
  130. package/dist/cjs/texture/Nice3DTexturePainter.js +707 -440
  131. package/dist/cjs/ui/NiceUIDesigner.js +954 -527
  132. package/dist/cjs/vector/NiceSvgToCode.js +586 -446
  133. package/dist/cjs/vector/VectorEditor.js +290 -117
  134. package/dist/cjs/vector/VectorEditor.module.css.js +86 -5
  135. package/dist/cjs/vector/VectorEditorMenuBar.js +333 -275
  136. package/dist/cjs/vector/VectorEditorRightPanel.js +1094 -371
  137. package/dist/cjs/vector/VectorEditorShapeRenderer.js +198 -60
  138. package/dist/cjs/vector/VectorEditorStatusBar.js +39 -13
  139. package/dist/cjs/vector/useVectorEditor.js +848 -889
  140. package/dist/cjs/vector/vectorAnimation.js +110 -137
  141. package/dist/cjs/vector/vectorBooleanOps.js +398 -485
  142. package/dist/cjs/vector/vectorEditorExport.js +201 -203
  143. package/dist/cjs/vector/vectorEditorImport.js +173 -189
  144. package/dist/cjs/vector/vectorEditorTypes.js +42 -49
  145. package/dist/cjs/vector/vectorGradients.js +151 -174
  146. package/dist/cjs/vector/vectorIconExport.js +52 -59
  147. package/dist/cjs/vector/vectorIconImport.js +169 -219
  148. package/dist/esm/animation/AnimatedPerson.js +470 -141
  149. package/dist/esm/animation/AnimationEditor.js +290 -100
  150. package/dist/esm/animation/Audience.js +83 -59
  151. package/dist/esm/animation/BodyRenderer.js +71 -25
  152. package/dist/esm/animation/animationHelper.js +284 -287
  153. package/dist/esm/animation/characterTypes.js +204 -202
  154. package/dist/esm/animation/choreoDSL.js +212 -218
  155. package/dist/esm/animation/choreography.js +8 -31
  156. package/dist/esm/animation/karaokeIntegration.js +74 -76
  157. package/dist/esm/animation/lottieExport.js +112 -113
  158. package/dist/esm/animation/motionPath.js +235 -247
  159. package/dist/esm/animation/physics.js +235 -253
  160. package/dist/esm/animation/rig/RigPlayer.js +53 -54
  161. package/dist/esm/animation/rig/RiggedBody.js +71 -24
  162. package/dist/esm/animation/rig/choreoRigBridge.js +74 -76
  163. package/dist/esm/animation/rig/ik.js +14 -17
  164. package/dist/esm/animation/rig/poseOps.js +37 -40
  165. package/dist/esm/animation/rig/presets.js +70 -71
  166. package/dist/esm/animation/rig/rigMath.js +28 -31
  167. package/dist/esm/animation/rig/rigTypes.js +62 -62
  168. package/dist/esm/animation/shapes/arms.js +32 -12
  169. package/dist/esm/animation/shapes/eyes.js +135 -46
  170. package/dist/esm/animation/shapes/hair.js +80 -44
  171. package/dist/esm/animation/shapes/heads.js +140 -56
  172. package/dist/esm/animation/shapes/headwear.js +54 -37
  173. package/dist/esm/animation/shapes/legs.js +32 -12
  174. package/dist/esm/animation/shapes/mouths.js +127 -43
  175. package/dist/esm/animation/shapes/noses.js +87 -24
  176. package/dist/esm/animation/shapes/outfits.js +106 -38
  177. package/dist/esm/animation/shapes/torsos.js +16 -10
  178. package/dist/esm/animation/spineExport.js +106 -120
  179. package/dist/esm/core/LocalUI.js +111 -42
  180. package/dist/esm/core/NiceBrushEngine.js +761 -551
  181. package/dist/esm/core/collaboration.js +255 -250
  182. package/dist/esm/core/colorBlindness.js +106 -114
  183. package/dist/esm/core/dragDrop.js +157 -157
  184. package/dist/esm/core/editorAsk.js +53 -40
  185. package/dist/esm/core/fixes.js +145 -170
  186. package/dist/esm/core/gridGuides.js +178 -200
  187. package/dist/esm/core/historyVisual.js +158 -134
  188. package/dist/esm/core/i18n.js +15 -13
  189. package/dist/esm/core/integrations.js +244 -248
  190. package/dist/esm/core/minimap.js +151 -150
  191. package/dist/esm/core/plugins.js +102 -112
  192. package/dist/esm/core/rtl.js +77 -82
  193. package/dist/esm/core/shortcuts.js +200 -224
  194. package/dist/esm/core/theme.js +150 -148
  195. package/dist/esm/core/yjsCollaboration.js +240 -292
  196. package/dist/esm/design/design-tools.js +13 -21
  197. package/dist/esm/font/NiceFontEditor.js +880 -315
  198. package/dist/esm/font/fontFormatUtils.js +394 -447
  199. package/dist/esm/game/GameAsset2dEditor.js +1202 -391
  200. package/dist/esm/game/GameAsset2dEditor.module.css.js +146 -3
  201. package/dist/esm/game/gameAssetTypes.js +8 -15
  202. package/dist/esm/game/gameAssetUtils.js +408 -412
  203. package/dist/esm/game/useGameAssetEditor.js +821 -762
  204. package/dist/esm/index.js +332 -69
  205. package/dist/esm/nice2dev-ui-graphics.css +1 -1
  206. package/dist/esm/node_modules/lib0/array.js +15 -69
  207. package/dist/esm/node_modules/lib0/binary.js +14 -19
  208. package/dist/esm/node_modules/lib0/broadcastchannel.js +27 -85
  209. package/dist/esm/node_modules/lib0/buffer.js +20 -80
  210. package/dist/esm/node_modules/lib0/conditions.js +4 -15
  211. package/dist/esm/node_modules/lib0/decoding.js +128 -286
  212. package/dist/esm/node_modules/lib0/dom.js +20 -43
  213. package/dist/esm/node_modules/lib0/encoding.js +90 -415
  214. package/dist/esm/node_modules/lib0/environment.js +33 -91
  215. package/dist/esm/node_modules/lib0/error.js +8 -28
  216. package/dist/esm/node_modules/lib0/function.js +31 -65
  217. package/dist/esm/node_modules/lib0/iterator.js +11 -32
  218. package/dist/esm/node_modules/lib0/logging.common.js +22 -21
  219. package/dist/esm/node_modules/lib0/logging.js +44 -70
  220. package/dist/esm/node_modules/lib0/map.js +21 -85
  221. package/dist/esm/node_modules/lib0/math.js +9 -31
  222. package/dist/esm/node_modules/lib0/number.js +7 -14
  223. package/dist/esm/node_modules/lib0/object.js +26 -87
  224. package/dist/esm/node_modules/lib0/observable.js +40 -77
  225. package/dist/esm/node_modules/lib0/pair.js +5 -19
  226. package/dist/esm/node_modules/lib0/prng.js +15 -76
  227. package/dist/esm/node_modules/lib0/promise.js +7 -29
  228. package/dist/esm/node_modules/lib0/random.js +10 -22
  229. package/dist/esm/node_modules/lib0/schema.js +367 -686
  230. package/dist/esm/node_modules/lib0/set.js +4 -9
  231. package/dist/esm/node_modules/lib0/storage.js +23 -54
  232. package/dist/esm/node_modules/lib0/string.js +26 -71
  233. package/dist/esm/node_modules/lib0/symbol.js +3 -11
  234. package/dist/esm/node_modules/lib0/time.js +3 -14
  235. package/dist/esm/node_modules/lib0/trait/equality.js +5 -27
  236. package/dist/esm/node_modules/lib0/url.js +5 -17
  237. package/dist/esm/node_modules/lib0/webcrypto.js +3 -4
  238. package/dist/esm/node_modules/y-protocols/auth.js +7 -18
  239. package/dist/esm/node_modules/y-protocols/awareness.js +58 -115
  240. package/dist/esm/node_modules/y-protocols/sync.js +26 -102
  241. package/dist/esm/node_modules/y-websocket/src/y-websocket.js +82 -218
  242. package/dist/esm/node_modules/yjs/dist/yjs.js +2263 -4899
  243. package/dist/esm/photo/FilterThumb.js +37 -23
  244. package/dist/esm/photo/NiceAITools.js +685 -466
  245. package/dist/esm/photo/PhotoEditor.js +34 -18
  246. package/dist/esm/photo/PhotoEditor.module.css.js +296 -3
  247. package/dist/esm/photo/PhotoEditorCanvas.js +250 -89
  248. package/dist/esm/photo/PhotoEditorLeftPanel.js +1086 -222
  249. package/dist/esm/photo/PhotoEditorToolbar.js +135 -17
  250. package/dist/esm/photo/photoEditorActions.js +93 -71
  251. package/dist/esm/photo/photoEditorTypes.js +32 -31
  252. package/dist/esm/photo/photoFilters.js +967 -984
  253. package/dist/esm/photo/photoOverlays.js +913 -944
  254. package/dist/esm/photo/photoSelection.js +438 -498
  255. package/dist/esm/photo/usePhotoEditor.js +740 -740
  256. package/dist/esm/pixel/HSVPicker.js +192 -174
  257. package/dist/esm/pixel/PixelEditor.js +160 -47
  258. package/dist/esm/pixel/PixelEditor.module.css.js +209 -3
  259. package/dist/esm/pixel/PixelEditorCanvas.js +29 -14
  260. package/dist/esm/pixel/PixelEditorMenuBar.js +160 -160
  261. package/dist/esm/pixel/PixelEditorRightPanel.js +377 -43
  262. package/dist/esm/pixel/PixelEditorStatusBar.js +47 -18
  263. package/dist/esm/pixel/PixelEditorTimeline.js +106 -21
  264. package/dist/esm/pixel/PixelEditorToolbar.js +99 -19
  265. package/dist/esm/pixel/SpriteGeneratorPanel.js +483 -301
  266. package/dist/esm/pixel/animalGeneratorPresets.js +782 -600
  267. package/dist/esm/pixel/asepriteFormat.js +517 -559
  268. package/dist/esm/pixel/buildingGeneratorPresets.js +699 -519
  269. package/dist/esm/pixel/characterGeneratorPresets.js +650 -543
  270. package/dist/esm/pixel/pixel-pro.js +53 -62
  271. package/dist/esm/pixel/pixelEditorExports.js +397 -427
  272. package/dist/esm/pixel/pixelEditorTypes.js +103 -107
  273. package/dist/esm/pixel/pixelEditorUtils.js +551 -560
  274. package/dist/esm/pixel/spriteGeneratorCore.js +223 -256
  275. package/dist/esm/pixel/usePixelEditor.js +1322 -1342
  276. package/dist/esm/texture/Nice3DTexturePainter.js +709 -439
  277. package/dist/esm/ui/NiceUIDesigner.js +957 -526
  278. package/dist/esm/vector/NiceSvgToCode.js +589 -445
  279. package/dist/esm/vector/VectorEditor.js +291 -116
  280. package/dist/esm/vector/VectorEditor.module.css.js +86 -3
  281. package/dist/esm/vector/VectorEditorMenuBar.js +333 -273
  282. package/dist/esm/vector/VectorEditorRightPanel.js +1094 -369
  283. package/dist/esm/vector/VectorEditorShapeRenderer.js +199 -59
  284. package/dist/esm/vector/VectorEditorStatusBar.js +39 -11
  285. package/dist/esm/vector/useVectorEditor.js +849 -888
  286. package/dist/esm/vector/vectorAnimation.js +115 -136
  287. package/dist/esm/vector/vectorBooleanOps.js +401 -484
  288. package/dist/esm/vector/vectorEditorExport.js +207 -202
  289. package/dist/esm/vector/vectorEditorImport.js +174 -188
  290. package/dist/esm/vector/vectorEditorTypes.js +50 -48
  291. package/dist/esm/vector/vectorGradients.js +158 -173
  292. package/dist/esm/vector/vectorIconExport.js +53 -58
  293. package/dist/esm/vector/vectorIconImport.js +171 -218
  294. package/package.json +9 -15
@@ -1,1116 +1,1090 @@
1
- 'use strict';
2
-
3
- /**
4
- * photoFilters.ts — Canvas-based photo filter engine.
5
- *
6
- * Pure functions that operate on ImageData pixel arrays.
7
- * Each filter takes ImageData + optional params and returns a new ImageData.
8
- * Composable via `applyFilterChain`.
9
- */
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
10
3
  const DEFAULT_ADJUSTMENTS = {
11
- brightness: 0,
12
- contrast: 0,
13
- saturation: 0,
14
- temperature: 0,
15
- tint: 0,
16
- exposure: 0,
17
- highlights: 0,
18
- shadows: 0,
19
- sharpness: 0,
20
- vignette: 0,
21
- grain: 0,
22
- blur: 0,
4
+ brightness: 0,
5
+ contrast: 0,
6
+ saturation: 0,
7
+ temperature: 0,
8
+ tint: 0,
9
+ exposure: 0,
10
+ highlights: 0,
11
+ shadows: 0,
12
+ sharpness: 0,
13
+ vignette: 0,
14
+ grain: 0,
15
+ blur: 0
23
16
  };
24
- // ── Pixel helpers ──
25
17
  function clamp(v) {
26
- return v < 0 ? 0 : v > 255 ? 255 : v | 0;
18
+ return v < 0 ? 0 : v > 255 ? 255 : v | 0;
27
19
  }
28
20
  function lerpColor(a, b, t) {
29
- return clamp(a + (b - a) * t);
21
+ return clamp(a + (b - a) * t);
30
22
  }
31
- /** Create a working copy of ImageData */
32
23
  function cloneImageData(src) {
33
- return new ImageData(new Uint8ClampedArray(src.data), src.width, src.height);
24
+ return new ImageData(new Uint8ClampedArray(src.data), src.width, src.height);
34
25
  }
35
- /** Mix original and filtered based on intensity */
36
26
  function blendIntensity(original, filtered, intensity) {
37
- if (intensity >= 1) {
38
- return filtered;
39
- }
40
- if (intensity <= 0) {
41
- return cloneImageData(original);
42
- }
43
- const out = cloneImageData(original);
44
- const od = out.data;
45
- const fd = filtered.data;
46
- for (let i = 0; i < od.length; i += 4) {
47
- od[i] = lerpColor(od[i], fd[i], intensity);
48
- od[i + 1] = lerpColor(od[i + 1], fd[i + 1], intensity);
49
- od[i + 2] = lerpColor(od[i + 2], fd[i + 2], intensity);
50
- }
51
- return out;
27
+ if (intensity >= 1) {
28
+ return filtered;
29
+ }
30
+ if (intensity <= 0) {
31
+ return cloneImageData(original);
32
+ }
33
+ const out = cloneImageData(original);
34
+ const od = out.data;
35
+ const fd = filtered.data;
36
+ for (let i = 0; i < od.length; i += 4) {
37
+ od[i] = lerpColor(od[i], fd[i], intensity);
38
+ od[i + 1] = lerpColor(od[i + 1], fd[i + 1], intensity);
39
+ od[i + 2] = lerpColor(od[i + 2], fd[i + 2], intensity);
40
+ }
41
+ return out;
52
42
  }
53
- // ── Core filter functions ──
54
43
  function grayscale(data) {
55
- const out = cloneImageData(data);
56
- const d = out.data;
57
- for (let i = 0; i < d.length; i += 4) {
58
- const gray = 0.299 * d[i] + 0.587 * d[i + 1] + 0.114 * d[i + 2];
59
- d[i] = d[i + 1] = d[i + 2] = gray;
60
- }
61
- return out;
44
+ const out = cloneImageData(data);
45
+ const d = out.data;
46
+ for (let i = 0; i < d.length; i += 4) {
47
+ const gray = 0.299 * d[i] + 0.587 * d[i + 1] + 0.114 * d[i + 2];
48
+ d[i] = d[i + 1] = d[i + 2] = gray;
49
+ }
50
+ return out;
62
51
  }
63
52
  function sepia(data) {
64
- const out = cloneImageData(data);
65
- const d = out.data;
66
- for (let i = 0; i < d.length; i += 4) {
67
- const r = d[i], g = d[i + 1], b = d[i + 2];
68
- d[i] = clamp(r * 0.393 + g * 0.769 + b * 0.189);
69
- d[i + 1] = clamp(r * 0.349 + g * 0.686 + b * 0.168);
70
- d[i + 2] = clamp(r * 0.272 + g * 0.534 + b * 0.131);
71
- }
72
- return out;
53
+ const out = cloneImageData(data);
54
+ const d = out.data;
55
+ for (let i = 0; i < d.length; i += 4) {
56
+ const r = d[i], g = d[i + 1], b = d[i + 2];
57
+ d[i] = clamp(r * 0.393 + g * 0.769 + b * 0.189);
58
+ d[i + 1] = clamp(r * 0.349 + g * 0.686 + b * 0.168);
59
+ d[i + 2] = clamp(r * 0.272 + g * 0.534 + b * 0.131);
60
+ }
61
+ return out;
73
62
  }
74
63
  function invert(data) {
75
- const out = cloneImageData(data);
76
- const d = out.data;
77
- for (let i = 0; i < d.length; i += 4) {
78
- d[i] = 255 - d[i];
79
- d[i + 1] = 255 - d[i + 1];
80
- d[i + 2] = 255 - d[i + 2];
81
- }
82
- return out;
64
+ const out = cloneImageData(data);
65
+ const d = out.data;
66
+ for (let i = 0; i < d.length; i += 4) {
67
+ d[i] = 255 - d[i];
68
+ d[i + 1] = 255 - d[i + 1];
69
+ d[i + 2] = 255 - d[i + 2];
70
+ }
71
+ return out;
83
72
  }
84
73
  function adjustBrightness(data, amount) {
85
- const out = cloneImageData(data);
86
- const d = out.data;
87
- const adj = (amount / 100) * 128;
88
- for (let i = 0; i < d.length; i += 4) {
89
- d[i] = clamp(d[i] + adj);
90
- d[i + 1] = clamp(d[i + 1] + adj);
91
- d[i + 2] = clamp(d[i + 2] + adj);
92
- }
93
- return out;
74
+ const out = cloneImageData(data);
75
+ const d = out.data;
76
+ const adj = amount / 100 * 128;
77
+ for (let i = 0; i < d.length; i += 4) {
78
+ d[i] = clamp(d[i] + adj);
79
+ d[i + 1] = clamp(d[i + 1] + adj);
80
+ d[i + 2] = clamp(d[i + 2] + adj);
81
+ }
82
+ return out;
94
83
  }
95
84
  function adjustContrast(data, amount) {
96
- const out = cloneImageData(data);
97
- const d = out.data;
98
- const factor = (259 * (amount + 255)) / (255 * (259 - amount));
99
- for (let i = 0; i < d.length; i += 4) {
100
- d[i] = clamp(factor * (d[i] - 128) + 128);
101
- d[i + 1] = clamp(factor * (d[i + 1] - 128) + 128);
102
- d[i + 2] = clamp(factor * (d[i + 2] - 128) + 128);
103
- }
104
- return out;
85
+ const out = cloneImageData(data);
86
+ const d = out.data;
87
+ const factor = 259 * (amount + 255) / (255 * (259 - amount));
88
+ for (let i = 0; i < d.length; i += 4) {
89
+ d[i] = clamp(factor * (d[i] - 128) + 128);
90
+ d[i + 1] = clamp(factor * (d[i + 1] - 128) + 128);
91
+ d[i + 2] = clamp(factor * (d[i + 2] - 128) + 128);
92
+ }
93
+ return out;
105
94
  }
106
95
  function adjustSaturation(data, amount) {
107
- const out = cloneImageData(data);
108
- const d = out.data;
109
- const sat = 1 + amount / 100;
110
- for (let i = 0; i < d.length; i += 4) {
111
- const gray = 0.2126 * d[i] + 0.7152 * d[i + 1] + 0.0722 * d[i + 2];
112
- d[i] = clamp(gray + sat * (d[i] - gray));
113
- d[i + 1] = clamp(gray + sat * (d[i + 1] - gray));
114
- d[i + 2] = clamp(gray + sat * (d[i + 2] - gray));
115
- }
116
- return out;
96
+ const out = cloneImageData(data);
97
+ const d = out.data;
98
+ const sat = 1 + amount / 100;
99
+ for (let i = 0; i < d.length; i += 4) {
100
+ const gray = 0.2126 * d[i] + 0.7152 * d[i + 1] + 0.0722 * d[i + 2];
101
+ d[i] = clamp(gray + sat * (d[i] - gray));
102
+ d[i + 1] = clamp(gray + sat * (d[i + 1] - gray));
103
+ d[i + 2] = clamp(gray + sat * (d[i + 2] - gray));
104
+ }
105
+ return out;
117
106
  }
118
107
  function adjustTemperature(data, amount) {
119
- const out = cloneImageData(data);
120
- const d = out.data;
121
- const adj = amount * 0.8;
122
- for (let i = 0; i < d.length; i += 4) {
123
- d[i] = clamp(d[i] + adj); // red
124
- d[i + 2] = clamp(d[i + 2] - adj); // blue (inverse)
125
- }
126
- return out;
108
+ const out = cloneImageData(data);
109
+ const d = out.data;
110
+ const adj = amount * 0.8;
111
+ for (let i = 0; i < d.length; i += 4) {
112
+ d[i] = clamp(d[i] + adj);
113
+ d[i + 2] = clamp(d[i + 2] - adj);
114
+ }
115
+ return out;
127
116
  }
128
117
  function adjustTint(data, amount) {
129
- const out = cloneImageData(data);
130
- const d = out.data;
131
- const adj = amount * 0.5;
132
- for (let i = 0; i < d.length; i += 4) {
133
- d[i + 1] = clamp(d[i + 1] - adj); // decrease green for magenta, increase for green
134
- }
135
- return out;
118
+ const out = cloneImageData(data);
119
+ const d = out.data;
120
+ const adj = amount * 0.5;
121
+ for (let i = 0; i < d.length; i += 4) {
122
+ d[i + 1] = clamp(d[i + 1] - adj);
123
+ }
124
+ return out;
136
125
  }
137
126
  function adjustExposure(data, amount) {
138
- const out = cloneImageData(data);
139
- const d = out.data;
140
- const factor = Math.pow(2, amount / 50);
141
- for (let i = 0; i < d.length; i += 4) {
142
- d[i] = clamp(d[i] * factor);
143
- d[i + 1] = clamp(d[i + 1] * factor);
144
- d[i + 2] = clamp(d[i + 2] * factor);
145
- }
146
- return out;
127
+ const out = cloneImageData(data);
128
+ const d = out.data;
129
+ const factor = Math.pow(2, amount / 50);
130
+ for (let i = 0; i < d.length; i += 4) {
131
+ d[i] = clamp(d[i] * factor);
132
+ d[i + 1] = clamp(d[i + 1] * factor);
133
+ d[i + 2] = clamp(d[i + 2] * factor);
134
+ }
135
+ return out;
147
136
  }
148
137
  function adjustHighlights(data, amount) {
149
- const out = cloneImageData(data);
150
- const d = out.data;
151
- const adj = amount / 100;
152
- for (let i = 0; i < d.length; i += 4) {
153
- const lum = (d[i] + d[i + 1] + d[i + 2]) / 3;
154
- if (lum > 128) {
155
- const factor = ((lum - 128) / 127) * adj * 40;
156
- d[i] = clamp(d[i] + factor);
157
- d[i + 1] = clamp(d[i + 1] + factor);
158
- d[i + 2] = clamp(d[i + 2] + factor);
159
- }
160
- }
161
- return out;
138
+ const out = cloneImageData(data);
139
+ const d = out.data;
140
+ const adj = amount / 100;
141
+ for (let i = 0; i < d.length; i += 4) {
142
+ const lum = (d[i] + d[i + 1] + d[i + 2]) / 3;
143
+ if (lum > 128) {
144
+ const factor = (lum - 128) / 127 * adj * 40;
145
+ d[i] = clamp(d[i] + factor);
146
+ d[i + 1] = clamp(d[i + 1] + factor);
147
+ d[i + 2] = clamp(d[i + 2] + factor);
148
+ }
149
+ }
150
+ return out;
162
151
  }
163
152
  function adjustShadows(data, amount) {
164
- const out = cloneImageData(data);
165
- const d = out.data;
166
- const adj = amount / 100;
167
- for (let i = 0; i < d.length; i += 4) {
168
- const lum = (d[i] + d[i + 1] + d[i + 2]) / 3;
169
- if (lum < 128) {
170
- const factor = ((128 - lum) / 128) * adj * 40;
171
- d[i] = clamp(d[i] + factor);
172
- d[i + 1] = clamp(d[i + 1] + factor);
173
- d[i + 2] = clamp(d[i + 2] + factor);
174
- }
175
- }
176
- return out;
153
+ const out = cloneImageData(data);
154
+ const d = out.data;
155
+ const adj = amount / 100;
156
+ for (let i = 0; i < d.length; i += 4) {
157
+ const lum = (d[i] + d[i + 1] + d[i + 2]) / 3;
158
+ if (lum < 128) {
159
+ const factor = (128 - lum) / 128 * adj * 40;
160
+ d[i] = clamp(d[i] + factor);
161
+ d[i + 1] = clamp(d[i + 1] + factor);
162
+ d[i + 2] = clamp(d[i + 2] + factor);
163
+ }
164
+ }
165
+ return out;
177
166
  }
178
167
  function posterize(data, levels = 4) {
179
- const out = cloneImageData(data);
180
- const d = out.data;
181
- const step = 255 / (levels - 1);
182
- for (let i = 0; i < d.length; i += 4) {
183
- d[i] = clamp(Math.round(d[i] / step) * step);
184
- d[i + 1] = clamp(Math.round(d[i + 1] / step) * step);
185
- d[i + 2] = clamp(Math.round(d[i + 2] / step) * step);
186
- }
187
- return out;
168
+ const out = cloneImageData(data);
169
+ const d = out.data;
170
+ const step = 255 / (levels - 1);
171
+ for (let i = 0; i < d.length; i += 4) {
172
+ d[i] = clamp(Math.round(d[i] / step) * step);
173
+ d[i + 1] = clamp(Math.round(d[i + 1] / step) * step);
174
+ d[i + 2] = clamp(Math.round(d[i + 2] / step) * step);
175
+ }
176
+ return out;
188
177
  }
189
178
  function solarize(data) {
190
- const out = cloneImageData(data);
191
- const d = out.data;
192
- for (let i = 0; i < d.length; i += 4) {
193
- d[i] = d[i] > 128 ? 255 - d[i] : d[i];
194
- d[i + 1] = d[i + 1] > 128 ? 255 - d[i + 1] : d[i + 1];
195
- d[i + 2] = d[i + 2] > 128 ? 255 - d[i + 2] : d[i + 2];
196
- }
197
- return out;
179
+ const out = cloneImageData(data);
180
+ const d = out.data;
181
+ for (let i = 0; i < d.length; i += 4) {
182
+ d[i] = d[i] > 128 ? 255 - d[i] : d[i];
183
+ d[i + 1] = d[i + 1] > 128 ? 255 - d[i + 1] : d[i + 1];
184
+ d[i + 2] = d[i + 2] > 128 ? 255 - d[i + 2] : d[i + 2];
185
+ }
186
+ return out;
198
187
  }
199
188
  function channelShift(data) {
200
- const out = cloneImageData(data);
201
- const d = out.data;
202
- for (let i = 0; i < d.length; i += 4) {
203
- const r = d[i], g = d[i + 1], b = d[i + 2];
204
- d[i] = g; // R ← G
205
- d[i + 1] = b; // G ← B
206
- d[i + 2] = r; // B ← R
207
- }
208
- return out;
189
+ const out = cloneImageData(data);
190
+ const d = out.data;
191
+ for (let i = 0; i < d.length; i += 4) {
192
+ const r = d[i], g = d[i + 1], b = d[i + 2];
193
+ d[i] = g;
194
+ d[i + 1] = b;
195
+ d[i + 2] = r;
196
+ }
197
+ return out;
209
198
  }
210
199
  function cyberpunk(data) {
211
- const out = cloneImageData(data);
212
- const d = out.data;
213
- for (let i = 0; i < d.length; i += 4) {
214
- const lum = 0.299 * d[i] + 0.587 * d[i + 1] + 0.114 * d[i + 2];
215
- d[i] = clamp(lum * 0.2 + d[i] * 0.8 + 30); // boost red
216
- d[i + 1] = clamp(lum * 0.5 + d[i + 1] * 0.15 - 10); // crush green
217
- d[i + 2] = clamp(lum * 0.3 + d[i + 2] * 0.9 + 50); // heavy blue
218
- }
219
- return out;
200
+ const out = cloneImageData(data);
201
+ const d = out.data;
202
+ for (let i = 0; i < d.length; i += 4) {
203
+ const lum = 0.299 * d[i] + 0.587 * d[i + 1] + 0.114 * d[i + 2];
204
+ d[i] = clamp(lum * 0.2 + d[i] * 0.8 + 30);
205
+ d[i + 1] = clamp(lum * 0.5 + d[i + 1] * 0.15 - 10);
206
+ d[i + 2] = clamp(lum * 0.3 + d[i + 2] * 0.9 + 50);
207
+ }
208
+ return out;
220
209
  }
221
210
  function retroWave(data) {
222
- const out = cloneImageData(data);
223
- const d = out.data;
224
- for (let i = 0; i < d.length; i += 4) {
225
- d[i] = clamp(d[i] * 1.1 + 20);
226
- d[i + 1] = clamp(d[i + 1] * 0.6 - 10);
227
- d[i + 2] = clamp(d[i + 2] * 1.3 + 30);
228
- }
229
- return adjustContrast(out, 30);
211
+ const out = cloneImageData(data);
212
+ const d = out.data;
213
+ for (let i = 0; i < d.length; i += 4) {
214
+ d[i] = clamp(d[i] * 1.1 + 20);
215
+ d[i + 1] = clamp(d[i + 1] * 0.6 - 10);
216
+ d[i + 2] = clamp(d[i + 2] * 1.3 + 30);
217
+ }
218
+ return adjustContrast(out, 30);
230
219
  }
231
220
  function vintageFilm(data) {
232
- let out = cloneImageData(data);
233
- const d = out.data;
234
- // warm tone overlay
235
- for (let i = 0; i < d.length; i += 4) {
236
- d[i] = clamp(d[i] * 1.08 + 8);
237
- d[i + 1] = clamp(d[i + 1] * 0.95 + 5);
238
- d[i + 2] = clamp(d[i + 2] * 0.85 - 5);
239
- }
240
- out = adjustContrast(out, -15);
241
- return adjustSaturation(out, -20);
221
+ let out = cloneImageData(data);
222
+ const d = out.data;
223
+ for (let i = 0; i < d.length; i += 4) {
224
+ d[i] = clamp(d[i] * 1.08 + 8);
225
+ d[i + 1] = clamp(d[i + 1] * 0.95 + 5);
226
+ d[i + 2] = clamp(d[i + 2] * 0.85 - 5);
227
+ }
228
+ out = adjustContrast(out, -15);
229
+ return adjustSaturation(out, -20);
242
230
  }
243
231
  function kodachrome(data) {
244
- const out = cloneImageData(data);
245
- const d = out.data;
246
- for (let i = 0; i < d.length; i += 4) {
247
- const r = d[i], g = d[i + 1], b = d[i + 2];
248
- d[i] = clamp(r * 1.129 + g * 0.097 + b * 0.035 - 12);
249
- d[i + 1] = clamp(r * 0.019 + g * 0.955 + b * 0.041 + 8);
250
- d[i + 2] = clamp(r * 0.016 + g * 0.033 + b * 0.837 + 28);
251
- }
252
- return out;
232
+ const out = cloneImageData(data);
233
+ const d = out.data;
234
+ for (let i = 0; i < d.length; i += 4) {
235
+ const r = d[i], g = d[i + 1], b = d[i + 2];
236
+ d[i] = clamp(r * 1.129 + g * 0.097 + b * 0.035 - 12);
237
+ d[i + 1] = clamp(r * 0.019 + g * 0.955 + b * 0.041 + 8);
238
+ d[i + 2] = clamp(r * 0.016 + g * 0.033 + b * 0.837 + 28);
239
+ }
240
+ return out;
253
241
  }
254
242
  function polaroid(data) {
255
- const out = cloneImageData(data);
256
- const d = out.data;
257
- for (let i = 0; i < d.length; i += 4) {
258
- const r = d[i], g = d[i + 1], b = d[i + 2];
259
- d[i] = clamp(r * 1.438 - g * 0.062 - b * 0.062 + 10);
260
- d[i + 1] = clamp(-r * 0.122 + g * 1.378 - b * 0.122 + 6);
261
- d[i + 2] = clamp(-r * 0.016 - g * 0.016 + b * 1.483 - 12);
262
- }
263
- return out;
243
+ const out = cloneImageData(data);
244
+ const d = out.data;
245
+ for (let i = 0; i < d.length; i += 4) {
246
+ const r = d[i], g = d[i + 1], b = d[i + 2];
247
+ d[i] = clamp(r * 1.438 - g * 0.062 - b * 0.062 + 10);
248
+ d[i + 1] = clamp(-r * 0.122 + g * 1.378 - b * 0.122 + 6);
249
+ d[i + 2] = clamp(-r * 0.016 - g * 0.016 + b * 1.483 - 12);
250
+ }
251
+ return out;
264
252
  }
265
253
  function technicolor(data) {
266
- const out = cloneImageData(data);
267
- const d = out.data;
268
- for (let i = 0; i < d.length; i += 4) {
269
- const r = d[i], g = d[i + 1], b = d[i + 2];
270
- d[i] = clamp(r * 1.913 - g * 0.282 - b * 0.023);
271
- d[i + 1] = clamp(-r * 0.204 + g * 1.397 - b * 0.018);
272
- d[i + 2] = clamp(-r * 0.199 - g * 0.291 + b * 1.765);
273
- }
274
- return out;
254
+ const out = cloneImageData(data);
255
+ const d = out.data;
256
+ for (let i = 0; i < d.length; i += 4) {
257
+ const r = d[i], g = d[i + 1], b = d[i + 2];
258
+ d[i] = clamp(r * 1.913 - g * 0.282 - b * 0.023);
259
+ d[i + 1] = clamp(-r * 0.204 + g * 1.397 - b * 0.018);
260
+ d[i + 2] = clamp(-r * 0.199 - g * 0.291 + b * 1.765);
261
+ }
262
+ return out;
275
263
  }
276
264
  function brownie(data) {
277
- const out = cloneImageData(data);
278
- const d = out.data;
279
- for (let i = 0; i < d.length; i += 4) {
280
- const r = d[i], g = d[i + 1], b = d[i + 2];
281
- d[i] = clamp(r * 0.599 + g * 0.345 + b * 0.272);
282
- d[i + 1] = clamp(r * 0.168 + g * 0.706 + b * 0.131);
283
- d[i + 2] = clamp(r * 0.131 + g * 0.168 + b * 0.706);
284
- }
285
- return out;
265
+ const out = cloneImageData(data);
266
+ const d = out.data;
267
+ for (let i = 0; i < d.length; i += 4) {
268
+ const r = d[i], g = d[i + 1], b = d[i + 2];
269
+ d[i] = clamp(r * 0.599 + g * 0.345 + b * 0.272);
270
+ d[i + 1] = clamp(r * 0.168 + g * 0.706 + b * 0.131);
271
+ d[i + 2] = clamp(r * 0.131 + g * 0.168 + b * 0.706);
272
+ }
273
+ return out;
286
274
  }
287
275
  function duotone(data, params) {
288
- const out = cloneImageData(data);
289
- const d = out.data;
290
- // audit-allow: literal-color +2 — the duotone filter's default inks, written into the photo
291
- const dark = hexToRgb((params === null || params === void 0 ? void 0 : params.darkColor) || '#001f3f');
292
- const light = hexToRgb((params === null || params === void 0 ? void 0 : params.lightColor) || '#ff851b');
293
- for (let i = 0; i < d.length; i += 4) {
294
- const lum = (0.299 * d[i] + 0.587 * d[i + 1] + 0.114 * d[i + 2]) / 255;
295
- d[i] = clamp(dark[0] + (light[0] - dark[0]) * lum);
296
- d[i + 1] = clamp(dark[1] + (light[1] - dark[1]) * lum);
297
- d[i + 2] = clamp(dark[2] + (light[2] - dark[2]) * lum);
298
- }
299
- return out;
276
+ const out = cloneImageData(data);
277
+ const d = out.data;
278
+ const dark = hexToRgb(params?.darkColor || "#001f3f");
279
+ const light = hexToRgb(params?.lightColor || "#ff851b");
280
+ for (let i = 0; i < d.length; i += 4) {
281
+ const lum = (0.299 * d[i] + 0.587 * d[i + 1] + 0.114 * d[i + 2]) / 255;
282
+ d[i] = clamp(dark[0] + (light[0] - dark[0]) * lum);
283
+ d[i + 1] = clamp(dark[1] + (light[1] - dark[1]) * lum);
284
+ d[i + 2] = clamp(dark[2] + (light[2] - dark[2]) * lum);
285
+ }
286
+ return out;
300
287
  }
301
288
  function threshold(data, level = 128) {
302
- const out = cloneImageData(data);
303
- const d = out.data;
304
- for (let i = 0; i < d.length; i += 4) {
305
- const lum = 0.299 * d[i] + 0.587 * d[i + 1] + 0.114 * d[i + 2];
306
- const v = lum >= level ? 255 : 0;
307
- d[i] = d[i + 1] = d[i + 2] = v;
308
- }
309
- return out;
289
+ const out = cloneImageData(data);
290
+ const d = out.data;
291
+ for (let i = 0; i < d.length; i += 4) {
292
+ const lum = 0.299 * d[i] + 0.587 * d[i + 1] + 0.114 * d[i + 2];
293
+ const v = lum >= level ? 255 : 0;
294
+ d[i] = d[i + 1] = d[i + 2] = v;
295
+ }
296
+ return out;
310
297
  }
311
298
  function emboss(data) {
312
- return convolve(data, [-2, -1, 0, -1, 1, 1, 0, 1, 2]);
299
+ return convolve(data, [-2, -1, 0, -1, 1, 1, 0, 1, 2]);
313
300
  }
314
301
  function edgeDetect(data) {
315
- return convolve(data, [-1, -1, -1, -1, 8, -1, -1, -1, -1]);
302
+ return convolve(data, [-1, -1, -1, -1, 8, -1, -1, -1, -1]);
316
303
  }
317
304
  function sharpen(data, amount = 1) {
318
- const k = amount;
319
- return convolve(data, [0, -k, 0, -k, 1 + 4 * k, -k, 0, -k, 0]);
305
+ const k = amount;
306
+ return convolve(data, [0, -k, 0, -k, 1 + 4 * k, -k, 0, -k, 0]);
320
307
  }
321
308
  function comicBook(data) {
322
- const edges = edgeDetect(data);
323
- const poster = posterize(data, 5);
324
- const out = cloneImageData(poster);
325
- const d = out.data;
326
- const ed = edges.data;
327
- for (let i = 0; i < d.length; i += 4) {
328
- const edgeLum = (ed[i] + ed[i + 1] + ed[i + 2]) / 3;
329
- if (edgeLum > 30) {
330
- d[i] = d[i + 1] = d[i + 2] = 0; // black edge lines
331
- }
332
- }
333
- return adjustSaturation(out, 40);
309
+ const edges = edgeDetect(data);
310
+ const poster = posterize(data, 5);
311
+ const out = cloneImageData(poster);
312
+ const d = out.data;
313
+ const ed = edges.data;
314
+ for (let i = 0; i < d.length; i += 4) {
315
+ const edgeLum = (ed[i] + ed[i + 1] + ed[i + 2]) / 3;
316
+ if (edgeLum > 30) {
317
+ d[i] = d[i + 1] = d[i + 2] = 0;
318
+ }
319
+ }
320
+ return adjustSaturation(out, 40);
334
321
  }
335
322
  function heatMap(data) {
336
- const out = cloneImageData(data);
337
- const d = out.data;
338
- for (let i = 0; i < d.length; i += 4) {
339
- const lum = (0.299 * d[i] + 0.587 * d[i + 1] + 0.114 * d[i + 2]) / 255;
340
- // heatmap: blue → cyan → green → yellow → red
341
- if (lum < 0.25) {
342
- d[i] = 0;
343
- d[i + 1] = clamp(lum * 4 * 255);
344
- d[i + 2] = 255;
345
- }
346
- else if (lum < 0.5) {
347
- d[i] = 0;
348
- d[i + 1] = 255;
349
- d[i + 2] = clamp((1 - (lum - 0.25) * 4) * 255);
350
- }
351
- else if (lum < 0.75) {
352
- d[i] = clamp((lum - 0.5) * 4 * 255);
353
- d[i + 1] = 255;
354
- d[i + 2] = 0;
355
- }
356
- else {
357
- d[i] = 255;
358
- d[i + 1] = clamp((1 - (lum - 0.75) * 4) * 255);
359
- d[i + 2] = 0;
360
- }
361
- }
362
- return out;
323
+ const out = cloneImageData(data);
324
+ const d = out.data;
325
+ for (let i = 0; i < d.length; i += 4) {
326
+ const lum = (0.299 * d[i] + 0.587 * d[i + 1] + 0.114 * d[i + 2]) / 255;
327
+ if (lum < 0.25) {
328
+ d[i] = 0;
329
+ d[i + 1] = clamp(lum * 4 * 255);
330
+ d[i + 2] = 255;
331
+ } else if (lum < 0.5) {
332
+ d[i] = 0;
333
+ d[i + 1] = 255;
334
+ d[i + 2] = clamp((1 - (lum - 0.25) * 4) * 255);
335
+ } else if (lum < 0.75) {
336
+ d[i] = clamp((lum - 0.5) * 4 * 255);
337
+ d[i + 1] = 255;
338
+ d[i + 2] = 0;
339
+ } else {
340
+ d[i] = 255;
341
+ d[i + 1] = clamp((1 - (lum - 0.75) * 4) * 255);
342
+ d[i + 2] = 0;
343
+ }
344
+ }
345
+ return out;
363
346
  }
364
347
  function nightVision(data) {
365
- const out = cloneImageData(data);
366
- const d = out.data;
367
- for (let i = 0; i < d.length; i += 4) {
368
- const lum = 0.299 * d[i] + 0.587 * d[i + 1] + 0.114 * d[i + 2];
369
- d[i] = 0;
370
- d[i + 1] = clamp(lum * 1.4 + 10);
371
- d[i + 2] = 0;
372
- }
373
- return out;
348
+ const out = cloneImageData(data);
349
+ const d = out.data;
350
+ for (let i = 0; i < d.length; i += 4) {
351
+ const lum = 0.299 * d[i] + 0.587 * d[i + 1] + 0.114 * d[i + 2];
352
+ d[i] = 0;
353
+ d[i + 1] = clamp(lum * 1.4 + 10);
354
+ d[i + 2] = 0;
355
+ }
356
+ return out;
374
357
  }
375
358
  function xRay(data) {
376
- let out = invert(data);
377
- out = grayscale(out);
378
- return adjustContrast(out, 40);
359
+ let out = invert(data);
360
+ out = grayscale(out);
361
+ return adjustContrast(out, 40);
379
362
  }
380
363
  function crossProcess(data) {
381
- const out = cloneImageData(data);
382
- const d = out.data;
383
- for (let i = 0; i < d.length; i += 4) {
384
- // S-curve on green, inverse on blue
385
- d[i] = clamp(d[i] * 1.1 + 10);
386
- d[i + 1] = clamp(Math.pow(d[i + 1] / 255, 0.85) * 280);
387
- d[i + 2] = clamp(255 - (255 - d[i + 2]) * 0.7);
388
- }
389
- return out;
364
+ const out = cloneImageData(data);
365
+ const d = out.data;
366
+ for (let i = 0; i < d.length; i += 4) {
367
+ d[i] = clamp(d[i] * 1.1 + 10);
368
+ d[i + 1] = clamp(Math.pow(d[i + 1] / 255, 0.85) * 280);
369
+ d[i + 2] = clamp(255 - (255 - d[i + 2]) * 0.7);
370
+ }
371
+ return out;
390
372
  }
391
373
  function lomoLeaks(data) {
392
- const out = cloneImageData(data);
393
- const d = out.data;
394
- const w = data.width, h = data.height;
395
- for (let y = 0; y < h; y++) {
396
- for (let x = 0; x < w; x++) {
397
- const i = (y * w + x) * 4;
398
- // Warm light leak from top-left
399
- const dist = Math.sqrt(x * x + y * y) / Math.sqrt(w * w + h * h);
400
- const leak = Math.max(0, 1 - dist * 1.8) * 60;
401
- d[i] = clamp(d[i] + leak * 1.5);
402
- d[i + 1] = clamp(d[i + 1] + leak * 0.8);
403
- d[i + 2] = clamp(d[i + 2] - leak * 0.3);
404
- }
405
- }
406
- return adjustSaturation(out, 15);
374
+ const out = cloneImageData(data);
375
+ const d = out.data;
376
+ const w = data.width, h = data.height;
377
+ for (let y = 0; y < h; y++) {
378
+ for (let x = 0; x < w; x++) {
379
+ const i = (y * w + x) * 4;
380
+ const dist = Math.sqrt(x * x + y * y) / Math.sqrt(w * w + h * h);
381
+ const leak = Math.max(0, 1 - dist * 1.8) * 60;
382
+ d[i] = clamp(d[i] + leak * 1.5);
383
+ d[i + 1] = clamp(d[i + 1] + leak * 0.8);
384
+ d[i + 2] = clamp(d[i + 2] - leak * 0.3);
385
+ }
386
+ }
387
+ return adjustSaturation(out, 15);
407
388
  }
408
389
  function fadeOut(data) {
409
- let out = cloneImageData(data);
410
- out = adjustContrast(out, -30);
411
- const d = out.data;
412
- for (let i = 0; i < d.length; i += 4) {
413
- d[i] = clamp(d[i] + 25);
414
- d[i + 1] = clamp(d[i + 1] + 20);
415
- d[i + 2] = clamp(d[i + 2] + 30);
416
- }
417
- return adjustSaturation(out, -30);
390
+ let out = cloneImageData(data);
391
+ out = adjustContrast(out, -30);
392
+ const d = out.data;
393
+ for (let i = 0; i < d.length; i += 4) {
394
+ d[i] = clamp(d[i] + 25);
395
+ d[i + 1] = clamp(d[i + 1] + 20);
396
+ d[i + 2] = clamp(d[i + 2] + 30);
397
+ }
398
+ return adjustSaturation(out, -30);
418
399
  }
419
400
  function glitch(data) {
420
- const out = cloneImageData(data);
421
- const d = out.data;
422
- const w = data.width;
423
- // Shift some rows horizontally by random amounts
424
- for (let y = 0; y < data.height; y++) {
425
- if (Math.random() > 0.92) {
426
- const shift = Math.floor(Math.random() * 30 - 15);
427
- for (let x = 0; x < w; x++) {
428
- const srcX = (((x + shift) % w) + w) % w;
429
- const di = (y * w + x) * 4;
430
- const si = (y * w + srcX) * 4;
431
- // Red channel from shifted position
432
- d[di] = data.data[si];
433
- }
434
- }
435
- }
436
- return out;
401
+ const out = cloneImageData(data);
402
+ const d = out.data;
403
+ const w = data.width;
404
+ for (let y = 0; y < data.height; y++) {
405
+ if (Math.random() > 0.92) {
406
+ const shift = Math.floor(Math.random() * 30 - 15);
407
+ for (let x = 0; x < w; x++) {
408
+ const srcX = ((x + shift) % w + w) % w;
409
+ const di = (y * w + x) * 4;
410
+ const si = (y * w + srcX) * 4;
411
+ d[di] = data.data[si];
412
+ }
413
+ }
414
+ }
415
+ return out;
437
416
  }
438
417
  function pixelate(data, blockSize = 8) {
439
- const out = cloneImageData(data);
440
- const d = out.data;
441
- const w = data.width, h = data.height;
442
- for (let by = 0; by < h; by += blockSize) {
443
- for (let bx = 0; bx < w; bx += blockSize) {
444
- let rSum = 0, gSum = 0, bSum = 0, count = 0;
445
- for (let dy = 0; dy < blockSize && by + dy < h; dy++) {
446
- for (let dx = 0; dx < blockSize && bx + dx < w; dx++) {
447
- const i = ((by + dy) * w + (bx + dx)) * 4;
448
- rSum += d[i];
449
- gSum += d[i + 1];
450
- bSum += d[i + 2];
451
- count++;
452
- }
453
- }
454
- const rAvg = rSum / count, gAvg = gSum / count, bAvg = bSum / count;
455
- for (let dy = 0; dy < blockSize && by + dy < h; dy++) {
456
- for (let dx = 0; dx < blockSize && bx + dx < w; dx++) {
457
- const i = ((by + dy) * w + (bx + dx)) * 4;
458
- d[i] = rAvg;
459
- d[i + 1] = gAvg;
460
- d[i + 2] = bAvg;
461
- }
462
- }
418
+ const out = cloneImageData(data);
419
+ const d = out.data;
420
+ const w = data.width, h = data.height;
421
+ for (let by = 0; by < h; by += blockSize) {
422
+ for (let bx = 0; bx < w; bx += blockSize) {
423
+ let rSum = 0, gSum = 0, bSum = 0, count = 0;
424
+ for (let dy = 0; dy < blockSize && by + dy < h; dy++) {
425
+ for (let dx = 0; dx < blockSize && bx + dx < w; dx++) {
426
+ const i = ((by + dy) * w + (bx + dx)) * 4;
427
+ rSum += d[i];
428
+ gSum += d[i + 1];
429
+ bSum += d[i + 2];
430
+ count++;
463
431
  }
432
+ }
433
+ const rAvg = rSum / count, gAvg = gSum / count, bAvg = bSum / count;
434
+ for (let dy = 0; dy < blockSize && by + dy < h; dy++) {
435
+ for (let dx = 0; dx < blockSize && bx + dx < w; dx++) {
436
+ const i = ((by + dy) * w + (bx + dx)) * 4;
437
+ d[i] = rAvg;
438
+ d[i + 1] = gAvg;
439
+ d[i + 2] = bAvg;
440
+ }
441
+ }
464
442
  }
465
- return out;
443
+ }
444
+ return out;
466
445
  }
467
446
  function oilPainting(data, radius = 3) {
468
- const out = cloneImageData(data);
469
- const d = out.data;
470
- const src = data.data;
471
- const w = data.width, h = data.height;
472
- const levels = 20;
473
- for (let y = 0; y < h; y++) {
474
- for (let x = 0; x < w; x++) {
475
- const counts = new Int32Array(levels);
476
- const rSum = new Float64Array(levels);
477
- const gSum = new Float64Array(levels);
478
- const bSum = new Float64Array(levels);
479
- for (let ky = -radius; ky <= radius; ky++) {
480
- for (let kx = -radius; kx <= radius; kx++) {
481
- const ny = Math.min(h - 1, Math.max(0, y + ky));
482
- const nx = Math.min(w - 1, Math.max(0, x + kx));
483
- const ni = (ny * w + nx) * 4;
484
- const lum = Math.floor((((src[ni] + src[ni + 1] + src[ni + 2]) / 3) * levels) / 256);
485
- const li = Math.min(lum, levels - 1);
486
- counts[li]++;
487
- rSum[li] += src[ni];
488
- gSum[li] += src[ni + 1];
489
- bSum[li] += src[ni + 2];
490
- }
491
- }
492
- let maxCount = 0, maxIdx = 0;
493
- for (let l = 0; l < levels; l++) {
494
- if (counts[l] > maxCount) {
495
- maxCount = counts[l];
496
- maxIdx = l;
497
- }
498
- }
499
- const i = (y * w + x) * 4;
500
- d[i] = rSum[maxIdx] / maxCount;
501
- d[i + 1] = gSum[maxIdx] / maxCount;
502
- d[i + 2] = bSum[maxIdx] / maxCount;
447
+ const out = cloneImageData(data);
448
+ const d = out.data;
449
+ const src = data.data;
450
+ const w = data.width, h = data.height;
451
+ const levels = 20;
452
+ for (let y = 0; y < h; y++) {
453
+ for (let x = 0; x < w; x++) {
454
+ const counts = new Int32Array(levels);
455
+ const rSum = new Float64Array(levels);
456
+ const gSum = new Float64Array(levels);
457
+ const bSum = new Float64Array(levels);
458
+ for (let ky = -radius; ky <= radius; ky++) {
459
+ for (let kx = -radius; kx <= radius; kx++) {
460
+ const ny = Math.min(h - 1, Math.max(0, y + ky));
461
+ const nx = Math.min(w - 1, Math.max(0, x + kx));
462
+ const ni = (ny * w + nx) * 4;
463
+ const lum = Math.floor((src[ni] + src[ni + 1] + src[ni + 2]) / 3 * levels / 256);
464
+ const li = Math.min(lum, levels - 1);
465
+ counts[li]++;
466
+ rSum[li] += src[ni];
467
+ gSum[li] += src[ni + 1];
468
+ bSum[li] += src[ni + 2];
503
469
  }
504
- }
505
- return out;
470
+ }
471
+ let maxCount = 0, maxIdx = 0;
472
+ for (let l = 0; l < levels; l++) {
473
+ if (counts[l] > maxCount) {
474
+ maxCount = counts[l];
475
+ maxIdx = l;
476
+ }
477
+ }
478
+ const i = (y * w + x) * 4;
479
+ d[i] = rSum[maxIdx] / maxCount;
480
+ d[i + 1] = gSum[maxIdx] / maxCount;
481
+ d[i + 2] = bSum[maxIdx] / maxCount;
482
+ }
483
+ }
484
+ return out;
506
485
  }
507
486
  function tiltShift(data) {
508
- // Simple blur for top and bottom thirds
509
- const out = cloneImageData(data);
510
- const d = out.data;
511
- const src = data.data;
512
- const w = data.width, h = data.height;
513
- const centerY = h / 2;
514
- const focusHalf = h * 0.15;
515
- for (let y = 0; y < h; y++) {
516
- const dist = Math.abs(y - centerY);
517
- const blurRadius = dist < focusHalf ? 0 : Math.min(6, Math.floor((dist - focusHalf) / (h * 0.1)));
518
- if (blurRadius === 0) {
519
- continue;
520
- }
521
- for (let x = 0; x < w; x++) {
522
- let rSum = 0, gSum = 0, bSum = 0, count = 0;
523
- for (let ky = -blurRadius; ky <= blurRadius; ky++) {
524
- for (let kx = -blurRadius; kx <= blurRadius; kx++) {
525
- const ny = Math.min(h - 1, Math.max(0, y + ky));
526
- const nx = Math.min(w - 1, Math.max(0, x + kx));
527
- const si = (ny * w + nx) * 4;
528
- rSum += src[si];
529
- gSum += src[si + 1];
530
- bSum += src[si + 2];
531
- count++;
532
- }
533
- }
534
- const i = (y * w + x) * 4;
535
- d[i] = rSum / count;
536
- d[i + 1] = gSum / count;
537
- d[i + 2] = bSum / count;
487
+ const out = cloneImageData(data);
488
+ const d = out.data;
489
+ const src = data.data;
490
+ const w = data.width, h = data.height;
491
+ const centerY = h / 2;
492
+ const focusHalf = h * 0.15;
493
+ for (let y = 0; y < h; y++) {
494
+ const dist = Math.abs(y - centerY);
495
+ const blurRadius = dist < focusHalf ? 0 : Math.min(6, Math.floor((dist - focusHalf) / (h * 0.1)));
496
+ if (blurRadius === 0) {
497
+ continue;
498
+ }
499
+ for (let x = 0; x < w; x++) {
500
+ let rSum = 0, gSum = 0, bSum = 0, count = 0;
501
+ for (let ky = -blurRadius; ky <= blurRadius; ky++) {
502
+ for (let kx = -blurRadius; kx <= blurRadius; kx++) {
503
+ const ny = Math.min(h - 1, Math.max(0, y + ky));
504
+ const nx = Math.min(w - 1, Math.max(0, x + kx));
505
+ const si = (ny * w + nx) * 4;
506
+ rSum += src[si];
507
+ gSum += src[si + 1];
508
+ bSum += src[si + 2];
509
+ count++;
538
510
  }
539
- }
540
- return adjustSaturation(out, 20);
511
+ }
512
+ const i = (y * w + x) * 4;
513
+ d[i] = rSum / count;
514
+ d[i + 1] = gSum / count;
515
+ d[i + 2] = bSum / count;
516
+ }
517
+ }
518
+ return adjustSaturation(out, 20);
541
519
  }
542
520
  function pencilSketch(data) {
543
- const gray = grayscale(data);
544
- const inv = invert(gray);
545
- // Simple Gaussian-like blur on inverted
546
- const blurred = boxBlur(inv, 8);
547
- const out = cloneImageData(gray);
548
- const d = out.data;
549
- const bd = blurred.data;
550
- // Color dodge blend
551
- for (let i = 0; i < d.length; i += 4) {
552
- const base = d[i];
553
- const blend = bd[i];
554
- const r = blend === 255 ? 255 : clamp((base * 256) / (255 - blend));
555
- d[i] = d[i + 1] = d[i + 2] = r;
556
- }
557
- return out;
521
+ const gray = grayscale(data);
522
+ const inv = invert(gray);
523
+ const blurred = boxBlur(inv, 8);
524
+ const out = cloneImageData(gray);
525
+ const d = out.data;
526
+ const bd = blurred.data;
527
+ for (let i = 0; i < d.length; i += 4) {
528
+ const base = d[i];
529
+ const blend = bd[i];
530
+ const r = blend === 255 ? 255 : clamp(base * 256 / (255 - blend));
531
+ d[i] = d[i + 1] = d[i + 2] = r;
532
+ }
533
+ return out;
558
534
  }
559
535
  function watercolor(data) {
560
- let out = boxBlur(data, 3);
561
- out = adjustSaturation(out, 30);
562
- out = adjustContrast(out, -10);
563
- // Slight edge darkening
564
- const edges = edgeDetect(data);
565
- const d = out.data;
566
- const ed = edges.data;
567
- for (let i = 0; i < d.length; i += 4) {
568
- const edgeLum = (ed[i] + ed[i + 1] + ed[i + 2]) / 3;
569
- const darken = Math.min(edgeLum * 0.15, 25);
570
- d[i] = clamp(d[i] - darken);
571
- d[i + 1] = clamp(d[i + 1] - darken);
572
- d[i + 2] = clamp(d[i + 2] - darken);
573
- }
574
- return out;
536
+ let out = boxBlur(data, 3);
537
+ out = adjustSaturation(out, 30);
538
+ out = adjustContrast(out, -10);
539
+ const edges = edgeDetect(data);
540
+ const d = out.data;
541
+ const ed = edges.data;
542
+ for (let i = 0; i < d.length; i += 4) {
543
+ const edgeLum = (ed[i] + ed[i + 1] + ed[i + 2]) / 3;
544
+ const darken = Math.min(edgeLum * 0.15, 25);
545
+ d[i] = clamp(d[i] - darken);
546
+ d[i + 1] = clamp(d[i + 1] - darken);
547
+ d[i + 2] = clamp(d[i + 2] - darken);
548
+ }
549
+ return out;
575
550
  }
576
551
  function dreamyGlow(data) {
577
- const blurred = boxBlur(data, 6);
578
- const out = cloneImageData(data);
579
- const d = out.data;
580
- const bd = blurred.data;
581
- // Screen blend
582
- for (let i = 0; i < d.length; i += 4) {
583
- d[i] = clamp(255 - ((255 - d[i]) * (255 - bd[i])) / 255);
584
- d[i + 1] = clamp(255 - ((255 - d[i + 1]) * (255 - bd[i + 1])) / 255);
585
- d[i + 2] = clamp(255 - ((255 - d[i + 2]) * (255 - bd[i + 2])) / 255);
586
- }
587
- return adjustSaturation(out, 15);
552
+ const blurred = boxBlur(data, 6);
553
+ const out = cloneImageData(data);
554
+ const d = out.data;
555
+ const bd = blurred.data;
556
+ for (let i = 0; i < d.length; i += 4) {
557
+ d[i] = clamp(255 - (255 - d[i]) * (255 - bd[i]) / 255);
558
+ d[i + 1] = clamp(255 - (255 - d[i + 1]) * (255 - bd[i + 1]) / 255);
559
+ d[i + 2] = clamp(255 - (255 - d[i + 2]) * (255 - bd[i + 2]) / 255);
560
+ }
561
+ return adjustSaturation(out, 15);
588
562
  }
589
563
  function frostedGlass(data) {
590
- const out = cloneImageData(data);
591
- const d = out.data;
592
- const src = data.data;
593
- const w = data.width, h = data.height;
594
- const radius = 4;
595
- for (let y = 0; y < h; y++) {
596
- for (let x = 0; x < w; x++) {
597
- const ox = x + Math.floor(Math.random() * radius * 2 - radius);
598
- const oy = y + Math.floor(Math.random() * radius * 2 - radius);
599
- const nx = Math.min(w - 1, Math.max(0, ox));
600
- const ny = Math.min(h - 1, Math.max(0, oy));
601
- const di = (y * w + x) * 4;
602
- const si = (ny * w + nx) * 4;
603
- d[di] = src[si];
604
- d[di + 1] = src[si + 1];
605
- d[di + 2] = src[si + 2];
606
- }
607
- }
608
- return out;
564
+ const out = cloneImageData(data);
565
+ const d = out.data;
566
+ const src = data.data;
567
+ const w = data.width, h = data.height;
568
+ const radius = 4;
569
+ for (let y = 0; y < h; y++) {
570
+ for (let x = 0; x < w; x++) {
571
+ const ox = x + Math.floor(Math.random() * radius * 2 - radius);
572
+ const oy = y + Math.floor(Math.random() * radius * 2 - radius);
573
+ const nx = Math.min(w - 1, Math.max(0, ox));
574
+ const ny = Math.min(h - 1, Math.max(0, oy));
575
+ const di = (y * w + x) * 4;
576
+ const si = (ny * w + nx) * 4;
577
+ d[di] = src[si];
578
+ d[di + 1] = src[si + 1];
579
+ d[di + 2] = src[si + 2];
580
+ }
581
+ }
582
+ return out;
609
583
  }
610
584
  function pop(data) {
611
- let out = adjustSaturation(data, 50);
612
- out = adjustContrast(out, 20);
613
- return adjustBrightness(out, 5);
585
+ let out = adjustSaturation(data, 50);
586
+ out = adjustContrast(out, 20);
587
+ return adjustBrightness(out, 5);
614
588
  }
615
589
  function moody(data) {
616
- let out = adjustSaturation(data, -25);
617
- out = adjustContrast(out, 15);
618
- out = adjustTemperature(out, -15);
619
- return adjustBrightness(out, -10);
590
+ let out = adjustSaturation(data, -25);
591
+ out = adjustContrast(out, 15);
592
+ out = adjustTemperature(out, -15);
593
+ return adjustBrightness(out, -10);
620
594
  }
621
595
  function golden(data) {
622
- const out = cloneImageData(data);
623
- const d = out.data;
624
- for (let i = 0; i < d.length; i += 4) {
625
- const lum = (d[i] + d[i + 1] + d[i + 2]) / 3;
626
- d[i] = clamp(lum * 0.4 + d[i] * 0.7 + 20);
627
- d[i + 1] = clamp(lum * 0.3 + d[i + 1] * 0.6 + 10);
628
- d[i + 2] = clamp(lum * 0.1 + d[i + 2] * 0.3 - 10);
629
- }
630
- return adjustContrast(out, 10);
596
+ const out = cloneImageData(data);
597
+ const d = out.data;
598
+ for (let i = 0; i < d.length; i += 4) {
599
+ const lum = (d[i] + d[i + 1] + d[i + 2]) / 3;
600
+ d[i] = clamp(lum * 0.4 + d[i] * 0.7 + 20);
601
+ d[i + 1] = clamp(lum * 0.3 + d[i + 1] * 0.6 + 10);
602
+ d[i + 2] = clamp(lum * 0.1 + d[i + 2] * 0.3 - 10);
603
+ }
604
+ return adjustContrast(out, 10);
631
605
  }
632
606
  function radioactive(data) {
633
- const out = cloneImageData(data);
634
- const d = out.data;
635
- for (let i = 0; i < d.length; i += 4) {
636
- d[i] = clamp(d[i] * 0.3);
637
- d[i + 1] = clamp(d[i + 1] * 1.6 + 30);
638
- d[i + 2] = clamp(d[i + 2] * 0.2);
639
- }
640
- return out;
607
+ const out = cloneImageData(data);
608
+ const d = out.data;
609
+ for (let i = 0; i < d.length; i += 4) {
610
+ d[i] = clamp(d[i] * 0.3);
611
+ d[i + 1] = clamp(d[i + 1] * 1.6 + 30);
612
+ d[i + 2] = clamp(d[i + 2] * 0.2);
613
+ }
614
+ return out;
641
615
  }
642
616
  function arctic(data) {
643
- let out = adjustTemperature(data, -50);
644
- out = adjustSaturation(out, -15);
645
- out = adjustBrightness(out, 10);
646
- return adjustContrast(out, 10);
617
+ let out = adjustTemperature(data, -50);
618
+ out = adjustSaturation(out, -15);
619
+ out = adjustBrightness(out, 10);
620
+ return adjustContrast(out, 10);
647
621
  }
648
622
  function sunset(data) {
649
- const out = cloneImageData(data);
650
- const d = out.data;
651
- for (let i = 0; i < d.length; i += 4) {
652
- d[i] = clamp(d[i] * 1.15 + 15);
653
- d[i + 1] = clamp(d[i + 1] * 0.85 + 5);
654
- d[i + 2] = clamp(d[i + 2] * 0.65 - 10);
655
- }
656
- return adjustContrast(out, 10);
623
+ const out = cloneImageData(data);
624
+ const d = out.data;
625
+ for (let i = 0; i < d.length; i += 4) {
626
+ d[i] = clamp(d[i] * 1.15 + 15);
627
+ d[i + 1] = clamp(d[i + 1] * 0.85 + 5);
628
+ d[i + 2] = clamp(d[i + 2] * 0.65 - 10);
629
+ }
630
+ return adjustContrast(out, 10);
657
631
  }
658
- // ── Convolution helper ──
659
632
  function convolve(data, kernel) {
660
- const out = cloneImageData(data);
661
- const d = out.data;
662
- const src = data.data;
663
- const w = data.width, h = data.height;
664
- const size = Math.sqrt(kernel.length) | 0;
665
- const half = size >> 1;
666
- for (let y = 0; y < h; y++) {
667
- for (let x = 0; x < w; x++) {
668
- let r = 0, g = 0, b = 0;
669
- for (let ky = 0; ky < size; ky++) {
670
- for (let kx = 0; kx < size; kx++) {
671
- const ny = Math.min(h - 1, Math.max(0, y + ky - half));
672
- const nx = Math.min(w - 1, Math.max(0, x + kx - half));
673
- const weight = kernel[ky * size + kx];
674
- const si = (ny * w + nx) * 4;
675
- r += src[si] * weight;
676
- g += src[si + 1] * weight;
677
- b += src[si + 2] * weight;
678
- }
679
- }
680
- const i = (y * w + x) * 4;
681
- d[i] = clamp(r);
682
- d[i + 1] = clamp(g);
683
- d[i + 2] = clamp(b);
633
+ const out = cloneImageData(data);
634
+ const d = out.data;
635
+ const src = data.data;
636
+ const w = data.width, h = data.height;
637
+ const size = Math.sqrt(kernel.length) | 0;
638
+ const half = size >> 1;
639
+ for (let y = 0; y < h; y++) {
640
+ for (let x = 0; x < w; x++) {
641
+ let r = 0, g = 0, b = 0;
642
+ for (let ky = 0; ky < size; ky++) {
643
+ for (let kx = 0; kx < size; kx++) {
644
+ const ny = Math.min(h - 1, Math.max(0, y + ky - half));
645
+ const nx = Math.min(w - 1, Math.max(0, x + kx - half));
646
+ const weight = kernel[ky * size + kx];
647
+ const si = (ny * w + nx) * 4;
648
+ r += src[si] * weight;
649
+ g += src[si + 1] * weight;
650
+ b += src[si + 2] * weight;
684
651
  }
685
- }
686
- return out;
652
+ }
653
+ const i = (y * w + x) * 4;
654
+ d[i] = clamp(r);
655
+ d[i + 1] = clamp(g);
656
+ d[i + 2] = clamp(b);
657
+ }
658
+ }
659
+ return out;
687
660
  }
688
661
  function boxBlur(data, radius) {
689
- const size = radius * 2 + 1;
690
- const weight = 1 / (size * size);
691
- const kernel = new Array(size * size).fill(weight);
692
- return convolve(data, kernel);
662
+ const size = radius * 2 + 1;
663
+ const weight = 1 / (size * size);
664
+ const kernel = new Array(size * size).fill(weight);
665
+ return convolve(data, kernel);
693
666
  }
694
667
  function hexToRgb(hex) {
695
- const h = hex.replace('#', '');
696
- return [
697
- parseInt(h.substring(0, 2), 16),
698
- parseInt(h.substring(2, 4), 16),
699
- parseInt(h.substring(4, 6), 16),
700
- ];
668
+ const h = hex.replace("#", "");
669
+ return [
670
+ parseInt(h.substring(0, 2), 16),
671
+ parseInt(h.substring(2, 4), 16),
672
+ parseInt(h.substring(4, 6), 16)
673
+ ];
701
674
  }
702
- // ── Canvas helpers for vignette & grain (applied via context) ──
703
675
  function applyVignette(ctx, w, h, amount) {
704
- if (amount <= 0) {
705
- return;
706
- }
707
- const cx = w / 2, cy = h / 2;
708
- const radius = Math.max(w, h) * 0.7;
709
- const grad = ctx.createRadialGradient(cx, cy, radius * 0.4, cx, cy, radius);
710
- grad.addColorStop(0, 'transparent');
711
- grad.addColorStop(1, `rgba(0,0,0,${(amount / 100) * 0.7})`);
712
- ctx.fillStyle = grad;
713
- ctx.fillRect(0, 0, w, h);
676
+ if (amount <= 0) {
677
+ return;
678
+ }
679
+ const cx = w / 2, cy = h / 2;
680
+ const radius = Math.max(w, h) * 0.7;
681
+ const grad = ctx.createRadialGradient(cx, cy, radius * 0.4, cx, cy, radius);
682
+ grad.addColorStop(0, "transparent");
683
+ grad.addColorStop(1, `rgba(0,0,0,${amount / 100 * 0.7})`);
684
+ ctx.fillStyle = grad;
685
+ ctx.fillRect(0, 0, w, h);
714
686
  }
715
687
  function applyGrain(ctx, w, h, amount) {
716
- if (amount <= 0) {
717
- return;
718
- }
719
- const imageData = ctx.getImageData(0, 0, w, h);
720
- const d = imageData.data;
721
- const intensity = (amount / 100) * 50;
722
- for (let i = 0; i < d.length; i += 4) {
723
- const noise = (Math.random() - 0.5) * intensity;
724
- d[i] = clamp(d[i] + noise);
725
- d[i + 1] = clamp(d[i + 1] + noise);
726
- d[i + 2] = clamp(d[i + 2] + noise);
727
- }
728
- ctx.putImageData(imageData, 0, 0);
688
+ if (amount <= 0) {
689
+ return;
690
+ }
691
+ const imageData = ctx.getImageData(0, 0, w, h);
692
+ const d = imageData.data;
693
+ const intensity = amount / 100 * 50;
694
+ for (let i = 0; i < d.length; i += 4) {
695
+ const noise = (Math.random() - 0.5) * intensity;
696
+ d[i] = clamp(d[i] + noise);
697
+ d[i + 1] = clamp(d[i + 1] + noise);
698
+ d[i + 2] = clamp(d[i + 2] + noise);
699
+ }
700
+ ctx.putImageData(imageData, 0, 0);
729
701
  }
730
- // ── Filter catalog ──
731
702
  const PHOTO_FILTERS = [
732
- // Color
733
- {
734
- id: 'none',
735
- name: 'Original',
736
- category: 'color',
737
- icon: 'square',
738
- apply: (d) => cloneImageData(d),
739
- },
740
- {
741
- id: 'grayscale',
742
- name: 'B&W',
743
- category: 'color',
744
- icon: 'circle',
745
- apply: (d, p) => { var _a; return blendIntensity(d, grayscale(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
746
- },
747
- {
748
- id: 'sepia',
749
- name: 'Sepia',
750
- category: 'color',
751
- icon: 'droplet',
752
- apply: (d, p) => { var _a; return blendIntensity(d, sepia(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
753
- },
754
- {
755
- id: 'invert',
756
- name: 'Negative',
757
- category: 'color',
758
- icon: 'refresh',
759
- apply: (d, p) => { var _a; return blendIntensity(d, invert(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
760
- },
761
- {
762
- id: 'duotone',
763
- name: 'Duotone',
764
- category: 'color',
765
- icon: 'palette',
766
- apply: (d, p) => { var _a; return blendIntensity(d, duotone(d, p), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
767
- },
768
- {
769
- id: 'channelShift',
770
- name: 'Channel Shift',
771
- category: 'color',
772
- icon: 'layers',
773
- apply: (d, p) => { var _a; return blendIntensity(d, channelShift(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
774
- },
775
- {
776
- id: 'threshold',
777
- name: 'Threshold',
778
- category: 'color',
779
- icon: 'hexagon',
780
- apply: (d, p) => { var _a; return blendIntensity(d, threshold(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
781
- },
782
- {
783
- id: 'pop',
784
- name: 'Pop',
785
- category: 'color',
786
- icon: 'zap',
787
- apply: (d, p) => { var _a; return blendIntensity(d, pop(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
788
- },
789
- // Light
790
- {
791
- id: 'dreamyGlow',
792
- name: 'Dreamy Glow',
793
- category: 'light',
794
- icon: 'wand',
795
- apply: (d, p) => { var _a; return blendIntensity(d, dreamyGlow(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
796
- },
797
- {
798
- id: 'lomoLeaks',
799
- name: 'Light Leaks',
800
- category: 'light',
801
- icon: 'sun',
802
- apply: (d, p) => { var _a; return blendIntensity(d, lomoLeaks(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
803
- },
804
- {
805
- id: 'fadeOut',
806
- name: 'Fade',
807
- category: 'light',
808
- icon: 'cloud',
809
- apply: (d, p) => { var _a; return blendIntensity(d, fadeOut(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
810
- },
811
- {
812
- id: 'golden',
813
- name: 'Golden',
814
- category: 'light',
815
- icon: 'star',
816
- apply: (d, p) => { var _a; return blendIntensity(d, golden(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
817
- },
818
- {
819
- id: 'sunset',
820
- name: 'Sunset',
821
- category: 'light',
822
- icon: 'mountain',
823
- apply: (d, p) => { var _a; return blendIntensity(d, sunset(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
824
- },
825
- {
826
- id: 'moody',
827
- name: 'Moody',
828
- category: 'light',
829
- icon: 'moon',
830
- apply: (d, p) => { var _a; return blendIntensity(d, moody(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
831
- },
832
- {
833
- id: 'arctic',
834
- name: 'Arctic',
835
- category: 'light',
836
- icon: 'thermometer',
837
- apply: (d, p) => { var _a; return blendIntensity(d, arctic(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
838
- },
839
- // Vintage
840
- {
841
- id: 'vintageFilm',
842
- name: 'Vintage Film',
843
- category: 'vintage',
844
- icon: 'video',
845
- apply: (d, p) => { var _a; return blendIntensity(d, vintageFilm(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
846
- },
847
- {
848
- id: 'kodachrome',
849
- name: 'Kodachrome',
850
- category: 'vintage',
851
- icon: 'camera',
852
- apply: (d, p) => { var _a; return blendIntensity(d, kodachrome(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
853
- },
854
- {
855
- id: 'polaroid',
856
- name: 'Polaroid',
857
- category: 'vintage',
858
- icon: 'image',
859
- apply: (d, p) => { var _a; return blendIntensity(d, polaroid(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
860
- },
861
- {
862
- id: 'technicolor',
863
- name: 'Technicolor',
864
- category: 'vintage',
865
- icon: 'play',
866
- apply: (d, p) => { var _a; return blendIntensity(d, technicolor(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
867
- },
868
- {
869
- id: 'brownie',
870
- name: 'Brownie',
871
- category: 'vintage',
872
- icon: 'box',
873
- apply: (d, p) => { var _a; return blendIntensity(d, brownie(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
874
- },
875
- {
876
- id: 'crossProcess',
877
- name: 'Cross Process',
878
- category: 'vintage',
879
- icon: 'flask',
880
- apply: (d, p) => { var _a; return blendIntensity(d, crossProcess(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
881
- },
882
- // Artistic
883
- {
884
- id: 'pencilSketch',
885
- name: 'Pencil sketch',
886
- category: 'artistic',
887
- icon: 'pen',
888
- apply: (d, p) => { var _a; return blendIntensity(d, pencilSketch(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
889
- },
890
- {
891
- id: 'oilPainting',
892
- name: 'Oil paint',
893
- category: 'artistic',
894
- icon: 'palette',
895
- apply: (d, p) => { var _a; return blendIntensity(d, oilPainting(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
896
- },
897
- {
898
- id: 'watercolor',
899
- name: 'Watercolor',
900
- category: 'artistic',
901
- icon: 'brush',
902
- apply: (d, p) => { var _a; return blendIntensity(d, watercolor(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
903
- },
904
- {
905
- id: 'comicBook',
906
- name: 'Comic book',
907
- category: 'artistic',
908
- icon: 'message',
909
- apply: (d, p) => { var _a; return blendIntensity(d, comicBook(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
910
- },
911
- {
912
- id: 'posterize',
913
- name: 'Poster',
914
- category: 'artistic',
915
- icon: 'layers',
916
- apply: (d, p) => { var _a; return blendIntensity(d, posterize(d, 5), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
917
- },
918
- {
919
- id: 'emboss',
920
- name: 'Emboss',
921
- category: 'artistic',
922
- icon: 'triangle',
923
- apply: (d, p) => { var _a; return blendIntensity(d, emboss(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
924
- },
925
- {
926
- id: 'edgeDetect',
927
- name: 'Edges',
928
- category: 'artistic',
929
- icon: 'search',
930
- apply: (d, p) => { var _a; return blendIntensity(d, edgeDetect(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
931
- },
932
- {
933
- id: 'tiltShift',
934
- name: 'Tilt Shift',
935
- category: 'artistic',
936
- icon: 'target',
937
- apply: (d, p) => { var _a; return blendIntensity(d, tiltShift(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
938
- },
939
- // Fun
940
- {
941
- id: 'cyberpunk',
942
- name: 'Cyberpunk',
943
- category: 'fun',
944
- icon: 'code',
945
- apply: (d, p) => { var _a; return blendIntensity(d, cyberpunk(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
946
- },
947
- {
948
- id: 'retroWave',
949
- name: 'Retrowave',
950
- category: 'fun',
951
- icon: 'gamepad',
952
- apply: (d, p) => { var _a; return blendIntensity(d, retroWave(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
953
- },
954
- {
955
- id: 'nightVision',
956
- name: 'Night Vision',
957
- category: 'fun',
958
- icon: 'eye',
959
- apply: (d, p) => { var _a; return blendIntensity(d, nightVision(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
960
- },
961
- {
962
- id: 'xRay',
963
- name: 'X-Ray',
964
- category: 'fun',
965
- icon: 'slash',
966
- apply: (d, p) => { var _a; return blendIntensity(d, xRay(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
967
- },
968
- {
969
- id: 'heatMap',
970
- name: 'Heat Map',
971
- category: 'fun',
972
- icon: 'thermometer',
973
- apply: (d, p) => { var _a; return blendIntensity(d, heatMap(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
974
- },
975
- {
976
- id: 'radioactive',
977
- name: 'Radioactive',
978
- category: 'fun',
979
- icon: 'warning',
980
- apply: (d, p) => { var _a; return blendIntensity(d, radioactive(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
981
- },
982
- {
983
- id: 'glitch',
984
- name: 'Glitch',
985
- category: 'fun',
986
- icon: 'monitor',
987
- apply: (d, p) => { var _a; return blendIntensity(d, glitch(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
988
- },
989
- {
990
- id: 'pixelate',
991
- name: 'Pixelate',
992
- category: 'fun',
993
- icon: 'grid',
994
- apply: (d, p) => { var _a; return blendIntensity(d, pixelate(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
995
- },
996
- {
997
- id: 'frostedGlass',
998
- name: 'Frosted glass',
999
- category: 'fun',
1000
- icon: 'box',
1001
- apply: (d, p) => { var _a; return blendIntensity(d, frostedGlass(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
1002
- },
1003
- {
1004
- id: 'solarize',
1005
- name: 'Solarize',
1006
- category: 'fun',
1007
- icon: 'sun',
1008
- apply: (d, p) => { var _a; return blendIntensity(d, solarize(d), (_a = p === null || p === void 0 ? void 0 : p.intensity) !== null && _a !== void 0 ? _a : 1); },
1009
- },
703
+ // Color
704
+ {
705
+ id: "none",
706
+ name: "Original",
707
+ category: "color",
708
+ icon: "square",
709
+ apply: (d) => cloneImageData(d)
710
+ },
711
+ {
712
+ id: "grayscale",
713
+ name: "B&W",
714
+ category: "color",
715
+ icon: "circle",
716
+ apply: (d, p) => blendIntensity(d, grayscale(d), p?.intensity ?? 1)
717
+ },
718
+ {
719
+ id: "sepia",
720
+ name: "Sepia",
721
+ category: "color",
722
+ icon: "droplet",
723
+ apply: (d, p) => blendIntensity(d, sepia(d), p?.intensity ?? 1)
724
+ },
725
+ {
726
+ id: "invert",
727
+ name: "Negative",
728
+ category: "color",
729
+ icon: "refresh",
730
+ apply: (d, p) => blendIntensity(d, invert(d), p?.intensity ?? 1)
731
+ },
732
+ {
733
+ id: "duotone",
734
+ name: "Duotone",
735
+ category: "color",
736
+ icon: "palette",
737
+ apply: (d, p) => blendIntensity(d, duotone(d, p), p?.intensity ?? 1)
738
+ },
739
+ {
740
+ id: "channelShift",
741
+ name: "Channel Shift",
742
+ category: "color",
743
+ icon: "layers",
744
+ apply: (d, p) => blendIntensity(d, channelShift(d), p?.intensity ?? 1)
745
+ },
746
+ {
747
+ id: "threshold",
748
+ name: "Threshold",
749
+ category: "color",
750
+ icon: "hexagon",
751
+ apply: (d, p) => blendIntensity(d, threshold(d), p?.intensity ?? 1)
752
+ },
753
+ {
754
+ id: "pop",
755
+ name: "Pop",
756
+ category: "color",
757
+ icon: "zap",
758
+ apply: (d, p) => blendIntensity(d, pop(d), p?.intensity ?? 1)
759
+ },
760
+ // Light
761
+ {
762
+ id: "dreamyGlow",
763
+ name: "Dreamy Glow",
764
+ category: "light",
765
+ icon: "wand",
766
+ apply: (d, p) => blendIntensity(d, dreamyGlow(d), p?.intensity ?? 1)
767
+ },
768
+ {
769
+ id: "lomoLeaks",
770
+ name: "Light Leaks",
771
+ category: "light",
772
+ icon: "sun",
773
+ apply: (d, p) => blendIntensity(d, lomoLeaks(d), p?.intensity ?? 1)
774
+ },
775
+ {
776
+ id: "fadeOut",
777
+ name: "Fade",
778
+ category: "light",
779
+ icon: "cloud",
780
+ apply: (d, p) => blendIntensity(d, fadeOut(d), p?.intensity ?? 1)
781
+ },
782
+ {
783
+ id: "golden",
784
+ name: "Golden",
785
+ category: "light",
786
+ icon: "star",
787
+ apply: (d, p) => blendIntensity(d, golden(d), p?.intensity ?? 1)
788
+ },
789
+ {
790
+ id: "sunset",
791
+ name: "Sunset",
792
+ category: "light",
793
+ icon: "mountain",
794
+ apply: (d, p) => blendIntensity(d, sunset(d), p?.intensity ?? 1)
795
+ },
796
+ {
797
+ id: "moody",
798
+ name: "Moody",
799
+ category: "light",
800
+ icon: "moon",
801
+ apply: (d, p) => blendIntensity(d, moody(d), p?.intensity ?? 1)
802
+ },
803
+ {
804
+ id: "arctic",
805
+ name: "Arctic",
806
+ category: "light",
807
+ icon: "thermometer",
808
+ apply: (d, p) => blendIntensity(d, arctic(d), p?.intensity ?? 1)
809
+ },
810
+ // Vintage
811
+ {
812
+ id: "vintageFilm",
813
+ name: "Vintage Film",
814
+ category: "vintage",
815
+ icon: "video",
816
+ apply: (d, p) => blendIntensity(d, vintageFilm(d), p?.intensity ?? 1)
817
+ },
818
+ {
819
+ id: "kodachrome",
820
+ name: "Kodachrome",
821
+ category: "vintage",
822
+ icon: "camera",
823
+ apply: (d, p) => blendIntensity(d, kodachrome(d), p?.intensity ?? 1)
824
+ },
825
+ {
826
+ id: "polaroid",
827
+ name: "Polaroid",
828
+ category: "vintage",
829
+ icon: "image",
830
+ apply: (d, p) => blendIntensity(d, polaroid(d), p?.intensity ?? 1)
831
+ },
832
+ {
833
+ id: "technicolor",
834
+ name: "Technicolor",
835
+ category: "vintage",
836
+ icon: "play",
837
+ apply: (d, p) => blendIntensity(d, technicolor(d), p?.intensity ?? 1)
838
+ },
839
+ {
840
+ id: "brownie",
841
+ name: "Brownie",
842
+ category: "vintage",
843
+ icon: "box",
844
+ apply: (d, p) => blendIntensity(d, brownie(d), p?.intensity ?? 1)
845
+ },
846
+ {
847
+ id: "crossProcess",
848
+ name: "Cross Process",
849
+ category: "vintage",
850
+ icon: "flask",
851
+ apply: (d, p) => blendIntensity(d, crossProcess(d), p?.intensity ?? 1)
852
+ },
853
+ // Artistic
854
+ {
855
+ id: "pencilSketch",
856
+ name: "Pencil sketch",
857
+ category: "artistic",
858
+ icon: "pen",
859
+ apply: (d, p) => blendIntensity(d, pencilSketch(d), p?.intensity ?? 1)
860
+ },
861
+ {
862
+ id: "oilPainting",
863
+ name: "Oil paint",
864
+ category: "artistic",
865
+ icon: "palette",
866
+ apply: (d, p) => blendIntensity(d, oilPainting(d), p?.intensity ?? 1)
867
+ },
868
+ {
869
+ id: "watercolor",
870
+ name: "Watercolor",
871
+ category: "artistic",
872
+ icon: "brush",
873
+ apply: (d, p) => blendIntensity(d, watercolor(d), p?.intensity ?? 1)
874
+ },
875
+ {
876
+ id: "comicBook",
877
+ name: "Comic book",
878
+ category: "artistic",
879
+ icon: "message",
880
+ apply: (d, p) => blendIntensity(d, comicBook(d), p?.intensity ?? 1)
881
+ },
882
+ {
883
+ id: "posterize",
884
+ name: "Poster",
885
+ category: "artistic",
886
+ icon: "layers",
887
+ apply: (d, p) => blendIntensity(d, posterize(d, 5), p?.intensity ?? 1)
888
+ },
889
+ {
890
+ id: "emboss",
891
+ name: "Emboss",
892
+ category: "artistic",
893
+ icon: "triangle",
894
+ apply: (d, p) => blendIntensity(d, emboss(d), p?.intensity ?? 1)
895
+ },
896
+ {
897
+ id: "edgeDetect",
898
+ name: "Edges",
899
+ category: "artistic",
900
+ icon: "search",
901
+ apply: (d, p) => blendIntensity(d, edgeDetect(d), p?.intensity ?? 1)
902
+ },
903
+ {
904
+ id: "tiltShift",
905
+ name: "Tilt Shift",
906
+ category: "artistic",
907
+ icon: "target",
908
+ apply: (d, p) => blendIntensity(d, tiltShift(d), p?.intensity ?? 1)
909
+ },
910
+ // Fun
911
+ {
912
+ id: "cyberpunk",
913
+ name: "Cyberpunk",
914
+ category: "fun",
915
+ icon: "code",
916
+ apply: (d, p) => blendIntensity(d, cyberpunk(d), p?.intensity ?? 1)
917
+ },
918
+ {
919
+ id: "retroWave",
920
+ name: "Retrowave",
921
+ category: "fun",
922
+ icon: "gamepad",
923
+ apply: (d, p) => blendIntensity(d, retroWave(d), p?.intensity ?? 1)
924
+ },
925
+ {
926
+ id: "nightVision",
927
+ name: "Night Vision",
928
+ category: "fun",
929
+ icon: "eye",
930
+ apply: (d, p) => blendIntensity(d, nightVision(d), p?.intensity ?? 1)
931
+ },
932
+ {
933
+ id: "xRay",
934
+ name: "X-Ray",
935
+ category: "fun",
936
+ icon: "slash",
937
+ apply: (d, p) => blendIntensity(d, xRay(d), p?.intensity ?? 1)
938
+ },
939
+ {
940
+ id: "heatMap",
941
+ name: "Heat Map",
942
+ category: "fun",
943
+ icon: "thermometer",
944
+ apply: (d, p) => blendIntensity(d, heatMap(d), p?.intensity ?? 1)
945
+ },
946
+ {
947
+ id: "radioactive",
948
+ name: "Radioactive",
949
+ category: "fun",
950
+ icon: "warning",
951
+ apply: (d, p) => blendIntensity(d, radioactive(d), p?.intensity ?? 1)
952
+ },
953
+ {
954
+ id: "glitch",
955
+ name: "Glitch",
956
+ category: "fun",
957
+ icon: "monitor",
958
+ apply: (d, p) => blendIntensity(d, glitch(d), p?.intensity ?? 1)
959
+ },
960
+ {
961
+ id: "pixelate",
962
+ name: "Pixelate",
963
+ category: "fun",
964
+ icon: "grid",
965
+ apply: (d, p) => blendIntensity(d, pixelate(d), p?.intensity ?? 1)
966
+ },
967
+ {
968
+ id: "frostedGlass",
969
+ name: "Frosted glass",
970
+ category: "fun",
971
+ icon: "box",
972
+ apply: (d, p) => blendIntensity(d, frostedGlass(d), p?.intensity ?? 1)
973
+ },
974
+ {
975
+ id: "solarize",
976
+ name: "Solarize",
977
+ category: "fun",
978
+ icon: "sun",
979
+ apply: (d, p) => blendIntensity(d, solarize(d), p?.intensity ?? 1)
980
+ }
1010
981
  ];
1011
- /** Get filter by ID */
1012
982
  function getFilter(id) {
1013
- return PHOTO_FILTERS.find((f) => f.id === id);
983
+ return PHOTO_FILTERS.find((f) => f.id === id);
1014
984
  }
1015
- /** Apply adjustments to ImageData */
1016
985
  function applyAdjustments(data, adj) {
1017
- let out = data;
1018
- if (adj.exposure && adj.exposure !== 0) {
1019
- out = adjustExposure(out, adj.exposure);
1020
- }
1021
- if (adj.brightness && adj.brightness !== 0) {
1022
- out = adjustBrightness(out, adj.brightness);
1023
- }
1024
- if (adj.contrast && adj.contrast !== 0) {
1025
- out = adjustContrast(out, adj.contrast);
1026
- }
1027
- if (adj.saturation && adj.saturation !== 0) {
1028
- out = adjustSaturation(out, adj.saturation);
1029
- }
1030
- if (adj.temperature && adj.temperature !== 0) {
1031
- out = adjustTemperature(out, adj.temperature);
1032
- }
1033
- if (adj.tint && adj.tint !== 0) {
1034
- out = adjustTint(out, adj.tint);
1035
- }
1036
- if (adj.highlights && adj.highlights !== 0) {
1037
- out = adjustHighlights(out, adj.highlights);
1038
- }
1039
- if (adj.shadows && adj.shadows !== 0) {
1040
- out = adjustShadows(out, adj.shadows);
1041
- }
1042
- if (adj.sharpness && adj.sharpness > 0) {
1043
- out = sharpen(out, adj.sharpness / 100);
1044
- }
1045
- return out;
986
+ let out = data;
987
+ if (adj.exposure && adj.exposure !== 0) {
988
+ out = adjustExposure(out, adj.exposure);
989
+ }
990
+ if (adj.brightness && adj.brightness !== 0) {
991
+ out = adjustBrightness(out, adj.brightness);
992
+ }
993
+ if (adj.contrast && adj.contrast !== 0) {
994
+ out = adjustContrast(out, adj.contrast);
995
+ }
996
+ if (adj.saturation && adj.saturation !== 0) {
997
+ out = adjustSaturation(out, adj.saturation);
998
+ }
999
+ if (adj.temperature && adj.temperature !== 0) {
1000
+ out = adjustTemperature(out, adj.temperature);
1001
+ }
1002
+ if (adj.tint && adj.tint !== 0) {
1003
+ out = adjustTint(out, adj.tint);
1004
+ }
1005
+ if (adj.highlights && adj.highlights !== 0) {
1006
+ out = adjustHighlights(out, adj.highlights);
1007
+ }
1008
+ if (adj.shadows && adj.shadows !== 0) {
1009
+ out = adjustShadows(out, adj.shadows);
1010
+ }
1011
+ if (adj.sharpness && adj.sharpness > 0) {
1012
+ out = sharpen(out, adj.sharpness / 100);
1013
+ }
1014
+ return out;
1046
1015
  }
1047
- /** Full pipeline: filter + adjustments → canvas, then vignette & grain via context */
1048
1016
  function renderToCanvas(canvas, sourceImage, filterId, filterParams, adjustments, cropRect, rotation, flipH, flipV) {
1049
- const ctx = canvas.getContext('2d', { willReadFrequently: true });
1050
- if (!ctx) {
1051
- return;
1052
- }
1053
- // Source dimensions
1054
- const sw = sourceImage.naturalWidth;
1055
- const sh = sourceImage.naturalHeight;
1056
- // Crop region (in source pixels)
1057
- const crop = cropRect !== null && cropRect !== void 0 ? cropRect : { x: 0, y: 0, w: sw, h: sh };
1058
- // Rotation affects output dimensions
1059
- const rot = (((rotation !== null && rotation !== void 0 ? rotation : 0) % 360) + 360) % 360;
1060
- const swapped = rot === 90 || rot === 270;
1061
- const outW = swapped ? crop.h : crop.w;
1062
- const outH = swapped ? crop.w : crop.h;
1063
- canvas.width = outW;
1064
- canvas.height = outH;
1065
- ctx.save();
1066
- ctx.translate(outW / 2, outH / 2);
1067
- if (rot) {
1068
- ctx.rotate((rot * Math.PI) / 180);
1069
- }
1070
- if (flipH) {
1071
- ctx.scale(-1, 1);
1072
- }
1073
- if (flipV) {
1074
- ctx.scale(1, -1);
1075
- }
1076
- ctx.drawImage(sourceImage, crop.x, crop.y, crop.w, crop.h, -crop.w / 2, -crop.h / 2, crop.w, crop.h);
1077
- ctx.restore();
1078
- // Apply filter
1079
- if (filterId && filterId !== 'none') {
1080
- const filter = getFilter(filterId);
1081
- if (filter) {
1082
- const imgData = ctx.getImageData(0, 0, outW, outH);
1083
- const filtered = filter.apply(imgData, filterParams);
1084
- ctx.putImageData(filtered, 0, 0);
1085
- }
1086
- }
1087
- // Apply adjustments
1088
- const hasAdj = Object.values(adjustments).some((v) => v !== 0 && v !== undefined);
1089
- if (hasAdj) {
1090
- const imgData = ctx.getImageData(0, 0, outW, outH);
1091
- const adjusted = applyAdjustments(imgData, adjustments);
1092
- ctx.putImageData(adjusted, 0, 0);
1093
- }
1094
- // Vignette & grain (applied via context drawing)
1095
- if (adjustments.vignette && adjustments.vignette > 0) {
1096
- applyVignette(ctx, outW, outH, adjustments.vignette);
1097
- }
1098
- if (adjustments.grain && adjustments.grain > 0) {
1099
- applyGrain(ctx, outW, outH, adjustments.grain);
1100
- }
1017
+ const ctx = canvas.getContext("2d", { willReadFrequently: true });
1018
+ if (!ctx) {
1019
+ return;
1020
+ }
1021
+ const sw = sourceImage.naturalWidth;
1022
+ const sh = sourceImage.naturalHeight;
1023
+ const crop = cropRect ?? { x: 0, y: 0, w: sw, h: sh };
1024
+ const rot = ((rotation ?? 0) % 360 + 360) % 360;
1025
+ const swapped = rot === 90 || rot === 270;
1026
+ const outW = swapped ? crop.h : crop.w;
1027
+ const outH = swapped ? crop.w : crop.h;
1028
+ canvas.width = outW;
1029
+ canvas.height = outH;
1030
+ ctx.save();
1031
+ ctx.translate(outW / 2, outH / 2);
1032
+ if (rot) {
1033
+ ctx.rotate(rot * Math.PI / 180);
1034
+ }
1035
+ if (flipH) {
1036
+ ctx.scale(-1, 1);
1037
+ }
1038
+ if (flipV) {
1039
+ ctx.scale(1, -1);
1040
+ }
1041
+ ctx.drawImage(
1042
+ sourceImage,
1043
+ crop.x,
1044
+ crop.y,
1045
+ crop.w,
1046
+ crop.h,
1047
+ -crop.w / 2,
1048
+ -crop.h / 2,
1049
+ crop.w,
1050
+ crop.h
1051
+ );
1052
+ ctx.restore();
1053
+ if (filterId && filterId !== "none") {
1054
+ const filter = getFilter(filterId);
1055
+ if (filter) {
1056
+ const imgData = ctx.getImageData(0, 0, outW, outH);
1057
+ const filtered = filter.apply(imgData, filterParams);
1058
+ ctx.putImageData(filtered, 0, 0);
1059
+ }
1060
+ }
1061
+ const hasAdj = Object.values(adjustments).some((v) => v !== 0 && v !== void 0);
1062
+ if (hasAdj) {
1063
+ const imgData = ctx.getImageData(0, 0, outW, outH);
1064
+ const adjusted = applyAdjustments(imgData, adjustments);
1065
+ ctx.putImageData(adjusted, 0, 0);
1066
+ }
1067
+ if (adjustments.vignette && adjustments.vignette > 0) {
1068
+ applyVignette(ctx, outW, outH, adjustments.vignette);
1069
+ }
1070
+ if (adjustments.grain && adjustments.grain > 0) {
1071
+ applyGrain(ctx, outW, outH, adjustments.grain);
1072
+ }
1101
1073
  }
1102
- /** Export canvas as File (for upload) */
1103
- function canvasToFile(canvas, filename = 'photo.jpg', quality = 0.92) {
1104
- return new Promise((resolve, reject) => {
1105
- canvas.toBlob((blob) => {
1106
- if (!blob) {
1107
- return reject(new Error('Canvas toBlob failed'));
1108
- }
1109
- resolve(new File([blob], filename, { type: 'image/jpeg' }));
1110
- }, 'image/jpeg', quality);
1111
- });
1074
+ function canvasToFile(canvas, filename = "photo.jpg", quality = 0.92) {
1075
+ return new Promise((resolve, reject) => {
1076
+ canvas.toBlob(
1077
+ (blob) => {
1078
+ if (!blob) {
1079
+ return reject(new Error("Canvas toBlob failed"));
1080
+ }
1081
+ resolve(new File([blob], filename, { type: "image/jpeg" }));
1082
+ },
1083
+ "image/jpeg",
1084
+ quality
1085
+ );
1086
+ });
1112
1087
  }
1113
-
1114
1088
  exports.DEFAULT_ADJUSTMENTS = DEFAULT_ADJUSTMENTS;
1115
1089
  exports.PHOTO_FILTERS = PHOTO_FILTERS;
1116
1090
  exports.applyAdjustments = applyAdjustments;