< prev index next >

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

Print this page




 189     public int getPixelStride() {
 190         return pixelStride;
 191     }
 192 
 193     /**
 194      * Returns a reference to the data array.
 195      */
 196     public int[] getDataStorage() {
 197         return data;
 198     }
 199 
 200     /**
 201      * Returns the data elements for all bands at the specified
 202      * location.
 203      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 204      * if the pixel coordinate is out of bounds.
 205      * A ClassCastException will be thrown if the input object is non null
 206      * and references anything other than an array of transferType.
 207      * @param x        The X coordinate of the pixel location.
 208      * @param y        The Y coordinate of the pixel location.
 209      * @param outData  An object reference to an array of type defined by
 210      *                 getTransferType() and length getNumDataElements().
 211      *                 If null an array of appropriate type and size will be
 212      *                 allocated.
 213      * @return         An object reference to an array of type defined by
 214      *                 getTransferType() with the request pixel data.
 215      */
 216     public Object getDataElements(int x, int y, Object obj) {
 217         if ((x < this.minX) || (y < this.minY) ||
 218             (x >= this.maxX) || (y >= this.maxY)) {
 219             throw new ArrayIndexOutOfBoundsException
 220                 ("Coordinate out of bounds!");
 221         }
 222         int outData[];
 223         if (obj == null) {
 224             outData = new int[1];
 225         } else {
 226             outData = (int[])obj;
 227         }
 228         int off = (y-minY)*scanlineStride + (x-minX) + dataOffsets[0];
 229         outData[0] = data[off];


 232     }
 233 
 234 
 235     /**
 236      * Returns an array  of data elements from the specified rectangular
 237      * region.
 238      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 239      * if the pixel coordinates are out of bounds.
 240      * A ClassCastException will be thrown if the input object is non null
 241      * and references anything other than an array of transferType.
 242      <pre>
 243      *       int[] bandData = (int[])raster.getDataElements(x, y, w, h, null);
 244      *       int numDataElements = raster.getNumDataElements();
 245      *       int[] pixel = new int[numDataElements];
 246      *       // To find a data element at location (x2, y2)
 247      *       System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
 248      *                        pixel, 0, numDataElements);
 249      * </pre>
 250      * @param x        The X coordinate of the upper left pixel location.
 251      * @param y        The Y coordinate of the upper left pixel location.
 252      * @param width    Width of the pixel rectangle.
 253      * @param height   Height of the pixel rectangle.
 254      * @param outData  An object reference to an array of type defined by
 255      *                 getTransferType() and length w*h*getNumDataElements().
 256      *                 If null an array of appropriate type and size will be
 257      *                 allocated.
 258      * @return         An object reference to an array of type defined by
 259      *                 getTransferType() with the request pixel data.
 260      */
 261     public Object getDataElements(int x, int y, int w, int h, Object obj) {
 262         if ((x < this.minX) || (y < this.minY) ||
 263             (x + w > this.maxX) || (y + h > this.maxY)) {
 264             throw new ArrayIndexOutOfBoundsException
 265                 ("Coordinate out of bounds!");
 266         }
 267         int outData[];
 268         if (obj instanceof int[]) {
 269             outData = (int[])obj;
 270         } else {
 271             outData = new int[w*h];
 272         }
 273         int yoff = (y-minY)*scanlineStride + (x-minX) + dataOffsets[0];
 274         int off = 0;
 275 
 276         for (int ystart = 0; ystart < h; ystart++) {
 277             System.arraycopy(data, yoff, outData, off, w);
 278             off += w;
 279             yoff += scanlineStride;
 280         }
 281 
 282         return outData;
 283     }
 284 
 285 
 286     /**
 287      * Stores the data elements for all bands at the specified location.
 288      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 289      * if the pixel coordinate is out of bounds.
 290      * A ClassCastException will be thrown if the input object is non null
 291      * and references anything other than an array of transferType.
 292      * @param x        The X coordinate of the pixel location.
 293      * @param y        The Y coordinate of the pixel location.
 294      * @param inData   An object reference to an array of type defined by
 295      *                 getTransferType() and length getNumDataElements()
 296      *                 containing the pixel data to place at x,y.
 297      */
 298     public void setDataElements(int x, int y, Object obj) {
 299         if ((x < this.minX) || (y < this.minY) ||
 300             (x >= this.maxX) || (y >= this.maxY)) {
 301             throw new ArrayIndexOutOfBoundsException
 302                 ("Coordinate out of bounds!");
 303         }
 304         int inData[] = (int[])obj;
 305 
 306         int off = (y-minY)*scanlineStride + (x-minX) + dataOffsets[0];
 307 
 308         data[off] = inData[0];
 309 
 310         markDirty();
 311     }
 312 
 313 
 314     /**


 393         }
 394     }
 395 
 396     /**
 397      * Stores an array of data elements into the specified rectangular
 398      * region.
 399      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 400      * if the pixel coordinates are out of bounds.
 401      * A ClassCastException will be thrown if the input object is non null
 402      * and references anything other than an array of transferType.
 403      * The data elements in the
 404      * data array are assumed to be packed.  That is, a data element
 405      * for the nth band at location (x2, y2) would be found at:
 406      * <pre>
 407      *      inData[((y2-y)*w + (x2-x))*numDataElements + n]
 408      * </pre>
 409      * @param x        The X coordinate of the upper left pixel location.
 410      * @param y        The Y coordinate of the upper left pixel location.
 411      * @param w        Width of the pixel rectangle.
 412      * @param h        Height of the pixel rectangle.
 413      * @param inData   An object reference to an array of type defined by
 414      *                 getTransferType() and length w*h*getNumDataElements()
 415      *                 containing the pixel data to place between x,y and
 416      *                 x+h, y+h.
 417      */
 418     public void setDataElements(int x, int y, int w, int h, Object obj) {
 419         if ((x < this.minX) || (y < this.minY) ||
 420             (x + w > this.maxX) || (y + h > this.maxY)) {
 421             throw new ArrayIndexOutOfBoundsException
 422                 ("Coordinate out of bounds!");
 423         }
 424         int inData[] = (int[])obj;
 425         int yoff = (y-minY)*scanlineStride + (x-minX) + dataOffsets[0];
 426         int off = 0;
 427 
 428         for (int ystart = 0; ystart < h; ystart++) {
 429             System.arraycopy(inData, off, data, yoff, w);
 430             off += w;
 431             yoff += scanlineStride;
 432         }
 433 




 189     public int getPixelStride() {
 190         return pixelStride;
 191     }
 192 
 193     /**
 194      * Returns a reference to the data array.
 195      */
 196     public int[] getDataStorage() {
 197         return data;
 198     }
 199 
 200     /**
 201      * Returns the data elements for all bands at the specified
 202      * location.
 203      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 204      * if the pixel coordinate is out of bounds.
 205      * A ClassCastException will be thrown if the input object is non null
 206      * and references anything other than an array of transferType.
 207      * @param x        The X coordinate of the pixel location.
 208      * @param y        The Y coordinate of the pixel location.
 209      * @param obj      An object reference to an array of type defined by
 210      *                 getTransferType() and length getNumDataElements().
 211      *                 If null an array of appropriate type and size will be
 212      *                 allocated.
 213      * @return         An object reference to an array of type defined by
 214      *                 getTransferType() with the request pixel data.
 215      */
 216     public Object getDataElements(int x, int y, Object obj) {
 217         if ((x < this.minX) || (y < this.minY) ||
 218             (x >= this.maxX) || (y >= this.maxY)) {
 219             throw new ArrayIndexOutOfBoundsException
 220                 ("Coordinate out of bounds!");
 221         }
 222         int outData[];
 223         if (obj == null) {
 224             outData = new int[1];
 225         } else {
 226             outData = (int[])obj;
 227         }
 228         int off = (y-minY)*scanlineStride + (x-minX) + dataOffsets[0];
 229         outData[0] = data[off];


 232     }
 233 
 234 
 235     /**
 236      * Returns an array  of data elements from the specified rectangular
 237      * region.
 238      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 239      * if the pixel coordinates are out of bounds.
 240      * A ClassCastException will be thrown if the input object is non null
 241      * and references anything other than an array of transferType.
 242      <pre>
 243      *       int[] bandData = (int[])raster.getDataElements(x, y, w, h, null);
 244      *       int numDataElements = raster.getNumDataElements();
 245      *       int[] pixel = new int[numDataElements];
 246      *       // To find a data element at location (x2, y2)
 247      *       System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
 248      *                        pixel, 0, numDataElements);
 249      * </pre>
 250      * @param x        The X coordinate of the upper left pixel location.
 251      * @param y        The Y coordinate of the upper left pixel location.
 252      * @param w        Width of the pixel rectangle.
 253      * @param h        Height of the pixel rectangle.
 254      * @param obj      An object reference to an array of type defined by
 255      *                 getTransferType() and length w*h*getNumDataElements().
 256      *                 If null an array of appropriate type and size will be
 257      *                 allocated.
 258      * @return         An object reference to an array of type defined by
 259      *                 getTransferType() with the request pixel data.
 260      */
 261     public Object getDataElements(int x, int y, int w, int h, Object obj) {
 262         if ((x < this.minX) || (y < this.minY) ||
 263             (x + w > this.maxX) || (y + h > this.maxY)) {
 264             throw new ArrayIndexOutOfBoundsException
 265                 ("Coordinate out of bounds!");
 266         }
 267         int outData[];
 268         if (obj instanceof int[]) {
 269             outData = (int[])obj;
 270         } else {
 271             outData = new int[w*h];
 272         }
 273         int yoff = (y-minY)*scanlineStride + (x-minX) + dataOffsets[0];
 274         int off = 0;
 275 
 276         for (int ystart = 0; ystart < h; ystart++) {
 277             System.arraycopy(data, yoff, outData, off, w);
 278             off += w;
 279             yoff += scanlineStride;
 280         }
 281 
 282         return outData;
 283     }
 284 
 285 
 286     /**
 287      * Stores the data elements for all bands at the specified location.
 288      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 289      * if the pixel coordinate is out of bounds.
 290      * A ClassCastException will be thrown if the input object is non null
 291      * and references anything other than an array of transferType.
 292      * @param x        The X coordinate of the pixel location.
 293      * @param y        The Y coordinate of the pixel location.
 294      * @param obj      An object reference to an array of type defined by
 295      *                 getTransferType() and length getNumDataElements()
 296      *                 containing the pixel data to place at x,y.
 297      */
 298     public void setDataElements(int x, int y, Object obj) {
 299         if ((x < this.minX) || (y < this.minY) ||
 300             (x >= this.maxX) || (y >= this.maxY)) {
 301             throw new ArrayIndexOutOfBoundsException
 302                 ("Coordinate out of bounds!");
 303         }
 304         int inData[] = (int[])obj;
 305 
 306         int off = (y-minY)*scanlineStride + (x-minX) + dataOffsets[0];
 307 
 308         data[off] = inData[0];
 309 
 310         markDirty();
 311     }
 312 
 313 
 314     /**


 393         }
 394     }
 395 
 396     /**
 397      * Stores an array of data elements into the specified rectangular
 398      * region.
 399      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 400      * if the pixel coordinates are out of bounds.
 401      * A ClassCastException will be thrown if the input object is non null
 402      * and references anything other than an array of transferType.
 403      * The data elements in the
 404      * data array are assumed to be packed.  That is, a data element
 405      * for the nth band at location (x2, y2) would be found at:
 406      * <pre>
 407      *      inData[((y2-y)*w + (x2-x))*numDataElements + n]
 408      * </pre>
 409      * @param x        The X coordinate of the upper left pixel location.
 410      * @param y        The Y coordinate of the upper left pixel location.
 411      * @param w        Width of the pixel rectangle.
 412      * @param h        Height of the pixel rectangle.
 413      * @param obj      An object reference to an array of type defined by
 414      *                 getTransferType() and length w*h*getNumDataElements()
 415      *                 containing the pixel data to place between x,y and
 416      *                 x+h, y+h.
 417      */
 418     public void setDataElements(int x, int y, int w, int h, Object obj) {
 419         if ((x < this.minX) || (y < this.minY) ||
 420             (x + w > this.maxX) || (y + h > this.maxY)) {
 421             throw new ArrayIndexOutOfBoundsException
 422                 ("Coordinate out of bounds!");
 423         }
 424         int inData[] = (int[])obj;
 425         int yoff = (y-minY)*scanlineStride + (x-minX) + dataOffsets[0];
 426         int off = 0;
 427 
 428         for (int ystart = 0; ystart < h; ystart++) {
 429             System.arraycopy(inData, off, data, yoff, w);
 430             off += w;
 431             yoff += scanlineStride;
 432         }
 433 


< prev index next >