pixel-data-js 0.9.0 → 0.9.1
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 +84 -0
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +81 -0
- package/dist/index.dev.js.map +1 -1
- package/dist/index.prod.cjs +84 -0
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +29 -19
- package/dist/index.prod.js +81 -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 +11 -2
package/dist/index.prod.d.ts
CHANGED
|
@@ -155,6 +155,10 @@ type SelectionRect = Rect & ({
|
|
|
155
155
|
mask?: null;
|
|
156
156
|
maskType?: null;
|
|
157
157
|
});
|
|
158
|
+
type Point = {
|
|
159
|
+
x: number;
|
|
160
|
+
y: number;
|
|
161
|
+
};
|
|
158
162
|
|
|
159
163
|
/**
|
|
160
164
|
* Packs RGBA into a 32-bit integer compatible with
|
|
@@ -276,6 +280,7 @@ declare enum BlendMode {
|
|
|
276
280
|
subtract = 21,
|
|
277
281
|
divide = 22
|
|
278
282
|
}
|
|
283
|
+
type BlendModeIndex = typeof BlendMode[keyof typeof BlendMode];
|
|
279
284
|
|
|
280
285
|
declare const overwriteFast: BlendColor32;
|
|
281
286
|
declare const sourceOverFast: BlendColor32;
|
|
@@ -325,16 +330,9 @@ declare const subtractFast: BlendColor32;
|
|
|
325
330
|
declare const divideFast: BlendColor32;
|
|
326
331
|
declare const FAST_BLENDER_REGISTRY: readonly [readonly [BlendMode.overwrite, BlendColor32], readonly [BlendMode.sourceOver, BlendColor32], readonly [BlendMode.darken, BlendColor32], readonly [BlendMode.multiply, BlendColor32], readonly [BlendMode.colorBurn, BlendColor32], readonly [BlendMode.linearBurn, BlendColor32], readonly [BlendMode.darkerColor, BlendColor32], readonly [BlendMode.lighten, BlendColor32], readonly [BlendMode.screen, BlendColor32], readonly [BlendMode.colorDodge, BlendColor32], readonly [BlendMode.linearDodge, BlendColor32], readonly [BlendMode.lighterColor, BlendColor32], readonly [BlendMode.overlay, BlendColor32], readonly [BlendMode.softLight, BlendColor32], readonly [BlendMode.hardLight, BlendColor32], readonly [BlendMode.vividLight, BlendColor32], readonly [BlendMode.linearLight, BlendColor32], readonly [BlendMode.pinLight, BlendColor32], readonly [BlendMode.hardMix, BlendColor32], readonly [BlendMode.difference, BlendColor32], readonly [BlendMode.exclusion, BlendColor32], readonly [BlendMode.subtract, BlendColor32], readonly [BlendMode.divide, BlendColor32]];
|
|
327
332
|
type RegisteredFastBlender = typeof FAST_BLENDER_REGISTRY[number][1];
|
|
328
|
-
type FastBlendModeIndex = number & {
|
|
329
|
-
readonly __brandBlendModeIndex: unique symbol;
|
|
330
|
-
};
|
|
331
333
|
declare const FAST_BLEND_MODES: BlendColor32[];
|
|
332
|
-
declare const FAST_BLEND_TO_INDEX:
|
|
333
|
-
|
|
334
|
-
};
|
|
335
|
-
declare const INDEX_TO_FAST_BLEND: {
|
|
336
|
-
get: (index: FastBlendModeIndex) => RegisteredFastBlender;
|
|
337
|
-
};
|
|
334
|
+
declare const FAST_BLEND_TO_INDEX: BaseBlendToIndexGetter<RegisteredFastBlender>;
|
|
335
|
+
declare const INDEX_TO_FAST_BLEND: BaseIndexToBlendGetter<RegisteredFastBlender>;
|
|
338
336
|
type FastBlendModes = {
|
|
339
337
|
[K in keyof typeof BlendMode]: RegisteredFastBlender;
|
|
340
338
|
};
|
|
@@ -388,21 +386,23 @@ declare const subtractPerfect: BlendColor32;
|
|
|
388
386
|
declare const dividePerfect: BlendColor32;
|
|
389
387
|
declare const PERFECT_BLENDER_REGISTRY: readonly [readonly [BlendMode.overwrite, BlendColor32], readonly [BlendMode.sourceOver, BlendColor32], readonly [BlendMode.darken, BlendColor32], readonly [BlendMode.multiply, BlendColor32], readonly [BlendMode.colorBurn, BlendColor32], readonly [BlendMode.linearBurn, BlendColor32], readonly [BlendMode.darkerColor, BlendColor32], readonly [BlendMode.lighten, BlendColor32], readonly [BlendMode.screen, BlendColor32], readonly [BlendMode.colorDodge, BlendColor32], readonly [BlendMode.linearDodge, BlendColor32], readonly [BlendMode.lighterColor, BlendColor32], readonly [BlendMode.overlay, BlendColor32], readonly [BlendMode.softLight, BlendColor32], readonly [BlendMode.hardLight, BlendColor32], readonly [BlendMode.vividLight, BlendColor32], readonly [BlendMode.linearLight, BlendColor32], readonly [BlendMode.pinLight, BlendColor32], readonly [BlendMode.hardMix, BlendColor32], readonly [BlendMode.difference, BlendColor32], readonly [BlendMode.exclusion, BlendColor32], readonly [BlendMode.subtract, BlendColor32], readonly [BlendMode.divide, BlendColor32]];
|
|
390
388
|
type RegisteredPerfectBlender = typeof PERFECT_BLENDER_REGISTRY[number][1];
|
|
391
|
-
type PerfectBlendModeIndex = number & {
|
|
392
|
-
readonly __brandBlendModeIndex: unique symbol;
|
|
393
|
-
};
|
|
394
389
|
declare const PERFECT_BLEND_MODES: BlendColor32[];
|
|
395
|
-
declare const PERFECT_BLEND_TO_INDEX:
|
|
396
|
-
|
|
397
|
-
};
|
|
398
|
-
declare const INDEX_TO_PERFECT_BLEND: {
|
|
399
|
-
get: (index: PerfectBlendModeIndex) => RegisteredPerfectBlender;
|
|
400
|
-
};
|
|
390
|
+
declare const PERFECT_BLEND_TO_INDEX: BaseBlendToIndexGetter<RegisteredPerfectBlender>;
|
|
391
|
+
declare const INDEX_TO_PERFECT_BLEND: BaseIndexToBlendGetter<RegisteredPerfectBlender>;
|
|
401
392
|
type PerfectBlendModes = {
|
|
402
393
|
[K in keyof typeof BlendMode]: RegisteredPerfectBlender;
|
|
403
394
|
};
|
|
404
395
|
declare const PERFECT_BLEND_MODE_BY_NAME: PerfectBlendModes;
|
|
405
396
|
|
|
397
|
+
type BaseIndexToBlendGetter<B extends BlendColor32> = {
|
|
398
|
+
get: (index: BlendModeIndex) => B;
|
|
399
|
+
};
|
|
400
|
+
type IndexToBlendGetter = typeof INDEX_TO_FAST_BLEND | typeof INDEX_TO_PERFECT_BLEND;
|
|
401
|
+
type BaseBlendToIndexGetter<B extends BlendColor32> = {
|
|
402
|
+
get: (blend: B) => BlendModeIndex;
|
|
403
|
+
};
|
|
404
|
+
type BlendToIndexGetter = typeof FAST_BLEND_TO_INDEX | typeof PERFECT_BLEND_TO_INDEX;
|
|
405
|
+
|
|
406
406
|
type PixelCanvas = {
|
|
407
407
|
readonly canvas: HTMLCanvasElement;
|
|
408
408
|
readonly ctx: CanvasRenderingContext2D;
|
|
@@ -877,6 +877,16 @@ declare function invertPixelData(pixelData: PixelData): PixelData;
|
|
|
877
877
|
*/
|
|
878
878
|
declare function pixelDataToAlphaMask(pixelData: PixelData): AlphaMask;
|
|
879
879
|
|
|
880
|
+
declare function reflectPixelDataHorizontal(pixelData: PixelData): void;
|
|
881
|
+
declare function reflectPixelDataVertical(pixelData: PixelData): void;
|
|
882
|
+
|
|
883
|
+
/**
|
|
884
|
+
* Rotates pixel data 90 degrees clockwise.
|
|
885
|
+
* If the image is square, it performs the rotation in-place.
|
|
886
|
+
* If rectangular, it returns a new Uint32Array and updates dimensions.
|
|
887
|
+
*/
|
|
888
|
+
declare function rotatePixelData(pixelData: PixelData): void;
|
|
889
|
+
|
|
880
890
|
/**
|
|
881
891
|
* Intersects a target rectangle with a boundary, trimming dimensions and masks in-place.
|
|
882
892
|
* This utility calculates the axis-aligned intersection between the `target` and `bounds`.
|
|
@@ -893,4 +903,4 @@ declare function pixelDataToAlphaMask(pixelData: PixelData): AlphaMask;
|
|
|
893
903
|
*/
|
|
894
904
|
declare function trimRectBounds<T extends Rect | SelectionRect>(target: T, bounds: Rect): void;
|
|
895
905
|
|
|
896
|
-
export { type AlphaMask, type AnyMask, type ApplyMaskOptions, type Base64EncodedUInt8Array, type BinaryMask, type BlendColor32, BlendMode, type Color32, type ColorBlendOptions, FAST_BLENDER_REGISTRY, FAST_BLEND_MODES, FAST_BLEND_MODE_BY_NAME, FAST_BLEND_TO_INDEX, type
|
|
906
|
+
export { type AlphaMask, type AnyMask, type ApplyMaskOptions, type Base64EncodedUInt8Array, type BinaryMask, type BlendColor32, BlendMode, type BlendModeIndex, type BlendToIndexGetter, type Color32, type ColorBlendOptions, FAST_BLENDER_REGISTRY, FAST_BLEND_MODES, FAST_BLEND_MODE_BY_NAME, FAST_BLEND_TO_INDEX, type FastBlendModes, type FloodFillImageDataOptions, type FloodFillResult, INDEX_TO_FAST_BLEND, INDEX_TO_PERFECT_BLEND, type ImageDataLike, type IndexToBlendGetter, type IndexedImage, MaskType, PERFECT_BLENDER_REGISTRY, PERFECT_BLEND_MODES, PERFECT_BLEND_MODE_BY_NAME, PERFECT_BLEND_TO_INDEX, type PerfectBlendModes, type PixelBlendOptions, type PixelCanvas, PixelData, type PixelOptions, type Point, type RGBA, type Rect, type RegisteredFastBlender, type RegisteredPerfectBlender, type ReusableCanvas, type SelectionRect, type SerializedImageData, UnsupportedFormatError, applyMaskToPixelData, base64DecodeArrayBuffer, base64EncodeArrayBuffer, blendColorPixelData, blendPixelData, clearPixelData, color32ToCssRGBA, color32ToHex, colorBurnFast, colorBurnPerfect, colorDistance, colorDodgeFast, colorDodgePerfect, copyImageData, copyImageDataLike, copyMask, darkenFast, darkenPerfect, darkerFast, darkerPerfect, deserializeImageData, deserializeNullableImageData, deserializeRawImageData, differenceFast, differencePerfect, divideFast, dividePerfect, exclusionFast, exclusionPerfect, extractImageDataPixels, extractMask, fileInputChangeToImageData, fileToImageData, fillPixelData, floodFillSelection, getImageDataFromClipboard, getSupportedPixelFormats, hardLightFast, hardLightPerfect, hardMixFast, hardMixPerfect, imageDataToAlphaMask, imageDataToDataUrl, imageDataToImgBlob, imgBlobToImageData, indexedImageToAverageColor, invertAlphaMask, invertBinaryMask, invertImageData, invertPixelData, lerpColor32, lerpColor32Fast, lightenFast, lightenPerfect, lighterFast, lighterPerfect, linearBurnFast, linearBurnPerfect, linearDodgeFast, linearDodgePerfect, linearLightFast, linearLightPerfect, makeIndexedImage, makePixelCanvas, makeReusableCanvas, mergeMasks, multiplyFast, multiplyPerfect, overlayFast, overlayPerfect, overwriteFast, overwritePerfect, packColor, packRGBA, pinLightFast, pinLightPerfect, pixelDataToAlphaMask, reflectPixelDataHorizontal, reflectPixelDataVertical, resizeImageData, rotatePixelData, screenFast, screenPerfect, serializeImageData, serializeNullableImageData, softLightFast, softLightPerfect, sourceOverFast, sourceOverPerfect, subtractFast, subtractPerfect, trimRectBounds, unpackAlpha, unpackBlue, unpackColor, unpackColorTo, unpackGreen, unpackRed, vividLightFast, vividLightPerfect, writeImageDataPixels, writeImageDataToClipboard, writeImgBlobToClipboard };
|
package/dist/index.prod.js
CHANGED
|
@@ -2250,6 +2250,84 @@ function invertPixelData(pixelData) {
|
|
|
2250
2250
|
}
|
|
2251
2251
|
return pixelData;
|
|
2252
2252
|
}
|
|
2253
|
+
|
|
2254
|
+
// src/PixelData/reflectPixelData.ts
|
|
2255
|
+
function reflectPixelDataHorizontal(pixelData) {
|
|
2256
|
+
const width = pixelData.width;
|
|
2257
|
+
const height = pixelData.height;
|
|
2258
|
+
const data = pixelData.data32;
|
|
2259
|
+
const halfWidth = Math.floor(width / 2);
|
|
2260
|
+
for (let y = 0; y < height; y++) {
|
|
2261
|
+
const rowOffset = y * width;
|
|
2262
|
+
for (let x = 0; x < halfWidth; x++) {
|
|
2263
|
+
const leftIdx = rowOffset + x;
|
|
2264
|
+
const rightIdx = rowOffset + (width - 1 - x);
|
|
2265
|
+
const temp = data[leftIdx];
|
|
2266
|
+
data[leftIdx] = data[rightIdx];
|
|
2267
|
+
data[rightIdx] = temp;
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
function reflectPixelDataVertical(pixelData) {
|
|
2272
|
+
const width = pixelData.width;
|
|
2273
|
+
const height = pixelData.height;
|
|
2274
|
+
const data = pixelData.data32;
|
|
2275
|
+
const halfHeight = Math.floor(height / 2);
|
|
2276
|
+
for (let y = 0; y < halfHeight; y++) {
|
|
2277
|
+
const topRowOffset = y * width;
|
|
2278
|
+
const bottomRowOffset = (height - 1 - y) * width;
|
|
2279
|
+
for (let x = 0; x < width; x++) {
|
|
2280
|
+
const topIdx = topRowOffset + x;
|
|
2281
|
+
const bottomIdx = bottomRowOffset + x;
|
|
2282
|
+
const temp = data[topIdx];
|
|
2283
|
+
data[topIdx] = data[bottomIdx];
|
|
2284
|
+
data[bottomIdx] = temp;
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
|
|
2289
|
+
// src/PixelData/rotatePixelData.ts
|
|
2290
|
+
function rotatePixelData(pixelData) {
|
|
2291
|
+
const width = pixelData.width;
|
|
2292
|
+
const height = pixelData.height;
|
|
2293
|
+
const data = pixelData.data32;
|
|
2294
|
+
if (width === height) {
|
|
2295
|
+
rotateSquareInPlace(pixelData);
|
|
2296
|
+
return;
|
|
2297
|
+
}
|
|
2298
|
+
const newWidth = height;
|
|
2299
|
+
const newHeight = width;
|
|
2300
|
+
const newData = new Uint32Array(data.length);
|
|
2301
|
+
for (let y = 0; y < height; y++) {
|
|
2302
|
+
for (let x = 0; x < width; x++) {
|
|
2303
|
+
const oldIdx = y * width + x;
|
|
2304
|
+
const newX = height - 1 - y;
|
|
2305
|
+
const newY = x;
|
|
2306
|
+
const newIdx = newY * newWidth + newX;
|
|
2307
|
+
newData[newIdx] = data[oldIdx];
|
|
2308
|
+
}
|
|
2309
|
+
}
|
|
2310
|
+
pixelData.width = newWidth;
|
|
2311
|
+
pixelData.height = newHeight;
|
|
2312
|
+
pixelData.data32 = newData;
|
|
2313
|
+
}
|
|
2314
|
+
function rotateSquareInPlace(pixelData) {
|
|
2315
|
+
const n = pixelData.width;
|
|
2316
|
+
const data = pixelData.data32;
|
|
2317
|
+
for (let i = 0; i < n / 2; i++) {
|
|
2318
|
+
for (let j = i; j < n - i - 1; j++) {
|
|
2319
|
+
const temp = data[i * n + j];
|
|
2320
|
+
const top = i * n + j;
|
|
2321
|
+
const right = j * n + (n - 1 - i);
|
|
2322
|
+
const bottom = (n - 1 - i) * n + (n - 1 - j);
|
|
2323
|
+
const left = (n - 1 - j) * n + i;
|
|
2324
|
+
data[top] = data[left];
|
|
2325
|
+
data[left] = data[bottom];
|
|
2326
|
+
data[bottom] = data[right];
|
|
2327
|
+
data[right] = temp;
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2253
2331
|
export {
|
|
2254
2332
|
BlendMode,
|
|
2255
2333
|
FAST_BLENDER_REGISTRY,
|
|
@@ -2342,7 +2420,10 @@ export {
|
|
|
2342
2420
|
pinLightFast,
|
|
2343
2421
|
pinLightPerfect,
|
|
2344
2422
|
pixelDataToAlphaMask,
|
|
2423
|
+
reflectPixelDataHorizontal,
|
|
2424
|
+
reflectPixelDataVertical,
|
|
2345
2425
|
resizeImageData,
|
|
2426
|
+
rotatePixelData,
|
|
2346
2427
|
screenFast,
|
|
2347
2428
|
screenPerfect,
|
|
2348
2429
|
serializeImageData,
|