diff --git a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java index b72dcc88d75..1773b200f65 100644 --- a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java +++ b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java @@ -1788,6 +1788,8 @@ class ImageTypeProducer { case JPEG.JCS_GRAYSCALE: return ImageTypeSpecifier.createFromBufferedImageType (BufferedImage.TYPE_BYTE_GRAY); + case JPEG.JCS_YCbCr: + //there is no YCbCr raw type so by default we assume it as RGB case JPEG.JCS_RGB: return ImageTypeSpecifier.createInterleaved(JPEG.JCS.sRGB, JPEG.bOffsRGB, diff --git a/jdk/src/java.desktop/share/classes/javax/imageio/ImageReader.java b/jdk/src/java.desktop/share/classes/javax/imageio/ImageReader.java index 25709a82ada..f9c29cd59dc 100644 --- a/jdk/src/java.desktop/share/classes/javax/imageio/ImageReader.java +++ b/jdk/src/java.desktop/share/classes/javax/imageio/ImageReader.java @@ -654,12 +654,11 @@ public abstract class ImageReader { } /** - * Returns an {@code ImageTypeSpecifier} indicating the - * {@code SampleModel} and {@code ColorModel} which most - * closely represents the "raw" internal format of the image. For - * example, for a JPEG image the raw type might have a YCbCr color - * space even though the image would conventionally be transformed - * into an RGB color space prior to display. The returned value + * Returns an ImageTypeSpecifier indicating the + * SampleModel and ColorModel which most + * closely represents the "raw" internal format of the image. If + * there is no close match then a type which preserves the most + * information from the image should be returned. The returned value * should also be included in the list of values returned by * {@code getImageTypes}. * diff --git a/jdk/test/javax/imageio/plugins/jpeg/JpegRawImageTypeTest.java b/jdk/test/javax/imageio/plugins/jpeg/JpegRawImageTypeTest.java new file mode 100644 index 00000000000..8749ca0daa6 --- /dev/null +++ b/jdk/test/javax/imageio/plugins/jpeg/JpegRawImageTypeTest.java @@ -0,0 +1,67 @@ +/* + * 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 8143562 + * @summary Test verifies whether getRawImageType API returns proper raw + * image type when color space is of type YCbCr. + * @run main JpegRawImageTypeTest + */ + +import java.io.File; +import java.util.Iterator; +import javax.imageio.ImageIO; +import javax.imageio.ImageReader; +import javax.imageio.ImageTypeSpecifier; +import javax.imageio.stream.ImageInputStream; + +public class JpegRawImageTypeTest { + + public static void main(String[] args) throws Exception { + + //nomarkers.jpg has YCbCr color space + 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 imageFile = new File(filePath); + + ImageInputStream inputStream = ImageIO. + createImageInputStream(imageFile); + Iterator readers = ImageIO.getImageReaders(inputStream); + + if(readers.hasNext()) { + ImageReader reader = readers.next(); + reader.setInput(inputStream); + + ImageTypeSpecifier typeSpecifier = reader.getRawImageType(0); + //check if ImageTypeSpecifier is null for YCbCr JPEG Image + if (typeSpecifier == null) { + throw new RuntimeException("ImageReader returns null raw image" + + " type"); + } + } + } +}