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

📄 raster.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                case DataBuffer.TYPE_USHORT:                    return new ShortInterleavedRaster(sm, db, location);            }        } else if (sm instanceof SinglePixelPackedSampleModel) {            switch(dataType) {                case DataBuffer.TYPE_BYTE:                    return new ByteInterleavedRaster(sm, db, location);                case DataBuffer.TYPE_USHORT:                    return new ShortInterleavedRaster(sm, db, location);                case DataBuffer.TYPE_INT:                    return new IntegerInterleavedRaster(sm, db, location);            }        } else if (sm instanceof MultiPixelPackedSampleModel &&                   dataType == DataBuffer.TYPE_BYTE &&                   sm.getSampleSize(0) < 8) {            return new BytePackedRaster(sm, db, location);        }        // we couldn't do anything special - do the generic thing        return new Raster(sm,db,location);    }    /**     *  Creates a WritableRaster with the specified SampleModel.     *  The upper left corner of the Raster is given by the location argument.     *  If location is null, (0, 0) will be used.     *  @param sm the specified <code>SampleModel</code>     *  @param location the upper-left corner of the      *         <code>WritableRaster</code>     *  @return a <code>WritableRaster</code> with the specified      *          <code>SampleModel</code> and location.     *  @throws RasterFormatException if computing either     *          <code>location.x + sm.getWidth()</code> or     *          <code>location.y + sm.getHeight()</code> results in integer     *          overflow     */    public static WritableRaster createWritableRaster(SampleModel sm,                                                      Point location) {        if (location == null) {           location = new Point(0,0);        }        return createWritableRaster(sm,                                    sm.createDataBuffer(),                                    location);    }    /**     *  Creates a WritableRaster with the specified SampleModel and DataBuffer.     *  The upper left corner of the Raster is given by the location argument.     *  If location is null, (0, 0) will be used.     *  @param sm the specified <code>SampleModel</code>     *  @param db the specified <code>DataBuffer</code>     *  @param location the upper-left corner of the      *         <code>WritableRaster</code>     *  @return a <code>WritableRaster</code> with the specified      *          <code>SampleModel</code>, <code>DataBuffer</code>, and     *          location.     * @throws RasterFormatException if computing either     *         <code>location.x + sm.getWidth()</code> or     *         <code>location.y + sm.getHeight()</code> results in integer     *         overflow     * @throws RasterFormatException if <code>dataBuffer</code> has more     *         than one bank and the <code>sampleModel</code> is     *         PixelInterleavedSampleModel, SinglePixelPackedSampleModel,     *         or MultiPixelPackedSampleModel.     * @throws NullPointerException if either SampleModel or DataBuffer is null     */    public static WritableRaster createWritableRaster(SampleModel sm,                                                      DataBuffer db,                                                      Point location) {        if ((sm == null) || (db == null)) {            throw new NullPointerException("SampleModel and DataBuffer cannot be null");        }        if (location == null) {           location = new Point(0,0);        }        int dataType = sm.getDataType();        if (sm instanceof PixelInterleavedSampleModel) {            switch(dataType) {                case DataBuffer.TYPE_BYTE:                    return new ByteInterleavedRaster(sm, db, location);                case DataBuffer.TYPE_USHORT:                    return new ShortInterleavedRaster(sm, db, location);            }        } else if (sm instanceof SinglePixelPackedSampleModel) {            switch(dataType) {                case DataBuffer.TYPE_BYTE:                    return new ByteInterleavedRaster(sm, db, location);                case DataBuffer.TYPE_USHORT:                    return new ShortInterleavedRaster(sm, db, location);                case DataBuffer.TYPE_INT:                    return new IntegerInterleavedRaster(sm, db, location);            }        } else if (sm instanceof MultiPixelPackedSampleModel &&                   dataType == DataBuffer.TYPE_BYTE &&                   sm.getSampleSize(0) < 8) {            return new BytePackedRaster(sm, db, location);        }        // we couldn't do anything special - do the generic thing        return new SunWritableRaster(sm,db,location);    }    /**     *  Constructs a Raster with the given SampleModel.  The Raster's     *  upper left corner is origin and it is the same size as the     *  SampleModel.  A DataBuffer large enough to describe the     *  Raster is automatically created.     *  @param sampleModel     The SampleModel that specifies the layout     *  @param origin          The Point that specified the origin     *  @throws RasterFormatException if computing either     *          <code>origin.x + sampleModel.getWidth()</code> or     *          <code>origin.y + sampleModel.getHeight()</code> results in     *          integer overflow     *  @throws NullPointerException either <code>sampleModel</code> or      *          <code>origin</code> is null     */    protected Raster(SampleModel sampleModel,                     Point origin) {        this(sampleModel,             sampleModel.createDataBuffer(),             new Rectangle(origin.x,                           origin.y,                           sampleModel.getWidth(),                           sampleModel.getHeight()),             origin,             null);    }    /**     *  Constructs a Raster with the given SampleModel and DataBuffer.     *  The Raster's upper left corner is origin and it is the same size     *  as the SampleModel.  The DataBuffer is not initialized and must     *  be compatible with SampleModel.     *  @param sampleModel     The SampleModel that specifies the layout     *  @param dataBuffer      The DataBuffer that contains the image data     *  @param origin          The Point that specifies the origin     *  @throws RasterFormatException if computing either     *          <code>origin.x + sampleModel.getWidth()</code> or     *          <code>origin.y + sampleModel.getHeight()</code> results in     *          integer overflow     *  @throws NullPointerException either <code>sampleModel</code> or     *          <code>origin</code> is null     */    protected Raster(SampleModel sampleModel,                     DataBuffer dataBuffer,                     Point origin) {	this(sampleModel,             dataBuffer,             new Rectangle(origin.x,                           origin.y,                           sampleModel.getWidth(),                           sampleModel.getHeight()),             origin,             null);    }    /**     * Constructs a Raster with the given SampleModel, DataBuffer, and     * parent.  aRegion specifies the bounding rectangle of the new     * Raster.  When translated into the base Raster's coordinate     * system, aRegion must be contained by the base Raster.     * (The base Raster is the Raster's ancestor which has no parent.)     * sampleModelTranslate specifies the sampleModelTranslateX and     * sampleModelTranslateY values of the new Raster.     *     * Note that this constructor should generally be called by other     * constructors or create methods, it should not be used directly.     * @param sampleModel     The SampleModel that specifies the layout     * @param dataBuffer      The DataBuffer that contains the image data     * @param aRegion         The Rectangle that specifies the image area          * @param sampleModelTranslate  The Point that specifies the translation     *                        from SampleModel to Raster coordinates     * @param parent          The parent (if any) of this raster     * @throws NullPointerException if any of <code>sampleModel</code>,      *         <code>dataBuffer</code>, <code>aRegion</code> or      *         <code>sampleModelTranslate</code> is null     * @throws RasterFormatException if <code>aRegion</code> has width     *         or height less than or equal to zero, or computing either     *         <code>aRegion.x + aRegion.width</code> or     *         <code>aRegion.y + aRegion.height</code> results in integer     *         overflow     */    protected Raster(SampleModel sampleModel,                     DataBuffer dataBuffer,                     Rectangle aRegion,                     Point sampleModelTranslate,	             Raster parent) {                if ((sampleModel == null) || (dataBuffer == null) ||             (aRegion == null) || (sampleModelTranslate == null)) {            throw new NullPointerException("SampleModel, dataBuffer, aRegion and " +                                           "sampleModelTranslate cannot be null");        }       this.sampleModel = sampleModel;       this.dataBuffer = dataBuffer;       minX = aRegion.x;       minY = aRegion.y;       width = aRegion.width;       height = aRegion.height;       if (width <= 0 || height <= 0) {           throw new RasterFormatException("negative or zero " +               ((width <= 0) ? "width" : "height"));       }       if ((minX + width) < minX) {           throw new RasterFormatException(               "overflow condition for X coordinates of Raster");       }       if ((minY + height) < minY) {           throw new RasterFormatException(               "overflow condition for Y coordinates of Raster");       }        sampleModelTranslateX = sampleModelTranslate.x;       sampleModelTranslateY = sampleModelTranslate.y;       numBands = sampleModel.getNumBands();       numDataElements = sampleModel.getNumDataElements();       this.parent = parent;    }    /**      * Returns the parent Raster (if any) of this Raster or null.      * @return the parent Raster or <code>null</code>.     */    public Raster getParent() {        return parent;    }    /**     * Returns the X translation from the coordinate system of the     * SampleModel to that of the Raster.  To convert a pixel's X     * coordinate from the Raster coordinate system to the SampleModel     * coordinate system, this value must be subtracted.     * @return the X translation from the coordinate space of the     *         Raster's SampleModel to that of the Raster.     */    final public int getSampleModelTranslateX() {	return sampleModelTranslateX;    }    /**     * Returns the Y translation from the coordinate system of the     * SampleModel to that of the Raster.  To convert a pixel's Y     * coordinate from the Raster coordinate system to the SampleModel     * coordinate system, this value must be subtracted.     * @return the Y translation from the coordinate space of the     *         Raster's SampleModel to that of the Raster.     */    final public int getSampleModelTranslateY() {	return sampleModelTranslateY;    }    /**     * Create a compatible WritableRaster the same size as this Raster with     * the same SampleModel and a new initialized DataBuffer.     * @return a compatible <code>WritableRaster</code> with the same sample     *         model and a new data buffer.     */    public WritableRaster createCompatibleWritableRaster() {        return new SunWritableRaster(sampleModel, new Point(0,0));    }    /**     * Create a compatible WritableRaster with the specified size, a new     * SampleModel, and a new initialized DataBuffer.     * @param w the specified width of the new <code>WritableRaster</code>     * @param h the specified height of the new <code>WritableRaster</code>     * @return a compatible <code>WritableRaster</code> with the specified      *         size and a new sample model and data buffer.     * @exception RasterFormatException if the width or height is less than     *                               or equal to zero.     */    public WritableRaster createCompatibleWritableRaster(int w, int h) {        if (w <= 0 || h <=0) {            throw new RasterFormatException("negative " +                                          ((w <= 0) ? "width" : "height"));        }        SampleModel sm = sampleModel.createCompatibleSampleModel(w,h);        return new SunWritableRaster(sm, new Point(0,0));

⌨️ 快捷键说明

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