< prev index next >

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

Print this page




 159             throw new RasterFormatException("ByteBandedRasters must have"+
 160                 "BandedSampleModels");
 161         }
 162         verify();
 163     }
 164 
 165 
 166     /**
 167      * Returns a copy of the data offsets array. For each band the data
 168      * offset is the index into the band's data array, of the first sample
 169      * of the band.
 170      */
 171     public int[] getDataOffsets() {
 172         return dataOffsets.clone();
 173     }
 174 
 175     /**
 176      * Returns data offset for the specified band.  The data offset
 177      * is the index into the band's data array
 178      * in which the first sample of the first scanline is stored.
 179      * @param The band whose offset is returned.
 180      */
 181     public int getDataOffset(int band) {
 182         return dataOffsets[band];
 183     }
 184 
 185     /**
 186      * Returns the scanline stride -- the number of data array elements
 187      * between a given sample and the sample in the same column
 188      * of the next row in the same band.
 189      */
 190     public int getScanlineStride() {
 191         return scanlineStride;
 192     }
 193 
 194     /**
 195      * Returns the pixel stride, which is always equal to one for
 196      * a Raster with a BandedSampleModel.
 197      */
 198     public int getPixelStride() {
 199         return 1;


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


 250         return outData;
 251     }
 252 
 253     /**
 254      * Returns an  array  of data elements from the specified
 255      * rectangular region.
 256      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 257      * if the pixel coordinates are out of bounds.
 258      * A ClassCastException will be thrown if the input object is non null
 259      * and references anything other than an array of transferType.
 260      * <pre>
 261      *       byte[] bandData = (byte[])raster.getDataElement(x, y, w, h, null);
 262      *       int numDataElements = raster.getNumDataElements();
 263      *       byte[] pixel = new byte[numDataElements];
 264      *       // To find a data element at location (x2, y2)
 265      *       System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
 266      *                        pixel, 0, numDataElements);
 267      * </pre>
 268      * @param x        The X coordinate of the upper left pixel location.
 269      * @param y        The Y coordinate of the upper left pixel location.
 270      * @param width    Width of the pixel rectangle.
 271      * @param height   Height of the pixel rectangle.
 272      * @param outData  An object reference to an array of type defined by
 273      *                 getTransferType() and length w*h*getNumDataElements().
 274      *                 If null an array of appropriate type and size will be
 275      *                 allocated.
 276      * @return         An object reference to an array of type defined by
 277      *                 getTransferType() with the request pixel data.
 278      */
 279     public Object getDataElements(int x, int y, int w, int h, Object obj) {
 280         if ((x < this.minX) || (y < this.minY) ||
 281             (x + w > this.maxX) || (y + h > this.maxY)) {
 282             throw new ArrayIndexOutOfBoundsException
 283                 ("Coordinate out of bounds!");
 284         }
 285         byte outData[];
 286         if (obj == null) {
 287             outData = new byte[numDataElements*w*h];
 288         } else {
 289             outData = (byte[])obj;
 290         }
 291         int yoff = (y-minY)*scanlineStride + (x-minX);
 292 


 303                     off += numDataElements;
 304                 }
 305             }
 306         }
 307 
 308         return outData;
 309     }
 310 
 311     /**
 312      * Returns a byte array  of data elements from the specified rectangular
 313      * region for the specified band.
 314      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 315      * if the pixel coordinates are out of bounds.
 316      * <pre>
 317      *       byte[] bandData = raster.getByteData(x, y, w, h, null);
 318      *       // To find the data element at location (x2, y2)
 319      *       byte bandElement = bandData[((y2-y)*w + (x2-x))];
 320      * </pre>
 321      * @param x        The X coordinate of the upper left pixel location.
 322      * @param y        The Y coordinate of the upper left pixel location.
 323      * @param width    Width of the pixel rectangle.
 324      * @param height   Height of the pixel rectangle.
 325      * @param band     The band to return.
 326      * @param outData  If non-null, data elements for all bands
 327      *                 at the specified location are returned in this array.
 328      * @return         Data array with data elements for all bands.
 329      */
 330     public byte[] getByteData(int x, int y, int w, int h,
 331                               int band, byte[] outData) {
 332         // Bounds check for 'band' will be performed automatically
 333         if ((x < this.minX) || (y < this.minY) ||
 334             (x + w > this.maxX) || (y + h > this.maxY)) {
 335             throw new ArrayIndexOutOfBoundsException
 336                 ("Coordinate out of bounds!");
 337         }
 338         if (outData == null) {
 339             outData = new byte[scanlineStride*h];
 340         }
 341         int yoff = (y-minY)*scanlineStride + (x-minX) + dataOffsets[band];
 342 
 343         if (scanlineStride == w) {
 344             System.arraycopy(data[band], yoff, outData, 0, w*h);


 351         }
 352 
 353         return outData;
 354     }
 355 
 356     /**
 357      * Returns a byte array of data elements from the specified rectangular
 358      * region.
 359      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 360      * if the pixel coordinates are out of bounds.
 361      * <pre>
 362      *       byte[] bandData = raster.getByteData(x, y, w, h, null);
 363      *       int numDataElements = raster.getNumDataElements();
 364      *       byte[] pixel = new byte[numDataElements];
 365      *       // To find a data element at location (x2, y2)
 366      *       System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
 367      *                        pixel, 0, numDataElements);
 368      * </pre>
 369      * @param x        The X coordinate of the upper left pixel location.
 370      * @param y        The Y coordinate of the upper left pixel location.
 371      * @param width    Width of the pixel rectangle.
 372      * @param height   Height of the pixel rectangle.
 373      * @param outData  If non-null, data elements for all bands
 374      *                 at the specified location are returned in this array.
 375      * @return         Data array with data elements for all bands.
 376      */
 377     public byte[] getByteData(int x, int y, int w, int h, byte[] outData) {
 378         if ((x < this.minX) || (y < this.minY) ||
 379             (x + w > this.maxX) || (y + h > this.maxY)) {
 380             throw new ArrayIndexOutOfBoundsException
 381                 ("Coordinate out of bounds!");
 382         }
 383         if (outData == null) {
 384             outData = new byte[numDataElements*scanlineStride*h];
 385         }
 386         int yoff = (y-minY)*scanlineStride + (x-minX);
 387 
 388         for (int c = 0; c < numDataElements; c++) {
 389             int off = c;
 390             byte[] bank = data[c];
 391             int dataOffset = dataOffsets[c];
 392 


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


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




 159             throw new RasterFormatException("ByteBandedRasters must have"+
 160                 "BandedSampleModels");
 161         }
 162         verify();
 163     }
 164 
 165 
 166     /**
 167      * Returns a copy of the data offsets array. For each band the data
 168      * offset is the index into the band's data array, of the first sample
 169      * of the band.
 170      */
 171     public int[] getDataOffsets() {
 172         return dataOffsets.clone();
 173     }
 174 
 175     /**
 176      * Returns data offset for the specified band.  The data offset
 177      * is the index into the band's data array
 178      * in which the first sample of the first scanline is stored.
 179      * @param band The band whose offset is returned.
 180      */
 181     public int getDataOffset(int band) {
 182         return dataOffsets[band];
 183     }
 184 
 185     /**
 186      * Returns the scanline stride -- the number of data array elements
 187      * between a given sample and the sample in the same column
 188      * of the next row in the same band.
 189      */
 190     public int getScanlineStride() {
 191         return scanlineStride;
 192     }
 193 
 194     /**
 195      * Returns the pixel stride, which is always equal to one for
 196      * a Raster with a BandedSampleModel.
 197      */
 198     public int getPixelStride() {
 199         return 1;


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


 250         return outData;
 251     }
 252 
 253     /**
 254      * Returns an  array  of data elements from the specified
 255      * rectangular region.
 256      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 257      * if the pixel coordinates are out of bounds.
 258      * A ClassCastException will be thrown if the input object is non null
 259      * and references anything other than an array of transferType.
 260      * <pre>
 261      *       byte[] bandData = (byte[])raster.getDataElement(x, y, w, h, null);
 262      *       int numDataElements = raster.getNumDataElements();
 263      *       byte[] pixel = new byte[numDataElements];
 264      *       // To find a data element at location (x2, y2)
 265      *       System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
 266      *                        pixel, 0, numDataElements);
 267      * </pre>
 268      * @param x        The X coordinate of the upper left pixel location.
 269      * @param y        The Y coordinate of the upper left pixel location.
 270      * @param w        Width of the pixel rectangle.
 271      * @param h        Height of the pixel rectangle.
 272      * @param obj      An object reference to an array of type defined by
 273      *                 getTransferType() and length w*h*getNumDataElements().
 274      *                 If null an array of appropriate type and size will be
 275      *                 allocated.
 276      * @return         An object reference to an array of type defined by
 277      *                 getTransferType() with the request pixel data.
 278      */
 279     public Object getDataElements(int x, int y, int w, int h, Object obj) {
 280         if ((x < this.minX) || (y < this.minY) ||
 281             (x + w > this.maxX) || (y + h > this.maxY)) {
 282             throw new ArrayIndexOutOfBoundsException
 283                 ("Coordinate out of bounds!");
 284         }
 285         byte outData[];
 286         if (obj == null) {
 287             outData = new byte[numDataElements*w*h];
 288         } else {
 289             outData = (byte[])obj;
 290         }
 291         int yoff = (y-minY)*scanlineStride + (x-minX);
 292 


 303                     off += numDataElements;
 304                 }
 305             }
 306         }
 307 
 308         return outData;
 309     }
 310 
 311     /**
 312      * Returns a byte array  of data elements from the specified rectangular
 313      * region for the specified band.
 314      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 315      * if the pixel coordinates are out of bounds.
 316      * <pre>
 317      *       byte[] bandData = raster.getByteData(x, y, w, h, null);
 318      *       // To find the data element at location (x2, y2)
 319      *       byte bandElement = bandData[((y2-y)*w + (x2-x))];
 320      * </pre>
 321      * @param x        The X coordinate of the upper left pixel location.
 322      * @param y        The Y coordinate of the upper left pixel location.
 323      * @param w        Width of the pixel rectangle.
 324      * @param h        Height of the pixel rectangle.
 325      * @param band     The band to return.
 326      * @param outData  If non-null, data elements for all bands
 327      *                 at the specified location are returned in this array.
 328      * @return         Data array with data elements for all bands.
 329      */
 330     public byte[] getByteData(int x, int y, int w, int h,
 331                               int band, byte[] outData) {
 332         // Bounds check for 'band' will be performed automatically
 333         if ((x < this.minX) || (y < this.minY) ||
 334             (x + w > this.maxX) || (y + h > this.maxY)) {
 335             throw new ArrayIndexOutOfBoundsException
 336                 ("Coordinate out of bounds!");
 337         }
 338         if (outData == null) {
 339             outData = new byte[scanlineStride*h];
 340         }
 341         int yoff = (y-minY)*scanlineStride + (x-minX) + dataOffsets[band];
 342 
 343         if (scanlineStride == w) {
 344             System.arraycopy(data[band], yoff, outData, 0, w*h);


 351         }
 352 
 353         return outData;
 354     }
 355 
 356     /**
 357      * Returns a byte array of data elements from the specified rectangular
 358      * region.
 359      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 360      * if the pixel coordinates are out of bounds.
 361      * <pre>
 362      *       byte[] bandData = raster.getByteData(x, y, w, h, null);
 363      *       int numDataElements = raster.getNumDataElements();
 364      *       byte[] pixel = new byte[numDataElements];
 365      *       // To find a data element at location (x2, y2)
 366      *       System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
 367      *                        pixel, 0, numDataElements);
 368      * </pre>
 369      * @param x        The X coordinate of the upper left pixel location.
 370      * @param y        The Y coordinate of the upper left pixel location.
 371      * @param w        Width of the pixel rectangle.
 372      * @param h        Height of the pixel rectangle.
 373      * @param outData  If non-null, data elements for all bands
 374      *                 at the specified location are returned in this array.
 375      * @return         Data array with data elements for all bands.
 376      */
 377     public byte[] getByteData(int x, int y, int w, int h, byte[] outData) {
 378         if ((x < this.minX) || (y < this.minY) ||
 379             (x + w > this.maxX) || (y + h > this.maxY)) {
 380             throw new ArrayIndexOutOfBoundsException
 381                 ("Coordinate out of bounds!");
 382         }
 383         if (outData == null) {
 384             outData = new byte[numDataElements*scanlineStride*h];
 385         }
 386         int yoff = (y-minY)*scanlineStride + (x-minX);
 387 
 388         for (int c = 0; c < numDataElements; c++) {
 389             int off = c;
 390             byte[] bank = data[c];
 391             int dataOffset = dataOffsets[c];
 392 


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


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


< prev index next >