< prev index next >

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

Print this page




 235     public int getPixelStride() {
 236         return pixelStride;
 237     }
 238 
 239     /**
 240      * Returns a reference to the data array.
 241      */
 242     public short[] getDataStorage() {
 243         return data;
 244     }
 245 
 246     /**
 247      * Returns the data elements for all bands at the specified
 248      * location.
 249      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 250      * if the pixel coordinate is out of bounds.
 251      * A ClassCastException will be thrown if the input object is non null
 252      * and references anything other than an array of transferType.
 253      * @param x        The X coordinate of the pixel location.
 254      * @param y        The Y coordinate of the pixel location.
 255      * @param outData  An object reference to an array of type defined by
 256      *                 getTransferType() and length getNumDataElements().
 257      *                 If null an array of appropriate type and size will be
 258      *                 allocated.
 259      * @return         An object reference to an array of type defined by
 260      *                 getTransferType() with the request pixel data.
 261      */
 262     public Object getDataElements(int x, int y, Object obj) {
 263         if ((x < this.minX) || (y < this.minY) ||
 264             (x >= this.maxX) || (y >= this.maxY)) {
 265             throw new ArrayIndexOutOfBoundsException
 266                 ("Coordinate out of bounds!");
 267         }
 268         short outData[];
 269         if (obj == null) {
 270             outData = new short[numDataElements];
 271         } else {
 272             outData = (short[])obj;
 273         }
 274         int off = (y-minY)*scanlineStride +
 275                   (x-minX)*pixelStride;


 281         return outData;
 282     }
 283 
 284     /**
 285      * Returns an array  of data elements from the specified rectangular
 286      * region.
 287      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 288      * if the pixel coordinates are out of bounds.
 289      * A ClassCastException will be thrown if the input object is non null
 290      * and references anything other than an array of transferType.
 291      * <pre>
 292      *       short[] bandData = (short[])Raster.getDataElements(x, y, w, h, null);
 293      *       int numDataElements = Raster.getBands();
 294      *       short[] pixel = new short[numDataElements];
 295      *       // To find the data element at location (x2, y2)
 296      *       System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
 297      *                        pixel, 0, numDataElements);
 298      * </pre>
 299      * @param x        The X coordinate of the upper left pixel location.
 300      * @param y        The Y coordinate of the upper left pixel location.
 301      * @param width    Width of the pixel rectangle.
 302      * @param height   Height of the pixel rectangle.
 303      * @param outData  An object reference to an array of type defined by
 304      *                 getTransferType() and length w*h*getNumDataElements().
 305      *                 If null an array of appropriate type and size will be
 306      *                 allocated.
 307      * @return         An object reference to an array of type defined by
 308      *                 getTransferType() with the request pixel data.
 309      */
 310     public Object getDataElements(int x, int y, int w, int h, Object obj) {
 311         if ((x < this.minX) || (y < this.minY) ||
 312             (x + w > this.maxX) || (y + h > this.maxY)) {
 313             throw new ArrayIndexOutOfBoundsException
 314                 ("Coordinate out of bounds!");
 315         }
 316         short outData[];
 317         if (obj == null) {
 318             outData = new short[w*h*numDataElements];
 319         } else {
 320             outData = (short[])obj;
 321         }
 322         int yoff = (y-minY)*scanlineStride +
 323                    (x-minX)*pixelStride;


 334                     outData[off++] = data[dataOffsets[c] + xoff];
 335                 }
 336             }
 337         }
 338 
 339         return outData;
 340     }
 341 
 342     /**
 343      * Returns a short integer array of data elements from the
 344      * specified rectangular region.
 345      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 346      * if the pixel coordinates are out of bounds.
 347      * <pre>
 348      *       short[] bandData = Raster.getShortData(x, y, w, h, null);
 349      *       // To find the data element at location (x2, y2)
 350      *       short dataElenent = bandData[((y2-y)*w + (x2-x))];
 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 sample rectangle.
 355      * @param height   Height of the sample rectangle.
 356      * @param band     The band to return.
 357      * @param outData  If non-null, data elements for all bands
 358      *                 at the specified location are returned in this array.
 359      * @return         Data array with data elements for all bands.
 360      */
 361     public short[] getShortData(int x, int y, int w, int h,
 362                                int band, short[] outData) {
 363         // Bounds check for 'band' will be performed automatically
 364         if ((x < this.minX) || (y < this.minY) ||
 365             (x + w > this.maxX) || (y + h > this.maxY)) {
 366             throw new ArrayIndexOutOfBoundsException
 367                 ("Coordinate out of bounds!");
 368         }
 369         if (outData == null) {
 370             outData = new short[numDataElements*w*h];
 371         }
 372         int yoff =  (y-minY)*scanlineStride +
 373                     (x-minX)*pixelStride+ dataOffsets[band];
 374         int xoff;
 375         int off = 0;


 397         }
 398 
 399         return outData;
 400     }
 401 
 402     /**
 403      * Returns a short integer array  of data elements from the
 404      * specified rectangular region.
 405      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 406      * if the pixel coordinates are out of bounds.
 407      * <pre>
 408      *       short[] bandData = Raster.getShortData(x, y, w, h, null);
 409      *       int numDataElements = Raster.getNumBands();
 410      *       short[] pixel = new short[numDataElements];
 411      *       // To find the data element at location (x2, y2)
 412      *       System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
 413      *                        pixel, 0, numDataElements);
 414      * </pre>
 415      * @param x        The X coordinate of the upper left pixel location.
 416      * @param y        The Y coordinate of the upper left pixel location.
 417      * @param width    Width of the pixel rectangle.
 418      * @param height   Height of the pixel rectangle.
 419      * @param outData  If non-null, data elements for all bands
 420      *                 at the specified location are returned in this array.
 421      * @return         Data array with data elements for all bands.
 422      */
 423     public short[] getShortData(int x, int y, int w, int h, short[] outData) {
 424         if ((x < this.minX) || (y < this.minY) ||
 425             (x + w > this.maxX) || (y + h > this.maxY)) {
 426             throw new ArrayIndexOutOfBoundsException
 427                 ("Coordinate out of bounds!");
 428         }
 429         if (outData == null) {
 430             outData = new short[numDataElements*w*h];
 431         }
 432         int yoff = (y-minY)*scanlineStride +
 433                    (x-minX)*pixelStride;
 434         int xoff;
 435         int off = 0;
 436         int xstart;
 437         int ystart;
 438 
 439         for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
 440             xoff = yoff;
 441             for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
 442                 for (int c = 0; c < numDataElements; c++) {
 443                     outData[off++] = data[dataOffsets[c] + xoff];
 444                 }
 445             }
 446         }
 447 
 448         return outData;
 449     }
 450 
 451     /**
 452      * Stores the data elements for all bands at the specified location.
 453      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 454      * if the pixel coordinate is out of bounds.
 455      * A ClassCastException will be thrown if the input object is non null
 456      * and references anything other than an array of transferType.
 457      * @param x        The X coordinate of the pixel location.
 458      * @param y        The Y coordinate of the pixel location.
 459      * @param inData   An object reference to an array of type defined by
 460      *                 getTransferType() and length getNumDataElements()
 461      *                 containing the pixel data to place at x,y.
 462      */
 463     public void setDataElements(int x, int y, Object obj) {
 464         if ((x < this.minX) || (y < this.minY) ||
 465             (x >= this.maxX) || (y >= this.maxY)) {
 466             throw new ArrayIndexOutOfBoundsException
 467                 ("Coordinate out of bounds!");
 468         }
 469         short inData[] = (short[])obj;
 470         int off = (y-minY)*scanlineStride +
 471                   (x-minX)*pixelStride;
 472         for (int i = 0; i < numDataElements; i++) {
 473             data[dataOffsets[i] + off] = inData[i];
 474         }
 475 
 476         markDirty();
 477     }
 478 
 479     /**


 536         }
 537     }
 538 
 539     /**
 540      * Stores an array of data elements into the specified rectangular
 541      * region.
 542      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 543      * if the pixel coordinates are out of bounds.
 544      * A ClassCastException will be thrown if the input object is non null
 545      * and references anything other than an array of transferType.
 546      * The data elements in the
 547      * data array are assumed to be packed.  That is, a data element
 548      * for the nth band at location (x2, y2) would be found at:
 549      * <pre>
 550      *      inData[((y2-y)*w + (x2-x))*numDataElements + n]
 551      * </pre>
 552      * @param x        The X coordinate of the upper left pixel location.
 553      * @param y        The Y coordinate of the upper left pixel location.
 554      * @param w        Width of the pixel rectangle.
 555      * @param h        Height of the pixel rectangle.
 556      * @param inData   An object reference to an array of type defined by
 557      *                 getTransferType() and length w*h*getNumDataElements()
 558      *                 containing the pixel data to place between x,y and
 559      *                 x+h, y+h.
 560      */
 561     public void setDataElements(int x, int y, int w, int h, Object obj) {
 562         if ((x < this.minX) || (y < this.minY) ||
 563             (x + w > this.maxX) || (y + h > this.maxY)) {
 564             throw new ArrayIndexOutOfBoundsException
 565                 ("Coordinate out of bounds!");
 566         }
 567         short inData[] = (short[])obj;
 568         int yoff = (y-minY)*scanlineStride +
 569                    (x-minX)*pixelStride;
 570         int xoff;
 571         int off = 0;
 572         int xstart;
 573         int ystart;
 574 
 575         for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
 576             xoff = yoff;




 235     public int getPixelStride() {
 236         return pixelStride;
 237     }
 238 
 239     /**
 240      * Returns a reference to the data array.
 241      */
 242     public short[] getDataStorage() {
 243         return data;
 244     }
 245 
 246     /**
 247      * Returns the data elements for all bands at the specified
 248      * location.
 249      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 250      * if the pixel coordinate is out of bounds.
 251      * A ClassCastException will be thrown if the input object is non null
 252      * and references anything other than an array of transferType.
 253      * @param x        The X coordinate of the pixel location.
 254      * @param y        The Y coordinate of the pixel location.
 255      * @param obj      An object reference to an array of type defined by
 256      *                 getTransferType() and length getNumDataElements().
 257      *                 If null an array of appropriate type and size will be
 258      *                 allocated.
 259      * @return         An object reference to an array of type defined by
 260      *                 getTransferType() with the request pixel data.
 261      */
 262     public Object getDataElements(int x, int y, Object obj) {
 263         if ((x < this.minX) || (y < this.minY) ||
 264             (x >= this.maxX) || (y >= this.maxY)) {
 265             throw new ArrayIndexOutOfBoundsException
 266                 ("Coordinate out of bounds!");
 267         }
 268         short outData[];
 269         if (obj == null) {
 270             outData = new short[numDataElements];
 271         } else {
 272             outData = (short[])obj;
 273         }
 274         int off = (y-minY)*scanlineStride +
 275                   (x-minX)*pixelStride;


 281         return outData;
 282     }
 283 
 284     /**
 285      * Returns an array  of data elements from the specified rectangular
 286      * region.
 287      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 288      * if the pixel coordinates are out of bounds.
 289      * A ClassCastException will be thrown if the input object is non null
 290      * and references anything other than an array of transferType.
 291      * <pre>
 292      *       short[] bandData = (short[])Raster.getDataElements(x, y, w, h, null);
 293      *       int numDataElements = Raster.getBands();
 294      *       short[] pixel = new short[numDataElements];
 295      *       // To find the data element at location (x2, y2)
 296      *       System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
 297      *                        pixel, 0, numDataElements);
 298      * </pre>
 299      * @param x        The X coordinate of the upper left pixel location.
 300      * @param y        The Y coordinate of the upper left pixel location.
 301      * @param w        Width of the pixel rectangle.
 302      * @param h        Height of the pixel rectangle.
 303      * @param obj      An object reference to an array of type defined by
 304      *                 getTransferType() and length w*h*getNumDataElements().
 305      *                 If null an array of appropriate type and size will be
 306      *                 allocated.
 307      * @return         An object reference to an array of type defined by
 308      *                 getTransferType() with the request pixel data.
 309      */
 310     public Object getDataElements(int x, int y, int w, int h, Object obj) {
 311         if ((x < this.minX) || (y < this.minY) ||
 312             (x + w > this.maxX) || (y + h > this.maxY)) {
 313             throw new ArrayIndexOutOfBoundsException
 314                 ("Coordinate out of bounds!");
 315         }
 316         short outData[];
 317         if (obj == null) {
 318             outData = new short[w*h*numDataElements];
 319         } else {
 320             outData = (short[])obj;
 321         }
 322         int yoff = (y-minY)*scanlineStride +
 323                    (x-minX)*pixelStride;


 334                     outData[off++] = data[dataOffsets[c] + xoff];
 335                 }
 336             }
 337         }
 338 
 339         return outData;
 340     }
 341 
 342     /**
 343      * Returns a short integer array of data elements from the
 344      * specified rectangular region.
 345      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 346      * if the pixel coordinates are out of bounds.
 347      * <pre>
 348      *       short[] bandData = Raster.getShortData(x, y, w, h, null);
 349      *       // To find the data element at location (x2, y2)
 350      *       short dataElenent = bandData[((y2-y)*w + (x2-x))];
 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 sample rectangle.
 355      * @param h        Height of the sample rectangle.
 356      * @param band     The band to return.
 357      * @param outData  If non-null, data elements for all bands
 358      *                 at the specified location are returned in this array.
 359      * @return         Data array with data elements for all bands.
 360      */
 361     public short[] getShortData(int x, int y, int w, int h,
 362                                int band, short[] outData) {
 363         // Bounds check for 'band' will be performed automatically
 364         if ((x < this.minX) || (y < this.minY) ||
 365             (x + w > this.maxX) || (y + h > this.maxY)) {
 366             throw new ArrayIndexOutOfBoundsException
 367                 ("Coordinate out of bounds!");
 368         }
 369         if (outData == null) {
 370             outData = new short[numDataElements*w*h];
 371         }
 372         int yoff =  (y-minY)*scanlineStride +
 373                     (x-minX)*pixelStride+ dataOffsets[band];
 374         int xoff;
 375         int off = 0;


 397         }
 398 
 399         return outData;
 400     }
 401 
 402     /**
 403      * Returns a short integer array  of data elements from the
 404      * specified rectangular region.
 405      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 406      * if the pixel coordinates are out of bounds.
 407      * <pre>
 408      *       short[] bandData = Raster.getShortData(x, y, w, h, null);
 409      *       int numDataElements = Raster.getNumBands();
 410      *       short[] pixel = new short[numDataElements];
 411      *       // To find the data element at location (x2, y2)
 412      *       System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
 413      *                        pixel, 0, numDataElements);
 414      * </pre>
 415      * @param x        The X coordinate of the upper left pixel location.
 416      * @param y        The Y coordinate of the upper left pixel location.
 417      * @param w        Width of the pixel rectangle.
 418      * @param h        Height of the pixel rectangle.
 419      * @param outData  If non-null, data elements for all bands
 420      *                 at the specified location are returned in this array.
 421      * @return         Data array with data elements for all bands.
 422      */
 423     public short[] getShortData(int x, int y, int w, int h, short[] outData) {
 424         if ((x < this.minX) || (y < this.minY) ||
 425             (x + w > this.maxX) || (y + h > this.maxY)) {
 426             throw new ArrayIndexOutOfBoundsException
 427                 ("Coordinate out of bounds!");
 428         }
 429         if (outData == null) {
 430             outData = new short[numDataElements*w*h];
 431         }
 432         int yoff = (y-minY)*scanlineStride +
 433                    (x-minX)*pixelStride;
 434         int xoff;
 435         int off = 0;
 436         int xstart;
 437         int ystart;
 438 
 439         for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
 440             xoff = yoff;
 441             for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
 442                 for (int c = 0; c < numDataElements; c++) {
 443                     outData[off++] = data[dataOffsets[c] + xoff];
 444                 }
 445             }
 446         }
 447 
 448         return outData;
 449     }
 450 
 451     /**
 452      * Stores the data elements for all bands at the specified location.
 453      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 454      * if the pixel coordinate is out of bounds.
 455      * A ClassCastException will be thrown if the input object is non null
 456      * and references anything other than an array of transferType.
 457      * @param x        The X coordinate of the pixel location.
 458      * @param y        The Y coordinate of the pixel location.
 459      * @param obj      An object reference to an array of type defined by
 460      *                 getTransferType() and length getNumDataElements()
 461      *                 containing the pixel data to place at x,y.
 462      */
 463     public void setDataElements(int x, int y, Object obj) {
 464         if ((x < this.minX) || (y < this.minY) ||
 465             (x >= this.maxX) || (y >= this.maxY)) {
 466             throw new ArrayIndexOutOfBoundsException
 467                 ("Coordinate out of bounds!");
 468         }
 469         short inData[] = (short[])obj;
 470         int off = (y-minY)*scanlineStride +
 471                   (x-minX)*pixelStride;
 472         for (int i = 0; i < numDataElements; i++) {
 473             data[dataOffsets[i] + off] = inData[i];
 474         }
 475 
 476         markDirty();
 477     }
 478 
 479     /**


 536         }
 537     }
 538 
 539     /**
 540      * Stores an array of data elements into the specified rectangular
 541      * region.
 542      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 543      * if the pixel coordinates are out of bounds.
 544      * A ClassCastException will be thrown if the input object is non null
 545      * and references anything other than an array of transferType.
 546      * The data elements in the
 547      * data array are assumed to be packed.  That is, a data element
 548      * for the nth band at location (x2, y2) would be found at:
 549      * <pre>
 550      *      inData[((y2-y)*w + (x2-x))*numDataElements + n]
 551      * </pre>
 552      * @param x        The X coordinate of the upper left pixel location.
 553      * @param y        The Y coordinate of the upper left pixel location.
 554      * @param w        Width of the pixel rectangle.
 555      * @param h        Height of the pixel rectangle.
 556      * @param obj      An object reference to an array of type defined by
 557      *                 getTransferType() and length w*h*getNumDataElements()
 558      *                 containing the pixel data to place between x,y and
 559      *                 x+h, y+h.
 560      */
 561     public void setDataElements(int x, int y, int w, int h, Object obj) {
 562         if ((x < this.minX) || (y < this.minY) ||
 563             (x + w > this.maxX) || (y + h > this.maxY)) {
 564             throw new ArrayIndexOutOfBoundsException
 565                 ("Coordinate out of bounds!");
 566         }
 567         short inData[] = (short[])obj;
 568         int yoff = (y-minY)*scanlineStride +
 569                    (x-minX)*pixelStride;
 570         int xoff;
 571         int off = 0;
 572         int xstart;
 573         int ystart;
 574 
 575         for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
 576             xoff = yoff;


< prev index next >