Note that there are some explanatory texts on larger screens.

plurals
  1. POwhy gradient colors and aliasing under Lion are different compare to Snow Leopard?
    primarykey
    data
    text
    <p>Just came across one weird problem. I generate programmatically a gradient inside round cornered square like so:</p> <pre><code>CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceAdobeRGB1998); CGContextRef mcontext = [[NSGraphicsContext currentContext] graphicsPort]; size_t capacityBarGradientNumLocations = 11; CGGradientRef Gradient; CGFloat capacityBarGradientLocations[11] = { /* skipped */ }; CGFloat capacityBarGradientColors[44] = { /* skipped */ }; Gradient = CGGradientCreateWithColorComponents (colorSpace, capacityBarGradientColors, capacityBarGradientLocations, capacityBarGradientNumLocations); CGContextDrawLinearGradient(mcontext,Gradient, CGPointMake(0,baroffset), CGPointMake(0,barheight+baroffset), 0); </code></pre> <p>I've just noticed that the same code produces completely different results between Lion and Snow Leopard on the same mac (I have a dual boot) and monitor with the same color profiles. Please take a look at the screenshot: <img src="https://i.stack.imgur.com/q4v8P.png" alt="Weird gradient problem under Lion"></p> <p>Left part if taken under Lion, the right one - under Snow Leopard. How can I fix my gradient appearance under Lion? </p> <p>Some extra info regarding the above picture. I've used a black color with variable alpha to generate semi transparent gradient i.e:</p> <pre><code>CGFloat capacityBarGradientColors[44] = { 0.0, 0.0, 0.0, .65, 0.0, 0.0, 0.0, .35, /* skipped */ 0.0, 0.0, 0.0, .35, 0.0, 0.0, 0.0, .65, }; </code></pre> <p>I thought maybe there is something wrong with the way i use alpha. Decided to use actual colors with Multiply blending mode and alpha set to 1.0 :</p> <pre><code>CGFloat capacityBarGradientColors[44] = { 0x59/255., 0x59/255., 0x59/255., 1.0, 0xa6/255., 0xa6/255., 0xa6/255., 1.0, /* skipped */ 0xa6/255., 0xa6/255., 0xa6/255., 1.0, 0x59/255., 0x59/255., 0x59/255., 1.0, }; </code></pre> <p>Under Snow Leopard I've got the result I've been looking for. But under Lion I've got completely different picture. take a look at the screenshot: <img src="https://i.stack.imgur.com/F3RDb.png" alt="lion blending mode problem"></p> <p>Left - Lion, right - Snow Leopard</p> <p>Here is the code changes I did:</p> <pre><code>Gradient = CGGradientCreateWithColorComponents (colorSpace, capacityBarGradientColors, capacityBarGradientLocations, capacityBarGradientNumLocations); CGContextSetBlendMode(mcontext, kCGBlendModeMultiply); CGContextDrawLinearGradient(mcontext,Gradient, CGPointMake(0,baroffset), CGPointMake(0,barheight+baroffset), 0); CGContextSetBlendMode(mcontext, kCGBlendModeNormal); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload