-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'LuminanceClosestColour'
- Loading branch information
Showing
7 changed files
with
44 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/uk/co/silentsoftware/core/helpers/colourdistance/LuminanceColourDistance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package uk.co.silentsoftware.core.helpers.colourdistance; | ||
|
||
import static uk.co.silentsoftware.config.LanguageSupport.getCaption; | ||
|
||
/** | ||
* Luminance colour distance adapted from http://appleoldies.ca/a2b/DHGRColors2017.htm | ||
*/ | ||
public class LuminanceColourDistance implements ColourDistanceStrategy { | ||
|
||
public static final double LUMA_RED = 0.298839; | ||
public static final double LUMA_GREEN = 0.586811; | ||
public static final double LUMA_BLUE = 0.114350; | ||
|
||
@Override | ||
public double getColourDistance(int red, int green, int blue, int[] paletteComps) { | ||
double luma1 = (red*LUMA_RED + green*LUMA_GREEN + blue*LUMA_BLUE) / (255.0*1000); | ||
double luma2 = (paletteComps[0]*LUMA_RED + paletteComps[1]*LUMA_GREEN + paletteComps[2]*LUMA_BLUE) / (255.0*1000); | ||
double lumaDiff = luma1-luma2; | ||
double diffR = (paletteComps[0]-red)/255.0; | ||
double diffG = (paletteComps[1]-green)/255.0; | ||
double diffB = (paletteComps[2]-blue)/255.0; | ||
return (diffR*diffR*LUMA_RED + diffG*diffG*LUMA_GREEN+ diffB*diffB*LUMA_BLUE)*0.75+ lumaDiff*lumaDiff; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getCaption("adv_colour_dist_luminance") ; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters