pixel-data-js 0.15.1 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.dev.cjs +1884 -1203
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +1858 -1190
- package/dist/index.dev.js.map +1 -1
- package/dist/index.prod.cjs +1884 -1203
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +320 -66
- package/dist/index.prod.js +1858 -1190
- package/dist/index.prod.js.map +1 -1
- package/package.json +1 -1
- package/src/BlendModes/BlendModeRegistry.ts +62 -0
- package/src/BlendModes/blend-modes-fast.ts +31 -84
- package/src/BlendModes/blend-modes-perfect.ts +343 -215
- package/src/BlendModes/blend-modes.ts +28 -30
- package/src/History/HistoryManager.ts +83 -0
- package/src/History/PixelAccumulator.ts +191 -0
- package/src/History/PixelEngineConfig.ts +18 -0
- package/src/History/PixelMutator/mutatorApplyMask.ts +20 -0
- package/src/History/PixelMutator/mutatorBlendColor.ts +22 -0
- package/src/History/PixelMutator/mutatorBlendPixel.ts +37 -0
- package/src/History/PixelMutator/mutatorBlendPixelData.ts +24 -0
- package/src/History/PixelMutator/mutatorFillPixelData.ts +21 -0
- package/src/History/PixelMutator/mutatorInvert.ts +18 -0
- package/src/History/PixelMutator.ts +18 -0
- package/src/History/PixelPatchTiles.ts +52 -0
- package/src/History/PixelWriter.ts +79 -0
- package/src/ImageData/{writeImageDataPixels.ts → writeImageDataBuffer.ts} +3 -3
- package/src/PixelData/applyCircleBrushToPixelData.ts +69 -0
- package/src/PixelData/applyMaskToPixelData.ts +1 -1
- package/src/PixelData/applyRectBrushToPixelData.ts +102 -0
- package/src/PixelData/blendPixelData.ts +2 -3
- package/src/PixelData/invertPixelData.ts +74 -7
- package/src/PixelData/writePixelDataBuffer.ts +65 -0
- package/src/_types.ts +31 -11
- package/src/index.ts +20 -10
- package/src/BlendModes/blend-mode-getters.ts +0 -14
package/package.json
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { BlendColor32 } from '../_types'
|
|
2
|
+
import type { BaseBlendModes } from './blend-modes'
|
|
3
|
+
|
|
4
|
+
export type BlendModeRegistry<
|
|
5
|
+
BlendModes extends BaseBlendModes = BaseBlendModes,
|
|
6
|
+
Name extends keyof BlendModes = keyof BlendModes,
|
|
7
|
+
Index extends BlendModes[Name] = BlendModes[Name]
|
|
8
|
+
> = ReturnType<typeof makeBlendModeRegistry<BlendModes, Name, Index>>
|
|
9
|
+
|
|
10
|
+
export function makeBlendModeRegistry<
|
|
11
|
+
BlendModes extends BaseBlendModes,
|
|
12
|
+
Name extends keyof BlendModes = keyof BlendModes,
|
|
13
|
+
Index extends BlendModes[Name] = BlendModes[Name]
|
|
14
|
+
|
|
15
|
+
>(
|
|
16
|
+
blendModes: BlendModes,
|
|
17
|
+
initialEntries: Record<Index, BlendColor32>,
|
|
18
|
+
) {
|
|
19
|
+
|
|
20
|
+
const blendToName = new Map<BlendColor32, Name>()
|
|
21
|
+
const blendToIndex = new Map<BlendColor32, Index>()
|
|
22
|
+
const indexToName: Name[] = []
|
|
23
|
+
const indexToBlend: BlendColor32[] = []
|
|
24
|
+
const nameToBlend = {} as { [K in keyof BlendModes]: BlendColor32 }
|
|
25
|
+
const nameToIndex = {} as Record<Name, Index>
|
|
26
|
+
|
|
27
|
+
const add = (name: Name, index: Index, blendFn: BlendColor32) => {
|
|
28
|
+
if (!Number.isFinite(index)) {
|
|
29
|
+
throw new Error(`Index "${index}" is not a number. Attempting to add name: "${name as string}", index: "${index}"`)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (indexToBlend[index]) {
|
|
33
|
+
throw new Error(`Blend Mode index: ${index} is already used. Attempting to add name: "${name as string}", index: "${index}"`)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
indexToName[index] = name
|
|
37
|
+
indexToBlend[index] = blendFn
|
|
38
|
+
blendToIndex.set(blendFn, index)
|
|
39
|
+
blendToName.set(blendFn, name)
|
|
40
|
+
nameToBlend[name] = blendFn
|
|
41
|
+
nameToIndex[name] = index
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
for (const [name, index] of Object.entries(blendModes)) {
|
|
45
|
+
const blend = initialEntries[index as Index]
|
|
46
|
+
add(name as Name, index as Index, blend)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
nameToBlend,
|
|
51
|
+
nameToIndex,
|
|
52
|
+
|
|
53
|
+
blendToIndex,
|
|
54
|
+
blendToName,
|
|
55
|
+
|
|
56
|
+
indexToBlend,
|
|
57
|
+
indexToName,
|
|
58
|
+
|
|
59
|
+
indexType: null as unknown as Index,
|
|
60
|
+
nameType: null as unknown as Name,
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BlendColor32, Color32 } from '../_types'
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import { BaseBlendMode, overwriteBase } from './blend-modes'
|
|
3
|
+
import { makeBlendModeRegistry } from './BlendModeRegistry'
|
|
4
4
|
|
|
5
5
|
export const overwriteFast = overwriteBase
|
|
6
6
|
|
|
@@ -575,88 +575,35 @@ export const divideFast: BlendColor32 = (src, dst) => {
|
|
|
575
575
|
return ((a << 24) | (b << 16) | (g << 8) | r) >>> 0 as Color32
|
|
576
576
|
}
|
|
577
577
|
|
|
578
|
-
export const
|
|
579
|
-
[
|
|
580
|
-
[
|
|
581
|
-
|
|
582
|
-
[
|
|
583
|
-
[
|
|
584
|
-
[
|
|
585
|
-
[
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
[
|
|
589
|
-
[
|
|
590
|
-
[
|
|
591
|
-
[
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
[
|
|
595
|
-
[
|
|
596
|
-
[
|
|
597
|
-
[
|
|
598
|
-
[
|
|
599
|
-
[
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
[
|
|
603
|
-
[
|
|
604
|
-
[
|
|
605
|
-
[BlendMode.divide, divideFast],
|
|
606
|
-
] as const
|
|
607
|
-
|
|
608
|
-
export type RegisteredFastBlender = typeof FAST_BLENDER_REGISTRY[number][1]
|
|
609
|
-
|
|
610
|
-
export const FAST_BLEND_MODES: BlendColor32[] = []
|
|
611
|
-
|
|
612
|
-
for (const [index, blend] of FAST_BLENDER_REGISTRY) {
|
|
613
|
-
FAST_BLEND_MODES[index as BlendModeIndex] = blend
|
|
578
|
+
export const BASE_FAST_BLEND_MODE_FUNCTIONS: Record<number, BlendColor32> = {
|
|
579
|
+
[BaseBlendMode.overwrite]: overwriteFast,
|
|
580
|
+
[BaseBlendMode.sourceOver]: sourceOverFast,
|
|
581
|
+
[BaseBlendMode.darken]: darkenFast,
|
|
582
|
+
[BaseBlendMode.multiply]: multiplyFast,
|
|
583
|
+
[BaseBlendMode.colorBurn]: colorBurnFast,
|
|
584
|
+
[BaseBlendMode.linearBurn]: linearBurnFast,
|
|
585
|
+
[BaseBlendMode.darkerColor]: darkerFast,
|
|
586
|
+
|
|
587
|
+
[BaseBlendMode.lighten]: lightenFast,
|
|
588
|
+
[BaseBlendMode.screen]: screenFast,
|
|
589
|
+
[BaseBlendMode.colorDodge]: colorDodgeFast,
|
|
590
|
+
[BaseBlendMode.linearDodge]: linearDodgeFast,
|
|
591
|
+
[BaseBlendMode.lighterColor]: lighterFast,
|
|
592
|
+
|
|
593
|
+
[BaseBlendMode.overlay]: overlayFast,
|
|
594
|
+
[BaseBlendMode.softLight]: softLightFast,
|
|
595
|
+
[BaseBlendMode.hardLight]: hardLightFast,
|
|
596
|
+
[BaseBlendMode.vividLight]: vividLightFast,
|
|
597
|
+
[BaseBlendMode.linearLight]: linearLightFast,
|
|
598
|
+
[BaseBlendMode.pinLight]: pinLightFast,
|
|
599
|
+
[BaseBlendMode.hardMix]: hardMixFast,
|
|
600
|
+
|
|
601
|
+
[BaseBlendMode.difference]: differenceFast,
|
|
602
|
+
[BaseBlendMode.exclusion]: exclusionFast,
|
|
603
|
+
[BaseBlendMode.subtract]: subtractFast,
|
|
604
|
+
[BaseBlendMode.divide]: divideFast,
|
|
614
605
|
}
|
|
615
606
|
|
|
616
|
-
export
|
|
617
|
-
|
|
618
|
-
return [
|
|
619
|
-
entry[1],
|
|
620
|
-
index as BlendModeIndex,
|
|
621
|
-
]
|
|
622
|
-
}),
|
|
623
|
-
) as BaseBlendToIndexGetter<RegisteredFastBlender>
|
|
624
|
-
|
|
625
|
-
export const INDEX_TO_FAST_BLEND = new Map<BlendModeIndex, RegisteredFastBlender>(
|
|
626
|
-
FAST_BLENDER_REGISTRY.map((entry, index) => {
|
|
627
|
-
return [
|
|
628
|
-
index as BlendModeIndex,
|
|
629
|
-
entry[1],
|
|
630
|
-
]
|
|
631
|
-
}),
|
|
632
|
-
) as BaseIndexToBlendGetter<RegisteredFastBlender>
|
|
633
|
-
|
|
634
|
-
export type FastBlendModes = {
|
|
635
|
-
[K in keyof typeof BlendMode]: RegisteredFastBlender
|
|
607
|
+
export function makeFastBlendModeRegistry() {
|
|
608
|
+
return makeBlendModeRegistry(BaseBlendMode, BASE_FAST_BLEND_MODE_FUNCTIONS)
|
|
636
609
|
}
|
|
637
|
-
|
|
638
|
-
export const FAST_BLEND_MODE_BY_NAME: FastBlendModes = {
|
|
639
|
-
overwrite: overwriteFast,
|
|
640
|
-
sourceOver: sourceOverFast,
|
|
641
|
-
darken: darkenFast,
|
|
642
|
-
multiply: multiplyFast,
|
|
643
|
-
colorBurn: colorBurnFast,
|
|
644
|
-
linearBurn: linearBurnFast,
|
|
645
|
-
darkerColor: darkerFast,
|
|
646
|
-
lighten: lightenFast,
|
|
647
|
-
screen: screenFast,
|
|
648
|
-
colorDodge: colorDodgeFast,
|
|
649
|
-
linearDodge: linearDodgeFast,
|
|
650
|
-
lighterColor: lighterFast,
|
|
651
|
-
overlay: overlayFast,
|
|
652
|
-
softLight: softLightFast,
|
|
653
|
-
hardLight: hardLightFast,
|
|
654
|
-
vividLight: vividLightFast,
|
|
655
|
-
linearLight: linearLightFast,
|
|
656
|
-
pinLight: pinLightFast,
|
|
657
|
-
hardMix: hardMixFast,
|
|
658
|
-
difference: differenceFast,
|
|
659
|
-
exclusion: exclusionFast,
|
|
660
|
-
subtract: subtractFast,
|
|
661
|
-
divide: divideFast,
|
|
662
|
-
} as const
|