qtimage.java

来自「This is a resource based on j2me embedde」· Java 代码 · 共 661 行 · 第 1/2 页

JAVA
661
字号
                    Vector uninterested = null;                    while (enum.hasMoreElements()) {                        ImageObserver observer;                        try {                            observer = (ImageObserver) enum.nextElement();                        } catch (NoSuchElementException e) {                            break;                        }                                                if (!observer.imageUpdate(img, info, x, y, w, h)) {                            if (uninterested == null) {                                uninterested = new Vector();                            }                            uninterested.addElement(observer);                        }                    }                    if (uninterested != null) {                        enum = uninterested.elements();                        while (enum.hasMoreElements()) {                            ImageObserver observer = (ImageObserver) enum.nextElement();                            removeObserver(observer);                        }                    }				}	synchronized void startProduction() {		if (producer != null && !started) {			if(!producer.isConsumer(this)){				producer.addConsumer(this);			}			started = true;			producer.startProduction(this);		}	}	public synchronized void flush() {            dispose();		             started = true;// Begin of: PBP/PP [6262553]// Take security fixes from J2SE SunToolkit.java into PBP/PP's SunToolkit.java.// Image cache is now maintained at the SunToolkit.java via a sun.misc.SoftCache.//            QtToolkit.clearCache(this);// End of: PBP/PP [6262553]            width = -1;            height = -1;				    if(!empty) {		status = 0;		started = false; 	    }        	    if(producer != null) {		producer.removeConsumer(this);            		if(producer instanceof sun.awt.image.InputStreamImageSource){			((sun.awt.image.InputStreamImageSource)producer).flush();		}	    }             }	public ImageProducer getSource() {		return producer;	}	void drawImage(int psd, int x, int y, Color bg) {		pDrawImage(psd, this.psd, x, y, bg);	}	private static native void pDrawImageScaled(int psd, int dx1, int dy1, int dx2, int dy2, int imagePSD, int sx1, int sy1, int sx2, int sy2, Color bg);	void drawImage(int psd, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bg)	{		pDrawImageScaled(psd, dx1, dy1, dx2, dy2, this.psd, sx1, sy1, sx2, sy2, bg);	}		boolean isComplete(){			return ((status & (ImageObserver.ALLBITS | ImageObserver.ERROR | ImageObserver.ABORT)) != 0);		}		boolean hasError() {			return ((status & ImageObserver.ERROR)!=0);		}	/*****  --- Consumer Stuff --- *****/	private native static void imageCompleteLoadBuffer(int imagePSD, boolean dispose);	public void imageComplete(int stat) {		switch (stat) {		case STATICIMAGEDONE:			status = ImageObserver.ALLBITS;			break;		case SINGLEFRAMEDONE:			status = ImageObserver.FRAMEBITS;			break;		case IMAGEERROR:			status = ImageObserver.ERROR;			break;		case IMAGEABORTED:			status = ImageObserver.ABORT;			break;		}		if (status != 0) {			imageCompleteLoadBuffer(psd, (status==ImageObserver.ALLBITS));			notifyObservers(this, status, 0, 0, width, height);		}				if (isComplete())			producer.removeConsumer(this);	}	public void setColorModel(ColorModel cm) {}	public synchronized void setDimensions(int width, int height) {		if ((width>0) && (height>0)) {			this.width = width;			this.height = height;			dispose();			psd = gc.createCompatibleImagePSD(width, height);			status = ImageObserver.WIDTH | ImageObserver.HEIGHT;			notifyObservers(this, status, 0, 0, width, height);		  }	}	public void setProperties(Hashtable props) {		properties = props;	}	public void setHints(int hints) {/*	 System.out.println("ImageHints:");	 if((hints&RANDOMPIXELORDER) != 0)	 System.out.println("Hints: random order");	 if((hints&TOPDOWNLEFTRIGHT) != 0)	 System.out.println("Hints: top down");	 if((hints&COMPLETESCANLINES) != 0)	 System.out.println("Hints: complete scan lines");	 if((hints&SINGLEPASS) != 0)	 System.out.println("Hints: single pass");	 if((hints&SINGLEFRAME) != 0)	 System.out.println("Hints: single frame");	 */}	/** Unaccelerated native function for setting pixels in the image from any kind of ColorModel. */	private static native void pSetColorModelBytePixels(int psd, int x, int y, int w, int h, ColorModel cm, byte[] pixels, int offset, int scansize);	/** Unaccelerated native function for setting pixels in the image from any kind of ColorModel. */	private static native void pSetColorModelIntPixels(int psd, int x, int y, int w, int h, ColorModel cm, int[] pixels, int offset, int scansize);	/** Accelerated native function for setting pixels in the image when the ColorModel is an IndexColorModel. */	private static native void pSetIndexColorModelBytePixels(int psd, int x, int y, int w, int h, ColorModel cm, byte[] pixels, int offset, int scansize);	/** Accelerated native function for setting pixels in the image when the ColorModel is an IndexColorModel. */	private static native void pSetIndexColorModelIntPixels(int psd, int x, int y, int w, int h, ColorModel cm, int[] pixels, int offset, int scansize);	/** Accelerated native function for setting pixels in the image when the ColorModel is a DirectColorModel. */	private static native void pSetDirectColorModelPixels(int psd, int x, int y, int w, int h, ColorModel cm, int[] pixels, int offset, int scansize, int totalMask);	/** Gets the ARGB color value at the supplied location. */	private static native int pGetRGB(int psd, int x, int y);		/* Gets an area of ARGB values and stores them in the array. */		private static native void pGetRGBArray(int psd, int x, int y, int w, int h, int[] pixels, int off, int scansize);		/* Sets the pixel at the supplied location to an ARGB value. */		private static native void pSetRGB(int psd, int x, int y, int rgb);	private static native void pSetRGBArray(int psd, int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize);			public void setPixels(int x, int y, int w, int h, ColorModel cm, byte[] pixels, int off, int scansize) {				if(psd<0) return;		/* 6199102 if ( pixels.length < h * scansize + off) */		if ( pixels.length < (h-1) * scansize + off + w)			throw new IllegalArgumentException("The pixel array is not big enough");			// Use accelerated set pixels routine if possible			 if (cm instanceof IndexColorModel)				pSetIndexColorModelBytePixels(psd, x, y, w, h, cm, pixels, off, scansize);			  else pSetColorModelBytePixels(psd, x, y, w, h, cm, pixels, off, scansize);					scanlineCount++;                status = ImageObserver.SOMEBITS;                		if (scanlineCount % REDRAW_COUNT == 0) {                    notifyObservers(this, ImageObserver.SOMEBITS, x, y, w, h);		}   //             System.out.println("SetPixelsByte " + new Rectangle(x, y, w, h));	}	public void setPixels(int x, int y, int w, int h, ColorModel cm, int[] pixels, int off, int scansize) {		if(psd<0) return;				/* 6199102 if ( pixels.length < h * scansize + off) */		if ( pixels.length < (h-1) * scansize + off + w)			throw new IllegalArgumentException("The pixel array is not big enough");			// Use accelerated set pixels routine if possible			if (cm instanceof DirectColorModel) {				DirectColorModel dcm = (DirectColorModel)cm;				int totalMask = dcm.getAlphaMask() | dcm.getRedMask() | dcm.getGreenMask() | dcm.getBlueMask();				pSetDirectColorModelPixels(psd, x, y, w, h, cm, pixels, off, scansize, totalMask);						}			else if (cm instanceof IndexColorModel)				pSetIndexColorModelIntPixels(psd, x, y, w, h, cm, pixels, off, scansize);			 else pSetColorModelIntPixels(psd, x, y, w, h, cm, pixels, off, scansize);				scanlineCount++;		status = ImageObserver.SOMEBITS;		if (scanlineCount % REDRAW_COUNT == 0) {                    notifyObservers(this, ImageObserver.SOMEBITS, x, y, w, h);		}     //           System.out.println("SetPixelsInt " + new Rectangle(x, y, w, h));	}	public int getType() {		return gc.getCompatibleImageType();	}	public ColorModel getColorModel() {		return gc.getColorModel();	}		public void setRGB(int x, int y, int rgb) {		if(x<0||y<0||x>=width||y>=height)			throw new java.lang.ArrayIndexOutOfBoundsException(x+y*width);			pSetRGB(psd, x, y, rgb);		};	public void setRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize) {				if((startX<0)||(startY<0)||(startX>=width)||(startY>=height))			return;				if(w>scansize) return; // Overrun!!						    pSetRGBArray(psd, startX, startY, w, h, rgbArray, offset, scansize);	}		public int getRGB(int x, int y) {		if(x<0||y<0||x>=width||y>=height)			throw new java.lang.ArrayIndexOutOfBoundsException(x+y*width);		// pGetPixel returns us an RGB color.	    int r = pGetRGB(psd, x, y);		return r;	}	public int[] getRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize) {		int yoff = offset;		int off;			  if((startX<0)||(startY<0)||((startX+w)>width)||((startY+h)>height))				   throw new java.lang.ArrayIndexOutOfBoundsException(startX+startY*width);			  // pGetPixelArray returns a RGB pixel			  if (rgbArray == null)					rgbArray = new int[offset + h * scansize];					else	if (rgbArray.length < offset + h * scansize)				throw new IllegalArgumentException("rgbArray is not large enough to store all the values");		    pGetRGBArray(psd, startX, startY, w, h, rgbArray, offset, scansize);		return rgbArray;	}	public String toString() {		return "[psd=" + psd + ",width=" + width + ",height=" + height + ",status=" + status + "]";	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?