Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/imageio/plugins/bmp/BMPPixelSpacingTest.java
41153 views
1
/*
2
* Copyright (c) 2015, 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 7182758
27
* @summary Test verifies whether we are getting correct Horizontal
28
* & Vertical Physical pixel spacing for active BMP image
29
* through stored metadata or not.
30
* @run main BMPPixelSpacingTest
31
*/
32
33
import java.io.ByteArrayInputStream;
34
import java.util.Iterator;
35
import javax.imageio.ImageIO;
36
import javax.imageio.ImageReader;
37
import javax.imageio.metadata.IIOMetadata;
38
import javax.imageio.stream.ImageInputStream;
39
import org.w3c.dom.NamedNodeMap;
40
import org.w3c.dom.Node;
41
import org.w3c.dom.NodeList;
42
43
public class BMPPixelSpacingTest {
44
45
public static void main(String[] args) throws Exception {
46
// Header contaning X & Y pixels-per-meter more than value 1
47
byte[] bmpHeaderData = { (byte) 0x42, (byte) 0x4d, (byte) 0x7e,
48
(byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
49
(byte) 0x00, (byte) 0x00, (byte) 0x3e, (byte) 0x00, (byte) 0x00,
50
(byte) 0x00, (byte) 0x28, (byte) 0x00, (byte) 0x00, (byte) 0x00,
51
(byte) 0x64, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64,
52
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
53
(byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
54
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
55
(byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02,
56
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
57
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0xff,
58
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
59
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
60
(byte) 0xff };
61
62
ImageInputStream imageInput = ImageIO.
63
createImageInputStream(new ByteArrayInputStream(bmpHeaderData));
64
65
for (Iterator<ImageReader> it = ImageIO.getImageReaders(imageInput);
66
it.hasNext(); ) {
67
ImageReader reader = it.next();
68
reader.setInput(imageInput);
69
IIOMetadata metadata = reader.getImageMetadata(0);
70
71
Node rootNode = metadata.getAsTree("javax_imageio_1.0");
72
NodeList nl = rootNode.getChildNodes();
73
74
//Parse until you get Dimension child node
75
for (int i = 0; i < nl.getLength(); i++) {
76
Node node = nl.item(i);
77
if ((node.getNodeName()).equals("Dimension")) {
78
//get childnode list under Dimension node
79
NodeList cl = node.getChildNodes();
80
//Corresponding node indices under Dimension node
81
int horizontalNodeIndex = 1;
82
int verticalNodeIndex = 2;
83
Node horizontalNode = cl.item(horizontalNodeIndex);
84
Node verticalNode = cl.item(verticalNodeIndex);
85
86
//get attributes for horizontal and vertical nodes
87
NamedNodeMap horizontalAttr = horizontalNode.
88
getAttributes();
89
NamedNodeMap verticalAttr = verticalNode.getAttributes();
90
91
//since they have only one attribute index is 0
92
int attributeIndex = 0;
93
Node horizontalValue = horizontalAttr.item(attributeIndex);
94
Node verticalValue = verticalAttr.item(attributeIndex);
95
float horizontalNodeValue = Float.
96
parseFloat((horizontalValue.getNodeValue()));
97
float verticalNodeValue = Float.
98
parseFloat((verticalValue.getNodeValue()));
99
100
float expectedHorizontalValue, expectedVerticalValue;
101
// in test metadata xPixelsPerMeter & yPixelsPerMeter is 2
102
expectedHorizontalValue = expectedVerticalValue =
103
1000.0F / 2;
104
//expected and returned values should be same
105
if ((Float.compare(horizontalNodeValue,
106
expectedHorizontalValue) != 0) ||
107
(Float.compare(verticalNodeValue,
108
expectedVerticalValue) != 0)) {
109
throw new RuntimeException("Invalid pixel spacing");
110
}
111
}
112
}
113
}
114
}
115
}
116
117