comparison common/src/main/java/digilib/image/ImageLoaderDocuImage.java @ 1034:c71795594406

another fix for brgt. fixes for mac osx 10.6.
author robcast
date Sun, 11 Mar 2012 16:35:53 +0100
parents 4e368c85cce4
children e4eb1209fa78
comparison
equal deleted inserted replaced
1033:d5e181e3401c 1034:c71795594406
63 * Implementation of DocuImage using the ImageLoader API of Java 1.4 and Java2D. 63 * Implementation of DocuImage using the ImageLoader API of Java 1.4 and Java2D.
64 */ 64 */
65 public class ImageLoaderDocuImage extends ImageInfoDocuImage { 65 public class ImageLoaderDocuImage extends ImageInfoDocuImage {
66 66
67 /** DocuImage version */ 67 /** DocuImage version */
68 public static final String version = "ImageLoaderDocuImage 2.1.2"; 68 public static final String version = "ImageLoaderDocuImage 2.1.3";
69 69
70 /** image object */ 70 /** image object */
71 protected BufferedImage img; 71 protected BufferedImage img;
72 72
73 /** the reader object */ 73 /** the reader object */
80 protected RenderingHints renderHint = null; 80 protected RenderingHints renderHint = null;
81 81
82 /** convolution kernels for blur() */ 82 /** convolution kernels for blur() */
83 protected static Kernel[] convolutionKernels = { 83 protected static Kernel[] convolutionKernels = {
84 null, new Kernel(1, 1, new float[] { 1f }), 84 null, new Kernel(1, 1, new float[] { 1f }),
85 new Kernel(2, 2, new float[] { 0.25f, 0.25f, 0.25f, 0.25f }), 85 new Kernel(2, 2, new float[] { 0.25f, 0.25f,
86 new Kernel(3, 3, new float[] { 1f / 9f, 1f / 9f, 1f / 9f, 1f / 9f, 1f / 9f, 1f / 9f, 1f / 9f, 1f / 9f, 1f / 9f }) }; 86 0.25f, 0.25f }),
87 new Kernel(3, 3, new float[] { 1f / 9f, 1f / 9f, 1f / 9f,
88 1f / 9f, 1f / 9f, 1f / 9f,
89 1f / 9f, 1f / 9f, 1f / 9f }) };
87 90
88 /* lookup tables for inverting images (byte) */ 91 /* lookup tables for inverting images (byte) */
89 protected static LookupTable invertSingleByteTable; 92 protected static LookupTable invertSingleByteTable;
90 protected static LookupTable invertRgbaByteTable; 93 protected static LookupTable invertRgbaByteTable;
91 protected static boolean needsInvertRgba = false; 94 protected static boolean needsInvertRgba = false;
127 mapB[i] = 0; 130 mapB[i] = 0;
128 } 131 }
129 } 132 }
130 // should(!) work for all color models 133 // should(!) work for all color models
131 invertSingleByteTable = new ByteLookupTable(0, invertByte); 134 invertSingleByteTable = new ByteLookupTable(0, invertByte);
135 invertRgbaByteTable = invertSingleByteTable;
132 // but doesn't work with alpha channel on all platforms 136 // but doesn't work with alpha channel on all platforms
133 String ver = System.getProperty("java.version"); 137 String ver = System.getProperty("java.version");
134 String os = System.getProperty("os.name"); 138 String os = System.getProperty("os.name");
135 String osver = System.getProperty("os.version"); 139 String osver = System.getProperty("os.version");
136 logger.debug("os="+os+" ver="+osver+" java_version="+ver); 140 logger.debug("os="+os+" ver="+osver+" java_version="+ver);
138 // GRAB(WTF?) works for Linux JDK1.6 with transparency 142 // GRAB(WTF?) works for Linux JDK1.6 with transparency
139 needsInvertRgba = true; 143 needsInvertRgba = true;
140 invertRgbaByteTable = new ByteLookupTable(0, new byte[][] { invertByte, invertByte, orderedByte, invertByte }); 144 invertRgbaByteTable = new ByteLookupTable(0, new byte[][] { invertByte, invertByte, orderedByte, invertByte });
141 needsRescaleRgba = true; 145 needsRescaleRgba = true;
142 needsMapBgr = true; 146 needsMapBgr = true;
143 } else { 147 } else if (os.startsWith("Mac OS X") && osver.startsWith("10.6")) {
144 invertRgbaByteTable = invertSingleByteTable; 148 needsRescaleRgba = true;
145 } 149 }
146 // this hopefully works for all 150 // this hopefully works for all
147 mapBgrByteTable = new ByteLookupTable(0, new byte[][] { mapR, mapG, mapB }); 151 mapBgrByteTable = new ByteLookupTable(0, new byte[][] { mapR, mapG, mapB });
148 logger.debug("ImageIO Hacks: needsRescaleRgba="+needsRescaleRgba+" needsInvertRgba="+needsInvertRgba+ 152 logger.debug("ImageIO Hacks: needsRescaleRgba="+needsRescaleRgba+" needsInvertRgba="+needsInvertRgba+
149 " needsMapBgr="+needsMapBgr); 153 " needsMapBgr="+needsMapBgr);
558 float[] da = new float[ncol]; 562 float[] da = new float[ncol];
559 for (int i = 0; i < ncol; i++) { 563 for (int i = 0; i < ncol; i++) {
560 dm[i] = (float) mult; 564 dm[i] = (float) mult;
561 da[i] = (float) add; 565 da[i] = (float) add;
562 } 566 }
563 op = new RescaleOp(dm, da, null); 567 if (img.getColorModel().hasAlpha()) {
568 // alpha channel should not be scaled
569 dm[ncol-1] = 1f;
570 da[ncol-1] = 0f;
571 }
572 op = new RescaleOp(dm, da, renderHint);
564 } else { 573 } else {
565 op = new RescaleOp(mult, add, renderHint); 574 op = new RescaleOp(mult, add, renderHint);
566 } 575 }
567 op.filter(img, img); 576 op.filter(img, img);
568 } 577 }