From 1a800b67d74c409fd2e4b6c11e04548b5bf5d999 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Fri, 6 Jun 2025 12:08:15 +1000 Subject: attempt at improving GCC ?saturation accuracy [skip ci] --- source/core/StarImageProcessing.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'source/core/StarImageProcessing.cpp') diff --git a/source/core/StarImageProcessing.cpp b/source/core/StarImageProcessing.cpp index 1cfd847..b18fcf1 100644 --- a/source/core/StarImageProcessing.cpp +++ b/source/core/StarImageProcessing.cpp @@ -354,6 +354,25 @@ StringList imageOperationReferences(List const& operations) { return references; } +#ifdef __GNUC__ +#pragma GCC push_options +#pragma GCC optimize("-fno-fast-math -fassociative-math -freciprocal-math") +#endif +static void processSaturationShift(Image& image, SaturationShiftImageOperation const* op) { + image.forEachPixel([&op](unsigned, unsigned, Vec4B& pixel) { + if (pixel[3] != 0) { + Color color = Color::rgba(pixel); + color.setSaturation(clamp(color.saturation() + op->saturationShiftAmount, 0.0f, 1.0f)); + pixel = color.toRgba(); + } + }); +} +#ifdef __GNUC__ +#pragma GCC pop_options +#endif + + + void processImageOperation(ImageOperation const& operation, Image& image, ImageReferenceCallback refCallback) { if (image.bytesPerPixel() == 3) { // Convert to an image format that has alpha so certain operations function properly @@ -365,13 +384,7 @@ void processImageOperation(ImageOperation const& operation, Image& image, ImageR pixel = Color::hueShiftVec4B(pixel, op->hueShiftAmount); }); } else if (auto op = operation.ptr()) { - image.forEachPixel([&op](unsigned, unsigned, Vec4B& pixel) { - if (pixel[3] != 0) { - Color color = Color::rgba(pixel); - color.setSaturation(clamp(color.saturation() + op->saturationShiftAmount, 0.0f, 1.0f)); - pixel = color.toRgba(); - } - }); + processSaturationShift(image, op); } else if (auto op = operation.ptr()) { image.forEachPixel([&op](unsigned, unsigned, Vec4B& pixel) { if (pixel[3] != 0) { -- cgit v1.2.3