Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Shading anomalies
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Shading anomalies

Hi there,

I discovered a problem with CGShadings on Tiger: If I draw a horizontal shading (i.e. the y-coordinates of start and end point are equal) and the red component of both the start and end points is equal to 1.0, the shading will be opaque (alpha values for both start and end point will be ignored).

If I change the red component for one of the points to a value less than 1.0, or change the y-coordinate of one of the points, the shading draws as expected. Here is the code:

- (void) drawRect: (NSRect) rect
  CGShadingRef shading;
  CGFunctionRef shadingFunction;
  CGColorSpaceRef colorSpace;
  CGFunctionCallbacks callbacks;

CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];

float inputValueRange[2] = {0.0f, 1.0f};
float outputValueRange[8] = {0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f};

  callbacks.version = 0;
  callbacks.evaluate = evaluateGradient;
  callbacks.releaseInfo = NULL;

  colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);

shadingFunction = CGFunctionCreate(NULL, 1, inputValueRange, 4, outputValueRange, &callbacks);
shading = CGShadingCreateAxial(colorSpace, CGPointMake (rect.origin.x, rect.size.height*0.5f),
CGPointMake(rect.size.width, rect.size.height*0.5f), shadingFunction, false, false);

  CGContextDrawShading(context, shading);


static void evaluateGradient(void *info, const float *in, float *out)
  float factor = in[0];

  // gradient from opaque white to transparent red

  out[0] = 1.0f*(1.0f - factor) + 1.0f*factor;
  out[1] = 1.0f*(1.0f - factor) + 0.0f*factor;
  out[2] = 1.0f*(1.0f - factor) + 0.0f*factor;
  out[3] = 1.0f*(1.0f - factor) + 0.0f*factor;

Am I doing something wrong or is this bug already known?

Thanks for any help,

_______________________________________________ Do not post admin requests to the list. They will be ignored. Quartz-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden

Visit the Apple Store online or at retail locations.

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.