From 730e315da5a4ce02229e23df5345572976425fa2 Mon Sep 17 00:00:00 2001 From: Hannes Vernooij Date: Fri, 17 Nov 2023 10:17:32 +0100 Subject: [PATCH] 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 --- src/OpenColorIO/ops/lut1d/Lut1DOpGPU.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OpenColorIO/ops/lut1d/Lut1DOpGPU.cpp b/src/OpenColorIO/ops/lut1d/Lut1DOpGPU.cpp index 59091817da..493d73b869 100644 --- a/src/OpenColorIO/ops/lut1d/Lut1DOpGPU.cpp +++ b/src/OpenColorIO/ops/lut1d/Lut1DOpGPU.cpp @@ -154,13 +154,13 @@ void GetLut1DGPUShaderProgram(GpuShaderCreatorRcPtr & shaderCreator, const unsigned long length = lutData->getArray().getLength(); const unsigned long width = std::min(length, defaultMaxWidth); - const unsigned long height = (length / defaultMaxWidth) + 1; + const unsigned long height = ((length - 1) / defaultMaxWidth) + 1; const unsigned long numChannels = lutData->getArray().getNumColorComponents(); - // Note: The 1D LUT needs a GPU texture for the Look-up table implementation. + // Note: The 1D LUT needs a GPU texture for the Look-up table implementation. // However, the texture type & content may vary based on the number of channels // i.e. when all channels are identical a F32 Red GPU texture is enough. - + const bool singleChannel = (numChannels == 1); // Adjust LUT texture to allow for correct 2d linear interpolation, if needed. @@ -335,13 +335,13 @@ void GetLut1DGPUShaderProgram(GpuShaderCreatorRcPtr & shaderCreator, { const std::string str = name + "_computePos(" + shaderCreator->getPixelName(); - ss.newLine() << shaderCreator->getPixelName() << ".r = " + ss.newLine() << shaderCreator->getPixelName() << ".r = " << ss.sampleTex2D(name, str + ".r)") << ".r;"; ss.newLine() << shaderCreator->getPixelName() << ".g = " << ss.sampleTex2D(name, str + ".g)") << (singleChannel ? ".r;" : ".g;"); - ss.newLine() << shaderCreator->getPixelName() << ".b = " + ss.newLine() << shaderCreator->getPixelName() << ".b = " << ss.sampleTex2D(name, str + ".b)") << (singleChannel ? ".r;" : ".b;"); } else