Function should return float, but it gets messed up!
Posted
by Andre
on Stack Overflow
See other posts from Stack Overflow
or by Andre
Published on 2010-04-07T10:27:57Z
Indexed on
2010/04/07
10:33 UTC
Read the original article
Hit count: 278
Hi guys,
I'm going crazy here.
I have a function that should return a float number:
- (float) getHue:(UIColor *)original
{
NSLog(@"getHue");
const CGFloat *componentColors = CGColorGetComponents(original.CGColor);
float red = componentColors[0];
float green = componentColors[1];
float blue = componentColors[2];
float h = 0.0f;
float maxChannel = fmax(red, fmax(green, blue));
float minChannel = fmin(red, fmin(green, blue));
if (maxChannel == minChannel)
h = 0.0f;
else if (maxChannel == red)
h = 0.166667f * (green - blue) / (maxChannel - minChannel) + 0.000000f;
else if (maxChannel == green)
h = 0.166667f * (blue - red) / (maxChannel - minChannel) + 0.333333f;
else if (maxChannel == blue)
h = 0.166667f * (red - green) / (maxChannel - minChannel) + 0.666667f;
else
h = 0.0f;
if (h < 0.0f)
h += 1.0f;
NSLog(@"getHue results: %f", h);
return h;
}
The NSLog will trace it correctly (i.e: 0.005), but the actual return value of the function is NULL.
I've tried getting that value in so many ways and it never works.
float originalHue = [self getHue:original];
results in a building error, as it says: "incompatible types in initialization"
float *originalHue = [self getHue:original];
results in a null return.
I've tried other ways, but it never actually gets the value properly.
Any thoughts?
Cheers guys, Andre
© Stack Overflow or respective owner