pixel-data-js 0.9.1 → 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.
@@ -687,6 +687,14 @@ declare function makeIndexedImage(imageData: ImageData): IndexedImage;
687
687
  */
688
688
  declare function indexedImageToAverageColor(indexedImage: IndexedImage, includeTransparent?: boolean): Color32;
689
689
 
690
+ /**
691
+ * Calculates the frequency of each palette index based on the image data.
692
+ * The index of the returned array maps directly to the index of the palette.
693
+ * @param indexedImage - The source image containing data and palette definitions.
694
+ * @returns A typed array where each entry represents the total count of that palette index.
695
+ */
696
+ declare function getIndexedImageColorCounts(indexedImage: IndexedImage): Int32Array;
697
+
690
698
  /**
691
699
  * A convenience wrapper that extracts the first {@link File} from an
692
700
  * {@link HTMLInputElement} change event and converts it into {@link ImageData}.
@@ -903,4 +911,4 @@ declare function rotatePixelData(pixelData: PixelData): void;
903
911
  */
904
912
  declare function trimRectBounds<T extends Rect | SelectionRect>(target: T, bounds: Rect): void;
905
913
 
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 };
914
+ 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, getIndexedImageColorCounts, 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 };
@@ -1662,6 +1662,18 @@ function indexedImageToAverageColor(indexedImage, includeTransparent = false) {
1662
1662
  return packColor(r, g, b, a);
1663
1663
  }
1664
1664
 
1665
+ // src/IndexedImage/getIndexedImageColorCounts.ts
1666
+ function getIndexedImageColorCounts(indexedImage) {
1667
+ const data = indexedImage.data;
1668
+ const palette = indexedImage.palette;
1669
+ const frequencies = new Int32Array(palette.length);
1670
+ for (let i = 0; i < data.length; i++) {
1671
+ const colorIndex = data[i];
1672
+ frequencies[colorIndex]++;
1673
+ }
1674
+ return frequencies;
1675
+ }
1676
+
1665
1677
  // src/Input/fileInputChangeToImageData.ts
1666
1678
  async function fileInputChangeToImageData(event) {
1667
1679
  const target = event.target;
@@ -2379,6 +2391,7 @@ export {
2379
2391
  fillPixelData,
2380
2392
  floodFillSelection,
2381
2393
  getImageDataFromClipboard,
2394
+ getIndexedImageColorCounts,
2382
2395
  getSupportedPixelFormats,
2383
2396
  hardLightFast,
2384
2397
  hardLightPerfect,