New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@thi.ng/pixel

Package Overview
Dependencies
Maintainers
1
Versions
231
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/pixel - npm Package Compare versions

Comparing version 2.1.5 to 2.2.0

27

api.d.ts

@@ -1,2 +0,2 @@

import type { FloatArray, Fn, Fn2, Fn3, FnN, FnU2, IObjectOf, NumericArray, TypedArray, UintType } from "@thi.ng/api";
import type { FloatArray, Fn, Fn2, Fn3, FnN, FnU2, IGrid2D, IObjectOf, NumericArray, TypedArray, UintType } from "@thi.ng/api";
/**

@@ -162,28 +162,7 @@ * ABGR 8bit lane/channel IDs

img: ImageData;
pixels: Uint32Array;
data: Uint32Array;
}
export interface IPixelBuffer<T extends TypedArray = TypedArray, P = any> {
readonly width: number;
readonly height: number;
export interface IPixelBuffer<T extends TypedArray = TypedArray, P = any> extends IGrid2D<T, P> {
readonly format: IABGRConvert<any>;
readonly stride: number;
readonly pixels: T;
/**
* Returns pixel value at given position. If pos is outside the
* defined region, returns a suitable zero value.
*
* @param x -
* @param y -
*/
getAt(x: number, y: number): P;
/**
* Writes pixel value at given position. Has no effect if outside of
* the defined region.
*
* @param x -
* @param y -
* @param col -
*/
setAt(x: number, y: number, col: P): this;
/**
* Extracts region as new pixel buffer in same format.

@@ -190,0 +169,0 @@ *

4

canvas.js

@@ -35,3 +35,3 @@ import { isNumber } from "@thi.ng/checks/is-number";

const img = ctx.getImageData(0, 0, canvas.width, canvas.height);
const pixels = new Uint32Array(img.data.buffer);
const data = new Uint32Array(img.data.buffer);
return {

@@ -41,3 +41,3 @@ canvas,

img,
pixels
data
};

@@ -44,0 +44,0 @@ }

@@ -6,42 +6,15 @@ # Change Log

## [2.1.5](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@2.1.4...@thi.ng/pixel@2.1.5) (2021-10-28)
# [2.2.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@2.1.5...@thi.ng/pixel@2.2.0) (2021-11-03)
**Note:** Version bump only for package @thi.ng/pixel
### Features
* **pixel:** add flood fill functions ([65796b9](https://github.com/thi-ng/umbrella/commit/65796b96fe77d5c4b999dd8cedfd142ea243a200))
* **pixel:** add shape drawing fns ([d1e284b](https://github.com/thi-ng/umbrella/commit/d1e284bfceabda62048500d42dbff19a3b1df1e8))
* **pixel:** add unsafe getters/setters ([714d6f7](https://github.com/thi-ng/umbrella/commit/714d6f7fc8bfffa37c09dfc2c4251b1041935a24))
## [2.1.4](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@2.1.3...@thi.ng/pixel@2.1.4) (2021-10-28)
**Note:** Version bump only for package @thi.ng/pixel
## [2.1.3](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@2.1.2...@thi.ng/pixel@2.1.3) (2021-10-25)
**Note:** Version bump only for package @thi.ng/pixel
## [2.1.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@2.1.1...@thi.ng/pixel@2.1.2) (2021-10-15)
**Note:** Version bump only for package @thi.ng/pixel
## [2.1.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@2.1.0...@thi.ng/pixel@2.1.1) (2021-10-15)
**Note:** Version bump only for package @thi.ng/pixel
# [2.1.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@2.0.1...@thi.ng/pixel@2.1.0) (2021-10-13)

@@ -58,10 +31,2 @@

## [2.0.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@2.0.0...@thi.ng/pixel@2.0.1) (2021-10-13)
**Note:** Version bump only for package @thi.ng/pixel
# [2.0.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@1.0.5...@thi.ng/pixel@2.0.0) (2021-10-12)

@@ -112,47 +77,47 @@

## [1.0.5](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@1.0.4...@thi.ng/pixel@1.0.5) (2021-09-03)
## [1.0.5](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@1.0.4...@thi.ng/pixel@1.0.5) (2021-09-03)
**Note:** Version bump only for package @thi.ng/pixel
**Note:** Version bump only for package @thi.ng/pixel
# [0.11.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.10.5...@thi.ng/pixel@0.11.0) (2021-08-04)
# [0.11.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.10.5...@thi.ng/pixel@0.11.0) (2021-08-04)
### Features
### Features
- **pixel:** add DominantColorOpts ([a57882b](https://github.com/thi-ng/umbrella/commit/a57882bbbf2f3520eb5ec849d548fb47c08c3bff))
- **pixel:** add DominantColorOpts ([a57882b](https://github.com/thi-ng/umbrella/commit/a57882bbbf2f3520eb5ec849d548fb47c08c3bff))
# [0.10.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.9.0...@thi.ng/pixel@0.10.0) (2021-04-19)
# [0.10.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.9.0...@thi.ng/pixel@0.10.0) (2021-04-19)
### Features
### Features
- **pixel:** add dominantColors(), update deps ([ad0617e](https://github.com/thi-ng/umbrella/commit/ad0617e6ed3077d8d0c1549416afc27df261edc9))
- **pixel:** add dominantColors(), update deps ([ad0617e](https://github.com/thi-ng/umbrella/commit/ad0617e6ed3077d8d0c1549416afc27df261edc9))
# [0.9.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.8.1...@thi.ng/pixel@0.9.0) (2021-04-03)
# [0.9.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.8.1...@thi.ng/pixel@0.9.0) (2021-04-03)
### Features
### Features
- **pixel:** add .upsize() impls, fix convolve() ([08f0d7c](https://github.com/thi-ng/umbrella/commit/08f0d7c200fa03bc4fb017d3dbc9237581af19ee))
- **pixel:** add imagePyramid() iterator ([7f77e07](https://github.com/thi-ng/umbrella/commit/7f77e07089eca68b5825715c3709312d4374c37a))
- **pixel:** add IToImageData & impls ([3172e1e](https://github.com/thi-ng/umbrella/commit/3172e1eb8582901bddf12281e65df618e4d4f476))
- **pixel:** update/fix convolution, add LANCZOS ([eadefda](https://github.com/thi-ng/umbrella/commit/eadefda5f119ee8453edb3df3109ebcba692b429))
- **pixel:** add .upsize() impls, fix convolve() ([08f0d7c](https://github.com/thi-ng/umbrella/commit/08f0d7c200fa03bc4fb017d3dbc9237581af19ee))
- **pixel:** add imagePyramid() iterator ([7f77e07](https://github.com/thi-ng/umbrella/commit/7f77e07089eca68b5825715c3709312d4374c37a))
- **pixel:** add IToImageData & impls ([3172e1e](https://github.com/thi-ng/umbrella/commit/3172e1eb8582901bddf12281e65df618e4d4f476))
- **pixel:** update/fix convolution, add LANCZOS ([eadefda](https://github.com/thi-ng/umbrella/commit/eadefda5f119ee8453edb3df3109ebcba692b429))
## [0.8.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.8.0...@thi.ng/pixel@0.8.1) (2021-03-20)
## [0.8.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.8.0...@thi.ng/pixel@0.8.1) (2021-03-20)
### Bug Fixes
### Bug Fixes
- **pixel:** update convolve() for even kernel sizes ([b086224](https://github.com/thi-ng/umbrella/commit/b086224a51c0dd23b4cae1d158c1e1236328d445))
- **pixel:** update convolve() for even kernel sizes ([b086224](https://github.com/thi-ng/umbrella/commit/b086224a51c0dd23b4cae1d158c1e1236328d445))
# [0.8.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.7.4...@thi.ng/pixel@0.8.0) (2021-03-17)
# [0.8.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.7.4...@thi.ng/pixel@0.8.0) (2021-03-17)
### Features
### Features
- **pixel:** add bicubic samplers, fix resize() ([951fa9e](https://github.com/thi-ng/umbrella/commit/951fa9e1263db6f165dcaee3c951c09b43e42fef))
- **pixel:** add defIndexed() HOF pixel format ([c13a568](https://github.com/thi-ng/umbrella/commit/c13a5687fac6d08c14d80f380b5c664422b18a3e))
- **pixel:** add defSampler(), resize() ([aa71eb7](https://github.com/thi-ng/umbrella/commit/aa71eb7a2ccf02fa543c68308371143882ae5e5f)), closes [#256](https://github.com/thi-ng/umbrella/issues/256)
- **pixel:** add float format samplers, update various types ([6f9dae6](https://github.com/thi-ng/umbrella/commit/6f9dae6010118e491ed161fa4a5bd40ec4719ad4))
- **pixel:** add bicubic samplers, fix resize() ([951fa9e](https://github.com/thi-ng/umbrella/commit/951fa9e1263db6f165dcaee3c951c09b43e42fef))
- **pixel:** add defIndexed() HOF pixel format ([c13a568](https://github.com/thi-ng/umbrella/commit/c13a5687fac6d08c14d80f380b5c664422b18a3e))
- **pixel:** add defSampler(), resize() ([aa71eb7](https://github.com/thi-ng/umbrella/commit/aa71eb7a2ccf02fa543c68308371143882ae5e5f)), closes [#256](https://github.com/thi-ng/umbrella/issues/256)
- **pixel:** add float format samplers, update various types ([6f9dae6](https://github.com/thi-ng/umbrella/commit/6f9dae6010118e491ed161fa4a5bd40ec4719ad4))
# [0.7.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.6.1...@thi.ng/pixel@0.7.0) (2021-03-03)
# [0.7.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.6.1...@thi.ng/pixel@0.7.0) (2021-03-03)
### Bug Fixes
### Bug Fixes
- **pixel:** add clamping for float->ABGR conversion ([41540e0](https://github.com/thi-ng/umbrella/commit/41540e085b2261208e44e6f25b327e3371eae2df))
- **pixel:** add clamping for float->ABGR conversion ([41540e0](https://github.com/thi-ng/umbrella/commit/41540e085b2261208e44e6f25b327e3371eae2df))
- **pixel:** fix POOL_NEAREST index ([b98d05d](https://github.com/thi-ng/umbrella/commit/b98d05d7827d98d3971bdbcd562735b96fa9b7ec))

@@ -166,5 +131,5 @@

- **pixel:** add defLargeKernel(), conv presets ([9c71165](https://github.com/thi-ng/umbrella/commit/9c71165adb71103fa88a5486987f270fecd2f439))
- **pixel:** add gradientImage() & FLOAT_NORMAL format ([78683b7](https://github.com/thi-ng/umbrella/commit/78683b701418bf184b2a1327cfd5e50397d687e0))
- **pixel:** add IEmpty impls for Float/PackedBuffer ([46ac1a1](https://github.com/thi-ng/umbrella/commit/46ac1a1906b256eefab0934efea300c67db7ea28))
- **pixel:** add normalMap(), add more kernels ([f32686d](https://github.com/thi-ng/umbrella/commit/f32686d463ffcb49b37e9b1b811ff5de06b58fed))
- **pixel:** add gradientImage() & FLOAT_NORMAL format ([78683b7](https://github.com/thi-ng/umbrella/commit/78683b701418bf184b2a1327cfd5e50397d687e0))
- **pixel:** add IEmpty impls for Float/PackedBuffer ([46ac1a1](https://github.com/thi-ng/umbrella/commit/46ac1a1906b256eefab0934efea300c67db7ea28))
- **pixel:** add normalMap(), add more kernels ([f32686d](https://github.com/thi-ng/umbrella/commit/f32686d463ffcb49b37e9b1b811ff5de06b58fed))
- **pixel:** add POOL_THRESHOLD preset ([5f1c1de](https://github.com/thi-ng/umbrella/commit/5f1c1dea87251f8a584cbe94d83784e7e4cc31a5))

@@ -186,55 +151,55 @@ - **pixel:** add step size support for normalMap() ([ab72a79](https://github.com/thi-ng/umbrella/commit/ab72a79532baab3f07f53419cb5970e90e97e0dd))

- **pixel:** add FLOAT_HSVA format, update FloatFormatSpec ([118c4ed](https://github.com/thi-ng/umbrella/commit/118c4edbacd75249262f26962153f614148cedec))
- **pixel:** add FloatBuffer.fromPacked() ([abd1ca8](https://github.com/thi-ng/umbrella/commit/abd1ca80d455999dd8c3af87d24b4f1905d7806d))
- **pixel:** add FLOAT_HSVA format, update FloatFormatSpec ([118c4ed](https://github.com/thi-ng/umbrella/commit/118c4edbacd75249262f26962153f614148cedec))
- **pixel:** add FloatBuffer.fromPacked() ([abd1ca8](https://github.com/thi-ng/umbrella/commit/abd1ca80d455999dd8c3af87d24b4f1905d7806d))
# [0.4.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.3.6...@thi.ng/pixel@0.4.0) (2020-07-22)
# [0.4.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.3.6...@thi.ng/pixel@0.4.0) (2020-07-22)
### Features
### Features
- **pixel:** add flipY() ([a5593c0](https://github.com/thi-ng/umbrella/commit/a5593c06a6ae61eccb9ecbaa4b3828ce0b29fbc0))
- **pixel:** add flipY() ([a5593c0](https://github.com/thi-ng/umbrella/commit/a5593c06a6ae61eccb9ecbaa4b3828ce0b29fbc0))
# [0.3.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.2.0...@thi.ng/pixel@0.3.0) (2020-05-29)
# [0.3.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.2.0...@thi.ng/pixel@0.3.0) (2020-05-29)
### Features
### Features
- **pixel:** add dither support for int buffers/formats ([4475fc1](https://github.com/thi-ng/umbrella/commit/4475fc14c65029e88a7216519350527fa3d2c3dc))
- **pixel:** add FloatBuffer and float format support ([d6c490f](https://github.com/thi-ng/umbrella/commit/d6c490fb22b3d43f188f85662bb431f59daa7f32))
- **pixel:** add/update float formats, tests ([6eb1f67](https://github.com/thi-ng/umbrella/commit/6eb1f671858c234e53f231ad8af0f07f2a423d96))
- **pixel:** add dither support for int buffers/formats ([4475fc1](https://github.com/thi-ng/umbrella/commit/4475fc14c65029e88a7216519350527fa3d2c3dc))
- **pixel:** add FloatBuffer and float format support ([d6c490f](https://github.com/thi-ng/umbrella/commit/d6c490fb22b3d43f188f85662bb431f59daa7f32))
- **pixel:** add/update float formats, tests ([6eb1f67](https://github.com/thi-ng/umbrella/commit/6eb1f671858c234e53f231ad8af0f07f2a423d96))
# [0.2.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.1.20...@thi.ng/pixel@0.2.0) (2020-05-19)
# [0.2.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.1.20...@thi.ng/pixel@0.2.0) (2020-05-19)
### Features
### Features
- **pixel:** add .copy(), update .blitCanvas() ([f4b2c3e](https://github.com/thi-ng/umbrella/commit/f4b2c3e374b45bd26396e436f3e71e9d3afbc131))
- **pixel:** update canvas2d(), imageCanvas() ([65929a2](https://github.com/thi-ng/umbrella/commit/65929a2ee6be9915e14bf69389520739073af5ee))
- **pixel:** add .copy(), update .blitCanvas() ([f4b2c3e](https://github.com/thi-ng/umbrella/commit/f4b2c3e374b45bd26396e436f3e71e9d3afbc131))
- **pixel:** update canvas2d(), imageCanvas() ([65929a2](https://github.com/thi-ng/umbrella/commit/65929a2ee6be9915e14bf69389520739073af5ee))
## [0.1.4](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.1.3...@thi.ng/pixel@0.1.4) (2019-09-21)
## [0.1.4](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.1.3...@thi.ng/pixel@0.1.4) (2019-09-21)
### Bug Fixes
### Bug Fixes
- **pixel:** clamp values in PackedChannel.setFloat() ([ce78467](https://github.com/thi-ng/umbrella/commit/ce78467))
- **pixel:** clamp values in PackedChannel.setFloat() ([ce78467](https://github.com/thi-ng/umbrella/commit/ce78467))
# 0.1.0 (2019-07-31)
# 0.1.0 (2019-07-31)
### Bug Fixes
### Bug Fixes
- **pixel:** byte order fixes, extract luminance fns ([b3c79e3](https://github.com/thi-ng/umbrella/commit/b3c79e3))
- **pixel:** fast-route check in setChannel() ([b59069a](https://github.com/thi-ng/umbrella/commit/b59069a))
- **pixel:** update 16bit formats & handling in getChannel ([aa15179](https://github.com/thi-ng/umbrella/commit/aa15179))
- **pixel:** update clampRegion(), adjust src pos if dest is outside ([bb6ba47](https://github.com/thi-ng/umbrella/commit/bb6ba47))
- **pixel:** update prepRegions() ([ad8d2d7](https://github.com/thi-ng/umbrella/commit/ad8d2d7))
- **pixel:** byte order fixes, extract luminance fns ([b3c79e3](https://github.com/thi-ng/umbrella/commit/b3c79e3))
- **pixel:** fast-route check in setChannel() ([b59069a](https://github.com/thi-ng/umbrella/commit/b59069a))
- **pixel:** update 16bit formats & handling in getChannel ([aa15179](https://github.com/thi-ng/umbrella/commit/aa15179))
- **pixel:** update clampRegion(), adjust src pos if dest is outside ([bb6ba47](https://github.com/thi-ng/umbrella/commit/bb6ba47))
- **pixel:** update prepRegions() ([ad8d2d7](https://github.com/thi-ng/umbrella/commit/ad8d2d7))
### Features
### Features
- **pixel:** ([#106](https://github.com/thi-ng/umbrella/issues/106)) add IBlend interface/impls, refactor IBlit ([e068f46](https://github.com/thi-ng/umbrella/commit/e068f46))
- **pixel:** ([#106](https://github.com/thi-ng/umbrella/issues/106)) add Uint16Buffer, update IColorChannel, add Channel.GRAY ([3088646](https://github.com/thi-ng/umbrella/commit/3088646))
- **pixel:** add 16bit formats, add docs, update readme ([5d72c37](https://github.com/thi-ng/umbrella/commit/5d72c37))
- **pixel:** add buffer() syntax sugar, PackedBuffer.forEach ([bc17ac9](https://github.com/thi-ng/umbrella/commit/bc17ac9))
- **pixel:** add channel float accessors, update PackedChannel ([b4168f8](https://github.com/thi-ng/umbrella/commit/b4168f8))
- **pixel:** add invert, add/split interfaces, refactor blit fns ([22a456a](https://github.com/thi-ng/umbrella/commit/22a456a))
- **pixel:** add PackedBuffer.fromCanvas(), update readme ([ac283ee](https://github.com/thi-ng/umbrella/commit/ac283ee))
- **pixel:** add pre/postmultiply & isPremultiplied checks ([969d6b8](https://github.com/thi-ng/umbrella/commit/969d6b8))
- **pixel:** complete rewrite/simplify/extend using format descriptors ([cde7bf9](https://github.com/thi-ng/umbrella/commit/cde7bf9))
- **pixel:** initial import pixel buffer pkg ([1836ea7](https://github.com/thi-ng/umbrella/commit/1836ea7))
- **pixel:** updat setChannel, add ALPHA8, update readme ([899f1a3](https://github.com/thi-ng/umbrella/commit/899f1a3))
- **pixel:** ([#106](https://github.com/thi-ng/umbrella/issues/106)) add IBlend interface/impls, refactor IBlit ([e068f46](https://github.com/thi-ng/umbrella/commit/e068f46))
- **pixel:** ([#106](https://github.com/thi-ng/umbrella/issues/106)) add Uint16Buffer, update IColorChannel, add Channel.GRAY ([3088646](https://github.com/thi-ng/umbrella/commit/3088646))
- **pixel:** add 16bit formats, add docs, update readme ([5d72c37](https://github.com/thi-ng/umbrella/commit/5d72c37))
- **pixel:** add buffer() syntax sugar, PackedBuffer.forEach ([bc17ac9](https://github.com/thi-ng/umbrella/commit/bc17ac9))
- **pixel:** add channel float accessors, update PackedChannel ([b4168f8](https://github.com/thi-ng/umbrella/commit/b4168f8))
- **pixel:** add invert, add/split interfaces, refactor blit fns ([22a456a](https://github.com/thi-ng/umbrella/commit/22a456a))
- **pixel:** add PackedBuffer.fromCanvas(), update readme ([ac283ee](https://github.com/thi-ng/umbrella/commit/ac283ee))
- **pixel:** add pre/postmultiply & isPremultiplied checks ([969d6b8](https://github.com/thi-ng/umbrella/commit/969d6b8))
- **pixel:** complete rewrite/simplify/extend using format descriptors ([cde7bf9](https://github.com/thi-ng/umbrella/commit/cde7bf9))
- **pixel:** initial import pixel buffer pkg ([1836ea7](https://github.com/thi-ng/umbrella/commit/1836ea7))
- **pixel:** updat setChannel, add ALPHA8, update readme ([899f1a3](https://github.com/thi-ng/umbrella/commit/899f1a3))
- **pixel:** update canvasPixels() ([5ea200d](https://github.com/thi-ng/umbrella/commit/5ea200d))
import type { TypedArray } from "@thi.ng/api";
import type { FloatFormat, PackedFormat } from "./api.js";
/** @internal */
export declare const ensureSize: (pixels: TypedArray, width: number, height: number, stride?: number) => void;
export declare const ensureSize: (data: TypedArray, width: number, height: number, stride?: number) => void;
/** @internal */

@@ -6,0 +6,0 @@ export declare const ensureChannel: (fmt: PackedFormat | FloatFormat, id: number) => import("./api.js").Lane | import("./api.js").PackedChannel;

import { assert } from "@thi.ng/errors/assert";
/** @internal */
export const ensureSize = (pixels, width, height, stride = 1) => assert(pixels.length >= width * height * stride, "pixel buffer too small");
export const ensureSize = (data, width, height, stride = 1) => assert(data.length >= width * height * stride, "pixel buffer too small");
/** @internal */

@@ -5,0 +5,0 @@ export const ensureChannel = (fmt, id) => {

@@ -48,3 +48,3 @@ import { isFunction } from "@thi.ng/checks/is-function";

ensureChannel(src.format, channel);
const dpix = dest.pixels;
const dpix = dest.data;
const stepX = strideX * srcStride;

@@ -157,3 +157,3 @@ const stepY = strideY * rowStride;

"const { min, max } = Math;",
"const { pixels: pix, stride, rowStride } = src;",
"const { data: pix, stride, rowStride } = src;",
"const maxX = (src.width - 1) * stride;",

@@ -179,3 +179,3 @@ "const maxY = (src.height - 1) * rowStride;",

return (src) => {
const { pixels, rowStride, stride } = src;
const { data, rowStride, stride } = src;
const x0 = -(w >> 1) * stride;

@@ -193,3 +193,3 @@ const x1 = -x0 + (w & 1 ? stride : 0);

sum +=
kernel[k] * pixels[row + clamp(xx + x, channel, $maxX)];
kernel[k] * data[row + clamp(xx + x, channel, $maxX)];
}

@@ -196,0 +196,0 @@ }

@@ -21,3 +21,3 @@ import { kmeans } from "@thi.ng/k-means/kmeans";

for (let i = 0, j = 0, s = img.stride; i < n; i++, j += s) {
const p = img.pixels.subarray(j, j + s);
const p = img.data.subarray(j, j + s);
if (filter(p, i))

@@ -24,0 +24,0 @@ mapped.push(p);

@@ -10,5 +10,5 @@ import type { Fn2, ICopy, IEmpty, NumericArray } from "@thi.ng/api";

* @param fmt -
* @param pixels -
* @param data -
*/
export declare function floatBuffer(w: number, h: number, fmt: FloatFormat | FloatFormatSpec, pixels?: Float32Array): FloatBuffer;
export declare function floatBuffer(w: number, h: number, fmt: FloatFormat | FloatFormatSpec, data?: Float32Array): FloatBuffer;
export declare function floatBuffer(src: PackedBuffer, fmt: FloatFormat | FloatFormatSpec): FloatBuffer;

@@ -31,6 +31,8 @@ export declare class FloatBuffer implements IPixelBuffer<Float32Array, NumericArray>, IToImageData, IResizable<FloatBuffer, FloatSampler>, IBlend<FloatBuffer, BlendFnFloat>, IBlit<FloatBuffer>, IInvert<FloatBuffer>, ICopy<FloatBuffer>, IEmpty<FloatBuffer> {

readonly rowStride: number;
readonly pixels: Float32Array;
readonly data: Float32Array;
readonly format: FloatFormat;
protected __empty: NumericArray;
constructor(w: number, h: number, fmt: FloatFormat | FloatFormatSpec, pixels?: Float32Array);
constructor(w: number, h: number, fmt: FloatFormat | FloatFormatSpec, data?: Float32Array);
/** @deprecated use `.data` instead */
get pixels(): Float32Array;
as(fmt: PackedFormat): PackedBuffer;

@@ -40,3 +42,5 @@ copy(): FloatBuffer;

getAt(x: number, y: number): NumericArray;
getAtUnsafe(x: number, y: number): Float32Array;
setAt(x: number, y: number, col: NumericArray): this;
setAtUnsafe(x: number, y: number, col: NumericArray): this;
getChannelAt(x: number, y: number, id: number): number | undefined;

@@ -43,0 +47,0 @@ setChannelAt(x: number, y: number, id: number, col: number): this;

@@ -19,3 +19,3 @@ import { isNumber } from "@thi.ng/checks/is-number";

export class FloatBuffer {
constructor(w, h, fmt, pixels) {
constructor(w, h, fmt, data) {
this.width = w;

@@ -28,3 +28,3 @@ this.height = h;

this.rowStride = w * this.stride;
this.pixels = pixels || new Float32Array(w * h * this.stride);
this.data = data || new Float32Array(w * h * this.stride);
this.__empty = (Object.freeze(new Array(this.stride).fill(0)));

@@ -44,4 +44,4 @@ }

const dest = new FloatBuffer(src.width, src.height, fmt);
const { pixels: dbuf, format: dfmt, stride } = dest;
const { pixels: sbuf, format: sfmt } = src;
const { data: dbuf, format: dfmt, stride } = dest;
const { data: sbuf, format: sfmt } = src;
for (let i = sbuf.length; --i >= 0;) {

@@ -52,8 +52,12 @@ dbuf.set(dfmt.fromABGR(sfmt.toABGR(sbuf[i])), i * stride);

}
/** @deprecated use `.data` instead */
get pixels() {
return this.data;
}
as(fmt) {
const { width, height, stride, pixels, format: sfmt } = this;
const { width, height, stride, data, format: sfmt } = this;
const dest = new PackedBuffer(width, height, fmt);
const dpixels = dest.pixels;
for (let i = 0, j = 0, n = pixels.length; i < n; i += stride, j++) {
dpixels[j] = fmt.fromABGR(sfmt.toABGR(pixels.subarray(i, i + stride)));
const dpixels = dest.data;
for (let i = 0, j = 0, n = data.length; i < n; i += stride, j++) {
dpixels[j] = fmt.fromABGR(sfmt.toABGR(data.subarray(i, i + stride)));
}

@@ -64,3 +68,3 @@ return dest;

const dest = this.empty();
dest.pixels.set(this.pixels);
dest.data.set(this.data);
return dest;

@@ -72,9 +76,11 @@ }

getAt(x, y) {
const { width, stride } = this;
if (x >= 0 && x < width && y >= 0 && y < this.height) {
const idx = (x | 0) * stride + (y | 0) * this.rowStride;
return this.pixels.subarray(idx, idx + stride);
}
return this.__empty;
return x >= 0 && x < this.width && y >= 0 && y < this.height
? this.getAtUnsafe(x, y)
: this.__empty;
}
getAtUnsafe(x, y) {
const stride = this.stride;
const idx = (x | 0) * stride + (y | 0) * this.rowStride;
return this.data.subarray(idx, idx + stride);
}
setAt(x, y, col) {

@@ -85,5 +91,9 @@ x >= 0 &&

y < this.height &&
this.pixels.set(col, (x | 0) * this.stride + (y | 0) * this.rowStride);
this.data.set(col, (x | 0) * this.stride + (y | 0) * this.rowStride);
return this;
}
setAtUnsafe(x, y, col) {
this.data.set(col, (x | 0) * this.stride + (y | 0) * this.rowStride);
return this;
}
getChannelAt(x, y, id) {

@@ -93,3 +103,3 @@ ensureChannel(this.format, id);

if (x >= 0 && x < width && y >= 0 && y < this.height) {
return this.pixels[(x | 0) * stride + (y | 0) * this.rowStride + id];
return this.data[(x | 0) * stride + (y | 0) * this.rowStride + id];
}

@@ -101,3 +111,3 @@ }

if (x >= 0 && x < width && y >= 0 && y < this.height) {
this.pixels[(x | 0) * stride + (y | 0) * this.rowStride + id] = col;
this.data[(x | 0) * stride + (y | 0) * this.rowStride + id] = col;
}

@@ -108,6 +118,6 @@ return this;

ensureChannel(this.format, id);
const { pixels, stride } = this;
const { data, stride } = this;
const dest = new Float32Array(this.width * this.height);
for (let i = id, j = 0, n = pixels.length; i < n; i += stride, j++) {
dest[j] = clamp01(pixels[i]);
for (let i = id, j = 0, n = data.length; i < n; i += stride, j++) {
dest[j] = clamp01(data[i]);
}

@@ -118,3 +128,3 @@ return new FloatBuffer(this.width, this.height, FLOAT_GRAY, dest);

ensureChannel(this.format, id);
const { pixels: dest, stride } = this;
const { data: dest, stride } = this;
if (isNumber(src)) {

@@ -126,3 +136,3 @@ for (let i = id, n = dest.length; i < n; i += stride) {

else {
const { pixels: sbuf, stride: sstride } = src;
const { data: sbuf, stride: sstride } = src;
ensureSize(sbuf, this.width, this.height, sstride);

@@ -140,4 +150,4 @@ for (let i = id, j = 0, n = dest.length; i < n; i += stride, j += sstride) {

return dest;
const sbuf = this.pixels;
const dbuf = dest.pixels;
const sbuf = this.data;
const dbuf = dest.data;
const sw = this.rowStride;

@@ -159,4 +169,4 @@ const dw = dest.rowStride;

return dest;
const sbuf = this.pixels;
const dbuf = dest.pixels;
const sbuf = this.data;
const dbuf = dest.data;
const sw = this.rowStride;

@@ -179,5 +189,5 @@ const dw = dest.rowStride;

const dest = new Uint32Array(idata.data.buffer);
const { stride, pixels, format } = this;
for (let i = 0, j = 0, n = pixels.length; i < n; i += stride, j++) {
dest[j] = format.toABGR(pixels.subarray(i, i + stride));
const { stride, data, format } = this;
for (let i = 0, j = 0, n = data.length; i < n; i += stride, j++) {
dest[j] = format.toABGR(data.subarray(i, i + stride));
}

@@ -196,5 +206,5 @@ return idata;

forEach(f) {
const { pixels, stride } = this;
for (let i = 0, j = 0, n = pixels.length; i < n; i += stride, j++) {
pixels.set(f(pixels.subarray(i, i + stride), j), i);
const { data, stride } = this;
for (let i = 0, j = 0, n = data.length; i < n; i += stride, j++) {
data.set(f(data.subarray(i, i + stride), j), i);
}

@@ -204,5 +214,5 @@ return this;

clamp() {
const pixels = this.pixels;
for (let i = pixels.length; --i >= 0;) {
pixels[i] = clamp01(pixels[i]);
const data = this.data;
for (let i = data.length; --i >= 0;) {
data[i] = clamp01(data[i]);
}

@@ -213,5 +223,5 @@ return this;

ensureChannel(this.format, id);
const { pixels, stride } = this;
for (let i = id, n = pixels.length; i < n; i += stride) {
pixels[i] = clamp01(pixels[i]);
const { data, stride } = this;
for (let i = id, n = data.length; i < n; i += stride) {
data[i] = clamp01(data[i]);
}

@@ -223,8 +233,8 @@ }

flipY() {
const { pixels, rowStride } = this;
const { data, rowStride } = this;
const tmp = new Float32Array(rowStride);
for (let i = 0, j = pixels.length - rowStride; i < j; i += rowStride, j -= rowStride) {
tmp.set(pixels.subarray(i, i + rowStride));
pixels.copyWithin(i, j, j + rowStride);
pixels.set(tmp, j);
for (let i = 0, j = data.length - rowStride; i < j; i += rowStride, j -= rowStride) {
tmp.set(data.subarray(i, i + rowStride));
data.copyWithin(i, j, j + rowStride);
data.set(tmp, j);
}

@@ -234,6 +244,6 @@ return this;

invert() {
const { pixels, format, stride } = this;
for (let i = 0, n = pixels.length, m = format.alpha ? stride - 1 : stride; i < n; i += stride) {
const { data, format, stride } = this;
for (let i = 0, n = data.length, m = format.alpha ? stride - 1 : stride; i < n; i += stride) {
for (let j = 0; j < m; j++)
pixels[i + j] = 1 - pixels[i + j];
data[i + j] = 1 - data[i + j];
}

@@ -251,3 +261,3 @@ return this;

const dest = floatBuffer(w, h, this.format);
const dpix = dest.pixels;
const dpix = dest.data;
const scaleX = w > 0 ? this.width / w : 0;

@@ -268,9 +278,9 @@ const scaleY = h > 0 ? this.height / h : 0;

upsize() {
const { width, height, pixels, stride, rowStride } = this;
const { width, height, data, stride, rowStride } = this;
const dstride = stride * 2;
const dest = floatBuffer(width * 2, height * 2, this.format);
const dpix = dest.pixels;
const dpix = dest.data;
for (let y = 0, si = 0; y < height; y++) {
for (let x = 0, di = y * rowStride * 4; x < width; x++, si += stride, di += dstride) {
dpix.set(pixels.subarray(si, si + stride), di);
dpix.set(data.subarray(si, si + stride), di);
}

@@ -277,0 +287,0 @@ }

{
"name": "@thi.ng/pixel",
"version": "2.1.5",
"description": "Typedarray integer & float pixel buffers w/ customizable formats, blitting, dithering, convolution",
"version": "2.2.0",
"description": "Typedarray integer & float pixel buffers w/ customizable formats, blitting, drawing, convolution",
"type": "module",

@@ -37,10 +37,10 @@ "module": "./index.js",

"dependencies": {
"@thi.ng/api": "^8.0.6",
"@thi.ng/binary": "^3.0.6",
"@thi.ng/api": "^8.1.0",
"@thi.ng/binary": "^3.0.7",
"@thi.ng/checks": "^3.0.6",
"@thi.ng/distance": "^2.0.6",
"@thi.ng/distance": "^2.0.7",
"@thi.ng/errors": "^2.0.6",
"@thi.ng/k-means": "^0.4.6",
"@thi.ng/math": "^5.0.6",
"@thi.ng/porter-duff": "^2.0.6"
"@thi.ng/k-means": "^0.4.7",
"@thi.ng/math": "^5.0.7",
"@thi.ng/porter-duff": "^2.0.7"
},

@@ -68,3 +68,3 @@ "devDependencies": {

"datastructure",
"dither",
"draw",
"float",

@@ -208,3 +208,3 @@ "format",

},
"gitHead": "c17a556ad25f6882dfa8f806a1d9e8ed7ac7cd71"
"gitHead": "852cd2450617c86d15d18477dc634f17f04202eb"
}

@@ -10,5 +10,5 @@ import type { Fn2, ICopy, IEmpty } from "@thi.ng/api";

* @param fmt -
* @param pixels -
* @param data -
*/
export declare function packedBuffer(w: number, h: number, fmt: PackedFormat | PackedFormatSpec, pixels?: UIntArray): PackedBuffer;
export declare function packedBuffer(w: number, h: number, fmt: PackedFormat | PackedFormatSpec, data?: UIntArray): PackedBuffer;
export declare function packedBuffer(src: PackedBuffer, fmt: PackedFormat | PackedFormatSpec): PackedBuffer;

@@ -37,5 +37,8 @@ /**

readonly format: PackedFormat;
readonly pixels: UIntArray;
constructor(w: number, h: number, fmt: PackedFormat | PackedFormatSpec, pixels?: UIntArray);
readonly data: UIntArray;
constructor(w: number, h: number, fmt: PackedFormat | PackedFormatSpec, data?: UIntArray);
/** @deprecated use `.data` instead */
get pixels(): UIntArray;
get stride(): number;
get rowStride(): number;
as(fmt: PackedFormat): PackedBuffer;

@@ -45,3 +48,5 @@ copy(): PackedBuffer;

getAt(x: number, y: number): number;
getAtUnsafe(x: number, y: number): number;
setAt(x: number, y: number, col: number): this;
setAtUnsafe(x: number, y: number, col: number): this;
getChannelAt(x: number, y: number, id: number, normalized?: boolean): number;

@@ -48,0 +53,0 @@ setChannelAt(x: number, y: number, id: number, col: number, normalized?: boolean): this;

@@ -43,7 +43,7 @@ import { typedArray, uintTypeForBits } from "@thi.ng/api/typedarray";

if (fmt === ABGR8888) {
dest = ctx.pixels;
dest = ctx.data;
}
else {
dest = typedArray(fmt.type, w * h);
const src = ctx.pixels;
const src = ctx.data;
const from = fmt.fromABGR;

@@ -57,3 +57,3 @@ for (let i = dest.length; --i >= 0;) {

export class PackedBuffer {
constructor(w, h, fmt, pixels) {
constructor(w, h, fmt, data) {
this.width = w;

@@ -64,7 +64,14 @@ this.height = h;

: defPackedFormat(fmt);
this.pixels = pixels || typedArray(fmt.type, w * h);
this.data = data || typedArray(fmt.type, w * h);
}
/** @deprecated use `.data` instead */
get pixels() {
return this.data;
}
get stride() {
return 1;
}
get rowStride() {
return this.width;
}
as(fmt) {

@@ -75,3 +82,3 @@ return this.getRegion(0, 0, this.width, this.height, fmt);

const dest = this.empty();
dest.pixels.set(this.pixels);
dest.data.set(this.data);
return dest;

@@ -84,5 +91,8 @@ }

return x >= 0 && x < this.width && y >= 0 && y < this.height
? this.pixels[(x | 0) + (y | 0) * this.width]
? this.data[(x | 0) + (y | 0) * this.width]
: 0;
}
getAtUnsafe(x, y) {
return this.data[(x | 0) + (y | 0) * this.width];
}
setAt(x, y, col) {

@@ -93,5 +103,9 @@ x >= 0 &&

y < this.height &&
(this.pixels[(x | 0) + (y | 0) * this.width] = col);
(this.data[(x | 0) + (y | 0) * this.width] = col);
return this;
}
setAtUnsafe(x, y, col) {
this.data[(x | 0) + (y | 0) * this.width] = col;
return this;
}
getChannelAt(x, y, id, normalized = false) {

@@ -114,4 +128,4 @@ const chan = ensureChannel(this.format, id);

return dest;
const sbuf = this.pixels;
const dbuf = dest.pixels;
const sbuf = this.data;
const dbuf = dest.data;
const sf = this.format.toABGR;

@@ -133,4 +147,4 @@ const df1 = dest.format.toABGR;

return dest;
const sbuf = this.pixels;
const dbuf = dest.pixels;
const sbuf = this.data;
const dbuf = dest.data;
const sf = this.format.toABGR;

@@ -159,3 +173,3 @@ const df = dest.format.fromABGR;

const dest = new Uint32Array(idata.data.buffer);
const src = this.pixels;
const src = this.data;
const fmt = this.format.toABGR;

@@ -185,4 +199,4 @@ for (let i = dest.length; --i >= 0;) {

});
const src = this.pixels;
const dest = buf.pixels;
const src = this.data;
const dest = buf.data;
const get = chan.int;

@@ -196,3 +210,3 @@ for (let i = src.length; --i >= 0;) {

const chan = ensureChannel(this.format, id);
const dbuf = this.pixels;
const dbuf = this.data;
const set = chan.setInt;

@@ -203,3 +217,3 @@ if (isNumber(src)) {

else {
const sbuf = src.pixels;
const sbuf = src.data;
const schan = src.format.channels[0];

@@ -217,6 +231,6 @@ ensureSize(sbuf, this.width, this.height);

invert() {
const { format, pixels } = this;
const { data, format } = this;
const mask = Math.pow(2, format.size - format.alpha) - 1;
for (let i = pixels.length; --i >= 0;) {
pixels[i] ^= mask;
for (let i = data.length; --i >= 0;) {
data[i] ^= mask;
}

@@ -226,11 +240,11 @@ return this;

premultiply() {
__transformABGR(this.pixels, this.format, premultiplyInt);
__transformABGR(this.data, this.format, premultiplyInt);
return this;
}
postmultiply() {
__transformABGR(this.pixels, this.format, postmultiplyInt);
__transformABGR(this.data, this.format, postmultiplyInt);
return this;
}
isPremultiplied() {
const pix = this.pixels;
const pix = this.data;
const to = this.format.toABGR;

@@ -245,3 +259,3 @@ for (let i = pix.length; --i >= 0;) {

forEach(f) {
const pix = this.pixels;
const pix = this.data;
for (let i = pix.length; --i >= 0;) {

@@ -256,8 +270,8 @@ pix[i] = f(pix[i], i);

flipY() {
const { pixels, width } = this;
const { data, width } = this;
const tmp = typedArray(this.format.type, width);
for (let i = 0, j = pixels.length - width; i < j; i += width, j -= width) {
tmp.set(pixels.subarray(i, i + width));
pixels.copyWithin(i, j, j + width);
pixels.set(tmp, j);
for (let i = 0, j = data.length - width; i < j; i += width, j -= width) {
tmp.set(data.subarray(i, i + width));
data.copyWithin(i, j, j + width);
data.set(tmp, j);
}

@@ -282,3 +296,3 @@ return this;

const dest = packedBuffer(w, h, this.format);
const dpix = dest.pixels;
const dpix = dest.data;
const scaleX = w > 0 ? this.width / w : 0;

@@ -298,8 +312,8 @@ const scaleY = h > 0 ? this.height / h : 0;

upsize() {
const { width, height, pixels } = this;
const { width, height, data } = this;
const dest = new PackedBuffer(width * 2, height * 2, this.format);
const dpix = dest.pixels;
const dpix = dest.data;
for (let y = 0, si = 0; y < height; y++) {
for (let x = 0, di = y * width * 4; x < width; x++, si++, di += 2) {
dpix[di] = pixels[si];
dpix[di] = data[si];
}

@@ -306,0 +320,0 @@ }

@@ -33,3 +33,3 @@ <!-- This file is generated - DO NOT EDIT! -->

Typedarray integer & float pixel buffers w/ customizable formats, blitting, dithering, convolution.
Typedarray integer & float pixel buffers w/ customizable formats, blitting, drawing, convolution.

@@ -61,5 +61,5 @@ ![screenshot](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/pixel/pixel-basics.png)

- 12 packed integer and 6 floating point preset formats (see table below)
- Ordered dithering w/ customizable Bayer matrix size and target color
steps (int formats only)
- Declarative custom format & optimized code generation
- Basic shape drawing/filling (circle, line, rect)
- Flood filling (solid or pattern)
- HTML canvas creation & `ImageData` utilities

@@ -339,3 +339,3 @@

Package sizes (gzipped, pre-treeshake): ESM: 8.84 KB
Package sizes (gzipped, pre-treeshake): ESM: 8.87 KB

@@ -342,0 +342,0 @@ ## Dependencies

@@ -53,23 +53,23 @@ import { assert } from "@thi.ng/errors/assert";

}
const sampleINC = ({ pixels, width, height }) => (x, y) => x >= 0 && x < width && y >= 0 && y < height
? pixels[(y | 0) * width + (x | 0)]
const sampleINC = ({ data, width, height }) => (x, y) => x >= 0 && x < width && y >= 0 && y < height
? data[(y | 0) * width + (x | 0)]
: 0;
const sampleINW = ({ pixels, width, height }) => (x, y) => pixels[mod(y | 0, height) * width + mod(x | 0, width)];
const sampleINR = ({ pixels, width, height }) => {
const sampleINW = ({ data, width, height }) => (x, y) => data[mod(y | 0, height) * width + mod(x | 0, width)];
const sampleINR = ({ data, width, height }) => {
const w1 = width - 1;
const h1 = height - 1;
return (x, y) => pixels[clamp(y | 0, 0, h1) * width + clamp(x | 0, 0, w1)];
return (x, y) => data[clamp(y | 0, 0, h1) * width + clamp(x | 0, 0, w1)];
};
const sampleFNC = ({ pixels, width, height, rowStride, stride }) => (x, y) => {
const sampleFNC = ({ data, width, height, rowStride, stride }) => (x, y) => {
let i;
return x >= 0 && x < width && y >= 0 && y < height
? ((i = (y | 0) * rowStride + (x | 0) * stride),
pixels.slice(i, i + stride))
data.slice(i, i + stride))
: [0];
};
const sampleFNW = ({ pixels, width, height, rowStride, stride }) => (x, y) => {
const sampleFNW = ({ data, width, height, rowStride, stride }) => (x, y) => {
let i = mod(y | 0, height) * rowStride + mod(x | 0, width) * stride;
return pixels.slice(i, i + stride);
return data.slice(i, i + stride);
};
const sampleFNR = ({ pixels, width, height, rowStride, stride, }) => {
const sampleFNR = ({ data, width, height, rowStride, stride, }) => {
const w1 = width - 1;

@@ -79,3 +79,3 @@ const h1 = height - 1;

let i = clamp(y | 0, 0, h1) * rowStride + clamp(x | 0, 0, w1) * stride;
return pixels.slice(i, i + stride);
return data.slice(i, i + stride);
};

@@ -82,0 +82,0 @@ };

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc