static long rgba_to_lchaba (char *src, char *dst, long n) { while (n--) { double R = ((double *) src)[0]; double G = ((double *) src)[1]; double B = ((double *) src)[2]; double alpha = ((double *) src)[3]; double X, Y, Z, L, a, b, C, H; //convert RGB to XYZ RGB_to_XYZ (R, G, B, &X, &Y, &Z); //convert XYZ to Lab XYZ_to_LAB (X, Y, Z, &L, &a, &b); //convert Lab to LCH(ab) ab_to_CHab (a, b, &C, &H); ((double *) dst)[0] = L; ((double *) dst)[1] = C; ((double *) dst)[2] = H; ((double *) dst)[3] = alpha; src += sizeof (double) * 4; dst += sizeof (double) * 4; } return n; }
static long rgba_to_lab (char *src, char *dst, long n) { while (n--) { double R = ((double *) src)[0]; double G = ((double *) src)[1]; double B = ((double *) src)[2]; double X, Y, Z, L, a, b; //convert RGB to XYZ RGB_to_XYZ (R, G, B, &X, &Y, &Z); //convert XYZ to Lab XYZ_to_LAB (X, Y, Z, &L, &a, &b); ((double *) dst)[0] = L; ((double *) dst)[1] = a; ((double *) dst)[2] = b; src += sizeof (double) * 4; dst += sizeof (double) * 3; } return n; }
//--------------------------------------------------------------------------- void __fastcall TMainForm::CalculateColors() { unsigned char red,green,blue; try { red = StrToInt(this->LabeledEdit1->Text); green = StrToInt(this->LabeledEdit2->Text); blue = StrToInt(this->LabeledEdit3->Text); } catch(...) { return; } double r,g,b; double x,y,z; double l,a,bb; double h,s,v; double ll; r = (double)red / 255.; g = (double)green / 255.; b = (double)blue / 255.; RGB_to_XYZ(r,g,b,x,y,z); LabeledEdit4->Text = FormatFloat("0.000", x); LabeledEdit5->Text = FormatFloat("0.000", y); LabeledEdit6->Text = FormatFloat("0.000", z); XYZ_to_LAB(x,y,z,l,a,bb); LabeledEdit7->Text = FormatFloat("000.000", l); LabeledEdit8->Text = FormatFloat("000.000", a); LabeledEdit9->Text = FormatFloat("000.000", bb); RGB_to_HSV(r,g,b,h,s,v); LabeledEdit10->Text = FormatFloat(".000", h); LabeledEdit11->Text = FormatFloat(".000", s); LabeledEdit12->Text = FormatFloat(".000", v); RGB_to_HSL(r,g,b,h,s,ll); LabeledEdit13->Text = FormatFloat(".000", h); LabeledEdit14->Text = FormatFloat(".000", s); LabeledEdit15->Text = FormatFloat(".000", ll); }
void CMultiColor::lab(double& l, double& a, double& b) { double x,y,z; RGB_to_XYZ(m_r, m_g, m_b, x,y,z); XYZ_to_LAB(x,y,z,l,a,b); }
void CMultiColor::xyz(double& x, double& y, double& z) { RGB_to_XYZ(m_r, m_g, m_b, x,y,z); }