Frames | No Frames |
1: /* QtImageConsumer.java -- 2: Copyright (C) 2005 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; see the file COPYING. If not, write to the 18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 USA. 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 31: independent module, the terms and conditions of the license of that 32: module. An independent module is a module which is not derived from 33: or based on this library. If you modify this library, you may extend 34: this exception to your version of the library, but you are not 35: obligated to do so. If you do not wish to do so, delete this 36: exception statement from your version. */ 37: 38: package gnu.java.awt.peer.qt; 39: 40: import java.awt.Graphics; 41: import java.awt.Image; 42: import java.awt.image.ColorModel; 43: import java.awt.image.DirectColorModel; 44: import java.awt.image.ImageConsumer; 45: import java.awt.image.ImageObserver; 46: import java.awt.image.ImageProducer; 47: import java.util.Hashtable; 48: import java.util.Vector; 49: 50: /** 51: * Helper class to QtImage. Sits and gathers pixels for a QtImage and then 52: * calls QtImage.setImage(). 53: * 54: * @author Sven de Marothy 55: */ 56: public class QtImageConsumer implements ImageConsumer 57: { 58: private QtImage target; 59: private int width, height; 60: private Hashtable properties; 61: private int[] pixelCache = null; 62: private ImageProducer source; 63: 64: public QtImageConsumer(QtImage target, ImageProducer source) 65: { 66: this.target = target; 67: this.source = source; 68: } 69: 70: public synchronized void imageComplete (int status) 71: { 72: source.removeConsumer(this); 73: target.setImage(width, height, pixelCache, properties); 74: } 75: 76: public synchronized void setColorModel (ColorModel model) 77: { 78: // This method is to inform on what the most used color model 79: // in the image is, for optimization reasons. We ignore this 80: // information. 81: } 82: 83: public synchronized void setDimensions (int width, int height) 84: { 85: pixelCache = new int[width*height]; 86: 87: this.width = width; 88: this.height = height; 89: } 90: 91: public synchronized void setHints (int flags) 92: { 93: // This method informs us in which order the pixels are 94: // delivered, for progressive-loading support, etc. 95: // Since we wait until it's all loaded, we can ignore the hints. 96: } 97: 98: public synchronized void setPixels (int x, int y, int width, int height, 99: ColorModel cm, byte[] pixels, 100: int offset, int scansize) 101: { 102: setPixels (x, y, width, height, cm, convertPixels (pixels), offset, 103: scansize); 104: } 105: 106: public synchronized void setPixels (int x, int y, int width, int height, 107: ColorModel cm, int[] pixels, 108: int offset, int scansize) 109: { 110: if (pixelCache == null) 111: return; // Not sure this should ever happen. 112: 113: if (cm.equals(QtImage.nativeModel)) 114: for (int i = 0; i < height; i++) 115: System.arraycopy (pixels, offset + (i * scansize), 116: pixelCache, (y + i) * this.width + x, 117: width); 118: else 119: { 120: for (int i = 0; i < height; i++) 121: for (int j = 0; j < width; j++) 122: { 123: // get in AARRGGBB and convert to AABBGGRR 124: int pix = cm.getRGB(pixels[offset + (i * scansize) + x + j]); 125: byte b = (byte)(pix & 0xFF); 126: byte r = (byte)(((pix & 0x00FF0000) >> 16) & 0xFF); 127: pix &= 0xFF00FF00; 128: pix |= ((b & 0xFF) << 16); 129: pix |= (r & 0xFF); 130: pixelCache[(y + i) * this.width + x + j] = pix; 131: } 132: } 133: } 134: 135: /** 136: * This is an old method, no idea if it's correct. 137: */ 138: private int[] convertPixels (byte[] pixels) 139: { 140: int ret[] = new int[pixels.length]; 141: 142: for (int i = 0; i < pixels.length; i++) 143: ret[i] = pixels[i] & 0xFF; 144: 145: return ret; 146: } 147: 148: public synchronized void setProperties (Hashtable props) 149: { 150: this.properties = props; 151: } 152: } 153: