< prev index next >

src/java.desktop/share/classes/sun/awt/image/ShortBandedRaster.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 117      * constructors or create methods, it should not be used directly.
 118      * @param sampleModel     The SampleModel that specifies the layout.
 119      * @param dataBuffer      The DataBufferUShort that contains the image data.
 120      * @param aRegion         The Rectangle that specifies the image area.
 121      * @param origin          The Point that specifies the origin.
 122      * @param parent          The parent (if any) of this raster.
 123      */
 124     public ShortBandedRaster(SampleModel sampleModel,
 125                              DataBufferUShort dataBuffer,
 126                              Rectangle aRegion,
 127                              Point origin,
 128                              ShortBandedRaster parent)
 129     {
 130         super(sampleModel, dataBuffer, aRegion, origin, parent);
 131         this.maxX = minX + width;
 132         this.maxY = minY + height;
 133 
 134         if (sampleModel instanceof BandedSampleModel) {
 135             BandedSampleModel bsm = (BandedSampleModel)sampleModel;
 136             this.scanlineStride = bsm.getScanlineStride();
 137             int bankIndices[] = bsm.getBankIndices();
 138             int bandOffsets[] = bsm.getBandOffsets();
 139             int dOffsets[] = dataBuffer.getOffsets();
 140             dataOffsets = new int[bankIndices.length];
 141             data = new short[bankIndices.length][];
 142             int xOffset = aRegion.x - origin.x;
 143             int yOffset = aRegion.y - origin.y;
 144             for (int i = 0; i < bankIndices.length; i++) {
 145                data[i] = stealData(dataBuffer, bankIndices[i]);
 146                dataOffsets[i] = dOffsets[bankIndices[i]] +
 147                    xOffset + yOffset*scanlineStride + bandOffsets[i];
 148             }
 149         } else {
 150             throw new RasterFormatException("ShortBandedRasters must have "+
 151                 "BandedSampleModels");
 152         }
 153         verify();
 154     }
 155 
 156     /**
 157      * Returns a copy of the data offsets array. For each band the data offset
 158      * is the index into the band's data array, of the first sample of the
 159      * band.


 208      * location.
 209      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 210      * if the pixel coordinate is out of bounds.
 211      * A ClassCastException will be thrown if the input object is non null
 212      * and references anything other than an array of transferType.
 213      * @param x        The X coordinate of the pixel location.
 214      * @param y        The Y coordinate of the pixel location.
 215      * @param obj      An object reference to an array of type defined by
 216      *                 getTransferType() and length getNumDataElements().
 217      *                 If null an array of appropriate type and size will be
 218      *                 allocated.
 219      * @return         An object reference to an array of type defined by
 220      *                 getTransferType() with the request pixel data.
 221      */
 222     public Object getDataElements(int x, int y, Object obj) {
 223         if ((x < this.minX) || (y < this.minY) ||
 224             (x >= this.maxX) || (y >= this.maxY)) {
 225             throw new ArrayIndexOutOfBoundsException
 226                 ("Coordinate out of bounds!");
 227         }
 228         short outData[];
 229         if (obj == null) {
 230             outData = new short[numDataElements];
 231         } else {
 232             outData = (short[])obj;
 233         }
 234 
 235         int off = (y-minY)*scanlineStride + (x-minX);
 236 
 237         for (int band = 0; band < numDataElements; band++) {
 238             outData[band] = data[band][dataOffsets[band] + off];
 239         }
 240 
 241         return outData;
 242     }
 243 
 244     /**
 245      * Returns an array  of data elements from the specified rectangular
 246      * region.
 247      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 248      * if the pixel coordinates are out of bounds.


 254      *       System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
 255      *                        pixel, 0, numDataElements);
 256      * </pre>
 257      * @param x        The X coordinate of the upper left pixel location.
 258      * @param y        The Y coordinate of the upper left pixel location.
 259      * @param w        Width of the pixel rectangle.
 260      * @param h        Height of the pixel rectangle.
 261      * @param obj      An object reference to an array of type defined by
 262      *                 getTransferType() and length w*h*getNumDataElements().
 263      *                 If null an array of appropriate type and size will be
 264      *                 allocated.
 265      * @return         An object reference to an array of type defined by
 266      *                 getTransferType() with the request pixel data.
 267      */
 268     public Object getDataElements(int x, int y, int w, int h, Object obj) {
 269         if ((x < this.minX) || (y < this.minY) ||
 270             (x + w > this.maxX) || (y + h > this.maxY)) {
 271             throw new ArrayIndexOutOfBoundsException
 272                 ("Coordinate out of bounds!");
 273         }
 274         short outData[];
 275         if (obj == null) {
 276             outData = new short[numDataElements*w*h];
 277         } else {
 278             outData = (short[])obj;
 279         }
 280         int yoff = (y-minY)*scanlineStride + (x-minX);
 281 
 282         for (int c = 0; c < numDataElements; c++) {
 283             int off = c;
 284             short[] bank = data[c];
 285             int dataOffset = dataOffsets[c];
 286 
 287             int yoff2 = yoff;
 288             for (int ystart=0; ystart < h; ystart++, yoff2 += scanlineStride) {
 289                 int xoff = dataOffset + yoff2;
 290                 for (int xstart=0; xstart < w; xstart++) {
 291                     outData[off] = bank[xoff++];
 292                     off += numDataElements;
 293                 }
 294             }


 394     }
 395 
 396     /**
 397      * Stores the data element for all bands at the specified location.
 398      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 399      * if the pixel coordinate is out of bounds.
 400      * A ClassCastException will be thrown if the input object is non null
 401      * and references anything other than an array of transferType.
 402      * @param x        The X coordinate of the pixel location.
 403      * @param y        The Y coordinate of the pixel location.
 404      * @param obj      An object reference to an array of type defined by
 405      *                 getTransferType() and length getNumDataElements()
 406      *                 containing the pixel data to place at x,y.
 407      */
 408     public void setDataElements(int x, int y, Object obj) {
 409         if ((x < this.minX) || (y < this.minY) ||
 410             (x >= this.maxX) || (y >= this.maxY)) {
 411             throw new ArrayIndexOutOfBoundsException
 412                 ("Coordinate out of bounds!");
 413         }
 414         short inData[] = (short[])obj;
 415         int off = (y-minY)*scanlineStride + (x-minX);
 416         for (int i = 0; i < numDataElements; i++) {
 417             data[i][dataOffsets[i] + off] = inData[i];
 418         }
 419 
 420         markDirty();
 421     }
 422 
 423     /**
 424      * Stores the Raster data at the specified location.
 425      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 426      * if the pixel coordinates are out of bounds.
 427      * @param x          The X coordinate of the pixel location.
 428      * @param y          The Y coordinate of the pixel location.
 429      * @param inRaster   Raster of data to place at x,y location.
 430      */
 431     public void setDataElements(int x, int y, Raster inRaster) {
 432         int dstOffX = x + inRaster.getMinX();
 433         int dstOffY = y + inRaster.getMinY();
 434         int width  = inRaster.getWidth();


 491      * data array are assumed to be packed.  That is, a data element
 492      * for the nth band at location (x2, y2) would be found at:
 493      * <pre>
 494      *      inData[((y2-y)*w + (x2-x))*numDataElements + n]
 495      * </pre>
 496      * @param x        The X coordinate of the upper left pixel location.
 497      * @param y        The Y coordinate of the upper left pixel location.
 498      * @param w        Width of the pixel rectangle.
 499      * @param h        Height of the pixel rectangle.
 500      * @param obj      An object reference to an array of type defined by
 501      *                 getTransferType() and length w*h*getNumDataElements()
 502      *                 containing the pixel data to place between x,y and
 503      *                 x+h, y+h.
 504      */
 505     public void setDataElements(int x, int y, int w, int h, Object obj) {
 506         if ((x < this.minX) || (y < this.minY) ||
 507             (x + w > this.maxX) || (y + h > this.maxY)) {
 508             throw new ArrayIndexOutOfBoundsException
 509                 ("Coordinate out of bounds!");
 510         }
 511         short inData[] = (short[])obj;
 512         int yoff = (y-minY)*scanlineStride + (x-minX);
 513 
 514         for (int c = 0; c < numDataElements; c++) {
 515             int off = c;
 516             short[] bank = data[c];
 517             int dataOffset = dataOffsets[c];
 518 
 519             int yoff2 = yoff;
 520             for (int ystart=0; ystart < h; ystart++, yoff2 += scanlineStride) {
 521                 int xoff = dataOffset + yoff2;
 522                 for (int xstart=0; xstart < w; xstart++) {
 523                     bank[xoff++] = inData[off];
 524                     off += numDataElements;
 525                 }
 526             }
 527         }
 528 
 529         markDirty();
 530     }
 531 


 621      * coordinates specify the horizontal and vertical offsets
 622      * from the upper-left corner of this Raster to the upper-left corner
 623      * of the subRaster.  A subset of the bands of the parent Raster may
 624      * be specified.  If this is null, then all the bands are present in the
 625      * subRaster. A translation to the subRaster may also be specified.
 626      * Note that the subRaster will reference the same
 627      * DataBuffers as the parent Raster, but using different offsets.
 628      * @param x               X offset.
 629      * @param y               Y offset.
 630      * @param width           Width (in pixels) of the subraster.
 631      * @param height          Height (in pixels) of the subraster.
 632      * @param x0              Translated X origin of the subraster.
 633      * @param y0              Translated Y origin of the subraster.
 634      * @param bandList        Array of band indices.
 635      * @exception RasterFormatException
 636      *            if the specified bounding box is outside of the parent Raster.
 637      */
 638     public WritableRaster createWritableChild(int x, int y,
 639                                               int width, int height,
 640                                               int x0, int y0,
 641                                               int bandList[]) {
 642 
 643         if (x < this.minX) {
 644             throw new RasterFormatException("x lies outside raster");
 645         }
 646         if (y < this.minY) {
 647             throw new RasterFormatException("y lies outside raster");
 648         }
 649         if ((x+width < x) || (x+width > this.minX + this.width)) {
 650             throw new RasterFormatException("(x + width) is outside of Raster");
 651         }
 652         if ((y+height < y) || (y+height > this.minY + this.height)) {
 653             throw new RasterFormatException("(y + height) is outside of Raster");
 654         }
 655 
 656         SampleModel sm;
 657 
 658         if (bandList != null)
 659             sm = sampleModel.createSubsetSampleModel(bandList);
 660         else
 661             sm = sampleModel;


 677      * coordinates specify the horizontal and vertical offsets
 678      * from the upper-left corner of this raster to the upper-left corner
 679      * of the subraster.  A subset of the bands of the parent Raster may
 680      * be specified.  If this is null, then all the bands are present in the
 681      * subRaster. A translation to the subRaster may also be specified.
 682      * Note that the subraster will reference the same
 683      * DataBuffers as the parent raster, but using different offsets.
 684      * @param x               X offset.
 685      * @param y               Y offset.
 686      * @param width           Width (in pixels) of the subraster.
 687      * @param height          Height (in pixels) of the subraster.
 688      * @param x0              Translated X origin of the subraster.
 689      * @param y0              Translated Y origin of the subraster.
 690      * @param bandList        Array of band indices.
 691      * @exception RasterFormatException
 692      *            if the specified bounding box is outside of the parent raster.
 693      */
 694     public Raster createChild (int x, int y,
 695                                int width, int height,
 696                                int x0, int y0,
 697                                int bandList[]) {
 698         return createWritableChild(x, y, width, height, x0, y0, bandList);
 699     }
 700 
 701     /**
 702      * Creates a Raster with the same layout but using a different
 703      * width and height, and with new zeroed data arrays.
 704      */
 705     public WritableRaster createCompatibleWritableRaster(int w, int h) {
 706         if (w <= 0 || h <=0) {
 707             throw new RasterFormatException("negative "+
 708                                             ((w <= 0) ? "width" : "height"));
 709         }
 710 
 711         SampleModel sm = sampleModel.createCompatibleSampleModel(w,h);
 712 
 713         return new ShortBandedRaster(sm, new Point(0,0));
 714     }
 715 
 716     /**
 717      * Creates a Raster with the same layout and the same


   1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 117      * constructors or create methods, it should not be used directly.
 118      * @param sampleModel     The SampleModel that specifies the layout.
 119      * @param dataBuffer      The DataBufferUShort that contains the image data.
 120      * @param aRegion         The Rectangle that specifies the image area.
 121      * @param origin          The Point that specifies the origin.
 122      * @param parent          The parent (if any) of this raster.
 123      */
 124     public ShortBandedRaster(SampleModel sampleModel,
 125                              DataBufferUShort dataBuffer,
 126                              Rectangle aRegion,
 127                              Point origin,
 128                              ShortBandedRaster parent)
 129     {
 130         super(sampleModel, dataBuffer, aRegion, origin, parent);
 131         this.maxX = minX + width;
 132         this.maxY = minY + height;
 133 
 134         if (sampleModel instanceof BandedSampleModel) {
 135             BandedSampleModel bsm = (BandedSampleModel)sampleModel;
 136             this.scanlineStride = bsm.getScanlineStride();
 137             int[] bankIndices = bsm.getBankIndices();
 138             int[] bandOffsets = bsm.getBandOffsets();
 139             int[] dOffsets = dataBuffer.getOffsets();
 140             dataOffsets = new int[bankIndices.length];
 141             data = new short[bankIndices.length][];
 142             int xOffset = aRegion.x - origin.x;
 143             int yOffset = aRegion.y - origin.y;
 144             for (int i = 0; i < bankIndices.length; i++) {
 145                data[i] = stealData(dataBuffer, bankIndices[i]);
 146                dataOffsets[i] = dOffsets[bankIndices[i]] +
 147                    xOffset + yOffset*scanlineStride + bandOffsets[i];
 148             }
 149         } else {
 150             throw new RasterFormatException("ShortBandedRasters must have "+
 151                 "BandedSampleModels");
 152         }
 153         verify();
 154     }
 155 
 156     /**
 157      * Returns a copy of the data offsets array. For each band the data offset
 158      * is the index into the band's data array, of the first sample of the
 159      * band.


 208      * location.
 209      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 210      * if the pixel coordinate is out of bounds.
 211      * A ClassCastException will be thrown if the input object is non null
 212      * and references anything other than an array of transferType.
 213      * @param x        The X coordinate of the pixel location.
 214      * @param y        The Y coordinate of the pixel location.
 215      * @param obj      An object reference to an array of type defined by
 216      *                 getTransferType() and length getNumDataElements().
 217      *                 If null an array of appropriate type and size will be
 218      *                 allocated.
 219      * @return         An object reference to an array of type defined by
 220      *                 getTransferType() with the request pixel data.
 221      */
 222     public Object getDataElements(int x, int y, Object obj) {
 223         if ((x < this.minX) || (y < this.minY) ||
 224             (x >= this.maxX) || (y >= this.maxY)) {
 225             throw new ArrayIndexOutOfBoundsException
 226                 ("Coordinate out of bounds!");
 227         }
 228         short[] outData;
 229         if (obj == null) {
 230             outData = new short[numDataElements];
 231         } else {
 232             outData = (short[])obj;
 233         }
 234 
 235         int off = (y-minY)*scanlineStride + (x-minX);
 236 
 237         for (int band = 0; band < numDataElements; band++) {
 238             outData[band] = data[band][dataOffsets[band] + off];
 239         }
 240 
 241         return outData;
 242     }
 243 
 244     /**
 245      * Returns an array  of data elements from the specified rectangular
 246      * region.
 247      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 248      * if the pixel coordinates are out of bounds.


 254      *       System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
 255      *                        pixel, 0, numDataElements);
 256      * </pre>
 257      * @param x        The X coordinate of the upper left pixel location.
 258      * @param y        The Y coordinate of the upper left pixel location.
 259      * @param w        Width of the pixel rectangle.
 260      * @param h        Height of the pixel rectangle.
 261      * @param obj      An object reference to an array of type defined by
 262      *                 getTransferType() and length w*h*getNumDataElements().
 263      *                 If null an array of appropriate type and size will be
 264      *                 allocated.
 265      * @return         An object reference to an array of type defined by
 266      *                 getTransferType() with the request pixel data.
 267      */
 268     public Object getDataElements(int x, int y, int w, int h, Object obj) {
 269         if ((x < this.minX) || (y < this.minY) ||
 270             (x + w > this.maxX) || (y + h > this.maxY)) {
 271             throw new ArrayIndexOutOfBoundsException
 272                 ("Coordinate out of bounds!");
 273         }
 274         short[] outData;
 275         if (obj == null) {
 276             outData = new short[numDataElements*w*h];
 277         } else {
 278             outData = (short[])obj;
 279         }
 280         int yoff = (y-minY)*scanlineStride + (x-minX);
 281 
 282         for (int c = 0; c < numDataElements; c++) {
 283             int off = c;
 284             short[] bank = data[c];
 285             int dataOffset = dataOffsets[c];
 286 
 287             int yoff2 = yoff;
 288             for (int ystart=0; ystart < h; ystart++, yoff2 += scanlineStride) {
 289                 int xoff = dataOffset + yoff2;
 290                 for (int xstart=0; xstart < w; xstart++) {
 291                     outData[off] = bank[xoff++];
 292                     off += numDataElements;
 293                 }
 294             }


 394     }
 395 
 396     /**
 397      * Stores the data element for all bands at the specified location.
 398      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 399      * if the pixel coordinate is out of bounds.
 400      * A ClassCastException will be thrown if the input object is non null
 401      * and references anything other than an array of transferType.
 402      * @param x        The X coordinate of the pixel location.
 403      * @param y        The Y coordinate of the pixel location.
 404      * @param obj      An object reference to an array of type defined by
 405      *                 getTransferType() and length getNumDataElements()
 406      *                 containing the pixel data to place at x,y.
 407      */
 408     public void setDataElements(int x, int y, Object obj) {
 409         if ((x < this.minX) || (y < this.minY) ||
 410             (x >= this.maxX) || (y >= this.maxY)) {
 411             throw new ArrayIndexOutOfBoundsException
 412                 ("Coordinate out of bounds!");
 413         }
 414         short[] inData = (short[])obj;
 415         int off = (y-minY)*scanlineStride + (x-minX);
 416         for (int i = 0; i < numDataElements; i++) {
 417             data[i][dataOffsets[i] + off] = inData[i];
 418         }
 419 
 420         markDirty();
 421     }
 422 
 423     /**
 424      * Stores the Raster data at the specified location.
 425      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 426      * if the pixel coordinates are out of bounds.
 427      * @param x          The X coordinate of the pixel location.
 428      * @param y          The Y coordinate of the pixel location.
 429      * @param inRaster   Raster of data to place at x,y location.
 430      */
 431     public void setDataElements(int x, int y, Raster inRaster) {
 432         int dstOffX = x + inRaster.getMinX();
 433         int dstOffY = y + inRaster.getMinY();
 434         int width  = inRaster.getWidth();


 491      * data array are assumed to be packed.  That is, a data element
 492      * for the nth band at location (x2, y2) would be found at:
 493      * <pre>
 494      *      inData[((y2-y)*w + (x2-x))*numDataElements + n]
 495      * </pre>
 496      * @param x        The X coordinate of the upper left pixel location.
 497      * @param y        The Y coordinate of the upper left pixel location.
 498      * @param w        Width of the pixel rectangle.
 499      * @param h        Height of the pixel rectangle.
 500      * @param obj      An object reference to an array of type defined by
 501      *                 getTransferType() and length w*h*getNumDataElements()
 502      *                 containing the pixel data to place between x,y and
 503      *                 x+h, y+h.
 504      */
 505     public void setDataElements(int x, int y, int w, int h, Object obj) {
 506         if ((x < this.minX) || (y < this.minY) ||
 507             (x + w > this.maxX) || (y + h > this.maxY)) {
 508             throw new ArrayIndexOutOfBoundsException
 509                 ("Coordinate out of bounds!");
 510         }
 511         short[] inData = (short[])obj;
 512         int yoff = (y-minY)*scanlineStride + (x-minX);
 513 
 514         for (int c = 0; c < numDataElements; c++) {
 515             int off = c;
 516             short[] bank = data[c];
 517             int dataOffset = dataOffsets[c];
 518 
 519             int yoff2 = yoff;
 520             for (int ystart=0; ystart < h; ystart++, yoff2 += scanlineStride) {
 521                 int xoff = dataOffset + yoff2;
 522                 for (int xstart=0; xstart < w; xstart++) {
 523                     bank[xoff++] = inData[off];
 524                     off += numDataElements;
 525                 }
 526             }
 527         }
 528 
 529         markDirty();
 530     }
 531 


 621      * coordinates specify the horizontal and vertical offsets
 622      * from the upper-left corner of this Raster to the upper-left corner
 623      * of the subRaster.  A subset of the bands of the parent Raster may
 624      * be specified.  If this is null, then all the bands are present in the
 625      * subRaster. A translation to the subRaster may also be specified.
 626      * Note that the subRaster will reference the same
 627      * DataBuffers as the parent Raster, but using different offsets.
 628      * @param x               X offset.
 629      * @param y               Y offset.
 630      * @param width           Width (in pixels) of the subraster.
 631      * @param height          Height (in pixels) of the subraster.
 632      * @param x0              Translated X origin of the subraster.
 633      * @param y0              Translated Y origin of the subraster.
 634      * @param bandList        Array of band indices.
 635      * @exception RasterFormatException
 636      *            if the specified bounding box is outside of the parent Raster.
 637      */
 638     public WritableRaster createWritableChild(int x, int y,
 639                                               int width, int height,
 640                                               int x0, int y0,
 641                                               int[] bandList) {
 642 
 643         if (x < this.minX) {
 644             throw new RasterFormatException("x lies outside raster");
 645         }
 646         if (y < this.minY) {
 647             throw new RasterFormatException("y lies outside raster");
 648         }
 649         if ((x+width < x) || (x+width > this.minX + this.width)) {
 650             throw new RasterFormatException("(x + width) is outside of Raster");
 651         }
 652         if ((y+height < y) || (y+height > this.minY + this.height)) {
 653             throw new RasterFormatException("(y + height) is outside of Raster");
 654         }
 655 
 656         SampleModel sm;
 657 
 658         if (bandList != null)
 659             sm = sampleModel.createSubsetSampleModel(bandList);
 660         else
 661             sm = sampleModel;


 677      * coordinates specify the horizontal and vertical offsets
 678      * from the upper-left corner of this raster to the upper-left corner
 679      * of the subraster.  A subset of the bands of the parent Raster may
 680      * be specified.  If this is null, then all the bands are present in the
 681      * subRaster. A translation to the subRaster may also be specified.
 682      * Note that the subraster will reference the same
 683      * DataBuffers as the parent raster, but using different offsets.
 684      * @param x               X offset.
 685      * @param y               Y offset.
 686      * @param width           Width (in pixels) of the subraster.
 687      * @param height          Height (in pixels) of the subraster.
 688      * @param x0              Translated X origin of the subraster.
 689      * @param y0              Translated Y origin of the subraster.
 690      * @param bandList        Array of band indices.
 691      * @exception RasterFormatException
 692      *            if the specified bounding box is outside of the parent raster.
 693      */
 694     public Raster createChild (int x, int y,
 695                                int width, int height,
 696                                int x0, int y0,
 697                                int[] bandList) {
 698         return createWritableChild(x, y, width, height, x0, y0, bandList);
 699     }
 700 
 701     /**
 702      * Creates a Raster with the same layout but using a different
 703      * width and height, and with new zeroed data arrays.
 704      */
 705     public WritableRaster createCompatibleWritableRaster(int w, int h) {
 706         if (w <= 0 || h <=0) {
 707             throw new RasterFormatException("negative "+
 708                                             ((w <= 0) ? "width" : "height"));
 709         }
 710 
 711         SampleModel sm = sampleModel.createCompatibleSampleModel(w,h);
 712 
 713         return new ShortBandedRaster(sm, new Point(0,0));
 714     }
 715 
 716     /**
 717      * Creates a Raster with the same layout and the same


< prev index next >