IOS Gets the lab string value of the Uicolor object.

Source: Internet
Author: User



-(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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.