8143562: JPEG reader returns null for getRawImageType()
authorjdv
Tue, 19 Jan 2016 11:11:20 +0530
changeset 35678 ad6cfe2f2e13
parent 35677 c243e74116f8
child 35679 e4b92165fa8d
8143562: JPEG reader returns null for getRawImageType() Reviewed-by: prr, arapte
jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java
jdk/src/java.desktop/share/classes/javax/imageio/ImageReader.java
jdk/test/javax/imageio/plugins/jpeg/JpegRawImageTypeTest.java
--- a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java	Mon Jan 18 21:19:36 2016 +0300
+++ b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java	Tue Jan 19 11:11:20 2016 +0530
@@ -1788,6 +1788,8 @@
             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,
--- a/jdk/src/java.desktop/share/classes/javax/imageio/ImageReader.java	Mon Jan 18 21:19:36 2016 +0300
+++ b/jdk/src/java.desktop/share/classes/javax/imageio/ImageReader.java	Tue Jan 19 11:11:20 2016 +0530
@@ -654,12 +654,11 @@
     }
 
     /**
-     * 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 <code>ImageTypeSpecifier</code> indicating the
+     * <code>SampleModel</code> and <code>ColorModel</code> 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}.
      *
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/imageio/plugins/jpeg/JpegRawImageTypeTest.java	Tue Jan 19 11:11:20 2016 +0530
@@ -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<ImageReader> 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");
+            }
+        }
+    }
+}