692 lines · 27.7 KB · Java
RawDownload
                ("Coordinate out of bounds!");        }        int inData[] = (int[])obj;         int yoff = (y-minY)*scanlineStride +                   (x-minX)*pixelStride;        int xoff;        int off = 0;        int xstart;        int ystart;         for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {            xoff = yoff;            for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {                for (int c = 0; c < numDataElements; c++) {                    data[dataOffsets[c] + xoff] = inData[off++];                }            }        }         markDirty();    }      /**     * Creates a subraster given a region of the raster.  The x and y     * coordinates specify the horizontal and vertical offsets     * from the upper-left corner of this raster to the upper-left corner     * of the subraster.  A subset of the bands of the parent Raster may     * be specified.  If this is null, then all the bands are present in the     * subRaster. A translation to the subRaster may also be specified.     * Note that the subraster will reference the same     * DataBuffer as the parent raster, but using different offsets.     * @param x               X offset.     * @param y               Y offset.     * @param width           Width (in pixels) of the subraster.     * @param height          Height (in pixels) of the subraster.     * @param x0              Translated X origin of the subraster.     * @param y0              Translated Y origin of the subraster.     * @param bandList        Array of band indices.     * @exception RasterFormatException     *            if the specified bounding box is outside of the parent raster.     */    public WritableRaster createWritableChild (int x, int y,                                               int width, int height,                                               int x0, int y0,                                               int bandList[]) {        if (x < this.minX) {            throw new RasterFormatException("x lies outside raster");        }        if (y < this.minY) {            throw new RasterFormatException("y lies outside raster");        }        if ((x+width < x) || (x+width > this.minX + this.width)) {            throw new RasterFormatException("(x + width) is outside raster");        }        if ((y+height < y) || (y+height > this.minY + this.height)) {            throw new RasterFormatException("(y + height) is outside raster");        }         SampleModel sm;         if (bandList != null)            sm = sampleModel.createSubsetSampleModel(bandList);        else            sm = sampleModel;         int deltaX = x0 - x;        int deltaY = y0 - y;         return new IntegerComponentRaster(sm,                                          dataBuffer,                                          new Rectangle(x0,y0,width,height),                                          new Point(sampleModelTranslateX+deltaX,                                                    sampleModelTranslateY+deltaY),                                          this);    }      /**     * Creates a subraster given a region of the raster.  The x and y     * coordinates specify the horizontal and vertical offsets     * from the upper-left corner of this raster to the upper-left corner     * of the subraster.  A subset of the bands of the parent raster may     * be specified. If this is null, then all the bands are present in the     * subRaster. Note that the subraster will reference the same     * DataBuffer as the parent raster, but using different offsets.     * @param x               X offset.     * @param y               Y offset.     * @param width           Width (in pixels) of the subraster.     * @param height          Height (in pixels) of the subraster.     * @param x0              Translated X origin of the subRaster.     * @param y0              Translated Y origin of the subRaster.     * @param bandList        Array of band indices.     * @exception RasterFormatException     *            if the specified bounding box is outside of the parent raster.     */    public Raster createChild (int x, int y,                               int width, int height,                               int x0, int y0,                               int bandList[]) {        return createWritableChild(x, y, width, height, x0, y0, bandList);    }      /**     * Creates a raster with the same band layout but using a different     * width and height, and with new zeroed data arrays.     */    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 IntegerComponentRaster(sm, new Point(0,0));    }     /**     * Creates a raster with the same data layout and the same     * width and height, and with new zeroed data arrays.  If     * the raster is a subraster, this will call     * createCompatibleRaster(width, height).     */    public WritableRaster createCompatibleWritableRaster() {        return createCompatibleWritableRaster(width,height);    }     /**     * Verify that the layout parameters are consistent with     * the data.  If strictCheck     * is false, this method will check for ArrayIndexOutOfBounds conditions.  If     * strictCheck is true, this method will check for additional error     * conditions such as line wraparound (width of a line greater than     * the scanline stride).     * @return   String   Error string, if the layout is incompatible with     *                    the data.  Otherwise returns null.     */    private void verify (boolean strictCheck) {        if (dataOffsets[0] < 0) {            throw new RasterFormatException("Data offset ("+dataOffsets[0]+                                            ") must be >= 0");        }         int maxSize = 0;        int size;         for (int i=0; i < numDataElements; i++) {            size = (height-1)*scanlineStride + (width-1)*pixelStride +                dataOffsets[i];            if (size > maxSize) {                maxSize = size;            }        }        if (data.length < maxSize) {            throw new RasterFormatException("Data array too small (should be "+                                          maxSize                                          +" but is "+data.length+" )");        }    }     public String toString() {        return new String ("IntegerComponentRaster: width = "+width                           +" height = " + height                           +" #Bands = " + numBands                           +" #DataElements "+numDataElements                           +" xOff = "+sampleModelTranslateX                           +" yOff = "+sampleModelTranslateY                           +" dataOffset[0] "+dataOffsets[0]);    } //    /**//     * For debugging...  prints a region of a one-band IntegerComponentRaster//     *///    public void print(int x, int y, int w, int h) {//        // REMIND:  Only works for 1 band!//        System.out.println(this);//        int offset = dataOffsets[0] + y*scanlineStride + x*pixelStride;//        int off;//        for (int yoff=0; yoff < h; yoff++, offset += scanlineStride) {//            off = offset;//            System.out.print("Line "+(sampleModelTranslateY+y+yoff)+": ");//            for (int xoff = 0; xoff < w; xoff++, off+= pixelStride) {//                System.out.print(Integer.toHexString(data[off])+" ");//            }//            System.out.println("");//        }//    } }

Lines 501–692 of 692. Previous lines