8074967: [macosx] JPEGImageReader incorrectly identifies YCbCr JPEGs as RGB in standard metadata
Reviewed-by: prr, psadhukhan
--- a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGMetadata.java Tue Dec 01 19:21:40 2015 +0300
+++ b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGMetadata.java Wed Dec 02 00:34:35 2015 +0530
@@ -874,13 +874,13 @@
return chroma;
}
- boolean idsAreJFIF = true;
+ boolean idsAreJFIF = false;
- for (int i = 0; i < sof.componentSpecs.length; i++) {
- int id = sof.componentSpecs[i].componentId;
- if ((id < 1) || (id >= sof.componentSpecs.length)) {
- idsAreJFIF = false;
- }
+ int cid0 = sof.componentSpecs[0].componentId;
+ int cid1 = sof.componentSpecs[1].componentId;
+ int cid2 = sof.componentSpecs[2].componentId;
+ if ((cid0 == 1) && (cid1 == 2) && (cid2 == 3)) {
+ idsAreJFIF = true;
}
if (idsAreJFIF) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/imageio/plugins/jpeg/JpegMetadataColorSpaceTest.java Wed Dec 02 00:34:35 2015 +0530
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8074967
+ * @summary Test verifies if there is no JFIF & EXIF header
+ * and sampling factor is same of JPEG image, then
+ * JPEG colorspace should not be RGB.
+ * @run main JpegMetadataColorSpaceTest
+ */
+
+import javax.imageio.ImageIO;
+import javax.imageio.ImageReader;
+import javax.imageio.metadata.IIOMetadata;
+import javax.imageio.metadata.IIOMetadataFormatImpl;
+import javax.imageio.metadata.IIOMetadataNode;
+import javax.imageio.stream.ImageInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+
+public class JpegMetadataColorSpaceTest {
+ public static void main(String[] args) throws IOException {
+ String fileName = "nomarkers.jpg";
+ String sep = System.getProperty("file.separator");
+ String dir = System.getProperty("test.src", ".");
+ String filePath = dir+sep+fileName;
+ System.out.println("Test file: " + filePath);
+ File file = new File(filePath);
+ ImageInputStream stream = ImageIO.createImageInputStream(file);
+ Iterator<ImageReader> readers = ImageIO.getImageReaders(stream);
+
+ if(readers.hasNext()) {
+ ImageReader reader = readers.next();
+ reader.setInput(stream);
+ IIOMetadata metadata = reader.getImageMetadata(0);
+
+ IIOMetadataNode standardTree = (IIOMetadataNode)
+ metadata.getAsTree
+ (IIOMetadataFormatImpl.standardMetadataFormatName);
+ IIOMetadataNode colorSpaceType = (IIOMetadataNode)
+ standardTree.getElementsByTagName("ColorSpaceType").item(0);
+ String colorSpaceName = colorSpaceType.getAttribute("name");
+ if(colorSpaceName.equals("RGB"))
+ throw new RuntimeException("Identified incorrect ColorSpace");
+ }
+ }
+}
Binary file jdk/test/javax/imageio/plugins/jpeg/nomarkers.jpg has changed