Java examples for 2D Graphics:Color
different Color
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { int a = 2; int b = 2; boolean yuv = true; System.out.println(diffCol(a, b, yuv)); }// ww w . j av a2 s. co m public static int diffCol(int a, int b, boolean yuv) { //http://www.compuphase.com/cmetric.htm if (yuv) { return (int) Math .sqrt(((getY(a) - getY(b)) * (getY(a) - getY(b))) + ((getU(a) - getU(b)) * (getU(a) - getU(b))) + ((getV(a) - getV(b)) * (getV(a) - getV(b)))); } else { return (int) Math.sqrt(2 * ((getR(a) - getR(b)) * (getR(a) - getR(b))) + 4 * ((getG(a) - getG(b)) * (getG(a) - getG(b))) + 3 * ((getB(a) - getB(b)) * (getB(a) - getB(b)))); } } public static int getY(int col) { //just for readability tbh -- same as RGB return (col >> 16) & 0xFF; } public static int getU(int col) { return (col >> 8) & 0xFF; } public static int getV(int col) { return (col & 0xFF); } public static int getR(int col) { //N.B. BGR? return (col >> 16) & 0xFF; } public static int getG(int col) { return (col >> 8) & 0xFF; } public static int getB(int col) { return (col & 0xFF); } }