pixel-data-js 0.9.0 → 0.9.2
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 +98 -0
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +94 -0
- package/dist/index.dev.js.map +1 -1
- package/dist/index.prod.cjs +98 -0
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +37 -19
- package/dist/index.prod.js +94 -0
- package/dist/index.prod.js.map +1 -1
- package/package.json +3 -2
- package/src/BlendModes/blend-mode-getters.ts +14 -0
- package/src/BlendModes/blend-modes-fast.ts +9 -13
- package/src/BlendModes/blend-modes-perfect.ts +7 -7
- package/src/BlendModes/blend-modes.ts +3 -0
- package/src/IndexedImage/getIndexedImageColorCounts.ts +20 -0
- package/src/_types.ts +6 -0
- package/src/index.ts +12 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pixel-data-js",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.2",
|
|
5
5
|
"packageManager": "pnpm@10.30.0",
|
|
6
6
|
"description": "JS Pixel and ImageData operations",
|
|
7
7
|
"author": {
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"image",
|
|
17
17
|
"color",
|
|
18
18
|
"blend modes",
|
|
19
|
-
"color blend"
|
|
19
|
+
"color blend",
|
|
20
|
+
"canvas"
|
|
20
21
|
],
|
|
21
22
|
"main": "./dist/index.prod.cjs",
|
|
22
23
|
"module": "./dist/index.prod.js",
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BlendColor32 } from '../_types'
|
|
2
|
+
import type { BlendModeIndex } from './blend-modes'
|
|
3
|
+
import { FAST_BLEND_TO_INDEX, INDEX_TO_FAST_BLEND } from './blend-modes-fast'
|
|
4
|
+
import { type INDEX_TO_PERFECT_BLEND, PERFECT_BLEND_TO_INDEX } from './blend-modes-perfect'
|
|
5
|
+
|
|
6
|
+
export type BaseIndexToBlendGetter<B extends BlendColor32> = {
|
|
7
|
+
get: (index: BlendModeIndex) => B
|
|
8
|
+
}
|
|
9
|
+
export type IndexToBlendGetter = typeof INDEX_TO_FAST_BLEND | typeof INDEX_TO_PERFECT_BLEND
|
|
10
|
+
|
|
11
|
+
export type BaseBlendToIndexGetter<B extends BlendColor32> = {
|
|
12
|
+
get: (blend: B) => BlendModeIndex
|
|
13
|
+
}
|
|
14
|
+
export type BlendToIndexGetter = typeof FAST_BLEND_TO_INDEX | typeof PERFECT_BLEND_TO_INDEX
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { BlendColor32, Color32 } from '../_types'
|
|
2
|
-
import {
|
|
2
|
+
import type { BaseBlendToIndexGetter, BaseIndexToBlendGetter } from './blend-mode-getters'
|
|
3
|
+
import { BlendMode, type BlendModeIndex } from './blend-modes'
|
|
3
4
|
|
|
4
5
|
export const overwriteFast: BlendColor32 = (src, _dst) => src
|
|
5
6
|
|
|
@@ -605,35 +606,30 @@ export const FAST_BLENDER_REGISTRY = [
|
|
|
605
606
|
] as const
|
|
606
607
|
|
|
607
608
|
export type RegisteredFastBlender = typeof FAST_BLENDER_REGISTRY[number][1]
|
|
608
|
-
export type FastBlendModeIndex = number & { readonly __brandBlendModeIndex: unique symbol }
|
|
609
609
|
|
|
610
610
|
export const FAST_BLEND_MODES: BlendColor32[] = []
|
|
611
611
|
|
|
612
612
|
for (const [index, blend] of FAST_BLENDER_REGISTRY) {
|
|
613
|
-
FAST_BLEND_MODES[index as
|
|
613
|
+
FAST_BLEND_MODES[index as BlendModeIndex] = blend
|
|
614
614
|
}
|
|
615
615
|
|
|
616
|
-
export const FAST_BLEND_TO_INDEX = new Map<RegisteredFastBlender,
|
|
616
|
+
export const FAST_BLEND_TO_INDEX = new Map<RegisteredFastBlender, BlendModeIndex>(
|
|
617
617
|
FAST_BLENDER_REGISTRY.map((entry, index) => {
|
|
618
618
|
return [
|
|
619
619
|
entry[1],
|
|
620
|
-
index as
|
|
620
|
+
index as BlendModeIndex,
|
|
621
621
|
]
|
|
622
622
|
}),
|
|
623
|
-
) as
|
|
624
|
-
get: (blend: RegisteredFastBlender) => FastBlendModeIndex
|
|
625
|
-
}
|
|
623
|
+
) as BaseBlendToIndexGetter<RegisteredFastBlender>
|
|
626
624
|
|
|
627
|
-
export const INDEX_TO_FAST_BLEND = new Map<
|
|
625
|
+
export const INDEX_TO_FAST_BLEND = new Map<BlendModeIndex, RegisteredFastBlender>(
|
|
628
626
|
FAST_BLENDER_REGISTRY.map((entry, index) => {
|
|
629
627
|
return [
|
|
630
|
-
index as
|
|
628
|
+
index as BlendModeIndex,
|
|
631
629
|
entry[1],
|
|
632
630
|
]
|
|
633
631
|
}),
|
|
634
|
-
) as
|
|
635
|
-
get: (index: FastBlendModeIndex) => RegisteredFastBlender
|
|
636
|
-
}
|
|
632
|
+
) as BaseIndexToBlendGetter<RegisteredFastBlender>
|
|
637
633
|
|
|
638
634
|
export type FastBlendModes = {
|
|
639
635
|
[K in keyof typeof BlendMode]: RegisteredFastBlender
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { BlendColor32, Color32 } from '../_types'
|
|
2
|
-
import {
|
|
2
|
+
import type { BaseBlendToIndexGetter, BaseIndexToBlendGetter } from './blend-mode-getters'
|
|
3
|
+
import { BlendMode, type BlendModeIndex } from './blend-modes'
|
|
3
4
|
|
|
4
5
|
export const overwritePerfect: BlendColor32 = (src, _dst) => src
|
|
5
6
|
|
|
@@ -595,30 +596,29 @@ export const PERFECT_BLENDER_REGISTRY = [
|
|
|
595
596
|
] as const
|
|
596
597
|
|
|
597
598
|
export type RegisteredPerfectBlender = typeof PERFECT_BLENDER_REGISTRY[number][1]
|
|
598
|
-
export type PerfectBlendModeIndex = number & { readonly __brandBlendModeIndex: unique symbol }
|
|
599
599
|
|
|
600
600
|
export const PERFECT_BLEND_MODES: BlendColor32[] = []
|
|
601
601
|
for (const [index, blend] of PERFECT_BLENDER_REGISTRY) {
|
|
602
|
-
PERFECT_BLEND_MODES[index as
|
|
602
|
+
PERFECT_BLEND_MODES[index as BlendModeIndex] = blend
|
|
603
603
|
}
|
|
604
604
|
|
|
605
605
|
export const PERFECT_BLEND_TO_INDEX = new Map(
|
|
606
606
|
PERFECT_BLENDER_REGISTRY.map((entry, index) => {
|
|
607
607
|
return [
|
|
608
608
|
entry[1],
|
|
609
|
-
index as
|
|
609
|
+
index as BlendModeIndex,
|
|
610
610
|
]
|
|
611
611
|
}),
|
|
612
|
-
) as
|
|
612
|
+
) as BaseBlendToIndexGetter<RegisteredPerfectBlender>
|
|
613
613
|
|
|
614
614
|
export const INDEX_TO_PERFECT_BLEND = new Map(
|
|
615
615
|
PERFECT_BLENDER_REGISTRY.map((entry, index) => {
|
|
616
616
|
return [
|
|
617
|
-
index as
|
|
617
|
+
index as BlendModeIndex,
|
|
618
618
|
entry[1],
|
|
619
619
|
]
|
|
620
620
|
}),
|
|
621
|
-
) as
|
|
621
|
+
) as BaseIndexToBlendGetter<RegisteredPerfectBlender>
|
|
622
622
|
|
|
623
623
|
export type PerfectBlendModes = {
|
|
624
624
|
[K in keyof typeof BlendMode]: RegisteredPerfectBlender
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { IndexedImage } from './IndexedImage.ts'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Calculates the frequency of each palette index based on the image data.
|
|
5
|
+
* The index of the returned array maps directly to the index of the palette.
|
|
6
|
+
* @param indexedImage - The source image containing data and palette definitions.
|
|
7
|
+
* @returns A typed array where each entry represents the total count of that palette index.
|
|
8
|
+
*/
|
|
9
|
+
export function getIndexedImageColorCounts(indexedImage: IndexedImage): Int32Array {
|
|
10
|
+
const data = indexedImage.data
|
|
11
|
+
const palette = indexedImage.palette
|
|
12
|
+
const frequencies = new Int32Array(palette.length)
|
|
13
|
+
|
|
14
|
+
for (let i = 0; i < data.length; i++) {
|
|
15
|
+
const colorIndex = data[i]!
|
|
16
|
+
frequencies[colorIndex]++
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return frequencies
|
|
20
|
+
}
|
package/src/_types.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -3,7 +3,15 @@ export * from './color'
|
|
|
3
3
|
|
|
4
4
|
export * from './Algorithm/floodFillSelection'
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export {
|
|
7
|
+
BlendMode,
|
|
8
|
+
type BlendModeIndex,
|
|
9
|
+
} from './BlendModes/blend-modes'
|
|
10
|
+
export {
|
|
11
|
+
type BlendToIndexGetter,
|
|
12
|
+
type IndexToBlendGetter,
|
|
13
|
+
} from './BlendModes/blend-mode-getters'
|
|
14
|
+
|
|
7
15
|
export * from './BlendModes/blend-modes-fast'
|
|
8
16
|
export * from './BlendModes/blend-modes-perfect'
|
|
9
17
|
|
|
@@ -27,6 +35,7 @@ export * from './ImageData/writeImageDataPixels'
|
|
|
27
35
|
|
|
28
36
|
export * from './IndexedImage/IndexedImage'
|
|
29
37
|
export * from './IndexedImage/indexedImageToAverageColor'
|
|
38
|
+
export * from './IndexedImage/getIndexedImageColorCounts'
|
|
30
39
|
|
|
31
40
|
export * from './Input/fileInputChangeToImageData'
|
|
32
41
|
export * from './Input/fileToImageData'
|
|
@@ -45,6 +54,7 @@ export * from './PixelData/clearPixelData'
|
|
|
45
54
|
export * from './PixelData/fillPixelData'
|
|
46
55
|
export * from './PixelData/invertPixelData'
|
|
47
56
|
export * from './PixelData/pixelDataToAlphaMask'
|
|
57
|
+
export * from './PixelData/reflectPixelData'
|
|
58
|
+
export * from './PixelData/rotatePixelData'
|
|
48
59
|
|
|
49
60
|
export * from './Rect/trimRectBounds'
|
|
50
|
-
export { BlendMode } from './BlendModes/blend-modes'
|