Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/imageio/plugins/tiff/IFDTest.java
41153 views
1
/*
2
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/**
25
* @test
26
* @bug 8152966
27
* @summary Verify that casting of TIFFDirectory to TIFFIFD has been fixed.
28
*/
29
30
import java.awt.Color;
31
import java.awt.Graphics;
32
import java.awt.image.BufferedImage;
33
import java.io.*;
34
import javax.imageio.*;
35
import javax.imageio.metadata.*;
36
import javax.imageio.stream.*;
37
38
39
import javax.imageio.plugins.tiff.*;
40
41
42
public class IFDTest {
43
44
private ImageWriter getTIFFWriter() {
45
46
java.util.Iterator<ImageWriter> writers =
47
ImageIO.getImageWritersByFormatName("TIFF");
48
if (!writers.hasNext()) {
49
throw new RuntimeException("No readers available for TIFF format");
50
}
51
return writers.next();
52
}
53
54
private void writeImage() throws Exception {
55
56
File file = File.createTempFile("IFDTest", "tif", new File("."));
57
file.deleteOnExit();
58
59
OutputStream s = new BufferedOutputStream(
60
new FileOutputStream("test.tiff"));
61
try (ImageOutputStream ios = ImageIO.createImageOutputStream(s)) {
62
63
ImageWriter writer = getTIFFWriter();
64
writer.setOutput(ios);
65
66
BufferedImage img = new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB);
67
Graphics g = img.getGraphics();
68
g.setColor(Color.GRAY);
69
g.fillRect(0, 0, 20, 20);
70
g.dispose();
71
72
IIOMetadata metadata = writer.getDefaultImageMetadata(
73
new ImageTypeSpecifier(img), writer.getDefaultWriteParam());
74
75
TIFFDirectory dir = TIFFDirectory.createFromMetadata(metadata);
76
77
int type = TIFFTag.TIFF_IFD_POINTER;
78
int nTag = ExifParentTIFFTagSet.TAG_EXIF_IFD_POINTER;
79
TIFFTag tag = new TIFFTag("Exif IFD", nTag, 1 << type);
80
TIFFTagSet sets[] = {ExifTIFFTagSet.getInstance()};
81
82
TIFFField f = new TIFFField(tag, type, 42L, new TIFFDirectory(sets, tag));
83
dir.addTIFFField(f);
84
85
writer.write(new IIOImage(img, null, dir.getAsMetadata()));
86
87
ios.flush();
88
writer.dispose();
89
} finally {
90
s.close();
91
file.delete();
92
}
93
}
94
95
96
public static void main(String[] args) throws Exception {
97
(new IFDTest()).writeImage();
98
}
99
}
100
101