MCPcopy Index your code
hub / github.com/HumbleUI/Skija / ImageTest

Class ImageTest

tests/java/ImageTest.java:13–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11import io.github.humbleui.types.IRect;
12
13public class ImageTest implements Executable {
14 @Override
15 public void execute() throws Exception {
16 TestRunner.testMethod(this, "base");
17 TestRunner.testMethod(this, "makeSubset");
18 TestRunner.testMethod(this, "refCntToStringAfterClose");
19 }
20
21 public void base() throws Exception {
22 try (var surface = Surface.makeRaster(ImageInfo.makeN32Premul(100, 100));
23 var paint = new Paint().setColor(0xFFFF0000);
24 var path = new PathBuilder().moveTo(20, 80).lineTo(50, 20).lineTo(80, 80).closePath().build();)
25 {
26 var canvas = surface.getCanvas();
27 canvas.drawPath(path, paint);
28 try (var image = surface.makeImageSnapshot()) {
29 var dir = "target/tests/ImageTest/";
30 new File(dir).mkdirs();
31 Files.write(Path.of(dir, "polygon_default.png"), EncoderPNG.encode(image).getBytes());
32 Files.write(Path.of(dir, "polygon_default_none_1.png"), EncoderPNG.encode(image, EncodePNGOptions.DEFAULT.withFlags(EncodePNGFilterFlag.NONE).withZlibLevel(1)).getBytes());
33 Files.write(Path.of(dir, "polygon_jpeg_default.jpeg"), EncoderJPEG.encode(image).getBytes());
34 Files.write(Path.of(dir, "polygon_jpeg_50.jpeg"), EncoderJPEG.encode(image, EncodeJPEGOptions.DEFAULT.withQuality(50)).getBytes());
35 Files.write(Path.of(dir, "polygon_webp_default.webp"), EncoderWEBP.encode(image).getBytes());
36 Files.write(Path.of(dir, "polygon_webp_50.webp"), EncoderWEBP.encode(image,EncodeWEBPOptions.DEFAULT.withQuality(50)).getBytes());
37 Files.write(Path.of(dir, "polygon_webp_lossless.webp"), EncoderWEBP.encode(image,EncodeWEBPOptions.DEFAULT.withCompressionMode(EncodeWEBPCompressionMode.LOSSLESS)).getBytes());
38 }
39 }
40 }
41
42 public void makeSubset() throws Exception {
43 try (var surface = Surface.makeRaster(ImageInfo.makeN32Premul(100, 80))) {
44 var canvas = surface.getCanvas();
45 canvas.clear(0xFF112233);
46 try (var image = surface.makeImageSnapshot()) {
47 var subset = image.makeSubset(new IRect(10, 20, 70, 50));
48 assertNotNull(subset);
49 if (subset != null) {
50 assertEquals(60, subset.getWidth());
51 assertEquals(30, subset.getHeight());
52 subset.close();
53 }
54 }
55 }
56 }
57
58 public void refCntToStringAfterClose() throws Exception {
59 Bitmap bmp = new Bitmap();
60 bmp.allocN32Pixels(10, 20);
61 Image img = Image.makeRasterFromBitmap(bmp);
62 assertEquals(1, img.getRefCount());
63 img.toString();
64 img.close();
65 assertDoesNotThrow(() -> {
66 img.toString();
67 });
68 bmp.close();
69 }
70}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected