-(nsstring *) getcielabstring: (uicolor *) Origincolor {
//Method provided by the Colours class extension
nsdictionary *ciedict = [selfgetcie_labarraybycolor: Origincolor];
return [nsstringstringwithformat:@ "(%0.2f,%0.2f, %0.2f) ",
[ciedict[@ "cie_l"]floatvalue],
[ciedict[@ "cie_a"]floatvalue],
[ciedict[@ "Cie_b"]floatvalue];
}
#pragma mark-lab from Color
-(nsdictionary *) Getcie_labarraybycolor: (uicolor *) Origincolor {
//Convert Color to XYZ format first
nsdictionary *rgba = [selfgetrgbdictionarybycolor: Origincolor];
CGFloat R = [rgba[@ "R"]floatvalue];
CGFloat g = [rgba[@ "G"]floatvalue];
CGFloat b = [rgba[@ "B"]floatvalue];
//Create Deltar block
void (^DELTARGB) (cgfloat *r);
Deltargb = ^ (cgfloat *r) {
*r = (*r >0.04045)? POW ((*r +0.055)/1.055,2.40): (*r/12.92);
};
Deltargb (&R);
Deltargb (&G);
Deltargb (&B);
CGFloat X = r*41.24 + g*35.76 + b*18.05;
CGFloat Y = r*21.26 + g*71.52 + b*7.22;
CGFloat Z = r*1.93 + g*11.92 + b*95.05;
//Convert XYZ to l*a*b*
X = x/95.047;
Y = y/100.000;
Z = z/108.883;
//Create DELTAF block
void (^DELTAF) (cgfloat *f);
Deltaf = ^ (cgfloat *f) {
*f = (*f >pow((6.0/29.0),3.0))? POW (*f,1.0/3.0): (1/3) *POW((29.0/6.0),2.0 ) * *f + 4/29.0;
};
Deltaf (&X);
Deltaf (&y);
Deltaf (&Z);
nsnumber *l = @ (*y-+);
nsnumber *a = @ ( x-y);
nsnumber *b = @ ( y-z);
return@{@ "cie_l": L,
@ "Cie_a": A,
@ "Cie_b": B,
@ "Cie_alpha": rgba[@ "A"};
}
/**
* gets The RGB value of the Uicolor object .
*
* @return Dictionary objects that contain RGB values.
*/
-(nsdictionary *) Getrgbdictionarybycolor: (uicolor *) origincolor
{
cgfloat r=0, g=0, b=0, a=0;
if ([ self respondstoselector:@selector(getRed:green:blue:alpha:)]) {
[Origincolor getred: &r green: &g Blue: &b Alpha:&a];
}
Else {
Const cgfloat *components = cgcolorgetcomponents(origincolor. Cgcolor);
r = components[0];
g = components[1];
b = components[2];
A = components[3];
}
return @{@ "R":@ (R),
@ "G":@ (g),
@ "B":@ (b),
@ "A":@ (a)};
}
IOS Gets the lab string value of the Uicolor object.