Repository navigation
feat: colorGrade() in @jimp/plugin-lut, 3D LUT color grading from .cube files and Hald images - #1570
Merged
Merged
Conversation
image.lut(lut, { strength }) maps every pixel through a 3D LUT with
tetrahedral interpolation and blends with the original by strength.
Alpha is unchanged.
- parseCubeLut(text) reads .cube files: LUT_3D_SIZE, TITLE, DOMAIN_MIN,
DOMAIN_MAX, Resolve's LUT_3D_INPUT_RANGE, comments, a BOM and CRLF.
It rejects 1D LUTs (LUT_1D_SIZE, LUT_1D_INPUT_RANGE) and malformed
files with errors that name the line.
- The LUT is plain data (Float32Array, or a number[] from JSON), so it
works in apply() and can be posted to a worker.
- A Hald CLUT image (L³ × L³ pixels) can be passed instead, and is read
in place without converting it.
- Outputs are clamped to 0-255, inputs outside the domain are clamped,
and strength is clamped to 0-1.
The fixtures, including the reference outputs from FFmpeg's lut3d and
haldclut filters, are made by scripts/generate-fixtures.mjs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds lut() to Jimp and exports parseCubeLut and the Lut and LutOptions types from jimp. It adds 4.6 KB (1.8 KB gzipped, about 0.8%) to the browser bundle, less than plugin-dither, and lets apply(), @jimp/worker and @jimp/server use lut with the default Jimp class. Tests that a LUT and a Hald image can be sent to a worker in edits, and that the image server can apply LUTs by name through a custom method (LUTs are too large for URL params, so lut isn't in defaultAllowedEdits). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- lut() page with before/after images, a playground op with three Hald CLUT looks and a strength slider, and sections on apply/JSON, workers and serving named looks from @jimp/server. - parseCubeLut() page with the returned fields, the .cube format and its errors. - scripts/lut-images.mjs makes the looks (defined in the script, so no third-party LUTs) and the images in public/lut/. - @jimp/plugin-lut in the custom Jimp package table. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The method's name now says what it does, next to sepia, greyscale and color. Its options type is ColorGradeOptions, and the docs page moves to /methods/color-grade/. parseCubeLut, the Lut type and @jimp/plugin-lut keep their names, since they're about LUTs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Grades test-utils' dice.png with the teal and orange .cube LUT and with the Hald image of the same look, and snapshots both. The dice are on a transparent background, so the snapshots also show alpha is kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hipstersmoothie
force-pushed
the
sesh/lut-plugin
branch
from
November 25, 2026 03:46
301ea6e to
89c6a42
Compare
Collaborator
Author
|
🚀 PR was released in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
image.colorGrade(lut, { strength }), which color grades an image with a 3D LUT, andparseCubeLut(text), which reads.cubefiles.API
colorGrade(lut: Lut | JimpInstance, options?: ColorGradeOptions)strengthblends with the original. It's clamped to 0–1, likesepia(amount).parseCubeLut(text): LutLUT_3D_SIZE(2–256),TITLE,DOMAIN_MIN/DOMAIN_MAX, Resolve'sLUT_3D_INPUT_RANGE,#comments, blank lines, a BOM and CRLF line endings.LUT_1D_SIZEandLUT_1D_INPUT_RANGE(1D LUTs and shapers), plus malformed files. Each error names the line.Lutis plain data:{ title?, size, domainMin?, domainMax?, data }.datais aFloat32Array, butcolorGrade()also accepts anumber[](from JSON).lut()and was renamed tocolorGrade()(b7208bc) so the name says what it does.parseCubeLut,Lutand the package name@jimp/plugin-lutkeep "LUT", because they're about the LUT itself.Speed on a 12 MP image: about 150 ms with a
.cubeLUT and about 195 ms with a Hald image (sepiatakes about 370 ms). Parsing a 17³.cubetakes about 3 ms.Bundle size and the default
jimpbundle@jimp/plugin-lutalone (zod/types external)methodsonly (the parser tree-shaken out)main→ this PRI've added it to the default plugins, in its own commit (3105b19) so it's easy to drop. It costs +1.8 KB gzipped, and with it the default
Jimpworks withcolorGradeinapply(),@jimp/workerand@jimp/serverwithout needingcreateJimp. It also lets the docs page have a live playground. If you'd rather keep it out, drop that commit. The docs examples would then needcreateJimp, and the playground op would need to go.apply / worker / server
apply():["colorGrade", lut, { strength }]works. AFloat32Arraydoesn't surviveJSON.stringify, so the docs showArray.from(lut.data)for storing a LUT as JSON.@jimp/worker: a parsed LUT and a Hald image both work in edits, because the worker's protocol already copies typed arrays and images. Tested inworker.node.test.ts.@jimp/server: a LUT is too large to put in a URL, socolorGradestays out ofdefaultAllowedEdits. The recommended approach, documented and tested inhandler.test.ts, needs no server changes. Load the LUTs on the server and register a small custom method, e.g.look(image, name, options), then allow it withallowedEdits: [...defaultAllowedEdits, "look"]. Clients request a look by name through the signededitsparam.presetsoption (preset=warm→ a stored edit list) would serve named looks without signatures. That would be a general feature for any edits, not specific to LUTs, so I left it out of this PR.Tests
.cubefixture..cubeand Hald).strengthblend and clamping,number[]data from JSON, grading a Hald image with itself, andapply.lut3dandhaldclut(interp=tetrahedral) on a 64×64 RGBA sweep. Red, green and blue are always equal to FFmpeg's or exactly 1 higher, because FFmpeg truncates to 8 bits where Jimp rounds. Alpha is identical. The fixture LUT is non-separable, so FFmpeg's trilinear output differs from the tetrahedral reference by up to 40 levels. That means the test can tell the two methods apart.dice.pnggraded with the teal and orange.cubeLUT and with the Hald image of the same look, inplugins/plugin-lut/src/__image_snapshots__/(about 230 KB each). The dice are on a transparent background, so the snapshots also show alpha is kept.plugins/plugin-lut/scripts/generate-fixtures.mjs, and every docs look bypackages/docs/scripts/lut-images.mjs. No third-party LUTs are included.Root
pnpm build(with the browser bundle check),pnpm lint, the plugin-lut, jimp (including type tests), server and worker tests, and the docs build (astro check) all pass.Docs
methods/color-grade.mdx(before/after images, a playground op with three looks plus a strength slider, and apply/worker/server sections) andmethods/parse-cube-lut.mdx.data/methods.ts, and plugin-lut has a row in the custom-Jimp package table.🤖 Generated with Claude Code