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

Print this page


   1 /*
   2  * Copyright (c) 1997, 2007, 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


 190             this.dataOffsets = new int[1];
 191             this.dataOffsets[0] = dbOffset;
 192             int xOffset = aRegion.x - origin.x;
 193             int yOffset = aRegion.y - origin.y;
 194             dataOffsets[0] += xOffset+yOffset*scanlineStride;
 195         } else {
 196             throw new RasterFormatException("ShortComponentRasters must have"+
 197                 "ComponentSampleModel or SinglePixelPackedSampleModel");
 198         }
 199         this.bandOffset = this.dataOffsets[0];
 200 
 201         verify();
 202     }
 203 
 204     /**
 205      * Returns a copy of the data offsets array. For each band the data offset
 206      * is the index into the band's data array, of the first sample of the
 207      * band.
 208      */
 209     public int[] getDataOffsets() {
 210         return (int[]) dataOffsets.clone();
 211     }
 212 
 213     /**
 214      * Returns the data offset for the specified band.  The data offset
 215      * is the index into the data array in which the first sample
 216      * of the first scanline is stored.
 217      * @param band  The band whose offset is returned.
 218      */
 219     public int getDataOffset(int band) {
 220         return dataOffsets[band];
 221     }
 222 
 223     /**
 224      * Returns the scanline stride -- the number of data array elements between
 225      * a given sample and the same sample in the same column of the next row.
 226      */
 227     public int getScanlineStride() {
 228         return scanlineStride;
 229     }
 230 


 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] = (short) inData[i];
 474         }
 475 
 476         markDirty();
 477     }
 478 
 479     /**
 480      * Stores the Raster data at the specified location.
 481      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 482      * if the pixel coordinates are out of bounds.
 483      * @param x          The X coordinate of the pixel location.
 484      * @param y          The Y coordinate of the pixel location.
 485      * @param inRaster   Raster of data to place at x,y location.
 486      */
 487     public void setDataElements(int x, int y, Raster inRaster) {
 488         int dstOffX = x + inRaster.getMinX();
 489         int dstOffY = y + inRaster.getMinY();
 490         int width  = inRaster.getWidth();
 491         int height = inRaster.getHeight();
 492         if ((dstOffX < this.minX) || (dstOffY < this.minY) ||
 493             (dstOffX + width > this.maxX) || (dstOffY + height > this.maxY)) {


 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;
 577             for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
 578                 for (int c = 0; c < numDataElements; c++) {
 579                     data[dataOffsets[c] + xoff] = (short) inData[off++];
 580                 }
 581             }
 582         }
 583 
 584         markDirty();
 585     }
 586 
 587     /**
 588      * Stores a short integer array of data elements into the
 589      * specified rectangular region.
 590      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 591      * if the pixel coordinates are out of bounds.
 592      * The data elements in the
 593      * data array are assumed to be packed.  That is, a data element
 594      * at location (x2, y2) would be found at:
 595      * <pre>
 596      *      inData[((y2-y)*w + (x2-x))]
 597      * </pre>
 598      * @param x        The X coordinate of the upper left pixel location.
 599      * @param y        The Y coordinate of the upper left pixel location.


   1 /*
   2  * Copyright (c) 1997, 2014, 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


 190             this.dataOffsets = new int[1];
 191             this.dataOffsets[0] = dbOffset;
 192             int xOffset = aRegion.x - origin.x;
 193             int yOffset = aRegion.y - origin.y;
 194             dataOffsets[0] += xOffset+yOffset*scanlineStride;
 195         } else {
 196             throw new RasterFormatException("ShortComponentRasters must have"+
 197                 "ComponentSampleModel or SinglePixelPackedSampleModel");
 198         }
 199         this.bandOffset = this.dataOffsets[0];
 200 
 201         verify();
 202     }
 203 
 204     /**
 205      * Returns a copy of the data offsets array. For each band the data offset
 206      * is the index into the band's data array, of the first sample of the
 207      * band.
 208      */
 209     public int[] getDataOffsets() {
 210         return dataOffsets.clone();
 211     }
 212 
 213     /**
 214      * Returns the data offset for the specified band.  The data offset
 215      * is the index into the data array in which the first sample
 216      * of the first scanline is stored.
 217      * @param band  The band whose offset is returned.
 218      */
 219     public int getDataOffset(int band) {
 220         return dataOffsets[band];
 221     }
 222 
 223     /**
 224      * Returns the scanline stride -- the number of data array elements between
 225      * a given sample and the same sample in the same column of the next row.
 226      */
 227     public int getScanlineStride() {
 228         return scanlineStride;
 229     }
 230 


 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     /**
 480      * Stores the Raster data at the specified location.
 481      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 482      * if the pixel coordinates are out of bounds.
 483      * @param x          The X coordinate of the pixel location.
 484      * @param y          The Y coordinate of the pixel location.
 485      * @param inRaster   Raster of data to place at x,y location.
 486      */
 487     public void setDataElements(int x, int y, Raster inRaster) {
 488         int dstOffX = x + inRaster.getMinX();
 489         int dstOffY = y + inRaster.getMinY();
 490         int width  = inRaster.getWidth();
 491         int height = inRaster.getHeight();
 492         if ((dstOffX < this.minX) || (dstOffY < this.minY) ||
 493             (dstOffX + width > this.maxX) || (dstOffY + height > this.maxY)) {


 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;
 577             for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
 578                 for (int c = 0; c < numDataElements; c++) {
 579                     data[dataOffsets[c] + xoff] = inData[off++];
 580                 }
 581             }
 582         }
 583 
 584         markDirty();
 585     }
 586 
 587     /**
 588      * Stores a short integer array of data elements into the
 589      * specified rectangular region.
 590      * An ArrayIndexOutOfBounds exception will be thrown at runtime
 591      * if the pixel coordinates are out of bounds.
 592      * The data elements in the
 593      * data array are assumed to be packed.  That is, a data element
 594      * at location (x2, y2) would be found at:
 595      * <pre>
 596      *      inData[((y2-y)*w + (x2-x))]
 597      * </pre>
 598      * @param x        The X coordinate of the upper left pixel location.
 599      * @param y        The Y coordinate of the upper left pixel location.