From e300345cc8e854f9ad7fe5347d4fe07ec93cfc9c Mon Sep 17 00:00:00 2001 From: Jayathirth D V Date: Wed, 2 Dec 2015 00:34:35 +0530 Subject: [PATCH] 8074967: [macosx] JPEGImageReader incorrectly identifies YCbCr JPEGs as RGB in standard metadata Reviewed-by: prr, psadhukhan --- .../imageio/plugins/jpeg/JPEGMetadata.java | 12 +-- .../jpeg/JpegMetadataColorSpaceTest.java | 69 ++++++++++++++++++ .../javax/imageio/plugins/jpeg/nomarkers.jpg | Bin 0 -> 548 bytes 3 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 jdk/test/javax/imageio/plugins/jpeg/JpegMetadataColorSpaceTest.java create mode 100644 jdk/test/javax/imageio/plugins/jpeg/nomarkers.jpg diff --git a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGMetadata.java b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGMetadata.java index f25863955ec..7975efda580 100644 --- a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGMetadata.java +++ b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGMetadata.java @@ -874,13 +874,13 @@ public class JPEGMetadata extends IIOMetadata implements Cloneable { 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) { diff --git a/jdk/test/javax/imageio/plugins/jpeg/JpegMetadataColorSpaceTest.java b/jdk/test/javax/imageio/plugins/jpeg/JpegMetadataColorSpaceTest.java new file mode 100644 index 00000000000..dbe54f553e2 --- /dev/null +++ b/jdk/test/javax/imageio/plugins/jpeg/JpegMetadataColorSpaceTest.java @@ -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 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"); + } + } +} diff --git a/jdk/test/javax/imageio/plugins/jpeg/nomarkers.jpg b/jdk/test/javax/imageio/plugins/jpeg/nomarkers.jpg new file mode 100644 index 0000000000000000000000000000000000000000..3b08cdd3b02b159411cd54e30c2683be6d8ca6b0 GIT binary patch literal 548 zcmb79+YN#+6uq~lP-wvxTjbZoJs|PRE!@N%9K$h;L--h`wjq+BJmSgu>CJi7-Q5fJ zKnV%-h&&l*EQ(l`Br%tnlp+%%FG`gcx)4HDO0SKzR<1U6W$Myc6GD)BPsCEjQj?3^ z{0(;n&7p;sq6VUoYIHZSfCxiye>Oi?a8HmFfhei~@X`)V{p%Fm>O1r3-P~s)Bcavk saREhaa85va!DL0;bQO~VY_|CM3{XE@oe#TFE-Y0`OFO~L5HEPV0ZWiZasU7T literal 0 HcmV?d00001