[quote=“zamrate”]Let me finally add that the initial problem, namely filling a RGB image with a colour (or was it copying from one image to another?), ended up in these lines:
template <class Pixel>
forcedinline void set (const Pixel& src) noexcept
b = src.getBlue();
g = src.getGreen();
r = src.getRed();
If its going through here then I believe it is the case for filling an RGB image with a colour that is not gray (all three components equal). When JUCE copies an image at 100% opacity it usually does it line by line with memcpy, for speed (well, that’s what it did last time I looked).
For the case of filling an RGB image with a solid colour that is not gray, it can certainly be done much faster for the case where pixelStride = 3 or pixelStride = 4.
For pixelStride = 3 we need to prepare these 32-bit unsigned values:
BGRB GRBG RBGR …
The innermost loop will copy 3 longwords at a time. If the total number of pixels is below some small threshold (say, 4, 8, or 12 pixels) then we can just do it the long way. This will prevent us from running slower on thin rectangles from the setup overhead.
For RGB or ARGB where pixelStride==4 it is simply
Where A is the alpha for ARGB or simply ignored for RGB. This can be done with 32-bit unsigned copies, 64-bit unsigned copies where available, and also using whatever assembly facilities are available (MMX or the equivalent?)
For all other values of pixelStride we would of course need to use the “slow” routine which you posted.