1 /* Copyright (C) 2005-2011 Fabio Riccardi */ 2 3 package com.lightcrafts.ui.browser.model; 4 5 import com.lightcrafts.jai.JAIContext; 6 import com.lightcrafts.jai.utils.Functions; 7 8 import java.awt.image.RenderedImage; 9 import java.awt.image.ColorModel; 10 import java.awt.color.ColorSpace; 11 12 /** 13 * This static utility converts a given RenderedImage into a new 14 * RenderedImage that has been optimized for rendering on the display: 15 * <p> 16 * <ul> 17 * <li> 18 * Its colors have been converted to the display's color profile; 19 * </li><li> 20 * If it was not a BufferedImage, its pipeline has been run; and 21 * </li><li> 22 * Its color model has been set to sRGB, so AWT on Windows will not 23 * attempt further color space conversions. 24 * </li> 25 * </ul> 26 */ 27 class FastImageFactory { 28 systemColorSpaceImage(RenderedImage image)29 static RenderedImage systemColorSpaceImage(RenderedImage image) { 30 ColorModel colors = image.getColorModel(); 31 ColorSpace space = colors.getColorSpace(); 32 if (space != null) { 33 if (! space.equals(JAIContext.systemColorSpace)) { 34 image = Functions.toColorSpace( 35 image, JAIContext.systemColorSpace, null 36 ); 37 } 38 } 39 return new Functions.sRGBWrapper(image); 40 } 41 42 /** 43 * Make a new image like the given image and that is suitable for fast 44 * rendering on the screen. 45 **/ createFastImage(RenderedImage image)46 static RenderedImage createFastImage(RenderedImage image) { 47 image = systemColorSpaceImage(image); 48 image = Functions.toFastBufferedImage(image); 49 return image; 50 } 51 } 52