< prev index next >

src/java.desktop/share/classes/sun/awt/image/ShortComponentRaster.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


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


 290      *       System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
 291      *                        pixel, 0, numDataElements);
 292      * </pre>
 293      * @param x        The X coordinate of the upper left pixel location.
 294      * @param y        The Y coordinate of the upper left pixel location.
 295      * @param w        Width of the pixel rectangle.
 296      * @param h        Height of the pixel rectangle.
 297      * @param obj      An object reference to an array of type defined by
 298      *                 getTransferType() and length w*h*getNumDataElements().
 299      *                 If null an array of appropriate type and size will be
 300      *                 allocated.
 301      * @return         An object reference to an array of type defined by
 302      *                 getTransferType() with the request pixel data.
 303      */
 304     public Object getDataElements(int x, int y, int w, int h, Object obj) {
 305         if ((x < this.minX) || (y < this.minY) ||
 306             (x + w > this.maxX) || (y + h > this.maxY)) {
 307             throw new ArrayIndexOutOfBoundsException
 308                 ("Coordinate out of bounds!");
 309         }
 310         short outData[];
 311         if (obj == null) {
 312             outData = new short[w*h*numDataElements];
 313         } else {
 314             outData = (short[])obj;
 315         }
 316         int yoff = (y-minY)*scanlineStride +
 317                    (x-minX)*pixelStride;
 318 
 319         int xoff;
 320         int off = 0;
 321         int xstart;
 322         int ystart;
 323 
 324         for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
 325             xoff = yoff;
 326             for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
 327                 for (int c = 0; c < numDataElements; c++) {
 328                     outData[off++] = data[dataOffsets[c] + xoff];
 329                 }
 330             }


 443     }
 444 
 445     /**
 446      * Stores the data elements for all bands at the specified location.
 447      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 448      * if the pixel coordinate is out of bounds.
 449      * A ClassCastException will be thrown if the input object is non null
 450      * and references anything other than an array of transferType.
 451      * @param x        The X coordinate of the pixel location.
 452      * @param y        The Y coordinate of the pixel location.
 453      * @param obj      An object reference to an array of type defined by
 454      *                 getTransferType() and length getNumDataElements()
 455      *                 containing the pixel data to place at x,y.
 456      */
 457     public void setDataElements(int x, int y, Object obj) {
 458         if ((x < this.minX) || (y < this.minY) ||
 459             (x >= this.maxX) || (y >= this.maxY)) {
 460             throw new ArrayIndexOutOfBoundsException
 461                 ("Coordinate out of bounds!");
 462         }
 463         short inData[] = (short[])obj;
 464         int off = (y-minY)*scanlineStride +
 465                   (x-minX)*pixelStride;
 466         for (int i = 0; i < numDataElements; i++) {
 467             data[dataOffsets[i] + off] = inData[i];
 468         }
 469 
 470         markDirty();
 471     }
 472 
 473     /**
 474      * Stores the Raster data at the specified location.
 475      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 476      * if the pixel coordinates are out of bounds.
 477      * @param x          The X coordinate of the pixel location.
 478      * @param y          The Y coordinate of the pixel location.
 479      * @param inRaster   Raster of data to place at x,y location.
 480      */
 481     public void setDataElements(int x, int y, Raster inRaster) {
 482         int dstOffX = x + inRaster.getMinX();
 483         int dstOffY = y + inRaster.getMinY();


 541      * data array are assumed to be packed.  That is, a data element
 542      * for the nth band at location (x2, y2) would be found at:
 543      * <pre>
 544      *      inData[((y2-y)*w + (x2-x))*numDataElements + n]
 545      * </pre>
 546      * @param x        The X coordinate of the upper left pixel location.
 547      * @param y        The Y coordinate of the upper left pixel location.
 548      * @param w        Width of the pixel rectangle.
 549      * @param h        Height of the pixel rectangle.
 550      * @param obj      An object reference to an array of type defined by
 551      *                 getTransferType() and length w*h*getNumDataElements()
 552      *                 containing the pixel data to place between x,y and
 553      *                 x+h, y+h.
 554      */
 555     public void setDataElements(int x, int y, int w, int h, Object obj) {
 556         if ((x < this.minX) || (y < this.minY) ||
 557             (x + w > this.maxX) || (y + h > this.maxY)) {
 558             throw new ArrayIndexOutOfBoundsException
 559                 ("Coordinate out of bounds!");
 560         }
 561         short inData[] = (short[])obj;
 562         int yoff = (y-minY)*scanlineStride +
 563                    (x-minX)*pixelStride;
 564         int xoff;
 565         int off = 0;
 566         int xstart;
 567         int ystart;
 568 
 569         for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
 570             xoff = yoff;
 571             for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
 572                 for (int c = 0; c < numDataElements; c++) {
 573                     data[dataOffsets[c] + xoff] = inData[off++];
 574                 }
 575             }
 576         }
 577 
 578         markDirty();
 579     }
 580 
 581     /**


   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


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


 290      *       System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
 291      *                        pixel, 0, numDataElements);
 292      * </pre>
 293      * @param x        The X coordinate of the upper left pixel location.
 294      * @param y        The Y coordinate of the upper left pixel location.
 295      * @param w        Width of the pixel rectangle.
 296      * @param h        Height of the pixel rectangle.
 297      * @param obj      An object reference to an array of type defined by
 298      *                 getTransferType() and length w*h*getNumDataElements().
 299      *                 If null an array of appropriate type and size will be
 300      *                 allocated.
 301      * @return         An object reference to an array of type defined by
 302      *                 getTransferType() with the request pixel data.
 303      */
 304     public Object getDataElements(int x, int y, int w, int h, Object obj) {
 305         if ((x < this.minX) || (y < this.minY) ||
 306             (x + w > this.maxX) || (y + h > this.maxY)) {
 307             throw new ArrayIndexOutOfBoundsException
 308                 ("Coordinate out of bounds!");
 309         }
 310         short[] outData;
 311         if (obj == null) {
 312             outData = new short[w*h*numDataElements];
 313         } else {
 314             outData = (short[])obj;
 315         }
 316         int yoff = (y-minY)*scanlineStride +
 317                    (x-minX)*pixelStride;
 318 
 319         int xoff;
 320         int off = 0;
 321         int xstart;
 322         int ystart;
 323 
 324         for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
 325             xoff = yoff;
 326             for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
 327                 for (int c = 0; c < numDataElements; c++) {
 328                     outData[off++] = data[dataOffsets[c] + xoff];
 329                 }
 330             }


 443     }
 444 
 445     /**
 446      * Stores the data elements for all bands at the specified location.
 447      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 448      * if the pixel coordinate is out of bounds.
 449      * A ClassCastException will be thrown if the input object is non null
 450      * and references anything other than an array of transferType.
 451      * @param x        The X coordinate of the pixel location.
 452      * @param y        The Y coordinate of the pixel location.
 453      * @param obj      An object reference to an array of type defined by
 454      *                 getTransferType() and length getNumDataElements()
 455      *                 containing the pixel data to place at x,y.
 456      */
 457     public void setDataElements(int x, int y, Object obj) {
 458         if ((x < this.minX) || (y < this.minY) ||
 459             (x >= this.maxX) || (y >= this.maxY)) {
 460             throw new ArrayIndexOutOfBoundsException
 461                 ("Coordinate out of bounds!");
 462         }
 463         short[] inData = (short[])obj;
 464         int off = (y-minY)*scanlineStride +
 465                   (x-minX)*pixelStride;
 466         for (int i = 0; i < numDataElements; i++) {
 467             data[dataOffsets[i] + off] = inData[i];
 468         }
 469 
 470         markDirty();
 471     }
 472 
 473     /**
 474      * Stores the Raster data at the specified location.
 475      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 476      * if the pixel coordinates are out of bounds.
 477      * @param x          The X coordinate of the pixel location.
 478      * @param y          The Y coordinate of the pixel location.
 479      * @param inRaster   Raster of data to place at x,y location.
 480      */
 481     public void setDataElements(int x, int y, Raster inRaster) {
 482         int dstOffX = x + inRaster.getMinX();
 483         int dstOffY = y + inRaster.getMinY();


 541      * data array are assumed to be packed.  That is, a data element
 542      * for the nth band at location (x2, y2) would be found at:
 543      * <pre>
 544      *      inData[((y2-y)*w + (x2-x))*numDataElements + n]
 545      * </pre>
 546      * @param x        The X coordinate of the upper left pixel location.
 547      * @param y        The Y coordinate of the upper left pixel location.
 548      * @param w        Width of the pixel rectangle.
 549      * @param h        Height of the pixel rectangle.
 550      * @param obj      An object reference to an array of type defined by
 551      *                 getTransferType() and length w*h*getNumDataElements()
 552      *                 containing the pixel data to place between x,y and
 553      *                 x+h, y+h.
 554      */
 555     public void setDataElements(int x, int y, int w, int h, Object obj) {
 556         if ((x < this.minX) || (y < this.minY) ||
 557             (x + w > this.maxX) || (y + h > this.maxY)) {
 558             throw new ArrayIndexOutOfBoundsException
 559                 ("Coordinate out of bounds!");
 560         }
 561         short[] inData = (short[])obj;
 562         int yoff = (y-minY)*scanlineStride +
 563                    (x-minX)*pixelStride;
 564         int xoff;
 565         int off = 0;
 566         int xstart;
 567         int ystart;
 568 
 569         for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
 570             xoff = yoff;
 571             for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
 572                 for (int c = 0; c < numDataElements; c++) {
 573                     data[dataOffsets[c] + xoff] = inData[off++];
 574                 }
 575             }
 576         }
 577 
 578         markDirty();
 579     }
 580 
 581     /**


< prev index next >