Skip to content

Commit

Permalink
move inverse lookup to ColorManagement
Browse files Browse the repository at this point in the history
  • Loading branch information
Traneptora committed Sep 7, 2024
1 parent f881ccc commit 91f3b26
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 22 deletions.
8 changes: 4 additions & 4 deletions java/com/traneptora/jxlatte/JXLImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ private JXLImage toneMapLinear(CIEPrimaries primaries, CIEXY whitePoint) {
}
image.primariesXY = primaries;
image.whiteXY = whitePoint;
image.primaries = ColorFlags.getPrimaries(primaries);
image.whitePoint = ColorFlags.getWhitePoint(whitePoint);
image.primaries = ColorManagement.getPrimaries(primaries);
image.whitePoint = ColorManagement.getWhitePoint(whitePoint);
return image;
}

Expand Down Expand Up @@ -193,8 +193,8 @@ public JXLImage transform(CIEPrimaries primaries, CIEXY whitePoint, int transfer
}

public JXLImage transform(int primaries, int whitePoint, int transfer, int peakDetect) {
return transform(ColorFlags.getPrimaries(primaries), ColorFlags.getWhitePoint(whitePoint),
transfer, peakDetect);
return transform(ColorManagement.getPrimaries(primaries),
ColorManagement.getWhitePoint(whitePoint), transfer, peakDetect);
}

public JXLImage toneMap(CIEPrimaries primaries, CIEXY whitePoint) {
Expand Down
20 changes: 2 additions & 18 deletions java/com/traneptora/jxlatte/color/ColorFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static String transferToString(int transfer) {
}
}

public static CIEXY getWhitePoint(int whitePoint) {
static CIEXY getWhitePoint(int whitePoint) {
switch (whitePoint) {
case WP_D65:
return new CIEXY(0.3127f, 0.3290f);
Expand All @@ -134,15 +134,7 @@ public static CIEXY getWhitePoint(int whitePoint) {
return null;
}

public static int getWhitePoint(CIEXY wp) {
for (int white : new int[]{WP_D65, WP_E, WP_DCI, WP_D50}) {
if (CIEXY.matches(wp, getWhitePoint(white)))
return white;
}
return WP_CUSTOM;
}

public static CIEPrimaries getPrimaries(int primaries) {
static CIEPrimaries getPrimaries(int primaries) {
switch (primaries) {
case ColorFlags.PRI_SRGB:
return new CIEPrimaries(new CIEXY(0.639998686f, 0.330010138f),
Expand All @@ -160,12 +152,4 @@ public static CIEPrimaries getPrimaries(int primaries) {
}
return null;
}

public static int getPrimaries(CIEPrimaries primaries) {
for (int prim : new int[]{PRI_SRGB, PRI_BT2100, PRI_P3}) {
if (CIEPrimaries.matches(primaries, getPrimaries(prim)))
return prim;
}
return PRI_CUSTOM;
}
}
46 changes: 46 additions & 0 deletions java/com/traneptora/jxlatte/color/ColorManagement.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,52 @@ private static void validateLMS(float[] lms) {
}
}

public static CIEXY getWhitePoint(int wp) {
switch(wp) {
case ColorFlags.WP_D65:
return WP_D65;
case ColorFlags.WP_D50:
return WP_D50;
case ColorFlags.WP_DCI:
return WP_DCI;
case ColorFlags.WP_E:
return WP_E;
default:
return null;
}
}

public static CIEPrimaries getPrimaries(int prim) {
switch (prim) {
case ColorFlags.PRI_SRGB:
return PRI_SRGB;
case ColorFlags.PRI_P3:
return PRI_P3;
case ColorFlags.PRI_BT2100:
return PRI_BT2100;
default:
return null;
}
}

public static int getWhitePoint(CIEXY xy) {
int[] wp = new int[]{ColorFlags.WP_D65, ColorFlags.WP_E, ColorFlags.WP_DCI, ColorFlags.WP_D50};
for (int white : wp) {
if (CIEXY.matches(xy, getWhitePoint(white)))
return white;
}
return ColorFlags.WP_CUSTOM;
}

public static int getPrimaries(CIEPrimaries primaries) {
int[] pri = new int[]{ColorFlags.PRI_SRGB, ColorFlags.PRI_BT2100, ColorFlags.PRI_P3};
for (int prim : pri) {
if (CIEPrimaries.matches(primaries, getPrimaries(prim)))
return prim;
}
return ColorFlags.PRI_CUSTOM;
}

private static float[][] adaptWhitePoint(CIEXY targetWP, CIEXY currentWP) {
if (targetWP == null)
targetWP = WP_D50;
Expand Down

0 comments on commit 91f3b26

Please sign in to comment.