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 8041501 27 * @summary Test verifies if there is no JFIF & EXIF header 28 * and sampling factor is same of JPEG image, then 29 * imageIO should not override colorspace determined 30 * in IJG library. 31 * @run main JpegImageColorSpaceTest 32 */ 33 34 import java.awt.Color; 35 import java.awt.image.BufferedImage; 36 import java.io.File; 37 import javax.imageio.ImageIO; 38 39 public class JpegImageColorSpaceTest { 40 41 public static void main(String args[]) throws Exception { 42 43 String fileName = "nomarkers.jpg"; 44 String sep = System.getProperty("file.separator"); 45 String dir = System.getProperty("test.src", "."); 46 String filePath = dir+sep+fileName; 47 System.out.println("Test file: " + filePath); 48 File imageFile = new File(filePath); 49 50 BufferedImage bufferedImage = ImageIO.read(imageFile); 51 int imageWidth = bufferedImage.getWidth(); 52 int imageHeight = bufferedImage.getHeight(); 53 54 for (int i = 0; i < imageWidth; i++) { 55 for(int j = 0; j < imageHeight; j++) { 56 /* 57 * Since image is white we check individual pixel values from 58 * BufferedImage to verify if ImageIO.read() is done with proper 59 * color space or not. 60 */ 61 if (bufferedImage.getRGB(i, j) != Color.white.getRGB()) { 62 // color space is not proper 63 throw new RuntimeException("ColorSpace is not determined " 64 + "properly by ImageIO"); 65 } 66 } 67 } 68 } 69 }