?? omraster.java
字號:
// **********************************************************************// // <copyright>// // BBN Technologies// 10 Moulton Street// Cambridge, MA 02138// (617) 873-8000// // Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/omGraphics/OMRaster.java,v $// $RCSfile: OMRaster.java,v $// $Revision: 1.2.2.4 $// $Date: 2005/01/10 16:59:45 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.omGraphics;import java.awt.Color;import java.awt.Image;import java.awt.image.BufferedImage;import java.io.Serializable;import javax.swing.ImageIcon;import com.bbn.openmap.MoreMath;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;/** * The OMRaster object lets you create multi-colored images. An image * is a two dimensional array of pixel values that correspond to some * color values. The pixels are used from the top left, across each * row to the right, down to the bottom row. * <p> * There are two colormodels that are implemented in OMRaster - the * direct colormodel and the indexed colormodel. The direct colormodel * is implemented when the pixel values contain the actual * java.awt.Color values for the image. The indexed colormodel is * implemented when the pixel values are actually indexes into an * array of java.awt.Colors. NOTE: The direct colormodel OMRaster is * faster to display, because it doesn't need to take the time to * resolve the colortable values into pixels. * <P> * * For direct colormodel images: If you pass in a null pix or a pix * with a zero length, the object will create the pixels for you but * will not general a renderable version of the object. You will need * to call render before generate after the pixels have been set. This * feature is for cached rasters, where the content may be changed * later. Use this (null pix) if you are building images in a cache, * for tiled mapping data or something else where the data is not yet * known. The memory for the pixels will be allocated, and then they * can be set with image data later when a database is accessed. * <P> * * For ImageIcon OMRasters: Using an ImageIcon to create an OMRaster * gives you the ability to put an image on the screen based on an * ImageIcon made from file or URL. The OMRaster uses this ImageIcon * as is - there is no opportunity to change any parameters of this * image. So set the colors, transparency, etc. before you create the * OMRaster. * <P> * * For indexed colormodel images: If you pass in an empty byte array, * a byte array will be created based on the width and height. You * will have to resolve empty colortables and set the pixels later. * Use this method (null bytes) if you are building images in a cache, * for tiled mapping data or something else where the data is not yet * known. The memory for the pixels will be allocated, and then they * can be set with image data later when a database is accessed. * * There is the ability to add a filter to the image, to change it's * appearance for rendering. The most common filter, which is included * as a kind of default, is the scale filter. Filtering the * OMRasterObject replaces the bitmap variable, which is the internal * java.awt.Image used for rendering. For OMRasters created with * pixels, or with the colortable and the colortable index, the * original data is left intact, and can be recreated later, or * rescaled on the fly, because the internal bitmap will be recreated * prior to rescaling. For OMRasters created by ImageIcons or Images, * though, you'll need to hold on to the original Image. The internal * version is replaced by the filtered version. * * @see OMRasterObject */public class OMRaster extends OMRasterObject implements Serializable { /** * The integer colors that are needed in a java colortable. The * Color[] that gets passed into some of the constructors goes to * build this, but this array is really used to build the image * pixel array. */ protected int[] colors = null; /** * The transparency of the image. If this is set to anything less * than 255, this value is used for all colors in the image. If it * is set to 255, then the alpha value in each Color regulates the * transparency of the image. The value of this variable should * stay in the range: <code>0 <= transparent <= 255</code> */ protected int transparent = 255; /** * Constuct a blank OMRaster, to be filled in with setX calls. */ public OMRaster() { super(RENDERTYPE_UNKNOWN, LINETYPE_UNKNOWN, DECLUTTERTYPE_NONE); } ///////////////////////////////////// INT PIXELS - DIRECT // COLORMODEL /** * Creates an OMRaster images, Lat/Lon placement with a direct * colormodel. * * @param lt latitude of the top of the image. * @param ln longitude of the left side of the image. * @param w width of the image, in pixels. * @param h height of the image, in pixels. * @param pix color values for the pixels. * @see #setPixel */ public OMRaster(float lt, float ln, int w, int h, int[] pix) { super(RENDERTYPE_LATLON, LINETYPE_UNKNOWN, DECLUTTERTYPE_NONE); setColorModel(COLORMODEL_DIRECT); lat = lt; lon = ln; width = w; height = h; pixels = pix; if (pixels == null || pixels.length == 0) pixels = new int[height * width]; } /** * Create an OMRaster image, XY placement with a direct * colormodel. * * @param x1 window location of the left side of the image. * @param y1 window location of the top of the image. * @param w width of the image, in pixels. * @param h height of the image, in pixels. * @param pix color values for the pixels. * @see #setPixel */ public OMRaster(int x1, int y1, int w, int h, int[] pix) { super(RENDERTYPE_XY, LINETYPE_UNKNOWN, DECLUTTERTYPE_NONE); setColorModel(COLORMODEL_DIRECT); x = x1; y = y1; width = w; height = h; pixels = pix; if (pixels == null || pixels.length == 0) pixels = new int[height * width]; } /** * Create an OMRaster, Lat/lon placement with XY offset with a * direct colormodel. * * @param lt latitude of the top of the image, before the offset. * @param ln longitude of the left side of the image, before the * offset. * @param offset_x1 number of pixels to move image to the right. * @param offset_y1 number of pixels to move image down. * @param w width of the image, in pixels. * @param h height of the image, in pixels. * @param pix color values for the pixels. * @see #setPixel */ public OMRaster(float lt, float ln, int offset_x1, int offset_y1, int w, int h, int[] pix) { super(RENDERTYPE_OFFSET, LINETYPE_UNKNOWN, DECLUTTERTYPE_NONE); setColorModel(COLORMODEL_DIRECT); lat = lt; lon = ln; x = offset_x1; y = offset_y1; width = w; height = h; pixels = pix; if (pixels == null || pixels.length == 0) { pixels = new int[height * width]; } } ////////////////////////////////////// IMAGEICON /** * Create an OMRaster, Lat/Lon placement with an ImageIcon. * * @param lt latitude of the top of the image. * @param ln longitude of the left side of the image. * @param ii ImageIcon used for the image. */ public OMRaster(float lt, float ln, ImageIcon ii) { this(lt, ln, ii.getImage()); } /** * Create an OMRaster, Lat/Lon placement with an Image. * * @param lt latitude of the top of the image. * @param ln longitude of the left side of the image. * @param ii Image used for the image. */ public OMRaster(float lt, float ln, Image ii) { super(RENDERTYPE_LATLON, LINETYPE_UNKNOWN, DECLUTTERTYPE_NONE); setColorModel(COLORMODEL_IMAGEICON); lat = lt; lon = ln; setImage(ii); } /** * Create an OMRaster image, X/Y placement with an ImageIcon. * * @param x1 window location of the left side of the image. * @param y1 window location of the top of the image. * @param ii ImageIcon used for the image. */ public OMRaster(int x1, int y1, ImageIcon ii) { this(x1, y1, ii.getImage()); } /** * Create an OMRaster image, X/Y placement with an Image. * * @param x1 window location of the left side of the image. * @param y1 window location of the top of the image. * @param ii Image used for the image. */ public OMRaster(int x1, int y1, Image ii) { super(RENDERTYPE_XY, LINETYPE_UNKNOWN, DECLUTTERTYPE_NONE); setColorModel(COLORMODEL_IMAGEICON); x = x1; y = y1; setImage(ii); } /** * Create an OMRaster, Lat/Lon with X/Y placement with an * ImageIcon. * * @param lt latitude of the top of the image, before the offset. * @param ln longitude of the left side of the image, before the * offset. * @param offset_x1 number of pixels to move image to the right. * @param offset_y1 number of pixels to move image down. * @param ii ImageIcon used for the image. */ public OMRaster(float lt, float ln, int offset_x1, int offset_y1, ImageIcon ii) { this(lt, ln, offset_x1, offset_y1, ii.getImage()); } /** * Create an OMRaster, Lat/Lon with X/Y placement with an Image. * Make sure that the Image is complete( if being loaded over the * internet) and ready to be drawn. Otherwise, you have to figure * out when the Image is complete, so that you can get the layer * to paint it! Use the ImageIcon constructor if you don't mind * blocking to wait for the pixels to arrive. * * @param lt latitude of the top of the image, before the offset. * @param ln longitude of the left side of the image, before the * offset. * @param offset_x1 number of pixels to move image to the right. * @param offset_y1 number of pixels to move image down. * @param ii Image used for the image. */ public OMRaster(float lt, float ln, int offset_x1, int offset_y1, Image ii) { super(RENDERTYPE_OFFSET, LINETYPE_UNKNOWN, DECLUTTERTYPE_NONE); setColorModel(COLORMODEL_IMAGEICON); lat = lt; lon = ln; x = offset_x1; y = offset_y1; setImage(ii); } ////////////////////////////////////// BYTE PIXELS with // COLORTABLE /** * Lat/Lon placement with a indexed colormodel, which is using a * colortable and a byte array to contruct the int[] pixels. * * @param lt latitude of the top of the image. * @param ln longitude of the left side of the image. * @param w width of the image, in pixels. * @param h height of the image, in pixels. * @param bytes colortable index values for the pixels. * @param colorTable color array corresponding to bytes * @param trans transparency of image. * @see #setPixel */ public OMRaster(float lt, float ln, int w, int h, byte[] bytes, Color[] colorTable, int trans) { super(RENDERTYPE_LATLON, LINETYPE_UNKNOWN, DECLUTTERTYPE_NONE); setColorModel(COLORMODEL_INDEXED); lat = lt; lon = ln; width = w; height = h; bits = bytes; transparent = trans; if (colorTable != null) { setColors(colorTable); } if (bits != null && bits.length != 0) { if (colorTable != null && colors.length != 0) { computePixels(); } } else { bits = new byte[height * width]; } } /** * XY placement with a indexed colormodel, which is using a * colortable and a byte array to contruct the int[] pixels. * * @param x1 window location of the left side of the image. * @param y1 window location of the top of the image. * @param w width of the image, in pixels. * @param h height of the image, in pixels. * @param bytes colortable index values for the pixels. * @param colorTable color array corresponding to bytes * @param trans transparency of image. * @see #setPixel */ public OMRaster(int x1, int y1, int w, int h, byte[] bytes, Color[] colorTable, int trans) { super(RENDERTYPE_XY, LINETYPE_UNKNOWN, DECLUTTERTYPE_NONE); setColorModel(COLORMODEL_INDEXED); x = x1; y = y1; width = w; height = h; bits = bytes; transparent = trans; if (colorTable != null) { setColors(colorTable); } if (bits != null && bits.length != 0) { if (colorTable != null && colors.length != 0) { computePixels(); } } else { bits = new byte[height * width]; } } /** * Lat/lon placement with XY offset with a indexed colormodel, * which is using a colortable and a byte array to construct the * int[] pixels. * * @param lt latitude of the top of the image, before the offset. * @param ln longitude of the left side of the image, before the * offset. * @param offset_x1 number of pixels to move image to the right. * @param offset_y1 number of pixels to move image down. * @param w width of the image, in pixels. * @param h height of the image, in pixels. * @param bytes colortable index values for the pixels. * @param colorTable color array corresponding to bytes * @param trans transparency of image. * @see #setPixel */ public OMRaster(float lt, float ln, int offset_x1, int offset_y1, int w, int h, byte[] bytes, Color[] colorTable, int trans) { super(RENDERTYPE_OFFSET, LINETYPE_UNKNOWN, DECLUTTERTYPE_NONE); setColorModel(COLORMODEL_INDEXED); lat = lt; lon = ln; x = offset_x1; y = offset_y1; width = w; height = h; transparent = trans; bits = bytes; if (colorTable != null) { setColors(colorTable); } if (bits != null && bits.length != 0) { if (colorTable != null && colors.length != 0) { computePixels(); } } else { bits = new byte[height * width]; } } ////////////////////////////////////////////////////// /** * Just a simple check to see if the x, y pair actually fits into
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -