Difference in Mac and Windows versions of setGradientFill/fillEllipse when both alpha channel and RGB gradient used


Image 1 is basic image generated on Windows (software renderer).

Image 2 is generated on Windows by the following lines following the base image generation:

gd = ColourGradient(Colour(0x3bffffff), innerFlatRect.getCentreX(), innerFlatRect.getCentreY(),
    Colour(0x00000000), innerFlatRect.getCentreX(), innerFlatRect.getBottom(), true);


Image 3 is basic image generated on Mac (Core Graphics renderer)

Image 4 is generated on Mac by the same lines as above following the base image generation.

You may see the same lines lead to different image on Mac and Windows.

Image 5 is generated on Mac by instead of Colour(0x00000000), Colour(0x00ffffff) was used.

Also on Windows both Colour(0x00000000) and Colour(0x00ffffff) lead to the same result.

As you may see there’s a problem or difference in implementation when both alpha channel and RGB gradients are used at the same time.

JUCE 5.4.7

I’m not really sure but you’ve might stumbled on a bug?

Try adding the following line:

jassert (CGColorSpaceGetNumberOfComponents(colourSpace) == 4);


static CGGradientRef createGradient (const ColourGradient& g, CGColorSpaceRef colourSpace)

In juce_mac_CoreGraphicsContext.mm

It’ll fail. (at least on my machine).
For testing purposes try setting CGColorSpaceRef to be from:

CGColorSpaceCreateWithName (kCGColorSpaceSRGB);

Would be interesting to know if it helped on your case.
(another approach less nice is to premultiply the Colours).


There’s no difference between CGColorSpaceCreateWithName (kCGColorSpaceSRGB) or rgbColourSpace, in both cases CGColorSpaceGetNumberOfComponents(colourSpace) returns 3 in createGradient().

This failed for me as well in OS X 10.13.6 on a 27" imac from 2011. So, a normal imac, not a retina display or anything.

Can you explain this? I would really like to get matching gradients between what I’ve sketched out in an SVG editor and what I see in JUCE, and have no idea how to match them without using JUCE_LIVE_CONSTANT for the R, G, and B values while using Digital Color Meter to see what value I’m actually getting.