Ejemplo n.º 1
0
  /**
   * This method return the distance between two RGB points
   *
   * @param c1 : RGB point one
   * @param c2 : RGB point two
   * @return Integer with distance
   */
  public int getDistance(Rgb c1, Rgb c2) {
    int dRed = c1.getRed() - c2.getRed();
    int dBlue = c1.getBlue() - c2.getBlue();
    int dGreen = c1.getGreen() - c2.getGreen();

    return ((dRed * dRed) + (dBlue * dBlue) + (dGreen * dGreen));
  }
Ejemplo n.º 2
0
  /**
   * This method convert an RGB point to its respective CMYK
   *
   * @param rgbColor: RGB point
   * @return CMYK object
   */
  public Cmyk rgbToCmyk(Rgb rgbColor) {
    Cmyk cmykColor = null;
    int black =
        Math.min(
            Math.min(255 - rgbColor.getRed(), 255 - rgbColor.getGreen()), 255 - rgbColor.getBlue());

    if (black == 255) {
      cmykColor =
          new Cmyk(
              255 - rgbColor.getRed(), 255 - rgbColor.getGreen(), 255 - rgbColor.getBlue(), black);
    } else {
      cmykColor =
          new Cmyk(
              (int) ((255 - rgbColor.getRed() - black) / (255 - black)),
              (int) ((255 - rgbColor.getGreen() - black) / (255 - black)),
              (int) ((255 - rgbColor.getBlue() - black) / (255 - black)),
              black);
    }

    return (cmykColor);
  }