# pixel-utils

> Utility Functions for Pixels

Latest version **0.9.0** (published 2022-11-29) · CC0-1.0 license · 0 weekly downloads

## Install

```sh
npm install pixel-utils
pnpm add pixel-utils
yarn add pixel-utils
bun add pixel-utils
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.0 |
| Published | 2022-11-29 |
| First published | 2022-05-08 |
| Weekly downloads | 0 |
| License | CC0-1.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 185.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Daniel J. Dufour |
| Maintainers | danieljdufour |
| Keywords | color, pixel, rgb, rgba |

## Links

- npm: https://www.npmjs.com/package/pixel-utils
- Repository: https://github.com/DanielJDufour/pixel-utils
- Homepage: https://github.com/DanielJDufour/pixel-utils#readme
- Issues: https://github.com/DanielJDufour/pixel-utils/issues
- npm.io page: https://npm.io/package/pixel-utils

## Dependencies (3)

- [xdim](https://npm.io/package/xdim.md) ^1.10.0
- [type-fest](https://npm.io/package/type-fest.md) ^3.2.0
- [quick-scale](https://npm.io/package/quick-scale.md) ^0.2.0

## Alternatives

- [postcss-color-hex-alpha](https://npm.io/package/postcss-color-hex-alpha.md) — 6.4M weekly downloads
- [randomcolor](https://npm.io/package/randomcolor.md) — 348.0K weekly downloads
- [bows](https://npm.io/package/bows.md) — 1.3K weekly downloads
- [ep_prefer_color_scheme](https://npm.io/package/ep_prefer_color_scheme.md) — 260 weekly downloads
- [coc-yank](https://npm.io/package/coc-yank.md) — 61 weekly downloads

## Recent versions

- 0.9.0 (latest) — 2022-11-29
- 0.8.0 — 2022-11-29
- 0.7.0 — 2022-07-27
- 0.6.0 — 2022-07-27
- 0.5.0 — 2022-07-26
- 0.4.0 — 2022-07-11
- 0.3.0 — 2022-07-10
- 0.2.1 — 2022-06-18
- 0.2.0 — 2022-06-09
- 0.1.0 — 2022-05-16
- 0.0.3 — 2022-05-08
- 0.0.2 — 2022-05-08

## README

⚠️ This library is currently in beta, so the function signatures are subject to change.

---

# pixel-utils
> Minimalist Utility Functions for Pixels

## features
- no data values
- optional mutability for fast memory-preserving operations
- optimized for speed
- range flipping
- simple conversion between RGB and RGBA
- support for CommonJS and ES Modules
- typescript

## install
```bash
npm install pixel-utils
```

## functions
- **conversion**
  - [`rawToRgb`](https://github.com/DanielJDufour/pixel-converters/tree/main/src/raw-to-rgb) - convert a raw unprocessed pixel value to RGB
  - [`rawToRgba`](https://github.com/DanielJDufour/pixel-converters/tree/main/src/raw-to-rgba) - convert a raw unprocessed pixel value to RGBA
  - [`rgbToRgba`](https://github.com/DanielJDufour/pixel-converters/tree/main/src/rgb-to-rgba) - convert from RGB to RGBA
  - [`rgbaToRgb`](https://github.com/DanielJDufour/pixel-converters/tree/main/src/rgba-to-rgb) - convert from RGBA to RGB
- **no data**
  - `makeNoDataRgb` - create a no data RGB pixel
  - `makeNoDataRgba` - create a no data RGB pixel
- **iteration**
  - [`eachPixel`](https://github.com/DanielJDufour/pixel-converters/tree/main/src/each-pixel) - call a callback for each pixel
- **selection**
  - [`select`](https://github.com/DanielJDufour/pixel-converters/tree/main/src/select-pixel) - select a pixel from image data of arbitrary dimensions
- **transparency**
  - [`addAlpha`](https://github.com/DanielJDufour/pixel-converters/tree/main/src/add-alpha) - add an alpha transparency channel
  - [`isHidden`](https://github.com/DanielJDufour/pixel-converters/tree/main/src/is-hidden) - check if an RGBA pixel is transparent
  - [`setHidden`](https://github.com/DanielJDufour/pixel-converters/tree/main/src/set-hidden) - mutates input pixel, setting alpha channel to visible
  - [`showRGBA`](https://github.com/DanielJDufour/pixel-converters/tree/main/src/show-rgba) - make RGBA visible
- **[and many more](https://github.com/DanielJDufour/pixel-utils/tree/main/src)**

## core assumptions and constraints
An RGB pixel has these assumed properties:
- array of 3 numbers between zero and 255
- no data is represented by either black or white

An RGBA pixel has these assumed properties:
- array of 4 numbers between zero and 255
- the first 3 numbers are "data" values and the last value is an alpha tranparency value
- an alpha value of 0 indicates that at least one of the data bands is "no data"
- there may be a per-band no data value, but it is not required

A raw (unscaled) pixel value has these assumed properties:
- between 1 and inifinity number of bands
- number can be any valid number
- no data value must be the same for each band (we don't love this, but it's a common constraint)
- there is no transparency channel/band (we may work to remove this constraint)

## comparison
There are several other pixel manipulation libraries, including [p5js](https://p5js.org/) and [fabricjs](http://fabricjs.com/), 
however pixel-utils provides some unique features not found in other libraries:
- raw image data support: most (if not all) alternatives assume that an image is a 8-bit 0-255 RGBA data
- arbitrary image layout support: most (if not all) alternatives assume that your data is in a flat Uint8ClampedArray, but pixel-utils support all possible data layouts thanks to the [xdmin](https://github.com/danieljdufour/xdim) layout syntax.

---
_Source: https://npm.io/package/pixel-utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
