npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lcms-wasm

v1.0.3

Published

LittleCMS in JS with WASM

Downloads

177

Readme

lcms-wasm

This is a reboot of yoya/lcms.js (now several years old), using WASM instead of ASM.js for improved performance and memory growth. This allows for Little-CMS in JavaScript, with the specific goal of parsing, loading, and transforming between color spaces defined by ICC color profiles.

This should work in web, Node.js, and web workers, and possibly other JavaScript environments.

Install from npm

With npm and Node.js already installed:

npm install lcms-wasm

This is primarily tested against ES Modules rather than CommonJS code.

Docs

The API is quite low-level and relatively closely matches the Little-CMS library. This project also mainly exposes the bare color profile transformation features, rather than the entire color management system. Until some docs are written, see the Demos for example usage.

Example

Here is an example of loading a ICC profile into memory, and then printing its ASCII name and color space.

import { readFile } from "fs/promises";
import { instantiate, cmsInfoDescription } from "lcms-wasm";

const lcms = await instantiate();
const path = "path/to/profile.icc";
const buf = (await readFile(path)).buffer;
const profile = lcms.cmsOpenProfileFromMem(new Uint8Array(buf), buf.byteLength);
if (!profile) {
  throw new Error(`could not open profile ${path}`);
}
const name = lcms.cmsGetProfileInfoASCII(
  profile,
  cmsInfoDescription,
  "en",
  "US"
);
const space = lcms.cmsGetColorSpaceASCII(profile);
console.log(name, space);

See the Demos for more complex examples.

Web

Depending on your bundler, you may need to locate the WASM URI for correct loading, such as with Vite:

import { instantiate } from "lcms-wasm";
import wasmFileURI from "lcms-wasm/dist/lcms.wasm?url";

const lcms = await instantiate({
  locateFile: function (name) {
    return wasmFileURI;
  },
});

Demos

The test/ folder includes two demos:

  • CMYK to sRGB transform (you will need to bring your own ICC files for licensing reasons)
  • sRGB to CIE Lab* transform

You can also see yoya's original demo of the lcms.js library here:

Build from source

Clone the repo, then:

cd lcms-wasm
git submodule update --init --recursive
npm install

# if not already runnable
chmod +x ./build.sh

npm run build

# run the demos
node test/lab.js
node test/cmyk.js

Thanks

Thanks to yoya/lcms.js who did the heavy lifting to get this working with Emscripten in the first placea.

License

This code is MIT, see LICENSE.md. The submodule (Little-CMS) is also MIT.