1/* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/** 25 * @test 26 * @bug 8143562 27 * @summary Test verifies whether getRawImageType API returns proper raw 28 * image type when color space is of type YCbCr. 29 * @run main JpegRawImageTypeTest 30 */ 31 32import java.io.File; 33import java.util.Iterator; 34import javax.imageio.ImageIO; 35import javax.imageio.ImageReader; 36import javax.imageio.ImageTypeSpecifier; 37import javax.imageio.stream.ImageInputStream; 38 39public class JpegRawImageTypeTest { 40 41 public static void main(String[] args) throws Exception { 42 43 //nomarkers.jpg has YCbCr color space 44 String fileName = "nomarkers.jpg"; 45 String sep = System.getProperty("file.separator"); 46 String dir = System.getProperty("test.src", "."); 47 String filePath = dir+sep+fileName; 48 System.out.println("Test file: " + filePath); 49 File imageFile = new File(filePath); 50 51 ImageInputStream inputStream = ImageIO. 52 createImageInputStream(imageFile); 53 Iterator<ImageReader> readers = ImageIO.getImageReaders(inputStream); 54 55 if(readers.hasNext()) { 56 ImageReader reader = readers.next(); 57 reader.setInput(inputStream); 58 59 ImageTypeSpecifier typeSpecifier = reader.getRawImageType(0); 60 //check if ImageTypeSpecifier is null for YCbCr JPEG Image 61 if (typeSpecifier == null) { 62 throw new RuntimeException("ImageReader returns null raw image" 63 + " type"); 64 } 65 } 66 } 67} 68