cube-lut-factory

Cube LUT file utils

Usage no npm install needed!

<script type="module">
  import cubeLutFactory from 'https://cdn.skypack.dev/cube-lut-factory';
</script>

README

Cube LUT factory

Useful function to deal with Cube LUT files.

Install

$ npm install cube-lut-factory

Usage

const cubeLUT = require("cube-lut-factory");

Parse

// Parse Cube LUT content
const cubeLUT = require("cube-lut-factory");

let fs = require("fs");
let lutContent = fs.readFileSync("test/1DLUT.cube");
let lutObject = cubeLUT.parse(lutContent);

console.log(lutObject);
{
  title: "1D Identity Cube LUT",
  type: "1D",
  size: 4,
  domainMin: [0, 0, 0],
  domainMin: [1, 1, 1],
  dataPoints: [
    [0.0000, 0.0000, 0.0000],
    [0.3333, 0.3333, 0.3333],
    [0.6667, 0.6667, 0.6667],
    [1.0000, 1.0000, 1.0000],
  ]
}

Generate

  • header: Includes a header on the beginning of the file. (optional)
  • title: Defines the title. (mandatory)
  • type: Defines the type (1D or 3D). (mandatory)
  • size: Defines the size. (mandatory)
  • domainMin and domainMax: Vector of 3 values, containing the minimum and maximum of the domain, respectively.
  • R, G and B: Defines the function of each channel. If the type is 1D, it must be in function of the single variable t (R(t), G(t), B(t)). If the type is 3D, it must be in function of the three variable r, g and b (R(r, g, b), G(r, g, b), B(r, g, b)).
// Generate Cube LUT content
const cubeLUT = require("cube-lut-factory");

let lutObject = {
  title: "Test",
  type: "3D",
  size: 4,
  domainMin: [0, 0, 0],
  domainMax: [1, 1, 1],
  R: "(r^2 + g*b)/2",
  G: "(g^3 + r*2*b)/3",
  B: "(b^4 + r + b)/3",
};

let lutContent = cubeLUT.generate(lutObject);

console.log(lutContent);
# Cube LUT file generated with cube-lut-factory
# https://github.com/diegoinacio/cube-lut-factory.js
TITLE "Test"

# Cube LUT size
LUT_3D_SIZE 4

# Cube LUT domain
DOMAIN_MIN 0 0 0
DOMAIN_MAX 1 1 1

# Cube LUT data points
0 0 0
0.05555555555555555 0 0.1111111111111111
0.2222222222222222 0 0.2222222222222222
0.5 0 0.3333333333333333
0 0.012345679012345677 0
0.05555555555555555 0.012345679012345677 0.1111111111111111
0.2222222222222222 0.012345679012345677 0.2222222222222222
0.5 0.012345679012345677 0.3333333333333333
0 0.09876543209876541 0
0.05555555555555555 0.09876543209876541 0.1111111111111111
0.2222222222222222 0.09876543209876541 0.2222222222222222
0.5 0.09876543209876541 0.3333333333333333
0 0.3333333333333333 0
0.05555555555555555 0.3333333333333333 0.1111111111111111
0.2222222222222222 0.3333333333333333 0.2222222222222222
0.5 0.3333333333333333 0.3333333333333333
0 0 0.11522633744855966
0.05555555555555555 0.07407407407407407 0.22633744855967075
0.2222222222222222 0.14814814814814814 0.33744855967078186
0.5 0.2222222222222222 0.448559670781893
0.05555555555555555 0.012345679012345677 0.11522633744855966
0.1111111111111111 0.08641975308641975 0.22633744855967075
0.2777777777777778 0.16049382716049382 0.33744855967078186
0.5555555555555556 0.23456790123456786 0.448559670781893
0.1111111111111111 0.09876543209876541 0.11522633744855966
0.16666666666666666 0.17283950617283947 0.22633744855967075
0.3333333333333333 0.24691358024691357 0.33744855967078186
0.6111111111111112 0.3209876543209876 0.448559670781893
0.16666666666666666 0.3333333333333333 0.11522633744855966
0.2222222222222222 0.40740740740740744 0.22633744855967075
0.38888888888888884 0.48148148148148145 0.33744855967078186
0.6666666666666666 0.5555555555555555 0.448559670781893
0 0 0.28806584362139914
0.05555555555555555 0.14814814814814814 0.3991769547325103
0.2222222222222222 0.2962962962962963 0.5102880658436214
0.5 0.4444444444444444 0.6213991769547325
0.1111111111111111 0.012345679012345677 0.28806584362139914
0.16666666666666666 0.16049382716049382 0.3991769547325103
0.3333333333333333 0.30864197530864196 0.5102880658436214
0.6111111111111112 0.4567901234567901 0.6213991769547325
0.2222222222222222 0.09876543209876541 0.28806584362139914
0.2777777777777778 0.24691358024691357 0.3991769547325103
0.4444444444444444 0.3950617283950617 0.5102880658436214
0.7222222222222222 0.5432098765432098 0.6213991769547325
0.3333333333333333 0.3333333333333333 0.28806584362139914
0.38888888888888884 0.48148148148148145 0.3991769547325103
0.5555555555555556 0.6296296296296297 0.5102880658436214
0.8333333333333333 0.7777777777777777 0.6213991769547325
0 0 0.6666666666666666
0.05555555555555555 0.2222222222222222 0.7777777777777777
0.2222222222222222 0.4444444444444444 0.8888888888888888
0.5 0.6666666666666666 1
0.16666666666666666 0.012345679012345677 0.6666666666666666
0.2222222222222222 0.23456790123456786 0.7777777777777777
0.38888888888888884 0.4567901234567901 0.8888888888888888
0.6666666666666666 0.6790123456790124 1
0.3333333333333333 0.09876543209876541 0.6666666666666666
0.38888888888888884 0.3209876543209876 0.7777777777777777
0.5555555555555556 0.5432098765432098 0.8888888888888888
0.8333333333333333 0.7654320987654321 1
0.5 0.3333333333333333 0.6666666666666666
0.5555555555555556 0.5555555555555555 0.7777777777777777
0.7222222222222222 0.7777777777777777 0.8888888888888888
1 1 1