deps/kb_meme/meme-5.0.1/src/alph-in.c
/*
 * Convert a colour in the RGB colourspace into the CIELAB colourspace.
 * The CIELAB colourspace will allow us to determine how similar colours are.
 */
Convert a colour in the RGB colourspace into the CIELAB colourspace.
The CIELAB colourspace will allow us to determine how similar colours are.
Convert a colour in the RGB colourspace into the CIELAB colourspace . The CIELAB colourspace will allow us to determine how similar colours are .
static LAB_COLOUR_T rgb2lab(int rgb) {
  LAB_COLOUR_T out;
  double red, green, blue, c1, c2, c3, x, y, z;
  red = ((rgb >> 16) & 0xFF);
  green = ((rgb >> 8) & 0xFF);
  blue = (rgb & 0xFF);
  c1 = red / 255.0;
  c2 = green / 255.0;
  c3 = blue / 255.0;
  if (c1 > 0.04045) {
    c1 = (c1 + 0.055) / 1.055;
    c1 = pow(c1, 2.4);
  } else {
    c1 = c1 / 12.92;
  }
  if (c2 > 0.04045) {
    c2 = (c2 + 0.055) / 1.055;
    c2 = pow(c2, 2.4);
  } else {
    c2 = c2 / 12.92;
  }
  if (c3 > 0.04045) {
    c3 = (c3 + 0.055) / 1.055;
    c3 = pow(c3, 2.4);
  } else {
    c3 = c3 / 12.92;
  }
  c1 *= 100.0;
  c2 *= 100.0;
  c3 *= 100.0;
  x = (c1 * 0.4124) + (c2 * 0.3576) + (c3 * 0.1805);
  y = (c1 * 0.2126) + (c2 * 0.7152) + (c3 * 0.0722);
  z = (c1 * 0.0193) + (c2 * 0.1192) + (c3 * 0.9505);
  c1 = x / 95.047;
  c2 = y / 100.0;
  c3 = z / 108.883;
  if (c1 > 0.008856) {
    c1 = pow(c1, 1.0 / 3.0);
  } else {
    c1 = (7.787 * c1) + (16.0 / 116.0);
  }
  if (c2 > 0.008856) {
    c2 = pow(c2, 1.0 / 3.0);
  } else {
    c2 = (7.787 * c2) + (16.0 / 116.0);
  }
  if (c3 > 0.008856) {
    c3 = pow(c3, 1.0 / 3.0);
  } else {
    c3 = (7.787 * c3) + (16.0 / 116.0);
  }
  out.l = (116.0 * c2) - 16;
  out.a = 500.0 * (c1 - c2);
  out.b = 200.0 * (c2 - c3);
  return out;
}
static LAB_COLOUR_T rgb2lab ( int rgb ) { LAB_COLOUR_T out ; double red , green , blue , c1 , c2 , c3 , x , y , z ; red = ( ( rgb >> 16 ) & 0xFF ) ; green = ( ( rgb >> 8 ) & 0xFF ) ; blue = ( rgb & 0xFF ) ; c1 = red / 255.0 ; c2 = green / 255.0 ; c3 = blue / 255.0 ; if ( c1 > 0.04045 ) { c1 = ( c1 + 0.055 ) / 1.055 ; c1 = pow ( c1 , 2.4 ) ; } else { c1 = c1 / 12.92 ; } if ( c2 > 0.04045 ) { c2 = ( c2 + 0.055 ) / 1.055 ; c2 = pow ( c2 , 2.4 ) ; } else { c2 = c2 / 12.92 ; } if ( c3 > 0.04045 ) { c3 = ( c3 + 0.055 ) / 1.055 ; c3 = pow ( c3 , 2.4 ) ; } else { c3 = c3 / 12.92 ; } c1 *= 100.0 ; c2 *= 100.0 ; c3 *= 100.0 ; x = ( c1 * 0.4124 ) + ( c2 * 0.3576 ) + ( c3 * 0.1805 ) ; y = ( c1 * 0.2126 ) + ( c2 * 0.7152 ) + ( c3 * 0.0722 ) ; z = ( c1 * 0.0193 ) + ( c2 * 0.1192 ) + ( c3 * 0.9505 ) ; c1 = x / 95.047 ; c2 = y / 100.0 ; c3 = z / 108.883 ; if ( c1 > 0.008856 ) { c1 = pow ( c1 , 1.0 / 3.0 ) ; } else { c1 = ( 7.787 * c1 ) + ( 16.0 / 116.0 ) ; } if ( c2 > 0.008856 ) { c2 = pow ( c2 , 1.0 / 3.0 ) ; } else { c2 = ( 7.787 * c2 ) + ( 16.0 / 116.0 ) ; } if ( c3 > 0.008856 ) { c3 = pow ( c3 , 1.0 / 3.0 ) ; } else { c3 = ( 7.787 * c3 ) + ( 16.0 / 116.0 ) ; } out . l = ( 116.0 * c2 ) - 16 ; out . a = 500.0 * ( c1 - c2 ) ; out . b = 200.0 * ( c2 - c3 ) ; return out ; }
Convert a colour in the RGB colourspace into the CIELAB colourspace.
Convert a colour in the RGB colourspace into the CIELAB colourspace .
// Split into RGB components // ========================================================================= // Convert RGB into XYZ colourspace // ========================================================================= // start by changing the range to 0 to 1 // adjust values // adjust range again // apply matrix transform // ========================================================================= // Convert XYZ into Lab colourspace // =========================================================================