js-lcms
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

js-lcms

js-lcms is a fork of lcms.js, a low-level binding to LittleCMS based on emscripten.

Example Usage

The example below shows how to convert an RGB array from an sRGB profile to another sRGB profile:

import {
  INTENT_RELATIVE_COLORIMETRIC,
  cmsCreate_sRGBProfile,
  cmsFormatterForColorspaceOfProfile,
  cmsCreateTransform,
  cmsDoTransform,
  cmsDeleteTransform,
  cmsCloseProfile,
} from "js-lcms";

const inputProfile = cmsCreate_sRGBProfile();
const outputProfile = cmsCreate_sRGBProfile();
const isFloat = 0; // false

const inputFormat = cmsFormatterForColorspaceOfProfile(
  inputProfile,
  isFloat ? 0 : 2,
  isFloat
);

const outputFormat = cmsFormatterForColorspaceOfProfile(
  outputProfile,
  isFloat ? 0 : 2,
  isFloat
);

const transform = cmsCreateTransform(
  profile,
  inputFormat,
  profile,
  outputFormat,
  INTENT_RELATIVE_COLORIMETRIC,
  0
);

const image = Uint8Array.from([0, 127, 255]);
console.log(cmsDoTransform(transform, image, image.length / 3));

cmsDeleteTransform(transform);
cmsCloseProfile(inputProfile);
cmsCloseProfile(outputProfile);

Web Demo

A print-to-console web demo can be found in the ./demo directory. Run npm run demo to build it and start a local server.

Other Examples and Resources

LCMS.js color conversion demo by @yoya:

LittleCMS 2.12 documentation:

Developing

Make sure you have git and emscripten installed on your system.

js-lcms works by building LittleCMS to JavaScript with emscripten and directly appending another file that exports the public API.

LittleCMS should be present in the root directory as ./Little-CMS. You can clone this repository with --recurse-submodules or clone LittleCMS directly.

Finally, run the build script with npm run build. The build script is a NodeJS script in scripts/build-package.js. You can check if the build works by running the previous demo right after.

Acknowledgements

js-lcms is based on the following libraries:

Package Sidebar

Install

npm i js-lcms

Weekly Downloads

8

Version

0.1.4

License

MIT

Unpacked Size

975 kB

Total Files

5

Last publish

Collaborators

  • gfrancine