Exemple #1
0
  public LabColor rgb2lab(BaseColor baseColor) {
    double rLinear = baseColor.getRed() / 255f;
    double gLinear = baseColor.getGreen() / 255f;
    double bLinear = baseColor.getBlue() / 255f;

    // convert to a sRGB form
    double r =
        (rLinear > 0.04045) ? Math.pow((rLinear + 0.055) / (1 + 0.055), 2.2) : (rLinear / 12.92);
    double g =
        (gLinear > 0.04045) ? Math.pow((gLinear + 0.055) / (1 + 0.055), 2.2) : (gLinear / 12.92);
    double b =
        (bLinear > 0.04045) ? Math.pow((bLinear + 0.055) / (1 + 0.055), 2.2) : (bLinear / 12.92);

    // converts
    double x = r * 0.4124 + g * 0.3576 + b * 0.1805;
    double y = r * 0.2126 + g * 0.7152 + b * 0.0722;
    double z = r * 0.0193 + g * 0.1192 + b * 0.9505;

    float l = Math.round((116.0 * fXyz(y / whitePoint[1]) - 16) * 1000) / 1000f;
    float a =
        Math.round((500.0 * (fXyz(x / whitePoint[0]) - fXyz(y / whitePoint[1]))) * 1000) / 1000f;
    float bee =
        Math.round((200.0 * (fXyz(y / whitePoint[1]) - fXyz(z / whitePoint[2]))) * 1000) / 1000f;

    return new LabColor(this, l, a, bee);
  }
Exemple #2
0
 public static float[] getColorArray(BaseColor color) {
   int type = ExtendedColor.getType(color);
   switch (type) {
     case ExtendedColor.TYPE_GRAY:
       {
         return new float[] {((GrayColor) color).getGray()};
       }
     case ExtendedColor.TYPE_CMYK:
       {
         CMYKColor cmyk = (CMYKColor) color;
         return new float[] {cmyk.getCyan(), cmyk.getMagenta(), cmyk.getYellow(), cmyk.getBlack()};
       }
     case ExtendedColor.TYPE_SEPARATION:
       {
         return new float[] {((SpotColor) color).getTint()};
       }
     case ExtendedColor.TYPE_DEVICEN:
       {
         return ((DeviceNColor) color).getTints();
       }
     case ExtendedColor.TYPE_RGB:
       {
         return new float[] {
           color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f
         };
       }
   }
   throwColorSpaceError();
   return null;
 }