Skip to content

Commit 730e315

Browse files
fixed off-by-one error in the pixel height calculation
It should be max index / max size because 4096 / 4096 + 1 = 2, which means that two rows are allocated when a LUT1D with a size of 4096 fits in a 1D texture of 4096 pixels. Signed-off-by: Hannes Vernooij <[email protected]>
1 parent 4f4f30e commit 730e315

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/OpenColorIO/ops/lut1d/Lut1DOpGPU.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ void GetLut1DGPUShaderProgram(GpuShaderCreatorRcPtr & shaderCreator,
154154

155155
const unsigned long length = lutData->getArray().getLength();
156156
const unsigned long width = std::min(length, defaultMaxWidth);
157-
const unsigned long height = (length / defaultMaxWidth) + 1;
157+
const unsigned long height = ((length - 1) / defaultMaxWidth) + 1;
158158
const unsigned long numChannels = lutData->getArray().getNumColorComponents();
159159

160-
// Note: The 1D LUT needs a GPU texture for the Look-up table implementation.
160+
// Note: The 1D LUT needs a GPU texture for the Look-up table implementation.
161161
// However, the texture type & content may vary based on the number of channels
162162
// i.e. when all channels are identical a F32 Red GPU texture is enough.
163-
163+
164164
const bool singleChannel = (numChannels == 1);
165165

166166
// Adjust LUT texture to allow for correct 2d linear interpolation, if needed.
@@ -335,13 +335,13 @@ void GetLut1DGPUShaderProgram(GpuShaderCreatorRcPtr & shaderCreator,
335335
{
336336
const std::string str = name + "_computePos(" + shaderCreator->getPixelName();
337337

338-
ss.newLine() << shaderCreator->getPixelName() << ".r = "
338+
ss.newLine() << shaderCreator->getPixelName() << ".r = "
339339
<< ss.sampleTex2D(name, str + ".r)") << ".r;";
340340

341341
ss.newLine() << shaderCreator->getPixelName() << ".g = "
342342
<< ss.sampleTex2D(name, str + ".g)") << (singleChannel ? ".r;" : ".g;");
343343

344-
ss.newLine() << shaderCreator->getPixelName() << ".b = "
344+
ss.newLine() << shaderCreator->getPixelName() << ".b = "
345345
<< ss.sampleTex2D(name, str + ".b)") << (singleChannel ? ".r;" : ".b;");
346346
}
347347
else

0 commit comments

Comments
 (0)