⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gtkimage.java

📁 linux下建立JAVA虚拟机的源码KAFFE
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* GtkImage.java   Copyright (C) 2005, 2006 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package gnu.java.awt.peer.gtk;import java.awt.Graphics;import java.awt.Color;import java.awt.Image;import java.awt.image.ColorModel;import java.awt.image.DirectColorModel;import java.awt.image.MemoryImageSource;import java.awt.image.ImageConsumer;import java.awt.image.ImageObserver;import java.awt.image.ImageProducer;import java.io.File;import java.io.IOException;import java.util.Hashtable;import java.util.Vector;import java.io.ByteArrayOutputStream;import java.io.BufferedInputStream;import java.net.URL;import gnu.classpath.Pointer;/** * GtkImage - wraps a GdkPixbuf or GdkPixmap. * * The constructor GtkImage(int, int) creates an 'off-screen' GdkPixmap, * this can be drawn to (it's a GdkDrawable), and correspondingly, you can * create a GdkGraphics object for it.  * * This corresponds to the Image implementation returned by  * Component.createImage(int, int).  * * A GdkPixbuf is 'on-screen' and the gdk cannot draw to it, * this is used for the other constructors (and other createImage methods), and * corresponds to the Image implementations returned by the Toolkit.createImage * methods, and is basically immutable.  * * @author Sven de Marothy */public class GtkImage extends Image{  int width = -1, height = -1;  /**   * Properties.   */  Hashtable props;  /**   * Loaded or not flag, for asynchronous compatibility.   */  boolean isLoaded;  /**   * Pointer to the GdkPixbuf   */  Pointer pixmap;  /**   * Observer queue.   */  Vector observers;  /**   * If offScreen is set, a GdkBitmap is wrapped and not a Pixbuf.   */  boolean offScreen;  /**   * Error flag for loading.   */  boolean errorLoading;  /**   * Original source, if created from an ImageProducer.   */  ImageProducer source;  /*   * The 32-bit AABBGGRR format the GDK uses.   */  static ColorModel nativeModel = new DirectColorModel(32, 						       0x000000FF,						       0x0000FF00,						       0x00FF0000,						       0xFF000000);  /**   * Returns a copy of the pixel data as a java array.   * Should be called with the GdkPixbufDecoder.pixbufLock held.   */  private native int[] getPixels();  /**   * Sets the pixel data from a java array.   * Should be called with the GdkPixbufDecoder.pixbufLock held.   */  private native void setPixels(int[] pixels);  /**   * Loads an image using gdk-pixbuf from a file.   * Should be called with the GdkPixbufDecoder.pixbufLock held.   */  private native boolean loadPixbuf(String name);  /**   * Loads an image using gdk-pixbuf from data.   * Should be called with the GdkPixbufDecoder.pixbufLock held.   */  private native boolean loadImageFromData(byte[] data);  /**   * Allocates a Gtk Pixbuf or pixmap   * Should be called with the GdkPixbufDecoder.pixbufLock held.   */  private native void createPixmap();  /**   * Frees the above.   * Should be called with the GdkPixbufDecoder.pixbufLock held.   */  private native void freePixmap();  /**   * Sets the pixmap to scaled copy of src image. hints are rendering hints.   * Should be called with the GdkPixbufDecoder.pixbufLock held.   */  private native void createScaledPixmap(GtkImage src, int hints);  /**   * Draws the image, optionally scaled and composited.   * Should be called with the GdkPixbufDecoder.pixbufLock held.   * Also acquires global gdk lock for drawing.   */  private native void drawPixelsScaled (GdkGraphics gc, 					int bg_red, int bg_green, int bg_blue, 					int x, int y, int width, int height, 					boolean composite);  /**   * Draws the image, optionally scaled flipped and composited.   * Should be called with the GdkPixbufDecoder.pixbufLock held.   * Also acquires global gdk lock for drawing.   */  private native void drawPixelsScaledFlipped (GdkGraphics gc, 					       int bg_red, int bg_green, 					       int bg_blue, 					       boolean flipX, boolean flipY,					       int srcX, int srcY,					       int srcWidth, int srcHeight,					       int dstX, int dstY,					       int dstWidth, int dstHeight,					       boolean composite);  /**   * Constructs a GtkImage from an ImageProducer. Asynchronity is handled in   * the following manner:    * A GtkImageConsumer gets the image data, and calls setImage() when    * completely finished. The GtkImage is not considered loaded until the   * GtkImageConsumer is completely finished. We go for all "all or nothing".   */  public GtkImage (ImageProducer producer)  {    isLoaded = false;    observers = new Vector();    source = producer;    errorLoading = false;    source.startProduction(new GtkImageConsumer(this, source));    offScreen = false;  }  /**   * Constructs a blank GtkImage.  This is called when   * GtkToolkit.createImage (String) is called with an empty string   * argument ("").  A blank image is loaded immediately upon   * construction and has width -1 and height -1.   */  public GtkImage ()  {    isLoaded = true;    observers = null;    offScreen = false;    props = new Hashtable();    errorLoading = false;  }  /**   * Constructs a GtkImage by loading a given file.   *   * @throws IllegalArgumentException if the image could not be loaded.   */  public GtkImage (String filename)  {    File f = new File(filename);    try      {	String path = f.getCanonicalPath();	synchronized(GdkPixbufDecoder.pixbufLock)	  {	    if (loadPixbuf(f.getCanonicalPath()) != true)	      throw new IllegalArgumentException("Couldn't load image: "						 + filename);	  }      }     catch(IOException e)      {	IllegalArgumentException iae;	iae = new IllegalArgumentException("Couldn't load image: "					   + filename);	iae.initCause(e);	throw iae;      }    isLoaded = true;    observers = null;    offScreen = false;    props = new Hashtable();  }  /**   * Constructs a GtkImage from a byte array of an image file.   *   * @throws IllegalArgumentException if the image could not be   * loaded.   */  public GtkImage (byte[] data)  {    synchronized(GdkPixbufDecoder.pixbufLock)      {	if (loadImageFromData (data) != true)	  throw new IllegalArgumentException ("Couldn't load image.");      }    isLoaded = true;    observers = null;    offScreen = false;    props = new Hashtable();    errorLoading = false;  }  /**   * Constructs a GtkImage from a URL. May result in an error image.   */  public GtkImage (URL url)  {    isLoaded = false;    observers = new Vector();    errorLoading = false;    if( url == null)      return;    ByteArrayOutputStream baos = new ByteArrayOutputStream (5000);    try      {        BufferedInputStream bis = new BufferedInputStream (url.openStream());        byte[] buf = new byte[5000];        int n = 0;        while ((n = bis.read(buf)) != -1)	  baos.write(buf, 0, n);         bis.close();      }    catch(IOException e)      {	throw new IllegalArgumentException ("Couldn't load image.");      }    byte[] array = baos.toByteArray();    synchronized(GdkPixbufDecoder.pixbufLock)      {	if (loadImageFromData(array) != true)	  throw new IllegalArgumentException ("Couldn't load image.");      }    isLoaded = true;    observers = null;    props = new Hashtable();  }  /**   * Constructs an empty GtkImage.   */  public GtkImage (int width, int height)  {    this.width = width;    this.height = height;    props = new Hashtable();    isLoaded = true;    observers = null;    offScreen = true;    synchronized(GdkPixbufDecoder.pixbufLock)      {	createPixmap();      }  }  /**   * Constructs a scaled version of the src bitmap, using the GDK.   */

⌨️ 快捷键说明

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