Skip to content

Commit

Permalink
Might need some shrinking, or a gamut change.
Browse files Browse the repository at this point in the history
Either reverseLight() should slightly shrink L, and forwardLight might slightly expand it, or the gamut could be wrong because I haven't updated it.
  • Loading branch information
tommyettinger committed Sep 9, 2023
1 parent 536e562 commit 619fd8e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,21 @@ public void testPalette() {
}
}
public static double reverseLight(double L) {
L = Math.sqrt(L * 0x0.ffp0); // 255.0/256.0
final double shape = 1.52, turning = 0.963;
final double d = turning - L;
double r;
if(d < 0)
r = ((1.0 - turning) * (L - 1.0)) / (1.0 - (L + shape * d)) + 1.0;
else
r = (turning * L) / (1e-50 + (L + shape * d));
return r;
return Math.pow(L, 2.0/3.0);
}

// public static double reverseLight(double L) {
// L = Math.sqrt(L * 0x0.ffp0); // 255.0/256.0
// final double shape = 1.52, turning = 0.963;
// final double d = turning - L;
// double r;
// if(d < 0)
// r = ((1.0 - turning) * (L - 1.0)) / (1.0 - (L + shape * d)) + 1.0;
// else
// r = (turning * L) / (1e-50 + (L + shape * d));
// return r;
// }

/**
* Returns true if the given Oklab values are valid to convert losslessly back to RGBA.
* @param L lightness channel, as a double from 0 to 1
Expand All @@ -150,7 +154,7 @@ public static double reverseLight(double L) {
public static boolean inGamut(double L, double A, double B)
{
//reverseLight() for double
L = reverseLight(L);
L = reverseLight(L) * 0x0.ffp0;
//forwardLight() for double
// L = (L - 1.00457) / (1.0 - L * 0.4285714) + 1.00457;
A -= 0x1.fdfdfep-2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,19 @@ public static void generateByteString(final byte[] data, String filename){
System.out.println("Wrote code snippet to " + filename);
}
public static double reverseLight(double L) {
L = Math.sqrt(L);
final double shape = 1.55, turning = 0.95;
final double d = turning - L;
double r;
if(d < 0)
r = ((1.0 - turning) * (L - 1.0)) / (1.0 - (L + shape * d)) + 1.0;
else
r = (turning * L) / (1e-50 + (L + shape * d));
return r;
return Math.pow(L, 2.0/3.0);
}
// public static double reverseLight(double L) {
// L = Math.sqrt(L);
// final double shape = 1.55, turning = 0.95;
// final double d = turning - L;
// double r;
// if(d < 0)
// r = ((1.0 - turning) * (L - 1.0)) / (1.0 - (L + shape * d)) + 1.0;
// else
// r = (turning * L) / (1e-50 + (L + shape * d));
// return r;
// }

/**
* Returns true if the given Oklab values are valid to convert losslessly back to RGBA.
Expand Down

0 comments on commit 619fd8e

Please sign in to comment.