pixel-data-js 0.3.0 → 0.5.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 +1405 -70
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +1355 -68
- package/dist/index.dev.js.map +1 -1
- package/dist/index.prod.cjs +1405 -70
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +581 -64
- package/dist/index.prod.js +1355 -68
- package/dist/index.prod.js.map +1 -1
- package/package.json +14 -3
- package/src/Algorithm/floodFillSelection.ts +229 -0
- package/src/Canvas/PixelCanvas.ts +31 -0
- package/src/Canvas/ReusableCanvas.ts +44 -0
- package/src/Canvas/_constants.ts +2 -0
- package/src/Clipboard/getImageDataFromClipboard.ts +42 -0
- package/src/Clipboard/writeImageDataToClipboard.ts +25 -0
- package/src/Clipboard/writeImgBlobToClipboard.ts +13 -0
- package/src/ImageData/{extractImageData.ts → extractImageDataPixels.ts} +21 -3
- package/src/ImageData/imageDataToAlphaMask.ts +35 -0
- package/src/ImageData/imageDataToDataUrl.ts +27 -0
- package/src/ImageData/imageDataToImgBlob.ts +31 -0
- package/src/ImageData/imgBlobToImageData.ts +52 -0
- package/src/ImageData/invertImageData.ts +10 -0
- package/src/ImageData/resizeImageData.ts +75 -0
- package/src/ImageData/{writeImageData.ts → writeImageDataPixels.ts} +22 -3
- package/src/Input/fileInputChangeToImageData.ts +37 -0
- package/src/Input/fileToImageData.ts +75 -0
- package/src/Input/getSupportedRasterFormats.ts +74 -0
- package/src/Mask/extractMask.ts +86 -0
- package/src/Mask/mergeMasks.ts +1 -6
- package/src/PixelData/blendColorPixelData.ts +9 -9
- package/src/PixelData/fillPixelData.ts +51 -12
- package/src/PixelData/invertPixelData.ts +16 -0
- package/src/PixelData/pixelDataToAlphaMask.ts +28 -0
- package/src/Rect/trimRectBounds.ts +118 -0
- package/src/_types.ts +37 -20
- package/src/blend-modes.ts +506 -66
- package/src/color.ts +6 -6
- package/src/globals.d.ts +2 -0
- package/src/index.ts +37 -1
package/src/_types.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { sourceOverColor32 } from './blend-modes'
|
|
2
|
+
|
|
1
3
|
/** ALL values are 0-255 (including alpha which in CSS is 0-1) */
|
|
2
4
|
export type RGBA = { r: number, g: number, b: number, a: number }
|
|
3
5
|
|
|
@@ -15,7 +17,7 @@ export type BlendColor32 = (src: Color32, dst: Color32) => Color32
|
|
|
15
17
|
export type ImageDataLike = {
|
|
16
18
|
width: number
|
|
17
19
|
height: number
|
|
18
|
-
data: Uint8ClampedArray<
|
|
20
|
+
data: Uint8ClampedArray<ArrayBufferLike>
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
export type SerializedImageData = {
|
|
@@ -64,23 +66,23 @@ export type AnyMask = BinaryMask | AlphaMask
|
|
|
64
66
|
export interface PixelOptions {
|
|
65
67
|
/**
|
|
66
68
|
* The starting X coordinate in the destination buffer.
|
|
67
|
-
* @
|
|
68
|
-
|
|
69
|
+
* @default 0
|
|
70
|
+
*/
|
|
69
71
|
x?: number
|
|
70
72
|
/**
|
|
71
73
|
* The starting Y coordinate in the destination buffer.
|
|
72
|
-
* @
|
|
73
|
-
|
|
74
|
+
* @default 0
|
|
75
|
+
*/
|
|
74
76
|
y?: number
|
|
75
77
|
/**
|
|
76
78
|
* The width of the region to process.
|
|
77
|
-
* @
|
|
78
|
-
|
|
79
|
+
* @default Source width.
|
|
80
|
+
*/
|
|
79
81
|
w?: number
|
|
80
82
|
/**
|
|
81
83
|
* The height of the region to process.
|
|
82
|
-
* @
|
|
83
|
-
|
|
84
|
+
* @default Source height.
|
|
85
|
+
*/
|
|
84
86
|
h?: number
|
|
85
87
|
|
|
86
88
|
/**
|
|
@@ -91,29 +93,34 @@ export interface PixelOptions {
|
|
|
91
93
|
|
|
92
94
|
/**
|
|
93
95
|
* Mask width.
|
|
94
|
-
* @default w
|
|
95
|
-
|
|
96
|
+
* @default value of `w`
|
|
97
|
+
*/
|
|
96
98
|
mw?: number
|
|
97
99
|
|
|
98
100
|
/**
|
|
99
101
|
* X offset into the mask buffer.
|
|
100
102
|
* @default 0
|
|
101
|
-
|
|
103
|
+
*/
|
|
102
104
|
mx?: number
|
|
103
105
|
|
|
104
106
|
/**
|
|
105
107
|
* Y offset into the mask buffer.
|
|
106
108
|
* @default 0
|
|
107
|
-
|
|
109
|
+
*/
|
|
108
110
|
my?: number
|
|
109
111
|
|
|
110
112
|
/** An optional mask to restrict where pixels are written. */
|
|
111
113
|
mask?: AnyMask | null
|
|
112
114
|
|
|
113
|
-
/** The interpretation logic for the provided mask.
|
|
115
|
+
/** The interpretation logic for the provided mask.
|
|
116
|
+
* @default {@link MaskType.BINARY}
|
|
117
|
+
*/
|
|
114
118
|
maskType?: MaskType
|
|
115
119
|
|
|
116
|
-
/**
|
|
120
|
+
/**
|
|
121
|
+
* If true the inverse of the mask will be applied
|
|
122
|
+
* @default false
|
|
123
|
+
*/
|
|
117
124
|
invertMask?: boolean
|
|
118
125
|
}
|
|
119
126
|
|
|
@@ -133,7 +140,10 @@ export interface PixelBlendOptions extends PixelOptions {
|
|
|
133
140
|
*/
|
|
134
141
|
sy?: number
|
|
135
142
|
|
|
136
|
-
/**
|
|
143
|
+
/**
|
|
144
|
+
* The blending algorithm to use for blending pixels.
|
|
145
|
+
* @default {@link sourceOverColor32}
|
|
146
|
+
*/
|
|
137
147
|
blendFn?: BlendColor32
|
|
138
148
|
}
|
|
139
149
|
|
|
@@ -141,12 +151,19 @@ export interface PixelBlendOptions extends PixelOptions {
|
|
|
141
151
|
* Configuration for operations that require color blending.
|
|
142
152
|
*/
|
|
143
153
|
export interface ColorBlendOptions extends PixelOptions {
|
|
144
|
-
/**
|
|
154
|
+
/**
|
|
155
|
+
* The blending algorithm to use for blending pixels.
|
|
156
|
+
* @default {@link sourceOverColor32}
|
|
157
|
+
*/
|
|
145
158
|
blendFn?: BlendColor32
|
|
146
159
|
}
|
|
147
160
|
|
|
148
161
|
export type ApplyMaskOptions = Omit<PixelOptions, 'mask'>
|
|
149
162
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
163
|
+
export type SelectionRect = Rect & ({
|
|
164
|
+
mask: Uint8Array,
|
|
165
|
+
maskType: MaskType,
|
|
166
|
+
} | {
|
|
167
|
+
mask?: null
|
|
168
|
+
maskType?: null,
|
|
169
|
+
})
|