[Solved] Small ImageFill::copyRow change, which seems sensible to me


#1

Hi Jules, I know how you are feeling about software renderer optimization, but still I've decided to post that, maybe it would be useful to someone. Original method:

        forcedinline void copyRow (DestPixelType* dest, SrcPixelType const* src, int width) const noexcept
        {
            if (srcData.pixelStride == 3 && destData.pixelStride == 3)
            {
                memcpy (dest, src, sizeof (PixelRGB) * (size_t) width);
            }
            else if (srcData.pixelFormat == Image::PixelFormat::RGB && destData.pixelFormat == Image::PixelFormat::RGB && srcData.pixelStride == destData.pixelStride)
            {
                memcpy(dest, src, width * srcData.pixelStride);
            }
            else
            {
                const int destStride = destData.pixelStride;
                const int srcStride = srcData.pixelStride;

                do
                {
                    dest->blend (*src);
                    dest = addBytesToPointer (dest, destStride);
                    src = addBytesToPointer (src, srcStride);
                } while (--width > 0);
            }
        }

Applied change:

--- a/modules/juce_graphics/native/juce_RenderingHelpers.h
+++ b/modules/juce_graphics/native/juce_RenderingHelpers.h
@@ -894,6 +894,10 @@ namespace EdgeTableFillers
             {
                 memcpy (dest, src, sizeof (PixelRGB) * (size_t) width);
             }
+            else if (srcData.pixelFormat == Image::PixelFormat::RGB && destData.pixelFormat == Image::PixelFormat::RGB && srcData.pixelStride == destData.pixelStride)
+            {
+                memcpy(dest, src, width * srcData.pixelStride);
+            }
             else
             {
                 const int destStride = destData.pixelStride;

This change would allow to copy RGB WindowsBitmapImage when using drawImageTo instead of blending it (In this case both pixelStrides would be equal to 4 for 32-bit video card, but pixelFormat still would be RGB). Or maybe I'm missing something?


#2

Yes, can't see anything wrong with that! (And it could actually replace the previous if statement too) Thanks, I'll have a look and maybe make a change there.


#3

Yes, I also thought that previous if statement shouldn't be needed after this change. Thanks!