Here you can find the source of colordiffsq(int rgb0, int rgb1)
Parameter | Description |
---|---|
rgb0 | First color value. |
rgb1 | Second color value. |
public static float colordiffsq(int rgb0, int rgb1)
//package com.java2s; /*/*from w ww .ja v a 2 s . c o m*/ Copyright 2005, 2006 by Gerald Friedland and Kristian Jantz Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ public class Main { /** * Computes squared euclidian distance of two RGB color values. * <P> * Note: Faster to compute than colordiff * * @param rgb0 First color value. * @param rgb1 Second color value. * @return Squared Euclidian distance between the two color values. */ public static float colordiffsq(int rgb0, int rgb1) { final int rDist = getRed(rgb0) - getRed(rgb1); final int gDist = getGreen(rgb0) - getGreen(rgb1); final int bDist = getBlue(rgb0) - getBlue(rgb1); return rDist * rDist + gDist * gDist + bDist * bDist; } /** * Returns the red component of an (A)RGB value. * * @param rgb An (A)RGB color value. * @return The red component, ranging from 0 to 255. */ public static int getRed(int rgb) { return (rgb >> 16) & 0xFF; } /** * Returns the green component of an (A)RGB value. * * @param rgb An (A)RGB color value. * @return The green component, ranging from 0 to 255. */ public static int getGreen(int rgb) { return (rgb >> 8) & 0xFF; } /** * Returns the blue component of an (A)RGB value. * * @param rgb An (A)RGB color value. * @return The blue component, ranging from 0 to 255. */ public static int getBlue(int rgb) { return (rgb) & 0xFF; } }