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

📄 gdkpixbufdecoder.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* GdkPixbufDecoder.java -- Image data decoding object   Copyright (C) 2003, 2004, 2005  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 gnu.classpath.Configuration;import java.awt.image.BufferedImage;import java.awt.image.ColorModel;import java.awt.image.DirectColorModel;import java.awt.image.ImageConsumer;import java.awt.image.ImageProducer;import java.awt.image.Raster;import java.awt.image.RenderedImage;import java.io.DataOutput;import java.io.IOException;import java.io.InputStream;import java.net.URL;import java.util.ArrayList;import java.util.Hashtable;import java.util.Iterator;import java.util.Locale;import java.util.Vector;import javax.imageio.IIOImage;import javax.imageio.ImageReadParam;import javax.imageio.ImageReader;import javax.imageio.ImageTypeSpecifier;import javax.imageio.ImageWriteParam;import javax.imageio.ImageWriter;import javax.imageio.metadata.IIOMetadata;import javax.imageio.spi.IIORegistry;import javax.imageio.spi.ImageReaderSpi;import javax.imageio.spi.ImageWriterSpi;import javax.imageio.stream.ImageInputStream;import javax.imageio.stream.ImageOutputStream;public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder{  static   {    if (Configuration.INIT_LOAD_LIBRARY)      {        System.loadLibrary("gtkpeer");      }    initStaticState ();  }    static native void initStaticState();  private final int native_state = GtkGenericPeer.getUniqueInteger ();  // initState() has been called, but pumpDone() has not yet been called.  private boolean needsClose = false;  // the current set of ImageConsumers for this decoder  Vector curr;  // interface to GdkPixbuf  native void initState ();  native void pumpBytes (byte[] bytes, int len) throws IOException;  native void pumpDone () throws IOException;  native void finish (boolean needsClose);  static native void streamImage(int[] bytes, String format, int width, int height, boolean hasAlpha, DataOutput sink);    // gdk-pixbuf provids data in RGBA format  static final ColorModel cm = new DirectColorModel (32, 0xff000000,                                                      0x00ff0000,                                                      0x0000ff00,                                                      0x000000ff);  public GdkPixbufDecoder (InputStream in)  {    super (in);  }  public GdkPixbufDecoder (String filename)  {    super (filename);  }    public GdkPixbufDecoder (URL url)  {    super (url);  }  public GdkPixbufDecoder (byte[] imagedata, int imageoffset, int imagelength)  {    super (imagedata, imageoffset, imagelength);  }  // called back by native side: area_prepared_cb  void areaPrepared (int width, int height)  {    if (curr == null)      return;    for (int i = 0; i < curr.size (); i++)      {        ImageConsumer ic = (ImageConsumer) curr.elementAt (i);        ic.setDimensions (width, height);        ic.setColorModel (cm);        ic.setHints (ImageConsumer.RANDOMPIXELORDER);      }  }    // called back by native side: area_updated_cb  void areaUpdated (int x, int y, int width, int height,                     int pixels[], int scansize)  {    if (curr == null)      return;        for (int i = 0; i < curr.size (); i++)      {        ImageConsumer ic = (ImageConsumer) curr.elementAt (i);        ic.setPixels (x, y, width, height, cm, pixels, 0, scansize);      }  }    // called from an async image loader of one sort or another, this method  // repeatedly reads bytes from the input stream and passes them through a  // GdkPixbufLoader using the native method pumpBytes. pumpBytes in turn  // decodes the image data and calls back areaPrepared and areaUpdated on  // this object, feeding back decoded pixel blocks, which we pass to each  // of the ImageConsumers in the provided Vector.  public void produce (Vector v, InputStream is) throws IOException  {    curr = v;    byte bytes[] = new byte[4096];    int len = 0;    initState();    needsClose = true;    while ((len = is.read (bytes)) != -1)      pumpBytes (bytes, len);    pumpDone();    needsClose = false;        for (int i = 0; i < curr.size (); i++)      {        ImageConsumer ic = (ImageConsumer) curr.elementAt (i);        ic.imageComplete (ImageConsumer.STATICIMAGEDONE);      }    curr = null;  }  public void finalize()  {    finish(needsClose);  }  public static class ImageFormatSpec  {    public String name;    public boolean writable = false;        public ArrayList mimeTypes = new ArrayList();    public ArrayList extensions = new ArrayList();    public ImageFormatSpec(String name, boolean writable)    {      this.name = name;      this.writable = writable;    }    public synchronized void addMimeType(String m)    {      mimeTypes.add(m);    }    public synchronized void addExtension(String e)    {      extensions.add(e);    }      }  static ArrayList imageFormatSpecs;  public static ImageFormatSpec registerFormat(String name, boolean writable)   {    ImageFormatSpec ifs = new ImageFormatSpec(name, writable);    synchronized(GdkPixbufDecoder.class)      {        if (imageFormatSpecs == null)          imageFormatSpecs = new ArrayList();        imageFormatSpecs.add(ifs);      }    return ifs;  }  static String[] getFormatNames(boolean writable)  {    ArrayList names = new ArrayList();    synchronized (imageFormatSpecs)       {        Iterator i = imageFormatSpecs.iterator();        while (i.hasNext())          {            ImageFormatSpec ifs = (ImageFormatSpec) i.next();            if (writable && !ifs.writable)              continue;            names.add(ifs.name);            /*              * In order to make the filtering code work, we need to register             * this type under every "format name" likely to be used as a synonym.             * This generally means "all the extensions people might use".              */            Iterator j = ifs.extensions.iterator();            while (j.hasNext())              names.add((String) j.next());          }      }    Object[] objs = names.toArray();    String[] strings = new String[objs.length];    for (int i = 0; i < objs.length; ++i)      strings[i] = (String) objs[i];    return strings;  }  static String[] getFormatExtensions(boolean writable)  {    ArrayList extensions = new ArrayList();    synchronized (imageFormatSpecs)       {        Iterator i = imageFormatSpecs.iterator();        while (i.hasNext())          {            ImageFormatSpec ifs = (ImageFormatSpec) i.next();            if (writable && !ifs.writable)              continue;            Iterator j = ifs.extensions.iterator();            while (j.hasNext())              extensions.add((String) j.next());          }      }    Object[] objs = extensions.toArray();    String[] strings = new String[objs.length];    for (int i = 0; i < objs.length; ++i)      strings[i] = (String) objs[i];    return strings;  }  static String[] getFormatMimeTypes(boolean writable)  {    ArrayList mimeTypes = new ArrayList();    synchronized (imageFormatSpecs)       {        Iterator i = imageFormatSpecs.iterator();        while (i.hasNext())          {            ImageFormatSpec ifs = (ImageFormatSpec) i.next();            if (writable && !ifs.writable)              continue;            Iterator j = ifs.mimeTypes.iterator();            while (j.hasNext())              mimeTypes.add((String) j.next());          }      }    Object[] objs = mimeTypes.toArray();    String[] strings = new String[objs.length];    for (int i = 0; i < objs.length; ++i)      strings[i] = (String) objs[i];    return strings;  }    static String findFormatName(Object ext, boolean needWritable)  {    if (ext == null)      return null;    if (!(ext instanceof String))      throw new IllegalArgumentException("extension is not a string");    String str = (String) ext;    Iterator i = imageFormatSpecs.iterator();    while (i.hasNext())      {        ImageFormatSpec ifs = (ImageFormatSpec) i.next();        if (needWritable && !ifs.writable)          continue;        if (ifs.name.equals(str))          return str;        Iterator j = ifs.extensions.iterator();         while (j.hasNext())          {            String extension = (String)j.next();            if (extension.equals(str))              return ifs.name;          }        j = ifs.mimeTypes.iterator();         while (j.hasNext())          {            String mimeType = (String)j.next();            if (mimeType.equals(str))              return ifs.name;          }

⌨️ 快捷键说明

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