Skip to content

Commit

Permalink
one more lut refactor fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
toloudis committed Mar 28, 2024
1 parent 4dc9fd6 commit c055541
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/aics-image-viewer/shared/utils/controlPointsToLut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function clamp(x: number): number {

// @param {Object[]} controlPoints - array of {x:number, opacity:number, color:string}
// @return {Uint8Array} array of length 256*4 representing the rgba values of the gradient
export function controlPointsToLut(controlPoints: ControlPoint[]): Uint8Array {
export function controlPointsToLut(controlPoints: ControlPoint[]): Lut {
const grd = ctx.createLinearGradient(0, 0, 255, 0);
if (!controlPoints.length || controlPoints.length < 1) {
console.log("warning: bad control points submitted to makeColorGradient; reverting to linear greyscale gradient");
Expand All @@ -51,7 +51,14 @@ export function controlPointsToLut(controlPoints: ControlPoint[]): Uint8Array {
ctx.fillStyle = grd;
ctx.fillRect(0, 0, 256, 1);
const imgData = ctx.getImageData(0, 0, 256, 1);
return new Uint8Array(imgData.data.buffer);

const lut = new Lut();
lut.lut = new Uint8Array(imgData.data.buffer);
lut.controlPoints = controlPoints;

// TODO Replace this whole function with new Lut().createFromControlPoints(controlPoints) ?

return lut;
}

export function initializeLut(
Expand Down Expand Up @@ -107,6 +114,6 @@ export function initializeLut(
...controlPoint,
color: TFEDITOR_DEFAULT_COLOR,
}));
aimg.setLut(channelIndex, lutObject.lut);
aimg.setLut(channelIndex, lutObject);
return newControlPoints;
}

0 comments on commit c055541

Please sign in to comment.