@nice2dev/ui-graphics 1.3.15 → 1.3.16
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.
- package/CHANGELOG.md +9 -0
- package/dist/cjs/animation/AnimatedPerson.js +470 -143
- package/dist/cjs/animation/AnimationEditor.js +289 -101
- package/dist/cjs/animation/Audience.js +83 -61
- package/dist/cjs/animation/BodyRenderer.js +69 -28
- package/dist/cjs/animation/animationHelper.js +281 -288
- package/dist/cjs/animation/characterTypes.js +200 -203
- package/dist/cjs/animation/choreoDSL.js +205 -219
- package/dist/cjs/animation/choreography.js +4 -32
- package/dist/cjs/animation/karaokeIntegration.js +68 -77
- package/dist/cjs/animation/lottieExport.js +108 -114
- package/dist/cjs/animation/motionPath.js +225 -248
- package/dist/cjs/animation/physics.js +227 -254
- package/dist/cjs/animation/rig/RigPlayer.js +53 -56
- package/dist/cjs/animation/rig/RiggedBody.js +71 -26
- package/dist/cjs/animation/rig/choreoRigBridge.js +72 -77
- package/dist/cjs/animation/rig/ik.js +13 -18
- package/dist/cjs/animation/rig/poseOps.js +34 -41
- package/dist/cjs/animation/rig/presets.js +64 -72
- package/dist/cjs/animation/rig/rigMath.js +25 -32
- package/dist/cjs/animation/rig/rigTypes.js +59 -63
- package/dist/cjs/animation/shapes/arms.js +31 -13
- package/dist/cjs/animation/shapes/eyes.js +129 -47
- package/dist/cjs/animation/shapes/hair.js +72 -45
- package/dist/cjs/animation/shapes/heads.js +131 -57
- package/dist/cjs/animation/shapes/headwear.js +47 -38
- package/dist/cjs/animation/shapes/legs.js +31 -13
- package/dist/cjs/animation/shapes/mouths.js +120 -44
- package/dist/cjs/animation/shapes/noses.js +80 -25
- package/dist/cjs/animation/shapes/outfits.js +101 -39
- package/dist/cjs/animation/shapes/torsos.js +15 -11
- package/dist/cjs/animation/spineExport.js +103 -121
- package/dist/cjs/core/LocalUI.js +108 -43
- package/dist/cjs/core/NiceBrushEngine.js +758 -552
- package/dist/cjs/core/collaboration.js +249 -251
- package/dist/cjs/core/colorBlindness.js +100 -115
- package/dist/cjs/core/dragDrop.js +155 -158
- package/dist/cjs/core/editorAsk.js +51 -41
- package/dist/cjs/core/fixes.js +140 -171
- package/dist/cjs/core/gridGuides.js +166 -201
- package/dist/cjs/core/historyVisual.js +156 -135
- package/dist/cjs/core/i18n.js +13 -14
- package/dist/cjs/core/integrations.js +238 -249
- package/dist/cjs/core/minimap.js +149 -151
- package/dist/cjs/core/plugins.js +98 -113
- package/dist/cjs/core/rtl.js +71 -83
- package/dist/cjs/core/shortcuts.js +196 -225
- package/dist/cjs/core/theme.js +142 -149
- package/dist/cjs/core/yjsCollaboration.js +232 -293
- package/dist/cjs/design/design-tools.js +12 -22
- package/dist/cjs/font/NiceFontEditor.js +877 -316
- package/dist/cjs/font/fontFormatUtils.js +388 -448
- package/dist/cjs/game/GameAsset2dEditor.js +1201 -392
- package/dist/cjs/game/GameAsset2dEditor.module.css.js +146 -5
- package/dist/cjs/game/gameAssetTypes.js +7 -16
- package/dist/cjs/game/gameAssetUtils.js +390 -413
- package/dist/cjs/game/useGameAssetEditor.js +820 -763
- package/dist/cjs/index.js +81 -84
- package/dist/cjs/nice2dev-ui-graphics.css +1 -1
- package/dist/cjs/node_modules/lib0/array.js +8 -70
- package/dist/cjs/node_modules/lib0/binary.js +3 -20
- package/dist/cjs/node_modules/lib0/broadcastchannel.js +24 -86
- package/dist/cjs/node_modules/lib0/buffer.js +15 -82
- package/dist/cjs/node_modules/lib0/conditions.js +3 -16
- package/dist/cjs/node_modules/lib0/decoding.js +108 -287
- package/dist/cjs/node_modules/lib0/dom.js +14 -44
- package/dist/cjs/node_modules/lib0/encoding.js +68 -418
- package/dist/cjs/node_modules/lib0/environment.js +26 -92
- package/dist/cjs/node_modules/lib0/error.js +5 -29
- package/dist/cjs/node_modules/lib0/function.js +27 -66
- package/dist/cjs/node_modules/lib0/iterator.js +8 -33
- package/dist/cjs/node_modules/lib0/logging.common.js +12 -22
- package/dist/cjs/node_modules/lib0/logging.js +32 -71
- package/dist/cjs/node_modules/lib0/map.js +16 -86
- package/dist/cjs/node_modules/lib0/math.js +3 -32
- package/dist/cjs/node_modules/lib0/number.js +4 -15
- package/dist/cjs/node_modules/lib0/object.js +14 -88
- package/dist/cjs/node_modules/lib0/observable.js +38 -78
- package/dist/cjs/node_modules/lib0/pair.js +3 -20
- package/dist/cjs/node_modules/lib0/prng.js +8 -77
- package/dist/cjs/node_modules/lib0/promise.js +6 -30
- package/dist/cjs/node_modules/lib0/random.js +8 -23
- package/dist/cjs/node_modules/lib0/schema.js +313 -687
- package/dist/cjs/node_modules/lib0/set.js +3 -10
- package/dist/cjs/node_modules/lib0/storage.js +20 -55
- package/dist/cjs/node_modules/lib0/string.js +17 -72
- package/dist/cjs/node_modules/lib0/symbol.js +2 -12
- package/dist/cjs/node_modules/lib0/time.js +2 -15
- package/dist/cjs/node_modules/lib0/trait/equality.js +3 -28
- package/dist/cjs/node_modules/lib0/url.js +4 -18
- package/dist/cjs/node_modules/lib0/webcrypto.js +2 -5
- package/dist/cjs/node_modules/y-protocols/auth.js +5 -19
- package/dist/cjs/node_modules/y-protocols/awareness.js +53 -116
- package/dist/cjs/node_modules/y-protocols/sync.js +16 -103
- package/dist/cjs/node_modules/y-websocket/src/y-websocket.js +77 -219
- package/dist/cjs/node_modules/yjs/dist/yjs.js +2128 -4868
- package/dist/cjs/photo/FilterThumb.js +37 -25
- package/dist/cjs/photo/NiceAITools.js +679 -467
- package/dist/cjs/photo/PhotoEditor.js +34 -20
- package/dist/cjs/photo/PhotoEditor.module.css.js +296 -5
- package/dist/cjs/photo/PhotoEditorCanvas.js +250 -91
- package/dist/cjs/photo/PhotoEditorLeftPanel.js +1086 -224
- package/dist/cjs/photo/PhotoEditorToolbar.js +135 -19
- package/dist/cjs/photo/photoEditorActions.js +89 -72
- package/dist/cjs/photo/photoEditorTypes.js +29 -32
- package/dist/cjs/photo/photoFilters.js +959 -985
- package/dist/cjs/photo/photoOverlays.js +899 -945
- package/dist/cjs/photo/photoSelection.js +427 -499
- package/dist/cjs/photo/usePhotoEditor.js +739 -741
- package/dist/cjs/pixel/HSVPicker.js +191 -175
- package/dist/cjs/pixel/PixelEditor.js +159 -48
- package/dist/cjs/pixel/PixelEditor.module.css.js +209 -5
- package/dist/cjs/pixel/PixelEditorCanvas.js +29 -16
- package/dist/cjs/pixel/PixelEditorMenuBar.js +160 -162
- package/dist/cjs/pixel/PixelEditorRightPanel.js +377 -45
- package/dist/cjs/pixel/PixelEditorStatusBar.js +47 -20
- package/dist/cjs/pixel/PixelEditorTimeline.js +106 -23
- package/dist/cjs/pixel/PixelEditorToolbar.js +99 -21
- package/dist/cjs/pixel/SpriteGeneratorPanel.js +483 -303
- package/dist/cjs/pixel/animalGeneratorPresets.js +776 -601
- package/dist/cjs/pixel/asepriteFormat.js +511 -560
- package/dist/cjs/pixel/buildingGeneratorPresets.js +693 -520
- package/dist/cjs/pixel/characterGeneratorPresets.js +644 -544
- package/dist/cjs/pixel/pixel-pro.js +52 -63
- package/dist/cjs/pixel/pixelEditorExports.js +388 -428
- package/dist/cjs/pixel/pixelEditorTypes.js +91 -108
- package/dist/cjs/pixel/pixelEditorUtils.js +519 -561
- package/dist/cjs/pixel/spriteGeneratorCore.js +206 -257
- package/dist/cjs/pixel/usePixelEditor.js +1321 -1343
- package/dist/cjs/texture/Nice3DTexturePainter.js +707 -440
- package/dist/cjs/ui/NiceUIDesigner.js +954 -527
- package/dist/cjs/vector/NiceSvgToCode.js +586 -446
- package/dist/cjs/vector/VectorEditor.js +290 -117
- package/dist/cjs/vector/VectorEditor.module.css.js +86 -5
- package/dist/cjs/vector/VectorEditorMenuBar.js +333 -275
- package/dist/cjs/vector/VectorEditorRightPanel.js +1094 -371
- package/dist/cjs/vector/VectorEditorShapeRenderer.js +198 -60
- package/dist/cjs/vector/VectorEditorStatusBar.js +39 -13
- package/dist/cjs/vector/useVectorEditor.js +848 -889
- package/dist/cjs/vector/vectorAnimation.js +110 -137
- package/dist/cjs/vector/vectorBooleanOps.js +398 -485
- package/dist/cjs/vector/vectorEditorExport.js +201 -203
- package/dist/cjs/vector/vectorEditorImport.js +173 -189
- package/dist/cjs/vector/vectorEditorTypes.js +42 -49
- package/dist/cjs/vector/vectorGradients.js +151 -174
- package/dist/cjs/vector/vectorIconExport.js +52 -59
- package/dist/cjs/vector/vectorIconImport.js +169 -219
- package/dist/esm/animation/AnimatedPerson.js +470 -141
- package/dist/esm/animation/AnimationEditor.js +290 -100
- package/dist/esm/animation/Audience.js +83 -59
- package/dist/esm/animation/BodyRenderer.js +71 -25
- package/dist/esm/animation/animationHelper.js +284 -287
- package/dist/esm/animation/characterTypes.js +204 -202
- package/dist/esm/animation/choreoDSL.js +212 -218
- package/dist/esm/animation/choreography.js +8 -31
- package/dist/esm/animation/karaokeIntegration.js +74 -76
- package/dist/esm/animation/lottieExport.js +112 -113
- package/dist/esm/animation/motionPath.js +235 -247
- package/dist/esm/animation/physics.js +235 -253
- package/dist/esm/animation/rig/RigPlayer.js +53 -54
- package/dist/esm/animation/rig/RiggedBody.js +71 -24
- package/dist/esm/animation/rig/choreoRigBridge.js +74 -76
- package/dist/esm/animation/rig/ik.js +14 -17
- package/dist/esm/animation/rig/poseOps.js +37 -40
- package/dist/esm/animation/rig/presets.js +70 -71
- package/dist/esm/animation/rig/rigMath.js +28 -31
- package/dist/esm/animation/rig/rigTypes.js +62 -62
- package/dist/esm/animation/shapes/arms.js +32 -12
- package/dist/esm/animation/shapes/eyes.js +135 -46
- package/dist/esm/animation/shapes/hair.js +80 -44
- package/dist/esm/animation/shapes/heads.js +140 -56
- package/dist/esm/animation/shapes/headwear.js +54 -37
- package/dist/esm/animation/shapes/legs.js +32 -12
- package/dist/esm/animation/shapes/mouths.js +127 -43
- package/dist/esm/animation/shapes/noses.js +87 -24
- package/dist/esm/animation/shapes/outfits.js +106 -38
- package/dist/esm/animation/shapes/torsos.js +16 -10
- package/dist/esm/animation/spineExport.js +106 -120
- package/dist/esm/core/LocalUI.js +111 -42
- package/dist/esm/core/NiceBrushEngine.js +761 -551
- package/dist/esm/core/collaboration.js +255 -250
- package/dist/esm/core/colorBlindness.js +106 -114
- package/dist/esm/core/dragDrop.js +157 -157
- package/dist/esm/core/editorAsk.js +53 -40
- package/dist/esm/core/fixes.js +145 -170
- package/dist/esm/core/gridGuides.js +178 -200
- package/dist/esm/core/historyVisual.js +158 -134
- package/dist/esm/core/i18n.js +15 -13
- package/dist/esm/core/integrations.js +244 -248
- package/dist/esm/core/minimap.js +151 -150
- package/dist/esm/core/plugins.js +102 -112
- package/dist/esm/core/rtl.js +77 -82
- package/dist/esm/core/shortcuts.js +200 -224
- package/dist/esm/core/theme.js +150 -148
- package/dist/esm/core/yjsCollaboration.js +240 -292
- package/dist/esm/design/design-tools.js +13 -21
- package/dist/esm/font/NiceFontEditor.js +880 -315
- package/dist/esm/font/fontFormatUtils.js +394 -447
- package/dist/esm/game/GameAsset2dEditor.js +1202 -391
- package/dist/esm/game/GameAsset2dEditor.module.css.js +146 -3
- package/dist/esm/game/gameAssetTypes.js +8 -15
- package/dist/esm/game/gameAssetUtils.js +408 -412
- package/dist/esm/game/useGameAssetEditor.js +821 -762
- package/dist/esm/index.js +332 -69
- package/dist/esm/nice2dev-ui-graphics.css +1 -1
- package/dist/esm/node_modules/lib0/array.js +15 -69
- package/dist/esm/node_modules/lib0/binary.js +14 -19
- package/dist/esm/node_modules/lib0/broadcastchannel.js +27 -85
- package/dist/esm/node_modules/lib0/buffer.js +20 -80
- package/dist/esm/node_modules/lib0/conditions.js +4 -15
- package/dist/esm/node_modules/lib0/decoding.js +128 -286
- package/dist/esm/node_modules/lib0/dom.js +20 -43
- package/dist/esm/node_modules/lib0/encoding.js +90 -415
- package/dist/esm/node_modules/lib0/environment.js +33 -91
- package/dist/esm/node_modules/lib0/error.js +8 -28
- package/dist/esm/node_modules/lib0/function.js +31 -65
- package/dist/esm/node_modules/lib0/iterator.js +11 -32
- package/dist/esm/node_modules/lib0/logging.common.js +22 -21
- package/dist/esm/node_modules/lib0/logging.js +44 -70
- package/dist/esm/node_modules/lib0/map.js +21 -85
- package/dist/esm/node_modules/lib0/math.js +9 -31
- package/dist/esm/node_modules/lib0/number.js +7 -14
- package/dist/esm/node_modules/lib0/object.js +26 -87
- package/dist/esm/node_modules/lib0/observable.js +40 -77
- package/dist/esm/node_modules/lib0/pair.js +5 -19
- package/dist/esm/node_modules/lib0/prng.js +15 -76
- package/dist/esm/node_modules/lib0/promise.js +7 -29
- package/dist/esm/node_modules/lib0/random.js +10 -22
- package/dist/esm/node_modules/lib0/schema.js +367 -686
- package/dist/esm/node_modules/lib0/set.js +4 -9
- package/dist/esm/node_modules/lib0/storage.js +23 -54
- package/dist/esm/node_modules/lib0/string.js +26 -71
- package/dist/esm/node_modules/lib0/symbol.js +3 -11
- package/dist/esm/node_modules/lib0/time.js +3 -14
- package/dist/esm/node_modules/lib0/trait/equality.js +5 -27
- package/dist/esm/node_modules/lib0/url.js +5 -17
- package/dist/esm/node_modules/lib0/webcrypto.js +3 -4
- package/dist/esm/node_modules/y-protocols/auth.js +7 -18
- package/dist/esm/node_modules/y-protocols/awareness.js +58 -115
- package/dist/esm/node_modules/y-protocols/sync.js +26 -102
- package/dist/esm/node_modules/y-websocket/src/y-websocket.js +82 -218
- package/dist/esm/node_modules/yjs/dist/yjs.js +2263 -4899
- package/dist/esm/photo/FilterThumb.js +37 -23
- package/dist/esm/photo/NiceAITools.js +685 -466
- package/dist/esm/photo/PhotoEditor.js +34 -18
- package/dist/esm/photo/PhotoEditor.module.css.js +296 -3
- package/dist/esm/photo/PhotoEditorCanvas.js +250 -89
- package/dist/esm/photo/PhotoEditorLeftPanel.js +1086 -222
- package/dist/esm/photo/PhotoEditorToolbar.js +135 -17
- package/dist/esm/photo/photoEditorActions.js +93 -71
- package/dist/esm/photo/photoEditorTypes.js +32 -31
- package/dist/esm/photo/photoFilters.js +967 -984
- package/dist/esm/photo/photoOverlays.js +913 -944
- package/dist/esm/photo/photoSelection.js +438 -498
- package/dist/esm/photo/usePhotoEditor.js +740 -740
- package/dist/esm/pixel/HSVPicker.js +192 -174
- package/dist/esm/pixel/PixelEditor.js +160 -47
- package/dist/esm/pixel/PixelEditor.module.css.js +209 -3
- package/dist/esm/pixel/PixelEditorCanvas.js +29 -14
- package/dist/esm/pixel/PixelEditorMenuBar.js +160 -160
- package/dist/esm/pixel/PixelEditorRightPanel.js +377 -43
- package/dist/esm/pixel/PixelEditorStatusBar.js +47 -18
- package/dist/esm/pixel/PixelEditorTimeline.js +106 -21
- package/dist/esm/pixel/PixelEditorToolbar.js +99 -19
- package/dist/esm/pixel/SpriteGeneratorPanel.js +483 -301
- package/dist/esm/pixel/animalGeneratorPresets.js +782 -600
- package/dist/esm/pixel/asepriteFormat.js +517 -559
- package/dist/esm/pixel/buildingGeneratorPresets.js +699 -519
- package/dist/esm/pixel/characterGeneratorPresets.js +650 -543
- package/dist/esm/pixel/pixel-pro.js +53 -62
- package/dist/esm/pixel/pixelEditorExports.js +397 -427
- package/dist/esm/pixel/pixelEditorTypes.js +103 -107
- package/dist/esm/pixel/pixelEditorUtils.js +551 -560
- package/dist/esm/pixel/spriteGeneratorCore.js +223 -256
- package/dist/esm/pixel/usePixelEditor.js +1322 -1342
- package/dist/esm/texture/Nice3DTexturePainter.js +709 -439
- package/dist/esm/ui/NiceUIDesigner.js +957 -526
- package/dist/esm/vector/NiceSvgToCode.js +589 -445
- package/dist/esm/vector/VectorEditor.js +291 -116
- package/dist/esm/vector/VectorEditor.module.css.js +86 -3
- package/dist/esm/vector/VectorEditorMenuBar.js +333 -273
- package/dist/esm/vector/VectorEditorRightPanel.js +1094 -369
- package/dist/esm/vector/VectorEditorShapeRenderer.js +199 -59
- package/dist/esm/vector/VectorEditorStatusBar.js +39 -11
- package/dist/esm/vector/useVectorEditor.js +849 -888
- package/dist/esm/vector/vectorAnimation.js +115 -136
- package/dist/esm/vector/vectorBooleanOps.js +401 -484
- package/dist/esm/vector/vectorEditorExport.js +207 -202
- package/dist/esm/vector/vectorEditorImport.js +174 -188
- package/dist/esm/vector/vectorEditorTypes.js +50 -48
- package/dist/esm/vector/vectorGradients.js +158 -173
- package/dist/esm/vector/vectorIconExport.js +53 -58
- package/dist/esm/vector/vectorIconImport.js +171 -218
- package/package.json +9 -15
|
@@ -1,1116 +1,1090 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
18
|
+
return v < 0 ? 0 : v > 255 ? 255 : v | 0;
|
|
27
19
|
}
|
|
28
20
|
function lerpColor(a, b, t) {
|
|
29
|
-
|
|
21
|
+
return clamp(a + (b - a) * t);
|
|
30
22
|
}
|
|
31
|
-
/** Create a working copy of ImageData */
|
|
32
23
|
function cloneImageData(src) {
|
|
33
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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
|
-
|
|
299
|
+
return convolve(data, [-2, -1, 0, -1, 1, 1, 0, 1, 2]);
|
|
313
300
|
}
|
|
314
301
|
function edgeDetect(data) {
|
|
315
|
-
|
|
302
|
+
return convolve(data, [-1, -1, -1, -1, 8, -1, -1, -1, -1]);
|
|
316
303
|
}
|
|
317
304
|
function sharpen(data, amount = 1) {
|
|
318
|
-
|
|
319
|
-
|
|
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
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
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
|
-
|
|
377
|
-
|
|
378
|
-
|
|
359
|
+
let out = invert(data);
|
|
360
|
+
out = grayscale(out);
|
|
361
|
+
return adjustContrast(out, 40);
|
|
379
362
|
}
|
|
380
363
|
function crossProcess(data) {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
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
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
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
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
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
|
-
|
|
443
|
+
}
|
|
444
|
+
return out;
|
|
466
445
|
}
|
|
467
446
|
function oilPainting(data, radius = 3) {
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
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
|
-
|
|
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
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
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
|
-
|
|
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
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
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
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
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
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
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
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
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
|
-
|
|
612
|
-
|
|
613
|
-
|
|
585
|
+
let out = adjustSaturation(data, 50);
|
|
586
|
+
out = adjustContrast(out, 20);
|
|
587
|
+
return adjustBrightness(out, 5);
|
|
614
588
|
}
|
|
615
589
|
function moody(data) {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
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
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
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
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
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
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
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
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
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
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
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
|
-
|
|
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
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
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
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
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
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
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
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
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
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
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
|
-
|
|
983
|
+
return PHOTO_FILTERS.find((f) => f.id === id);
|
|
1014
984
|
}
|
|
1015
|
-
/** Apply adjustments to ImageData */
|
|
1016
985
|
function applyAdjustments(data, adj) {
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
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
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
ctx.
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
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
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
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;
|