From f05031a898399e5c4143caec41874c4b51c3be6f Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 10 Dec 2024 20:02:03 +0000 Subject: [PATCH] Image: Convert structs to lambdas in implementation --- modules/juce_graphics/images/juce_Image.cpp | 33 ++------------------- 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/modules/juce_graphics/images/juce_Image.cpp b/modules/juce_graphics/images/juce_Image.cpp index fa4c38d42f..adea8ffb34 100644 --- a/modules/juce_graphics/images/juce_Image.cpp +++ b/modules/juce_graphics/images/juce_Image.cpp @@ -550,15 +550,8 @@ struct PixelIterator static void iterate (const Image::BitmapData& data, const PixelOperation& pixelOp) { for (int y = 0; y < data.height; ++y) - { - auto p = data.getLinePointer (y); - for (int x = 0; x < data.width; ++x) - { - pixelOp (*reinterpret_cast (p)); - p += data.pixelStride; - } - } + pixelOp (*reinterpret_cast (data.getPixelPointer (x, y))); } }; @@ -575,40 +568,20 @@ static void performPixelOp (const Image::BitmapData& data, const PixelOperation& } } -struct AlphaMultiplyOp -{ - float alpha; - - template - void operator() (PixelType& pixel) const - { - pixel.multiplyAlpha (alpha); - } -}; - void Image::multiplyAllAlphas (float amountToMultiplyBy) { jassert (hasAlphaChannel()); const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), BitmapData::readWrite); - performPixelOp (destData, AlphaMultiplyOp { amountToMultiplyBy }); + performPixelOp (destData, [&] (auto& p) { p.multiplyAlpha (amountToMultiplyBy); }); } -struct DesaturateOp -{ - template - void operator() (PixelType& pixel) const - { - pixel.desaturate(); - } -}; - void Image::desaturate() { if (isARGB() || isRGB()) { const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), BitmapData::readWrite); - performPixelOp (destData, DesaturateOp()); + performPixelOp (destData, [] (auto& p) { p.desaturate(); }); } }