Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/imageio/plugins/gif/LogicalScreenDimensionTest.java
41154 views
1
/*
2
* Copyright (c) 2005, 2017, 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 6307618
27
* @summary Test verifies that GIF image writer updates the dimension of the
28
* logical screen according to image dimension
29
* @modules java.desktop/com.sun.imageio.plugins.gif
30
*/
31
32
import java.awt.Color;
33
import java.awt.Graphics2D;
34
import java.awt.image.BufferedImage;
35
import java.io.ByteArrayInputStream;
36
import java.io.ByteArrayOutputStream;
37
import java.io.IOException;
38
39
import javax.imageio.IIOImage;
40
import javax.imageio.ImageIO;
41
import javax.imageio.ImageReader;
42
import javax.imageio.ImageTypeSpecifier;
43
import javax.imageio.ImageWriteParam;
44
import javax.imageio.ImageWriter;
45
import javax.imageio.metadata.IIOMetadata;
46
import javax.imageio.stream.ImageInputStream;
47
import javax.imageio.stream.ImageOutputStream;
48
49
import com.sun.imageio.plugins.gif.GIFStreamMetadata;
50
51
public class LogicalScreenDimensionTest {
52
public static void main(String[] args) throws IOException {
53
String format = "GIF";
54
ImageWriter writer =
55
ImageIO.getImageWritersByFormatName(format).next();
56
if (writer == null) {
57
throw new RuntimeException("No available writers for " + format);
58
}
59
60
BufferedImage img = createTestImage(100, 100, BufferedImage.TYPE_BYTE_GRAY);
61
62
ImageWriteParam p = writer.getDefaultWriteParam();
63
ImageTypeSpecifier type =
64
ImageTypeSpecifier.createFromRenderedImage(img);
65
IIOMetadata inImageMetadata =
66
writer.getDefaultImageMetadata(type, p);
67
68
IIOMetadata inStreamMetadata = writer.getDefaultStreamMetadata(p);
69
70
// write and read image
71
ByteArrayOutputStream baos = new ByteArrayOutputStream();
72
73
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
74
writer.setOutput(ios);
75
76
writer.write(inStreamMetadata, new IIOImage(img, null, inImageMetadata), p);
77
78
ios.flush();
79
ios.close();
80
81
// read result
82
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
83
ImageInputStream iis = ImageIO.createImageInputStream(bais);
84
ImageReader reader = ImageIO.getImageReader(writer);
85
reader.setInput(iis);
86
87
IIOMetadata outStreamMetadata = reader.getStreamMetadata();
88
89
GIFStreamMetadata gifStreamMetadata = (GIFStreamMetadata)outStreamMetadata;
90
91
if (gifStreamMetadata.logicalScreenWidth != img.getWidth() ||
92
gifStreamMetadata.logicalScreenHeight != img.getHeight()) {
93
throw new RuntimeException("Test failed due to wrong logical screen dimension.");
94
}
95
}
96
97
private static BufferedImage createTestImage(int w, int h, int type) {
98
BufferedImage res = new BufferedImage(w, h, type);
99
Graphics2D g = res.createGraphics();
100
g.setColor(Color.white);
101
g.fillRect(0, 0, w, h);
102
g.setColor(Color.black);
103
g.fillRect(w/4, h/4, w/2, h/2);
104
105
106
return res;
107
}
108
}
109
110