8143562: JPEG reader returns null for getRawImageType()

Reviewed-by: prr, arapte
This commit is contained in:
Jayathirth D V 2016-01-19 11:11:20 +05:30
parent 0e2ceaee82
commit a757640460
3 changed files with 74 additions and 6 deletions

View File

@ -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,

View File

@ -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 <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}.
*

View File

@ -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");
}
}
}
}