< prev index next >

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

Print this page




 288     public int getPixelStride() {
 289         return pixelStride;
 290     }
 291 
 292     /**
 293      * Returns a reference to the data array.
 294      */
 295     public byte[] getDataStorage() {
 296         return data;
 297     }
 298 
 299     /**
 300      * Returns the data elements for all bands at the specified
 301      * location.
 302      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 303      * if the pixel coordinate is out of bounds.
 304      * A ClassCastException will be thrown if the input object is non null
 305      * and references anything other than an array of transferType.
 306      * @param x        The X coordinate of the pixel location.
 307      * @param y        The Y coordinate of the pixel location.
 308      * @param outData  An object reference to an array of type defined by
 309      *                 getTransferType() and length getNumDataElements().
 310      *                 If null an array of appropriate type and size will be
 311      *                 allocated.
 312      * @return         An object reference to an array of type defined by
 313      *                 getTransferType() with the request pixel data.
 314      */
 315     public Object getDataElements(int x, int y, Object obj) {
 316         if ((x < this.minX) || (y < this.minY) ||
 317             (x >= this.maxX) || (y >= this.maxY)) {
 318             throw new ArrayIndexOutOfBoundsException
 319                 ("Coordinate out of bounds!");
 320         }
 321         byte outData[];
 322         if (obj == null) {
 323             outData = new byte[numDataElements];
 324         } else {
 325             outData = (byte[])obj;
 326         }
 327         int off = (y-minY)*scanlineStride +
 328                   (x-minX)*pixelStride;


 334         return outData;
 335     }
 336 
 337     /**
 338      * Returns an array of data elements from the specified rectangular
 339      * region.
 340      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 341      * if the pixel coordinates are out of bounds.
 342      * A ClassCastException will be thrown if the input object is non null
 343      * and references anything other than an array of transferType.
 344      * <pre>
 345      *       byte[] bandData = (byte[])raster.getDataElements(x, y, w, h, null);
 346      *       int numDataElements = raster.getNumDataElements();
 347      *       byte[] pixel = new byte[numDataElements];
 348      *       // To find a data element at location (x2, y2)
 349      *       System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
 350      *                        pixel, 0, numDataElements);
 351      * </pre>
 352      * @param x        The X coordinate of the upper left pixel location.
 353      * @param y        The Y coordinate of the upper left pixel location.
 354      * @param width    Width of the pixel rectangle.
 355      * @param height   Height of the pixel rectangle.
 356      * @param outData  An object reference to an array of type defined by
 357      *                 getTransferType() and length w*h*getNumDataElements().
 358      *                 If null an array of appropriate type and size will be
 359      *                 allocated.
 360      * @return         An object reference to an array of type defined by
 361      *                 getTransferType() with the request pixel data.
 362      */
 363     public Object getDataElements(int x, int y, int w, int h, Object obj) {
 364         return getByteData(x, y, w, h, (byte[])obj);
 365     }
 366 
 367     /**
 368      * Returns a byte array of data elements from the specified rectangular
 369      * region for the specified band.
 370      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 371      * if the pixel coordinates are out of bounds.
 372      * <pre>
 373      *       byte[] bandData = raster.getByteData(x, y, w, h, null);
 374      *       // To find the data element at location (x2, y2)
 375      *       byte bandElement = bandData[((y2-y)*w + (x2-x))];
 376      * </pre>
 377      * @param x        The X coordinate of the upper left pixel location.
 378      * @param y        The Y coordinate of the upper left pixel location.
 379      * @param width    Width of the pixel rectangle.
 380      * @param height   Height of the pixel rectangle.
 381      * @param band     The band to return.
 382      * @param outData  If non-null, data elements for all bands
 383      *                 at the specified location are returned in this array.
 384      * @return         Data array with data elements for all bands.
 385      */
 386     public byte[] getByteData(int x, int y, int w, int h,
 387                               int band, byte[] outData) {
 388         // Bounds check for 'band' will be performed automatically
 389         if ((x < this.minX) || (y < this.minY) ||
 390             (x + w > this.maxX) || (y + h > this.maxY)) {
 391             throw new ArrayIndexOutOfBoundsException
 392                 ("Coordinate out of bounds!");
 393         }
 394         if (outData == null) {
 395             outData = new byte[w*h];
 396         }
 397         int yoff = (y-minY)*scanlineStride +
 398                    (x-minX)*pixelStride + dataOffsets[band];
 399         int xoff;
 400         int off = 0;


 420         }
 421 
 422         return outData;
 423     }
 424 
 425     /**
 426      * Returns a byte array of data elements from the specified rectangular
 427      * region.
 428      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 429      * if the pixel coordinates are out of bounds.
 430      * <pre>
 431      *       byte[] bandData = raster.getByteData(x, y, w, h, null);
 432      *       int numDataElements = raster.getnumDataElements();
 433      *       byte[] pixel = new byte[numDataElements];
 434      *       // To find a data element at location (x2, y2)
 435      *       System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
 436      *                        pixel, 0, numDataElements);
 437      * </pre>
 438      * @param x        The X coordinate of the upper left pixel location.
 439      * @param y        The Y coordinate of the upper left pixel location.
 440      * @param width    Width of the pixel rectangle.
 441      * @param height   Height of the pixel rectangle.
 442      * @param outData  If non-null, data elements for all bands
 443      *                 at the specified location are returned in this array.
 444      * @return         Data array with data elements for all bands.
 445      */
 446     public byte[] getByteData(int x, int y, int w, int h, byte[] outData) {
 447         if ((x < this.minX) || (y < this.minY) ||
 448             (x + w > this.maxX) || (y + h > this.maxY)) {
 449             throw new ArrayIndexOutOfBoundsException
 450                 ("Coordinate out of bounds!");
 451         }
 452         if (outData == null) {
 453             outData = new byte[numDataElements*w*h];
 454         }
 455         int yoff = (y-minY)*scanlineStride +
 456                    (x-minX)*pixelStride;
 457         int xoff;
 458         int off = 0;
 459         int xstart;
 460         int ystart;
 461 


 519                 xoff = yoff;
 520                 for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
 521                     for (int c = 0; c < numDataElements; c++) {
 522                         outData[off++] = data[dataOffsets[c] + xoff];
 523                     }
 524                 }
 525             }
 526         }
 527 
 528         return outData;
 529     }
 530 
 531     /**
 532      * Stores the data elements for all bands at the specified location.
 533      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 534      * if the pixel coordinate is out of bounds.
 535      * A ClassCastException will be thrown if the input object is non null
 536      * and references anything other than an array of transferType.
 537      * @param x        The X coordinate of the pixel location.
 538      * @param y        The Y coordinate of the pixel location.
 539      * @param inData   An object reference to an array of type defined by
 540      *                 getTransferType() and length getNumDataElements()
 541      *                 containing the pixel data to place at x,y.
 542      */
 543     public void setDataElements(int x, int y, Object obj) {
 544         if ((x < this.minX) || (y < this.minY) ||
 545             (x >= this.maxX) || (y >= this.maxY)) {
 546             throw new ArrayIndexOutOfBoundsException
 547                 ("Coordinate out of bounds!");
 548         }
 549         byte inData[] = (byte[])obj;
 550         int off = (y-minY)*scanlineStride +
 551                   (x-minX)*pixelStride;
 552 
 553         for (int i = 0; i < numDataElements; i++) {
 554             data[dataOffsets[i] + off] = inData[i];
 555         }
 556 
 557         markDirty();
 558     }
 559 


 649         }
 650     }
 651 
 652     /**
 653      * Stores an array of data elements into the specified rectangular
 654      * region.
 655      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 656      * if the pixel coordinates are out of bounds.
 657      * A ClassCastException will be thrown if the input object is non null
 658      * and references anything other than an array of transferType.
 659      * The data elements in the
 660      * data array are assumed to be packed.  That is, a data element
 661      * for the nth band at location (x2, y2) would be found at:
 662      * <pre>
 663      *      inData[((y2-y)*w + (x2-x))*numDataElements + n]
 664      * </pre>
 665      * @param x        The X coordinate of the upper left pixel location.
 666      * @param y        The Y coordinate of the upper left pixel location.
 667      * @param w        Width of the pixel rectangle.
 668      * @param h        Height of the pixel rectangle.
 669      * @param inData   An object reference to an array of type defined by
 670      *                 getTransferType() and length w*h*getNumDataElements()
 671      *                 containing the pixel data to place between x,y and
 672      *                 x+h, y+h.
 673      */
 674     public void setDataElements(int x, int y, int w, int h, Object obj) {
 675         putByteData(x, y, w, h, (byte[])obj);
 676     }
 677 
 678     /**
 679      * Stores a byte array of data elements into the specified rectangular
 680      * region for the specified band.
 681      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 682      * if the pixel coordinates are out of bounds.
 683      * The data elements in the
 684      * data array are assumed to be packed.  That is, a data element
 685      * at location (x2, y2) would be found at:
 686      * <pre>
 687      *      inData[((y2-y)*w + (x2-x)) + n]
 688      * </pre>
 689      * @param x        The X coordinate of the upper left pixel location.




 288     public int getPixelStride() {
 289         return pixelStride;
 290     }
 291 
 292     /**
 293      * Returns a reference to the data array.
 294      */
 295     public byte[] getDataStorage() {
 296         return data;
 297     }
 298 
 299     /**
 300      * Returns the data elements for all bands at the specified
 301      * location.
 302      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 303      * if the pixel coordinate is out of bounds.
 304      * A ClassCastException will be thrown if the input object is non null
 305      * and references anything other than an array of transferType.
 306      * @param x        The X coordinate of the pixel location.
 307      * @param y        The Y coordinate of the pixel location.
 308      * @param obj      An object reference to an array of type defined by
 309      *                 getTransferType() and length getNumDataElements().
 310      *                 If null an array of appropriate type and size will be
 311      *                 allocated.
 312      * @return         An object reference to an array of type defined by
 313      *                 getTransferType() with the request pixel data.
 314      */
 315     public Object getDataElements(int x, int y, Object obj) {
 316         if ((x < this.minX) || (y < this.minY) ||
 317             (x >= this.maxX) || (y >= this.maxY)) {
 318             throw new ArrayIndexOutOfBoundsException
 319                 ("Coordinate out of bounds!");
 320         }
 321         byte outData[];
 322         if (obj == null) {
 323             outData = new byte[numDataElements];
 324         } else {
 325             outData = (byte[])obj;
 326         }
 327         int off = (y-minY)*scanlineStride +
 328                   (x-minX)*pixelStride;


 334         return outData;
 335     }
 336 
 337     /**
 338      * Returns an array of data elements from the specified rectangular
 339      * region.
 340      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 341      * if the pixel coordinates are out of bounds.
 342      * A ClassCastException will be thrown if the input object is non null
 343      * and references anything other than an array of transferType.
 344      * <pre>
 345      *       byte[] bandData = (byte[])raster.getDataElements(x, y, w, h, null);
 346      *       int numDataElements = raster.getNumDataElements();
 347      *       byte[] pixel = new byte[numDataElements];
 348      *       // To find a data element at location (x2, y2)
 349      *       System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
 350      *                        pixel, 0, numDataElements);
 351      * </pre>
 352      * @param x        The X coordinate of the upper left pixel location.
 353      * @param y        The Y coordinate of the upper left pixel location.
 354      * @param w        Width of the pixel rectangle.
 355      * @param h        Height of the pixel rectangle.
 356      * @param obj      An object reference to an array of type defined by
 357      *                 getTransferType() and length w*h*getNumDataElements().
 358      *                 If null an array of appropriate type and size will be
 359      *                 allocated.
 360      * @return         An object reference to an array of type defined by
 361      *                 getTransferType() with the request pixel data.
 362      */
 363     public Object getDataElements(int x, int y, int w, int h, Object obj) {
 364         return getByteData(x, y, w, h, (byte[])obj);
 365     }
 366 
 367     /**
 368      * Returns a byte array of data elements from the specified rectangular
 369      * region for the specified band.
 370      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 371      * if the pixel coordinates are out of bounds.
 372      * <pre>
 373      *       byte[] bandData = raster.getByteData(x, y, w, h, null);
 374      *       // To find the data element at location (x2, y2)
 375      *       byte bandElement = bandData[((y2-y)*w + (x2-x))];
 376      * </pre>
 377      * @param x        The X coordinate of the upper left pixel location.
 378      * @param y        The Y coordinate of the upper left pixel location.
 379      * @param w        Width of the pixel rectangle.
 380      * @param h        Height of the pixel rectangle.
 381      * @param band     The band to return.
 382      * @param outData  If non-null, data elements for all bands
 383      *                 at the specified location are returned in this array.
 384      * @return         Data array with data elements for all bands.
 385      */
 386     public byte[] getByteData(int x, int y, int w, int h,
 387                               int band, byte[] outData) {
 388         // Bounds check for 'band' will be performed automatically
 389         if ((x < this.minX) || (y < this.minY) ||
 390             (x + w > this.maxX) || (y + h > this.maxY)) {
 391             throw new ArrayIndexOutOfBoundsException
 392                 ("Coordinate out of bounds!");
 393         }
 394         if (outData == null) {
 395             outData = new byte[w*h];
 396         }
 397         int yoff = (y-minY)*scanlineStride +
 398                    (x-minX)*pixelStride + dataOffsets[band];
 399         int xoff;
 400         int off = 0;


 420         }
 421 
 422         return outData;
 423     }
 424 
 425     /**
 426      * Returns a byte array of data elements from the specified rectangular
 427      * region.
 428      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 429      * if the pixel coordinates are out of bounds.
 430      * <pre>
 431      *       byte[] bandData = raster.getByteData(x, y, w, h, null);
 432      *       int numDataElements = raster.getnumDataElements();
 433      *       byte[] pixel = new byte[numDataElements];
 434      *       // To find a data element at location (x2, y2)
 435      *       System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
 436      *                        pixel, 0, numDataElements);
 437      * </pre>
 438      * @param x        The X coordinate of the upper left pixel location.
 439      * @param y        The Y coordinate of the upper left pixel location.
 440      * @param w        Width of the pixel rectangle.
 441      * @param h        Height of the pixel rectangle.
 442      * @param outData  If non-null, data elements for all bands
 443      *                 at the specified location are returned in this array.
 444      * @return         Data array with data elements for all bands.
 445      */
 446     public byte[] getByteData(int x, int y, int w, int h, byte[] outData) {
 447         if ((x < this.minX) || (y < this.minY) ||
 448             (x + w > this.maxX) || (y + h > this.maxY)) {
 449             throw new ArrayIndexOutOfBoundsException
 450                 ("Coordinate out of bounds!");
 451         }
 452         if (outData == null) {
 453             outData = new byte[numDataElements*w*h];
 454         }
 455         int yoff = (y-minY)*scanlineStride +
 456                    (x-minX)*pixelStride;
 457         int xoff;
 458         int off = 0;
 459         int xstart;
 460         int ystart;
 461 


 519                 xoff = yoff;
 520                 for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
 521                     for (int c = 0; c < numDataElements; c++) {
 522                         outData[off++] = data[dataOffsets[c] + xoff];
 523                     }
 524                 }
 525             }
 526         }
 527 
 528         return outData;
 529     }
 530 
 531     /**
 532      * Stores the data elements for all bands at the specified location.
 533      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 534      * if the pixel coordinate is out of bounds.
 535      * A ClassCastException will be thrown if the input object is non null
 536      * and references anything other than an array of transferType.
 537      * @param x        The X coordinate of the pixel location.
 538      * @param y        The Y coordinate of the pixel location.
 539      * @param obj      An object reference to an array of type defined by
 540      *                 getTransferType() and length getNumDataElements()
 541      *                 containing the pixel data to place at x,y.
 542      */
 543     public void setDataElements(int x, int y, Object obj) {
 544         if ((x < this.minX) || (y < this.minY) ||
 545             (x >= this.maxX) || (y >= this.maxY)) {
 546             throw new ArrayIndexOutOfBoundsException
 547                 ("Coordinate out of bounds!");
 548         }
 549         byte inData[] = (byte[])obj;
 550         int off = (y-minY)*scanlineStride +
 551                   (x-minX)*pixelStride;
 552 
 553         for (int i = 0; i < numDataElements; i++) {
 554             data[dataOffsets[i] + off] = inData[i];
 555         }
 556 
 557         markDirty();
 558     }
 559 


 649         }
 650     }
 651 
 652     /**
 653      * Stores an array of data elements into the specified rectangular
 654      * region.
 655      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 656      * if the pixel coordinates are out of bounds.
 657      * A ClassCastException will be thrown if the input object is non null
 658      * and references anything other than an array of transferType.
 659      * The data elements in the
 660      * data array are assumed to be packed.  That is, a data element
 661      * for the nth band at location (x2, y2) would be found at:
 662      * <pre>
 663      *      inData[((y2-y)*w + (x2-x))*numDataElements + n]
 664      * </pre>
 665      * @param x        The X coordinate of the upper left pixel location.
 666      * @param y        The Y coordinate of the upper left pixel location.
 667      * @param w        Width of the pixel rectangle.
 668      * @param h        Height of the pixel rectangle.
 669      * @param obj      An object reference to an array of type defined by
 670      *                 getTransferType() and length w*h*getNumDataElements()
 671      *                 containing the pixel data to place between x,y and
 672      *                 x+h, y+h.
 673      */
 674     public void setDataElements(int x, int y, int w, int h, Object obj) {
 675         putByteData(x, y, w, h, (byte[])obj);
 676     }
 677 
 678     /**
 679      * Stores a byte array of data elements into the specified rectangular
 680      * region for the specified band.
 681      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 682      * if the pixel coordinates are out of bounds.
 683      * The data elements in the
 684      * data array are assumed to be packed.  That is, a data element
 685      * at location (x2, y2) would be found at:
 686      * <pre>
 687      *      inData[((y2-y)*w + (x2-x)) + n]
 688      * </pre>
 689      * @param x        The X coordinate of the upper left pixel location.


< prev index next >