pixel-format
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

pixel-format

Convert from one pixel format to another

Installation

Install using npm

npm i pixel-format

Examples

const PixelFormat = require("pixel-format");

// Convert a number from RGB888 to RGBA5551
// "A" will default to 1
const converted = PixelFormat.convertInteger(0xA16942, "RGB888", "RGBA5551");
converted.toString(16); // => a351

// Convert a full array of pixel data
const arr = PixelFormat.convertArray([1, 2, 3, 4, 5, 6], "ABC888", "CBA888")); 
arr; // => [3, 2, 1, 6, 5, 4]

// Extract components of a color
const components = (new PixelFormat.Format("RGB888")).parseInteger(0xA1B2C3);
components; // => 
// [ { value: 0.7647058823529411, variable: 'B' },
//   { value: 0.6980392156862745, variable: 'G' },
//   { value: 0.6313725490196078, variable: 'R' } ]

Formats

A format can be defined in the form RGB888 (All variables followed by numbers of bits for each individual) or R8G8B8 (Variable names with the number of bits followed immediately). Any character can be used as a variable name. If the target format contains a value that is not defined in the source, it will default to the maximum possible.

Limitations

  • Individual pixels in an array must start at a full byte offset. 7 bit colors will have an padding bit at the end.
  • Parts with more than 9 bit resolution can't be formatted as "RGB161616" and must be specified as "R16G16B16"
  • Colors that need more than the bit limit of javascript integers can't be converted with convertInteger()

License

MIT

Package Sidebar

Install

npm i pixel-format

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

14.1 kB

Total Files

9

Last publish

Collaborators

  • lordvonadel