https://github.com/dy/pxls
Convert any input pixels array to normalized 4-channel uint8 array
https://github.com/dy/pxls
Last synced: 9 months ago
JSON representation
Convert any input pixels array to normalized 4-channel uint8 array
- Host: GitHub
- URL: https://github.com/dy/pxls
- Owner: dy
- License: mit
- Created: 2018-11-13T19:53:49.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-04-09T20:31:17.000Z (about 4 years ago)
- Last Synced: 2024-12-27T23:44:04.896Z (over 1 year ago)
- Language: JavaScript
- Size: 33.2 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# pxls [](http://github.com/badges/stability-badges) [](https://travis-ci.org/dy/pxls)
Take in custom pixels container, return normalized 4-channel Uint8Array with pixels. Detects float/int input pixels, handles Infinities, unfolds structures.
[](https://npmjs.org/package/pxls/)
```js
var pxls = require('pxls')
var ndarray = require('ndarray')
pxls([[0,0,0], [1,1,1]]) //
pxls([0, 1], 1) //
pxls([0,0,0, 1,1,1], [2,1]) //
pxls(new Ndarray([0,1], [2,1]) //
pxls(new Ndarray([0,0,0,1,1,1], [2,1,3]) //
```
## `let pixels = pxls(arr, shape|step?)`
Takes input actual pixels container `arr` and returns 4 channels flat _Uint8Array_ `pixels` with layout `[r,g,b,a, r,g,b,a, r,g,b,a, ...]`.
`arr` can be an Array of Arrays, TypedArray, Ndarray, ImageData or DOM container Image, Video, ImageBitmap, Canvas2D, Context2D, WebGLContext.
1-channel input is mapped as grayscale `[v,v,v,255, v,v,v,255]`. 3-channel input fills last channel with `255` `[r,g,b,255, r,g,b,255]`.
`shape` can describe the shape of input array, eg. `[100,100,3]` or `[10,10]`.
`step` optionally can define input number of channels in flat array, that is detected automatically for nested/ndarrays.
## See also
* [to-uint8](https://ghub.io/to-uint8) − convert input argument to uint8 array.
* [ndarray-to-bitmap-rgba](https://github.com/Jam3/ndarray-bitmap-to-rgba) − convert ndarray to rgba bitmap ndarray.
## License
(c) 2018 Dmitry Yv. MIT License