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

**URL:** <https://forum.juce.com/t/difference-in-mac-and-windows-versions-of-setgradientfill-fillellipse-when-both-alpha-channel-and-rgb-gradient-used/41744>\
**Category:** General JUCE discussion\
**Created:** [September 14, 2020, 8:46pm UTC](https://forum.juce.com/t/difference-in-mac-and-windows-versions-of-setgradientfill-fillellipse-when-both-alpha-channel-and-rgb-gradient-used/41744 "2020-09-14T20:46:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vladg](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/vladg/32/78_2.png) [@vladg](https://forum.juce.com/u/vladg)\
**Post date:** [September 14, 2020, 8:46pm UTC](https://forum.juce.com/t/difference-in-mac-and-windows-versions-of-setgradientfill-fillellipse-when-both-alpha-channel-and-rgb-gradient-used/41744/1 "2020-09-14T20:46:28Z")

</div>

![screenshot](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/7/776c3dd750c17d15d7107b5ea964e9177550aa22.png)

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);

g.setGradientFill(gd);
g.fillEllipse(innerFlatRect);

```

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

---

<div class="post-metadata">

**Author:** ![ttg](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ttg/32/14456_2.png) [@ttg](https://forum.juce.com/u/ttg)\
**Post date:** [September 15, 2020, 12:59pm UTC](https://forum.juce.com/t/difference-in-mac-and-windows-versions-of-setgradientfill-fillellipse-when-both-alpha-channel-and-rgb-gradient-used/41744/2 "2020-09-15T12:59:39Z")

</div>

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

Try adding the following line:

```
jassert (CGColorSpaceGetNumberOfComponents(colourSpace) == 4);

```

To:

```auto
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:

```auto
CGColorSpaceCreateWithName (kCGColorSpaceSRGB);

```

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

---

<div class="post-metadata">

**Author:** ![vladg](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/vladg/32/78_2.png) [@vladg](https://forum.juce.com/u/vladg)\
**Post date:** [September 16, 2020, 1:08pm UTC](https://forum.juce.com/t/difference-in-mac-and-windows-versions-of-setgradientfill-fillellipse-when-both-alpha-channel-and-rgb-gradient-used/41744/3 "2020-09-16T13:08:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![matkatmusic](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@matkatmusic](https://forum.juce.com/u/matkatmusic)\
**Post date:** [February 18, 2021, 6:52am UTC](https://forum.juce.com/t/difference-in-mac-and-windows-versions-of-setgradientfill-fillellipse-when-both-alpha-channel-and-rgb-gradient-used/41744/4 "2021-02-18T06:52:54Z")

</div>

> [@ttg](#):
>
> `jassert (CGColorSpaceGetNumberOfComponents(colourSpace) == 4);`

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.

> [@ttg](#):
>
> (another approach less nice is to premultiply the Colours).

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.
