Skip to content

Kittl/Little-CMS

Repository files navigation

Little-CMS binding for JavaScript

Upstream repository: Little-CMS
Website: www.littlecms.com

JavaScript / TypeScript bindings for LittleCMS (lcms2) compiled to WebAssembly.

Supports Node.js and browsers.


Installation

npm install @kittl/little-cms

Initialization

Before using the API, initialize the WASM runtime:

import { initWasm } from "littlecms";

await initWasm();

You can also install an optional error handler:

import { cmsSetLogErrorHandler } from "littlecms";

cmsSetLogErrorHandler((code, message) => {
  console.error(code, message);
});

Examples

Create an sRGB profile

Create a built-in sRGB ICC profile:

import { cmsCreate_sRGBProfile, cmsCloseProfile } from "littlecms";

const profile = cmsCreate_sRGBProfile();

if (profile.value) {
  cmsCloseProfile(profile.value);
}

Load an ICC profile

Load an ICC profile from memory.

import { readFileSync } from "fs";
import { cmsOpenProfileFromMem, cmsCloseProfile } from "littlecms";

const bytes = new Uint8Array(readFileSync("./profile.icc"));
const profile = cmsOpenProfileFromMem(bytes);

if (profile.value) {
  cmsCloseProfile(profile.value);
}

Read profile information

Read metadata from an ICC profile.

import { cmsGetProfileInfoASCII, CmsPrintInfoType } from "littlecms";

const info = cmsGetProfileInfoASCII(profile.value, CmsPrintInfoType.Description, "en", "US");

console.log(info.value);

Color transform

Create a color transform and convert pixel data between color spaces.

import {
  cmsCreateTransform,
  cmsDoTransform,
  cmsDeleteTransform,
  CmsIntent,
  TYPE_RGB_8,
  TYPE_CMYK_8,
  FLAGS_IDENTITY
} from "littlecms";

const transform = cmsCreateTransform(
  srgbProfile,
  TYPE_RGB_8,
  cmykProfile,
  TYPE_CMYK_8,
  CmsIntent.RelativeColorimetric,
  FLAGS_IDENTITY
);

const result = cmsDoTransform(
  transform.value,
  new Uint8Array([
    255,255,255,
    0,0,0,
    235,235,235,
    234,22,21
  ]),
  4,
);

cmsDeleteTransform(transform.value);

Build

Build the TypeScript bindings and WebAssembly output:

pnpm build

About

wasm fork of Little-CMS

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors