1 /*
2 * Copyright (c) 1998, 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
163 this.dataOffsets[0] = dbus.getOffset();
164 int xOffset = aRegion.x - origin.x;
165 int yOffset = aRegion.y - origin.y;
166 dataOffsets[0] += xOffset+yOffset*scanlineStride;
167 } else {
168 throw new RasterFormatException("ShortInterleavedRasters must "+
169 "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
170 " or 1 band ComponentSampleModel. Sample model is "+
171 sampleModel);
172 }
173 this.bandOffset = this.dataOffsets[0];
174 verify();
175 }
176
177 /**
178 * Returns a copy of the data offsets array. For each band the data offset
179 * is the index into the band's data array, of the first sample of the
180 * band.
181 */
182 public int[] getDataOffsets() {
183 return (int[]) dataOffsets.clone();
184 }
185
186 /**
187 * Returns the data offset for the specified band. The data offset
188 * is the index into the data array in which the first sample
189 * of the first scanline is stored.
190 * @param band The band whose offset is returned.
191 */
192 public int getDataOffset(int band) {
193 return dataOffsets[band];
194 }
195
196 /**
197 * Returns the scanline stride -- the number of data array elements between
198 * a given sample and the same sample in the same column of the next row.
199 */
200 public int getScanlineStride() {
201 return scanlineStride;
202 }
203
426 * An ArrayIndexOutOfBounds exception will be thrown at runtime
427 * if the pixel coordinate is out of bounds.
428 * A ClassCastException will be thrown if the input object is non null
429 * and references anything other than an array of transferType.
430 * @param x The X coordinate of the pixel location.
431 * @param y The Y coordinate of the pixel location.
432 * @param inData An object reference to an array of type defined by
433 * getTransferType() and length getNumDataElements()
434 * containing the pixel data to place at x,y.
435 */
436 public void setDataElements(int x, int y, Object obj) {
437 if ((x < this.minX) || (y < this.minY) ||
438 (x >= this.maxX) || (y >= this.maxY)) {
439 throw new ArrayIndexOutOfBoundsException
440 ("Coordinate out of bounds!");
441 }
442 short inData[] = (short[])obj;
443 int off = (y-minY)*scanlineStride +
444 (x-minX)*pixelStride;
445 for (int i = 0; i < numDataElements; i++) {
446 data[dataOffsets[i] + off] = (short) inData[i];
447 }
448 markDirty();
449 }
450
451 /**
452 * Stores the Raster data at the specified location.
453 * An ArrayIndexOutOfBounds exception will be thrown at runtime
454 * if the pixel coordinates are out of bounds.
455 * @param x The X coordinate of the pixel location.
456 * @param y The Y coordinate of the pixel location.
457 * @param inRaster Raster of data to place at x,y location.
458 */
459 public void setDataElements(int x, int y, Raster inRaster) {
460 int dstOffX = x + inRaster.getMinX();
461 int dstOffY = y + inRaster.getMinY();
462 int width = inRaster.getWidth();
463 int height = inRaster.getHeight();
464 if ((dstOffX < this.minX) || (dstOffY < this.minY) ||
465 (dstOffX + width > this.maxX) || (dstOffY + height > this.maxY)) {
466 throw new ArrayIndexOutOfBoundsException
531 * x+h, y+h.
532 */
533 public void setDataElements(int x, int y, int w, int h, Object obj) {
534 if ((x < this.minX) || (y < this.minY) ||
535 (x + w > this.maxX) || (y + h > this.maxY)) {
536 throw new ArrayIndexOutOfBoundsException
537 ("Coordinate out of bounds!");
538 }
539 short inData[] = (short[])obj;
540 int yoff = (y-minY)*scanlineStride +
541 (x-minX)*pixelStride;
542 int xoff;
543 int off = 0;
544 int xstart;
545 int ystart;
546
547 for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
548 xoff = yoff;
549 for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
550 for (int c = 0; c < numDataElements; c++) {
551 data[dataOffsets[c] + xoff] = (short) inData[off++];
552 }
553 }
554 }
555
556 markDirty();
557 }
558
559 /**
560 * Stores a short integer array of data elements into the
561 * specified rectangular region.
562 * An ArrayIndexOutOfBounds exception will be thrown at runtime
563 * if the pixel coordinates are out of bounds.
564 * The data elements in the
565 * data array are assumed to be packed. That is, a data element
566 * at location (x2, y2) would be found at:
567 * <pre>
568 * inData[((y2-y)*w + (x2-x))]
569 * </pre>
570 * @param x The X coordinate of the upper left pixel location.
571 * @param y The Y coordinate of the upper left pixel location.
|
1 /*
2 * Copyright (c) 1998, 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
163 this.dataOffsets[0] = dbus.getOffset();
164 int xOffset = aRegion.x - origin.x;
165 int yOffset = aRegion.y - origin.y;
166 dataOffsets[0] += xOffset+yOffset*scanlineStride;
167 } else {
168 throw new RasterFormatException("ShortInterleavedRasters must "+
169 "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
170 " or 1 band ComponentSampleModel. Sample model is "+
171 sampleModel);
172 }
173 this.bandOffset = this.dataOffsets[0];
174 verify();
175 }
176
177 /**
178 * Returns a copy of the data offsets array. For each band the data offset
179 * is the index into the band's data array, of the first sample of the
180 * band.
181 */
182 public int[] getDataOffsets() {
183 return dataOffsets.clone();
184 }
185
186 /**
187 * Returns the data offset for the specified band. The data offset
188 * is the index into the data array in which the first sample
189 * of the first scanline is stored.
190 * @param band The band whose offset is returned.
191 */
192 public int getDataOffset(int band) {
193 return dataOffsets[band];
194 }
195
196 /**
197 * Returns the scanline stride -- the number of data array elements between
198 * a given sample and the same sample in the same column of the next row.
199 */
200 public int getScanlineStride() {
201 return scanlineStride;
202 }
203
426 * An ArrayIndexOutOfBounds exception will be thrown at runtime
427 * if the pixel coordinate is out of bounds.
428 * A ClassCastException will be thrown if the input object is non null
429 * and references anything other than an array of transferType.
430 * @param x The X coordinate of the pixel location.
431 * @param y The Y coordinate of the pixel location.
432 * @param inData An object reference to an array of type defined by
433 * getTransferType() and length getNumDataElements()
434 * containing the pixel data to place at x,y.
435 */
436 public void setDataElements(int x, int y, Object obj) {
437 if ((x < this.minX) || (y < this.minY) ||
438 (x >= this.maxX) || (y >= this.maxY)) {
439 throw new ArrayIndexOutOfBoundsException
440 ("Coordinate out of bounds!");
441 }
442 short inData[] = (short[])obj;
443 int off = (y-minY)*scanlineStride +
444 (x-minX)*pixelStride;
445 for (int i = 0; i < numDataElements; i++) {
446 data[dataOffsets[i] + off] = inData[i];
447 }
448 markDirty();
449 }
450
451 /**
452 * Stores the Raster data at the specified location.
453 * An ArrayIndexOutOfBounds exception will be thrown at runtime
454 * if the pixel coordinates are out of bounds.
455 * @param x The X coordinate of the pixel location.
456 * @param y The Y coordinate of the pixel location.
457 * @param inRaster Raster of data to place at x,y location.
458 */
459 public void setDataElements(int x, int y, Raster inRaster) {
460 int dstOffX = x + inRaster.getMinX();
461 int dstOffY = y + inRaster.getMinY();
462 int width = inRaster.getWidth();
463 int height = inRaster.getHeight();
464 if ((dstOffX < this.minX) || (dstOffY < this.minY) ||
465 (dstOffX + width > this.maxX) || (dstOffY + height > this.maxY)) {
466 throw new ArrayIndexOutOfBoundsException
531 * x+h, y+h.
532 */
533 public void setDataElements(int x, int y, int w, int h, Object obj) {
534 if ((x < this.minX) || (y < this.minY) ||
535 (x + w > this.maxX) || (y + h > this.maxY)) {
536 throw new ArrayIndexOutOfBoundsException
537 ("Coordinate out of bounds!");
538 }
539 short inData[] = (short[])obj;
540 int yoff = (y-minY)*scanlineStride +
541 (x-minX)*pixelStride;
542 int xoff;
543 int off = 0;
544 int xstart;
545 int ystart;
546
547 for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
548 xoff = yoff;
549 for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
550 for (int c = 0; c < numDataElements; c++) {
551 data[dataOffsets[c] + xoff] = inData[off++];
552 }
553 }
554 }
555
556 markDirty();
557 }
558
559 /**
560 * Stores a short integer array of data elements into the
561 * specified rectangular region.
562 * An ArrayIndexOutOfBounds exception will be thrown at runtime
563 * if the pixel coordinates are out of bounds.
564 * The data elements in the
565 * data array are assumed to be packed. That is, a data element
566 * at location (x2, y2) would be found at:
567 * <pre>
568 * inData[((y2-y)*w + (x2-x))]
569 * </pre>
570 * @param x The X coordinate of the upper left pixel location.
571 * @param y The Y coordinate of the upper left pixel location.
|