Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
KodeMunkie committed Oct 21, 2019
1 parent 60a2e91 commit 566b9fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public OrderedDitherConverterImpl() {
@Override
public ResultImage[] convert(final BufferedImage original) {

OptionsObject oo = OptionsObject.getInstance();
BufferedImage output = ImageHelper.copyImage(original);
int xMax = ditherStrategy.getMatrixWidth();
int yMax = ditherStrategy.getMatrixHeight();
Expand Down
23 changes: 14 additions & 9 deletions src/main/java/uk/co/silentsoftware/core/helpers/ColourHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public static double getClosestColourDistanceForGigascreenColours(int red, int g
double bestMatch = Double.MAX_VALUE;
for (GigaScreenColour colour : colours) {
final int[] colourSetComps = colour.getGigascreenColourRGB();
double diff = getColorDifferenceCompuphase(red, green, blue, colourSetComps); //Math.abs(red - colourSetComps[0]) + Math.abs(green - colourSetComps[1]) + Math.abs(blue - colourSetComps[2]);
double diff = getColourDifference(red, green, blue, colourSetComps); //Math.abs(red - colourSetComps[0]) + Math.abs(green - colourSetComps[1]) + Math.abs(blue - colourSetComps[2]);
bestMatch = Math.min(diff, bestMatch);
}
return bestMatch;
Expand Down Expand Up @@ -249,20 +249,25 @@ private static int getClosestColour(int red, int green, int blue, int[] colourSe
Integer closest = null;
for (int colour : colourSet) {
final int[] colourSetComps = intToRgbComponents(colour);
double diff = getColorDifferenceCompuphase(red, green, blue, colourSetComps);
if (diff <= bestMatch) {
double diff = getColourDifference(red, green, blue, colourSetComps);
if (diff < bestMatch) {
closest = colour;
bestMatch = diff;
}
}
return closest;
}

private static double getColorDifferenceEuclidean(int red, int green, int blue, int[] colourSetComps) {
private static double getColourDifference(int red, int green, int blue, int[] colourSetComps) {
// TODO: Use OptionsObject
return getColourDifferenceCompuphase(red, green, blue, colourSetComps);
}

private static double getColourDifferenceEuclidean(int red, int green, int blue, int[] colourSetComps) {
return Math.pow(red - colourSetComps[0], 2d) + Math.pow(green - colourSetComps[1], 2d) + Math.pow(blue - colourSetComps[2], 2d);
}

private static double getColorDifferenceCompuphase(int red, int green, int blue, int[] colourSetComps) {
private static double getColourDifferenceCompuphase(int red, int green, int blue, int[] colourSetComps) {
long rmean = ((long) colourSetComps[0] + (long) red) / 2;
long r = (long) colourSetComps[0] - (long) red;
long g = (long) colourSetComps[1] - (long) green;
Expand All @@ -274,9 +279,9 @@ private static double getColorDifferenceCompuphase(int red, int green, int blue,
* Computes the difference between two RGB colors by converting them to the L*a*b scale and
* comparing them using the CIE76 algorithm { http://en.wikipedia.org/wiki/Color_difference#CIE76}
*/
public static double getColorDifferenceCIE76(int r1, int g1, int b1, int r2, int g2, int b2) {
public static double getColourDifferenceCIE76(int r1, int g1, int b1, int[] colourSetComps) {
int[] lab1 = rgb2lab(r1, g1, b1);
int[] lab2 = rgb2lab(r2, g2, b2);
int[] lab2 = rgb2lab(colourSetComps[0], colourSetComps[1], colourSetComps[2]);
return Math.sqrt(Math.pow(lab2[0] - lab1[0], 2) + Math.pow(lab2[1] - lab1[1], 2) + Math.pow(lab2[2] - lab1[2], 2));
}

Expand Down Expand Up @@ -526,7 +531,7 @@ private static int correctRange(int value, int low, int high) {
* @param high the high value
* @return the ranged valued
*/
private static float correctRange(float value, float low, float high) {
public static float correctRange(float value, float low, float high) {
if (value < low) {
return low;
}
Expand Down Expand Up @@ -564,7 +569,7 @@ public static int componentsToAlphaRgb(int red, int green, int blue) {
* @param component the component to restrict
* @return the corrected component
*/
private static int correctRange(int component) {
public static int correctRange(int component) {
return ColourHelper.correctRange(component, 0, MAXIMUM_COMPONENT_VALUE);
}

Expand Down

0 comments on commit 566b9fb

Please sign in to comment.