/*-----------------------------------------------------------------* Color Red-Green Shade Blue-Yellow+L *-----------------------------------------------------------------*/ vec3 valuetoshadowcolorRGshadeBYL(float value, float shadewide, float shadow){ float l = L + shadewide *shaderange*1*1 - shadowrange*(1-shadow) * 1; float a = (value-0.5)* lab_a * 1, b = 1*lab_b* shadewide * 1; vec3 xyz = LabtoXYZ(l,a,b); //return vec3(l/100); return RGBnonlinearRGB(XYZtoRGB(xyz)); }
long CxImage::Histogram(long* red, long* green, long* blue, long* gray, long colorspace) { if (!pDib) return 0; RGBQUAD color; if (red) memset(red,0,256*sizeof(long)); if (green) memset(green,0,256*sizeof(long)); if (blue) memset(blue,0,256*sizeof(long)); if (gray) memset(gray,0,256*sizeof(long)); long xmin,xmax,ymin,ymax; if (pSelection){ xmin = info.rSelectionBox.left; xmax = info.rSelectionBox.right; ymin = info.rSelectionBox.bottom; ymax = info.rSelectionBox.top; } else { xmin = ymin = 0; xmax = head.biWidth; ymax=head.biHeight; } for(long y=ymin; y<ymax; y++){ for(long x=xmin; x<xmax; x++){ #if CXIMAGE_SUPPORT_SELECTION if (SelectionIsInside(x,y)) #endif //CXIMAGE_SUPPORT_SELECTION { switch (colorspace){ case 1: color = HSLtoRGB(GetPixelColor(x,y)); break; case 2: color = YUVtoRGB(GetPixelColor(x,y)); break; case 3: color = YIQtoRGB(GetPixelColor(x,y)); break; case 4: color = XYZtoRGB(GetPixelColor(x,y)); break; default: color = GetPixelColor(x,y); } if (red) red[color.rgbRed]++; if (green) green[color.rgbGreen]++; if (blue) blue[color.rgbBlue]++; if (gray) gray[(BYTE)RGB2GRAY(color.rgbRed,color.rgbGreen,color.rgbBlue)]++; } } } long n=0; for (int i=0; i<256; i++){ if (red && red[i]>n) n=red[i]; if (green && green[i]>n) n=green[i]; if (blue && blue[i]>n) n=blue[i]; if (gray && gray[i]>n) n=gray[i]; } return n; }
vec3 valuetocolor(float value){ float lab_a = 0.7, lab_b = 0.5, lab_c = 0.7, lab_d = 0.6; float labangle = radians(lab_a*100.0+(270.0-lab_a*100.0+(lab_b-0.5)*100.0)*(1.0-value)); vec3 xyz = LabtoXYZ(lab_d*100.0, (value-0.5)*30 + 0*lab_c*100.0*cos(labangle), 0*lab_c*100.0*sin(labangle)); vec3 rgb = XYZtoRGB(xyz); return RGBnonlinearRGB(rgb); }
void main(){ vec2 shadowTexCoord = Geom.screentexcoord * 0.5 + 0.5; shadowTexCoord.y = 1 - shadowTexCoord.y; shadowTexCoord *= shadowTexCoordSize; float shadow = texture(shadowTex, shadowTexCoord).x; Color = vec4 (RGBnonlinearRGB (XYZtoRGB (LabtoXYZ (inColorLab.x - shadowRange * (1 - shadow), inColorLab.y, inColorLab.z))), 1); }
void ColorSpace::XYZtoRGB (CoImage* pIn, CoImage* pOut) { assert (pIn->GetType() == MAT_Tfloat); assert (pOut->GetType() == MAT_Tbyte); float* prX = pIn->m_matX.data.fl[0]; float* prY = pIn->m_matY.data.fl[0]; float* prZ = pIn->m_matZ.data.fl[0]; BYTE* pbR = pOut->m_matX.data.ptr[0]; BYTE* pbG = pOut->m_matY.data.ptr[0]; BYTE* pbB = pOut->m_matZ.data.ptr[0]; for (int i = 0; i < pIn->GetHeight() * pIn->GetWidth(); i ++) { XYZtoRGB(prX[i], prY[i], prZ[i], &pbR[i], &pbG[i], &pbB[i]); } }
JNIEXPORT void JNICALL Java_jp_dego_sample_ipcv_MainActivity_checkColorSpace(JNIEnv *env, jobject obj, jobject bmp) { AndroidBitmapInfo info; void* pixels; // Bitmapの情報を取得 if (AndroidBitmap_getInfo(env, bmp, &info) < 0) return; // Bitmapのフォーマットをチェック if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) return; // Bitmapをロック if (AndroidBitmap_lockPixels(env, bmp, &pixels) < 0) return; int i, j; jint *p = pixels; for (j = 0; j < info.height; j++) { for (i = 0; i < info.width; i++) { ARGB argb = {0, 0, 0, 0}; argb.red = getR(p[j * info.width + i]); argb.green = getG(p[j * info.width + i]); argb.blue = getB(p[j * info.width + i]); XYZ xyz; // LUV luv; // RGBtoXYZ(&argb, &xyz); // XYZtoLUV(&xyz, &luv); // LUVtoXYZ(&luv, &xyz); // XYZtoRGB(&xyz, &argb); LAB lab; RGBtoXYZ(&argb, &xyz); XYZtoLAB(&xyz, &lab); LABtoXYZ(&lab, &xyz); XYZtoRGB(&xyz, &argb); p[j * info.width + i] = createColorFromARGB(argb); } } }
/// <summary> /// Converts CIELab to RGB. /// </summary> void ColorSpace::LabtoRGB(float l, float a, float b, BYTE* red, BYTE* green, BYTE* blue) { float x,y,z; LabtoXYZ(l, a, b, &x,&y,&z); XYZtoRGB(x,y,z,red,green,blue); }
//----------------------------------------------------------------------------- // LCH(uv) to RGB void LCHUVtoRGB(float L, float C, float H, float* RGB) { LCHtoLAB(L,C,H,RGB); LUVtoXYZ(RGB[0],RGB[1],RGB[2],RGB); XYZtoRGB(RGB[0],RGB[1],RGB[2],RGB); }
//----------------------------------------------------------------------------- // LUV to RGB void LUVtoRGB(float L, float U, float V, float* RGB) { LUVtoXYZ(L,U,V,RGB); XYZtoRGB(RGB[0],RGB[1],RGB[2],RGB); }
//----------------------------------------------------------------------------- void LABtoRGB(float L, float A, float B, float* RGB) { LABtoXYZ(L,A,B,RGB); XYZtoRGB(RGB[0],RGB[1],RGB[2],RGB); }
/*-----------------------------------------------------------------* Color Red-Green Shade Blue-Yellow b *-----------------------------------------------------------------*/ vec3 valuetoshadowcolorRGshadeBY(float value, float shadewide, float shadow){ float l = 75 - 30*(1-shadow), a = (value-0.5)*100*1.4 * 0, b = -shadewide * 0; vec3 xyz = LabtoXYZ(l,a,b); return RGBnonlinearRGB(XYZtoRGB(xyz)); }
void convert(unsigned char *buf, int width, int height, int de) { double angle_chroma[360]; double angle_hue[360]; double angle_hue2[360]; double minchroma = 999; double maxchroma = 0; { int i; for (i = 0; i < 360; i++) { angle_chroma[i] = 9999; } double f; for (f = 0; f < 360; f += .25) { angle_hue[(int) ((angletohue(f) - angletohue(0)) / (angletohue(360) - angletohue(0)) * 360)] = f; angle_hue2[(int) f] = ((angletohue(f) - angletohue(0)) / (angletohue(360) - angletohue(0)) * 360); } double a; for (a = -80; a <= 80; a += .1) { int dir; for (dir = -1; dir <= 1; dir += 2) { double b = dir * 335.582 * exp(- a * a / (2 * 15.5723 * 15.5723)) / (15.5723 * sqrt(2 * M_PI)); double h = atan2(b, a); double c = sqrt(a * a + b * b); h -= 0.075; if (h < 0) { h += 2 * M_PI; } h = floor(h * 180 / M_PI); if (c < angle_chroma[(int) h]) { angle_chroma[(int) h] = c; } } } for (i = 0; i < 360; i++) { if (angle_chroma[i] < minchroma) { minchroma = angle_chroma[i]; } if (angle_chroma[i] > maxchroma) { maxchroma = angle_chroma[i]; } } } int *buf2 = malloc(width * height * 4 * sizeof(int)); int x, y; for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { int r = buf[(y * width + x) * 4 + 0]; int g = buf[(y * width + x) * 4 + 1]; int b = buf[(y * width + x) * 4 + 2]; double X, Y, Z; double L, A, B; double C, H; RGBtoXYZ(r, g, b, &X, &Y, &Z); XYZtoLAB(X, Y, Z, &L, &A, &B); LABtoLCH(L, A, B, &L, &C, &H); if (H < 0) { H += 2 * M_PI; } if (de) { // desaturate C = C * minchroma / angle_chroma[(int) (H * 180 / M_PI)]; // shift hue int hh = (int) (H * 180 / M_PI + 720) % 360; H = angle_hue2[hh] * M_PI / 180; } else { // shift hue int hh = (int) (H * 180 / M_PI + 720) % 360; H = angle_hue[hh] * M_PI / 180; // resaturate C = C / minchroma * angle_chroma[(int) (H * 180 / M_PI)]; C *= minchroma / maxchroma; } LCHtoLAB(L, C, H, &L, &A, &B); LABtoXYZ(L, A, B, &X, &Y, &Z); XYZtoRGB(X, Y, Z, &r, &g, &b); buf2[(y * width + x) * 4 + 0] = r; buf2[(y * width + x) * 4 + 1] = g; buf2[(y * width + x) * 4 + 2] = b; } } int max = 0; for (x = 0; x < width * height; x++) { int i; for (i = 0; i < 3; i++) { if (buf2[x * 4 + i] > max) { max = buf2[x * 4 + i]; } } } for (x = 0; x < width * height; x++) { int i; for (i = 0; i < 3; i++) { buf[x * 4 + i] = buf2[x * 4 + i] * 255 / max; if (buf2[x * 4 + i] < 0) { buf[x * 4 + i] = 0; } } } }
/*-----------------------------------------------------------------* Color Red-Green *-----------------------------------------------------------------*/ vec3 valuetoshadowcolorRG(float shadow, float value){ float l = 75 - 40*(1-shadow), a = (value-0.5)*100*1.4, b = 0; vec3 xyz = LabtoXYZ(l,a,b); return RGBnonlinearRGB(XYZtoRGB(xyz)); }
vec3 valuetocolorRG(float value){ float l = 75, a = (value-0.5)*100*1.4, b = 0; vec3 xyz = LabtoXYZ(l,a,b); return RGBnonlinearRGB(XYZtoRGB(xyz))+vec3(0.1,0.1,0); }
vec3 valuetocolorYB(float value){ float l = 75, a = 0, b = (value-0.5)*100; vec3 xyz = LabtoXYZ(l,a,b); return RGBnonlinearRGB(XYZtoRGB(xyz)); }
void AcesInputFile::Data::initColorConversion () { const Header &header = rgbaFile->header(); Chromaticities fileChr; if (hasChromaticities (header)) fileChr = chromaticities (header); V2f fileNeutral = fileChr.white; if (hasAdoptedNeutral (header)) fileNeutral = adoptedNeutral (header); const Chromaticities acesChr = acesChromaticities(); V2f acesNeutral = acesChr.white; if (fileChr.red == acesChr.red && fileChr.green == acesChr.green && fileChr.blue == acesChr.blue && fileChr.white == acesChr.white && fileNeutral == acesNeutral) { // // The file already contains ACES data, // color conversion is not necessary. return; } mustConvertColor = true; minX = header.dataWindow().min.x; maxX = header.dataWindow().max.x; // // Create a matrix that transforms colors from the // RGB space of the input file into the ACES space // using a color adaptation transform to move the // white point. // // // We'll need the Bradford cone primary matrix and its inverse // static const M44f bradfordCPM (0.895100, -0.750200, 0.038900, 0.000000, 0.266400, 1.713500, -0.068500, 0.000000, -0.161400, 0.036700, 1.029600, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000); const static M44f inverseBradfordCPM (0.986993, 0.432305, -0.008529, 0.000000, -0.147054, 0.518360, 0.040043, 0.000000, 0.159963, 0.049291, 0.968487, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000); // // Convert the white points of the two RGB spaces to XYZ // float fx = fileNeutral.x; float fy = fileNeutral.y; V3f fileNeutralXYZ (fx / fy, 1, (1 - fx - fy) / fy); float ax = acesNeutral.x; float ay = acesNeutral.y; V3f acesNeutralXYZ (ax / ay, 1, (1 - ax - ay) / ay); // // Compute the Bradford transformation matrix // V3f ratio ((acesNeutralXYZ * bradfordCPM) / (fileNeutralXYZ * bradfordCPM)); M44f ratioMat (ratio[0], 0, 0, 0, 0, ratio[1], 0, 0, 0, 0, ratio[2], 0, 0, 0, 0, 1); M44f bradfordTrans = bradfordCPM * ratioMat * inverseBradfordCPM; // // Build a combined file-RGB-to-ACES-RGB conversion matrix // fileToAces = RGBtoXYZ (fileChr, 1) * bradfordTrans * XYZtoRGB (acesChr, 1); }
void Image::LabtoRGB(pixel3f *source, pixel4b *destination) { LabtoXYZ(source); XYZtoRGB(source, destination); }