Fix framing tool issues

* Print messages only in verbose mode
* Linearize 8-bit values to 16-bit values properly
* Fix memory leak
This commit is contained in:
Daniel Gao 2024-11-30 14:31:18 -05:00
parent f983da5d16
commit d3962c7e56
2 changed files with 17 additions and 9 deletions

View File

@ -1184,7 +1184,12 @@ Imagefloat* ImProcFunctions::drawFrame(Imagefloat* rgb, const FramingParams& par
// Color::gamma2curve expects a 16-bit value, but the GUI sliders are // Color::gamma2curve expects a 16-bit value, but the GUI sliders are
// using 8-bit values. Step up the user value to 16-bits. // using 8-bit values. Step up the user value to 16-bits.
auto clip = [](int v) { return std::max(0, std::min(v, 255)) * 256; }; auto clip = [](int v) -> int {
int sanitized = std::max(0, std::min(v, 255));
double normalized = static_cast<double>(sanitized) / 255.0;
return normalized * 65535.0;
};
float r = Color::gamma2curve[clip(params.borderRed)]; float r = Color::gamma2curve[clip(params.borderRed)];
float g = Color::gamma2curve[clip(params.borderGreen)]; float g = Color::gamma2curve[clip(params.borderGreen)];
@ -1223,6 +1228,7 @@ Imagefloat* ImProcFunctions::drawFrame(Imagefloat* rgb, const FramingParams& par
} }
} }
delete rgb;
return framed; return framed;
} }

View File

@ -1923,14 +1923,16 @@ private:
// If framing is not enabled, resize values simply pass through to output // If framing is not enabled, resize values simply pass through to output
ImProcFunctions::FramingData framingData = ipf.framing(framingArgs); ImProcFunctions::FramingData framingData = ipf.framing(framingArgs);
printf("Framing Parameters (enabled=%s)\n", framingData.enabled ? "yes" : "no"); if (settings->verbose) {
printf(" Crop: w=%d h=%d\n", cw, ch); printf("Framing Parameters (enabled=%s)\n", framingData.enabled ? "yes" : "no");
printf(" Original resize: w=%d h=%d s=%f\n", printf(" Crop: w=%d h=%d\n", cw, ch);
framingArgs.resizeWidth, framingArgs.resizeHeight, framingArgs.resizeScale); printf(" Original resize: w=%d h=%d s=%f\n",
printf(" Framed image size: w=%d h=%d s=%f\n", framingArgs.resizeWidth, framingArgs.resizeHeight, framingArgs.resizeScale);
framingData.imgWidth, framingData.imgHeight, framingData.scale); printf(" Framed image size: w=%d h=%d s=%f\n",
printf(" Total size: w=%d h=%d\n", framingData.imgWidth, framingData.imgHeight, framingData.scale);
framingData.framedWidth, framingData.framedHeight); printf(" Total size: w=%d h=%d\n",
framingData.framedWidth, framingData.framedHeight);
}
bool labResize = params.resize.enabled && params.resize.method != "Nearest" && bool labResize = params.resize.enabled && params.resize.method != "Nearest" &&
(framingData.scale != 1.0 || params.prsharpening.enabled || framingData.enabled); (framingData.scale != 1.0 || params.prsharpening.enabled || framingData.enabled);