-
-
Notifications
You must be signed in to change notification settings - Fork 440
Expand file tree
/
Copy pathTestImage.java
More file actions
73 lines (55 loc) · 1.89 KB
/
Copy pathTestImage.java
File metadata and controls
73 lines (55 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import app.f3d.F3D.*;
public class TestImage {
public static void main(String[] args) {
Engine.autoloadPlugins();
String testDataPath = args.length > 0 ? args[0] : ".";
String tmpPath = args.length > 1 ? args[1] : "/tmp/";
Image.getSupportedFormats();
Image img1 = new Image(300, 200, 3);
img1.getWidth();
img1.getHeight();
img1.getChannelCount();
img1.getChannelType();
img1.getChannelTypeSize();
byte[] buffer = new byte[300 * 200 * 3];
img1.setContent(buffer);
img1.getContent();
img1.getNormalizedPixel(10, 10);
img1.save(tmpPath + "test.png");
img1.save(tmpPath + "test.jpg", Image.SaveFormat.JPG);
img1.saveBuffer();
img1.saveBuffer(Image.SaveFormat.PNG);
img1.setMetadata("key1", "value1");
img1.getMetadata("key1");
img1.allMetadata();
Image img2 = new Image(300, 200, 3, Image.ChannelType.BYTE);
img1.compare(img2);
img1.equals(img2);
img1.notEquals(img2);
Image img3 = new Image(testDataPath + "data/world.png");
img3.getWidth();
img3.toTerminalText();
img1.setContent(buffer)
.setMetadata("author", "F3D")
.save(tmpPath + "chained.png");
img1.delete();
img2.delete();
img3.delete();
// --- Exception handling tests ---
// Reading a nonexistent image file must throw ReadException instead of crashing the JVM.
try {
new Image("/absolutely_nonexistent_image_f3d_test.png");
throw new RuntimeException("Expected Image.ReadException was not thrown");
} catch (Image.ReadException e) {
}
// Getting nonexistent metadata must throw MetadataException.
Image tmpImg = new Image(300, 200, 3);
try {
tmpImg.getMetadata("key_that_does_not_exist");
throw new RuntimeException("Expected Image.MetadataException was not thrown");
} catch (Image.MetadataException e) {
} finally {
tmpImg.delete();
}
}
}