static void rgba_to_ycbcra709 (const Babl *conversion, char *src, char *dst, long n) { while (n--) { double red = ((double *) src)[0]; double green = ((double *) src)[1]; double blue = ((double *) src)[2]; double alpha = ((double *) src)[3]; double luminance, cb, cr; red = linear_to_gamma_2_2 (red); green = linear_to_gamma_2_2 (green); blue = linear_to_gamma_2_2 (blue); luminance = 0.2126 * red + 0.7152 * green + 0.0722 * blue; cb = (blue - luminance) / 1.8556; cr = (red - luminance) / 1.5748; ((double *) dst)[0] = luminance; ((double *) dst)[1] = cb; ((double *) dst)[2] = cr; ((double *) dst)[3] = alpha; src += sizeof (double) * 4; dst += sizeof (double) * 4; } }
static void rgba_to_hsv_step (char *src, char *dst) { double hue, saturation, value; double min, chroma; double red = linear_to_gamma_2_2 (((double *) src)[0]); double green = linear_to_gamma_2_2 (((double *) src)[1]); double blue = linear_to_gamma_2_2 (((double *) src)[2]); if (red > green) { value = MAX (red, blue); min = MIN (green, blue); } else { value = MAX (green, blue); min = MIN (red, blue); } chroma = value - min; if (value < EPSILON) saturation = 0.0; else saturation = chroma / value; if (saturation < EPSILON) { hue = 0.0; } else { if (fabs (red - value) < EPSILON) { hue = (green - blue) / chroma; if (hue < 0.0) hue += 6.0; } else if (fabs (green - value) < EPSILON) hue = 2.0 + (blue - red) / chroma; else hue = 4.0 + (red - green) / chroma; hue /= 6.0; } ((double *) dst)[0] = hue; ((double *) dst)[1] = saturation; ((double *) dst)[2] = value; }
static void table_init (void) { if (table_inited) return; table_inited = 1; /* fill tables for conversion from integer to float */ { int i; for (i = 0; i < 1 << 8; i++) { float direct = i / 255.0; table_8_F[i] = direct; table_8g_F[i] = gamma_2_2_to_linear (direct); } } /* fill tables for conversion from float to integer */ { union { float f; uint32_t s; } u; u.f = 0.0; //u.s[0] = 0; for (u.s = 0; u.s < 4294900000U; u.s += 32768) { int c; int cg; if (u.f <= 0.0) { c = 0; cg = 0; } else { c = (u.f * 255.1619) + 0.5; cg = (linear_to_gamma_2_2 (u.f) * 255.1619) + 0.5; if (cg > 255) cg = 255; if (c > 255) c = 255; } table_F_8[(u.s >> 15) & ((1 << 17)-1)] = c; table_F_8g[(u.s >> 15) & ((1 << 17)-1)] = cg; } } #if 0 /* fix tables to ensure 1:1 conversions back and forth */ if (0) { int i; for (i = 0; i < 256; i++) { float f; unsigned short *hi = ((unsigned short *) (void *) &f); unsigned short *lo = ((unsigned short *) (void *) &f); f = table_8_F[i]; *lo = 0; table_F_8[*hi] = i; f = table_8g_F[i]; *lo = 0; table_F_8g[*hi] = i; } } #endif }