| 18 | import io.github.humbleui.skija.test.runner.Executable; |
| 19 | |
| 20 | public class ColorSpaceTest implements Executable { |
| 21 | @Override |
| 22 | public void execute() throws Exception { |
| 23 | testICC(); |
| 24 | testExtendedApi(); |
| 25 | } |
| 26 | |
| 27 | private void testICC() throws IOException { |
| 28 | ColorSpace cs1 = ColorSpace.makeFromICCProfile(new byte[0]); |
| 29 | assertNull(cs1); |
| 30 | |
| 31 | ColorSpace cs2 = ColorSpace.makeFromICCProfile(new byte[] { 1, 2, 3, 4, 5 }); |
| 32 | assertNull(cs2); |
| 33 | |
| 34 | for (String path: new String[] { "color_spaces/sRGB Profile.icc", "color_spaces/Display P3.icc" }) { |
| 35 | byte[] data = Files.readAllBytes(Path.of(path)); |
| 36 | try (ColorSpace cs = ColorSpace.makeFromICCProfile(data);) { |
| 37 | assertNotNull(cs); |
| 38 | assertEquals(true, cs.isGammaCloseToSRGB()); |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | private void testExtendedApi() throws IOException { |
| 44 | ColorSpace srgb = ColorSpace.getSRGB(); |
| 45 | assertEquals(true, srgb.isSRGB()); |
| 46 | assertNotNull(srgb.getTransferFn()); |
| 47 | assertNotNull(srgb.getInvTransferFn()); |
| 48 | assertNotNull(srgb.getNumericalTransferFn()); |
| 49 | |
| 50 | Matrix33 xyz = srgb.getToXYZD50(); |
| 51 | assertNotNull(xyz); |
| 52 | assertNotNull(srgb.getGamutTransformTo(ColorSpace.getDisplayP3())); |
| 53 | assertNotEquals(0, srgb.getToXYZD50Hash()); |
| 54 | assertNotEquals(0, srgb.getTransferFnHash()); |
| 55 | assertNotEquals(0L, srgb.getHash()); |
| 56 | |
| 57 | try (ColorSpace linear = srgb.makeLinearGamma(); |
| 58 | ColorSpace srgbGamma = linear.makeSRGBGamma(); |
| 59 | ColorSpace spun = srgb.makeColorSpin();) { |
| 60 | assertNotNull(linear); |
| 61 | assertEquals(true, linear.isGammaLinear()); |
| 62 | assertNotNull(srgbGamma); |
| 63 | assertNotNull(spun); |
| 64 | } |
| 65 | |
| 66 | TransferFunction transferFn = srgb.getTransferFn(); |
| 67 | assertNotNull(transferFn); |
| 68 | assertNotNull(xyz); |
| 69 | try (ColorSpace fromRGB = ColorSpace.makeRGB(transferFn, xyz)) { |
| 70 | assertNotNull(fromRGB); |
| 71 | assertEquals(true, fromRGB.isSRGB()); |
| 72 | } |
| 73 | |
| 74 | try (ColorSpace cicp = ColorSpace.makeCICP(ColorSpaceNamedPrimaries.REC709, ColorSpaceNamedTransferFn.SRGB)) { |
| 75 | assertNotNull(cicp); |
| 76 | } |
| 77 |
nothing calls this directly
no outgoing calls
no test coverage detected