Author: damjan Date: Fri Apr 27 08:21:25 2012 New Revision: 1331291 URL: http://svn.apache.org/viewvc?rev=1331291&view=rev Log: Speed up reading paletted TIFF files.
Jira issue key: SANSELAN-75 Submitted by: Gary Lucas <gwlucas at sonalysts dot com> Added: commons/proper/imaging/trunk/src/test/data/images/tiff/4/ commons/proper/imaging/trunk/src/test/data/images/tiff/4/IndexColorPalette.tif (with props) Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/photometricinterpreters/PhotometricInterpreterPalette.java Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/photometricinterpreters/PhotometricInterpreterPalette.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/photometricinterpreters/PhotometricInterpreterPalette.java?rev=1331291&r1=1331290&r2=1331291&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/photometricinterpreters/PhotometricInterpreterPalette.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/photometricinterpreters/PhotometricInterpreterPalette.java Fri Apr 27 08:21:25 2012 @@ -24,6 +24,13 @@ import org.apache.commons.imaging.common public class PhotometricInterpreterPalette extends PhotometricInterpreter { private final int[] fColorMap; + + /** + * The color map of integer ARGB values tied to the + * pixel index of the palette + */ + private final int[] indexColorMap; + public PhotometricInterpreterPalette(int fSamplesPerPixel, int fBitsPerSample[], int Predictor, int width, int height, @@ -32,24 +39,26 @@ public class PhotometricInterpreterPalet super(fSamplesPerPixel, fBitsPerSample, Predictor, width, height); this.fColorMap = fColorMap; + + int fBitsPerPixel = bitsPerSample[0]; + int colormap_scale = (1 << fBitsPerPixel); + indexColorMap = new int[colormap_scale]; + for (int index = 0; index < colormap_scale; index++) + { + int red = (fColorMap[index]>>8)&0xff; + int green = (fColorMap[index + (colormap_scale)]>>8)&0xff; + int blue = (fColorMap[index + (2 * colormap_scale)]>>8)&0xff; + indexColorMap[index] = + 0xff000000 | (red << 16) | (green << 8) | blue; + } + + } @Override public void interpretPixel(ImageBuilder imageBuilder, int samples[], int x, int y) throws ImageReadException, IOException { - int fBitsPerPixel = bitsPerSample[0]; - int colormap_scale = (1 << fBitsPerPixel); - // int expected_colormap_size = 3 * (1 << fBitsPerPixel); - - int index = samples[0]; - int red = fColorMap[index] >> 8; - int green = fColorMap[index + (colormap_scale)] >> 8; - int blue = fColorMap[index + (2 * colormap_scale)] >> 8; - - int alpha = 0xff; - int rgb = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0); - imageBuilder.setRGB(x, y, rgb); - + imageBuilder.setRGB(x, y, indexColorMap[samples[0]]); } } \ No newline at end of file Added: commons/proper/imaging/trunk/src/test/data/images/tiff/4/IndexColorPalette.tif URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/data/images/tiff/4/IndexColorPalette.tif?rev=1331291&view=auto ============================================================================== Binary file - no diff available. Propchange: commons/proper/imaging/trunk/src/test/data/images/tiff/4/IndexColorPalette.tif ------------------------------------------------------------------------------ svn:mime-type = image/tiff