1 /*
2 * Portions Copyright 1997-2007 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26 /* ****************************************************************
27 ******************************************************************
28 ******************************************************************
29 *** COPYRIGHT (c) Eastman Kodak Company, 1997
30 *** As an unpublished work pursuant to Title 17 of the United
31 *** States Code. All rights reserved.
32 ******************************************************************
33 ******************************************************************
34 ******************************************************************/
35
36 package java.awt.image;
37 import java.awt.Rectangle;
38 import java.awt.Point;
39
40 /**
41 * This class extends Raster to provide pixel writing capabilities.
42 * Refer to the class comment for Raster for descriptions of how
43 * a Raster stores pixels.
44 *
45 * <p> The constructors of this class are protected. To instantiate
46 * a WritableRaster, use one of the createWritableRaster factory methods
47 * in the Raster class.
48 */
49 public class WritableRaster extends Raster {
50
51 /**
52 * Constructs a WritableRaster with the given SampleModel. The
53 * WritableRaster's upper left corner is origin and it is the
54 * same size as the SampleModel. A DataBuffer large enough to
55 * describe the WritableRaster is automatically created.
56 * @param sampleModel The SampleModel that specifies the layout.
57 * @param origin The Point that specifies the origin.
58 * @throws RasterFormatException if computing either
59 * <code>origin.x + sampleModel.getWidth()</code> or
60 * <code>origin.y + sampleModel.getHeight()</code> results
61 * in integer overflow
62 */
63 protected WritableRaster(SampleModel sampleModel,
64 Point origin) {
65 this(sampleModel,
66 sampleModel.createDataBuffer(),
67 new Rectangle(origin.x,
68 origin.y,
69 sampleModel.getWidth(),
70 sampleModel.getHeight()),
71 origin,
72 null);
73 }
74
75 /**
76 * Constructs a WritableRaster with the given SampleModel and DataBuffer.
77 * The WritableRaster's upper left corner is origin and it is the same
78 * size as the SampleModel. The DataBuffer is not initialized and must
79 * be compatible with SampleModel.
80 * @param sampleModel The SampleModel that specifies the layout.
81 * @param dataBuffer The DataBuffer that contains the image data.
82 * @param origin The Point that specifies the origin.
83 * @throws RasterFormatException if computing either
84 * <code>origin.x + sampleModel.getWidth()</code> or
85 * <code>origin.y + sampleModel.getHeight()</code> results
86 * in integer overflow
87 */
88 protected WritableRaster(SampleModel sampleModel,
89 DataBuffer dataBuffer,
90 Point origin) {
91 this(sampleModel,
92 dataBuffer,
93 new Rectangle(origin.x,
94 origin.y,
95 sampleModel.getWidth(),
96 sampleModel.getHeight()),
97 origin,
98 null);
99 }
100
101 /**
102 * Constructs a WritableRaster with the given SampleModel, DataBuffer,
103 * and parent. aRegion specifies the bounding rectangle of the new
104 * Raster. When translated into the base Raster's coordinate
105 * system, aRegion must be contained by the base Raster.
106 * (The base Raster is the Raster's ancestor which has no parent.)
107 * sampleModelTranslate specifies the sampleModelTranslateX and
108 * sampleModelTranslateY values of the new Raster.
109 *
110 * Note that this constructor should generally be called by other
111 * constructors or create methods, it should not be used directly.
112 * @param sampleModel The SampleModel that specifies the layout.
113 * @param dataBuffer The DataBuffer that contains the image data.
114 * @param aRegion The Rectangle that specifies the image area.
115 * @param sampleModelTranslate The Point that specifies the translation
116 * from SampleModel to Raster coordinates.
117 * @param parent The parent (if any) of this raster.
118 * @throws RasterFormatException if <code>aRegion</code> has width
119 * or height less than or equal to zero, or computing either
120 * <code>aRegion.x + aRegion.width</code> or
121 * <code>aRegion.y + aRegion.height</code> results in integer
122 * overflow
123 */
124 protected WritableRaster(SampleModel sampleModel,
125 DataBuffer dataBuffer,
126 Rectangle aRegion,
127 Point sampleModelTranslate,
128 WritableRaster parent){
129 super(sampleModel,dataBuffer,aRegion,sampleModelTranslate,parent);
130 }
131
132 /** Returns the parent WritableRaster (if any) of this WritableRaster,
133 * or else null.
134 * @return the parent of this <code>WritableRaster</code>, or
135 * <code>null</code>.
136 */
137 public WritableRaster getWritableParent() {
138 return (WritableRaster)parent;
139 }
140
141 /**
142 * Create a WritableRaster with the same size, SampleModel and DataBuffer
143 * as this one, but with a different location. The new WritableRaster
144 * will possess a reference to the current WritableRaster, accessible
145 * through its getParent() and getWritableParent() methods.
146 *
147 * @param childMinX X coord of the upper left corner of the new Raster.
148 * @param childMinY Y coord of the upper left corner of the new Raster.
149 * @return a <code>WritableRaster</code> the same as this one except
150 * for the specified location.
151 * @throws RasterFormatException if computing either
152 * <code>childMinX + this.getWidth()</code> or
153 * <code>childMinY + this.getHeight()</code> results in integer
154 * overflow
155 */
156 public WritableRaster createWritableTranslatedChild(int childMinX,
157 int childMinY) {
158 return createWritableChild(minX,minY,width,height,
159 childMinX,childMinY,null);
160 }
161
162 /**
163 * Returns a new WritableRaster which shares all or part of this
164 * WritableRaster's DataBuffer. The new WritableRaster will
165 * possess a reference to the current WritableRaster, accessible
166 * through its getParent() and getWritableParent() methods.
167 *
168 * <p> The parentX, parentY, width and height parameters form a
169 * Rectangle in this WritableRaster's coordinate space, indicating
170 * the area of pixels to be shared. An error will be thrown if
171 * this Rectangle is not contained with the bounds of the current
172 * WritableRaster.
173 *
174 * <p> The new WritableRaster may additionally be translated to a
175 * different coordinate system for the plane than that used by the current
176 * WritableRaster. The childMinX and childMinY parameters give
177 * the new (x, y) coordinate of the upper-left pixel of the
178 * returned WritableRaster; the coordinate (childMinX, childMinY)
179 * in the new WritableRaster will map to the same pixel as the
180 * coordinate (parentX, parentY) in the current WritableRaster.
181 *
182 * <p> The new WritableRaster may be defined to contain only a
183 * subset of the bands of the current WritableRaster, possibly
184 * reordered, by means of the bandList parameter. If bandList is
185 * null, it is taken to include all of the bands of the current
186 * WritableRaster in their current order.
187 *
188 * <p> To create a new WritableRaster that contains a subregion of
189 * the current WritableRaster, but shares its coordinate system
190 * and bands, this method should be called with childMinX equal to
191 * parentX, childMinY equal to parentY, and bandList equal to
192 * null.
193 *
194 * @param parentX X coordinate of the upper left corner in this
195 * WritableRaster's coordinates.
196 * @param parentY Y coordinate of the upper left corner in this
197 * WritableRaster's coordinates.
198 * @param w Width of the region starting at (parentX, parentY).
199 * @param h Height of the region starting at (parentX, parentY).
200 * @param childMinX X coordinate of the upper left corner of
201 * the returned WritableRaster.
202 * @param childMinY Y coordinate of the upper left corner of
203 * the returned WritableRaster.
204 * @param bandList Array of band indices, or null to use all bands.
205 * @return a <code>WritableRaster</code> sharing all or part of the
206 * <code>DataBuffer</code> of this <code>WritableRaster</code>.
207 * @exception RasterFormatException if the subregion is outside of the
208 * raster bounds.
209 * @throws RasterFormatException if <code>w</code> or
210 * <code>h</code>
211 * is less than or equal to zero, or computing any of
212 * <code>parentX + w</code>, <code>parentY + h</code>,
213 * <code>childMinX + w</code>, or
214 * <code>childMinY + h</code> results in integer
215 * overflow
216 */
217 public WritableRaster createWritableChild(int parentX, int parentY,
218 int w, int h,
219 int childMinX, int childMinY,
220 int bandList[]) {
221 if (parentX < this.minX) {
222 throw new RasterFormatException("parentX lies outside raster");
223 }
224 if (parentY < this.minY) {
225 throw new RasterFormatException("parentY lies outside raster");
226 }
227 if ((parentX+w < parentX) || (parentX+w > this.width + this.minX)) {
228 throw new RasterFormatException("(parentX + width) is outside raster");
229 }
230 if ((parentY+h < parentY) || (parentY+h > this.height + this.minY)) {
231 throw new RasterFormatException("(parentY + height) is outside raster");
232 }
233
234 SampleModel sm;
235 // Note: the SampleModel for the child Raster should have the same
236 // width and height as that for the parent, since it represents
237 // the physical layout of the pixel data. The child Raster's width
238 // and height represent a "virtual" view of the pixel data, so
239 // they may be different than those of the SampleModel.
240 if (bandList != null) {
241 sm = sampleModel.createSubsetSampleModel(bandList);
242 }
243 else {
244 sm = sampleModel;
245 }
246
247 int deltaX = childMinX - parentX;
248 int deltaY = childMinY - parentY;
249
250 return new WritableRaster(sm,
251 getDataBuffer(),
252 new Rectangle(childMinX,childMinY,
253 w, h),
254 new Point(sampleModelTranslateX+deltaX,
255 sampleModelTranslateY+deltaY),
256 this);
257 }
258
259 /**
260 * Sets the data for a single pixel from a
261 * primitive array of type TransferType. For image data supported by
262 * the Java 2D(tm) API, this will be one of DataBuffer.TYPE_BYTE,
263 * DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT,
264 * DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE. Data in the array
265 * may be in a packed format, thus increasing efficiency for data
266 * transfers.
267 * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
268 * not in bounds, or if inData is not large enough to hold the pixel data.
269 * However, explicit bounds checking is not guaranteed.
270 * A ClassCastException will be thrown if the input object is not null
271 * and references anything other than an array of TransferType.
272 * @see java.awt.image.SampleModel#setDataElements(int, int, Object, DataBuffer)
273 * @param x The X coordinate of the pixel location.
274 * @param y The Y coordinate of the pixel location.
275 * @param inData An object reference to an array of type defined by
276 * getTransferType() and length getNumDataElements()
277 * containing the pixel data to place at x,y.
278 *
279 * @throws ArrayIndexOutOfBoundsException if the coordinates are not
280 * in bounds, or if inData is too small to hold the input.
281 */
282 public void setDataElements(int x, int y, Object inData) {
283 sampleModel.setDataElements(x-sampleModelTranslateX,
284 y-sampleModelTranslateY,
285 inData, dataBuffer);
286 }
287
288 /**
289 * Sets the data for a rectangle of pixels from an input Raster.
290 * The input Raster must be compatible with this WritableRaster
291 * in that they must have the same number of bands, corresponding bands
292 * must have the same number of bits per sample, the TransferTypes
293 * and NumDataElements must be the same, and the packing used by
294 * the getDataElements/setDataElements must be identical.
295 * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
296 * not in bounds.
297 * However, explicit bounds checking is not guaranteed.
298 * @param x The X coordinate of the pixel location.
299 * @param y The Y coordinate of the pixel location.
300 * @param inRaster Raster containing data to place at x,y.
301 *
302 * @throws NullPointerException if inRaster is null.
303 * @throws ArrayIndexOutOfBoundsException if the coordinates are not
304 * in bounds.
305 */
306 public void setDataElements(int x, int y, Raster inRaster) {
307 int dstOffX = x+inRaster.getMinX();
308 int dstOffY = y+inRaster.getMinY();
309 int width = inRaster.getWidth();
310 int height = inRaster.getHeight();
311 if ((dstOffX < this.minX) || (dstOffY < this.minY) ||
312 (dstOffX + width > this.minX + this.width) ||
313 (dstOffY + height > this.minY + this.height)) {
314 throw new ArrayIndexOutOfBoundsException
315 ("Coordinate out of bounds!");
316 }
317
318 int srcOffX = inRaster.getMinX();
319 int srcOffY = inRaster.getMinY();
320 Object tdata = null;
321
322 for (int startY=0; startY < height; startY++) {
323 tdata = inRaster.getDataElements(srcOffX, srcOffY+startY,
324 width, 1, tdata);
325 setDataElements(dstOffX, dstOffY+startY,
326 width, 1, tdata);
327 }
328 }
329
330 /**
331 * Sets the data for a rectangle of pixels from a
332 * primitive array of type TransferType. For image data supported by
333 * the Java 2D API, this will be one of DataBuffer.TYPE_BYTE,
334 * DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT,
335 * DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE. Data in the array
336 * may be in a packed format, thus increasing efficiency for data
337 * transfers.
338 * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
339 * not in bounds, or if inData is not large enough to hold the pixel data.
340 * However, explicit bounds checking is not guaranteed.
341 * A ClassCastException will be thrown if the input object is not null
342 * and references anything other than an array of TransferType.
343 * @see java.awt.image.SampleModel#setDataElements(int, int, int, int, Object, DataBuffer)
344 * @param x The X coordinate of the upper left pixel location.
345 * @param y The Y coordinate of the upper left pixel location.
346 * @param w Width of the pixel rectangle.
347 * @param h Height of the pixel rectangle.
348 * @param inData An object reference to an array of type defined by
349 * getTransferType() and length w*h*getNumDataElements()
350 * containing the pixel data to place between x,y and
351 * x+w-1, y+h-1.
352 *
353 * @throws NullPointerException if inData is null.
354 * @throws ArrayIndexOutOfBoundsException if the coordinates are not
355 * in bounds, or if inData is too small to hold the input.
356 */
357 public void setDataElements(int x, int y, int w, int h, Object inData) {
358 sampleModel.setDataElements(x-sampleModelTranslateX,
359 y-sampleModelTranslateY,
360 w,h,inData,dataBuffer);
361 }
362
363 /**
364 * Copies pixels from Raster srcRaster to this WritableRaster. Each pixel
365 * in srcRaster is copied to the same x,y address in this raster, unless
366 * the address falls outside the bounds of this raster. srcRaster
367 * must have the same number of bands as this WritableRaster. The
368 * copy is a simple copy of source samples to the corresponding destination
369 * samples.
370 * <p>
371 * If all samples of both source and destination Rasters are of
372 * integral type and less than or equal to 32 bits in size, then calling
373 * this method is equivalent to executing the following code for all
374 * <code>x,y</code> addresses valid in both Rasters.
375 * <pre>
376 * Raster srcRaster;
377 * WritableRaster dstRaster;
378 * for (int b = 0; b < srcRaster.getNumBands(); b++) {
379 * dstRaster.setSample(x, y, b, srcRaster.getSample(x, y, b));
380 * }
381 * </pre>
382 * Thus, when copying an integral type source to an integral type
383 * destination, if the source sample size is greater than the destination
384 * sample size for a particular band, the high order bits of the source
385 * sample are truncated. If the source sample size is less than the
386 * destination size for a particular band, the high order bits of the
387 * destination are zero-extended or sign-extended depending on whether
388 * srcRaster's SampleModel treats the sample as a signed or unsigned
389 * quantity.
390 * <p>
391 * When copying a float or double source to an integral type destination,
392 * each source sample is cast to the destination type. When copying an
393 * integral type source to a float or double destination, the source
394 * is first converted to a 32-bit int (if necessary), using the above
395 * rules for integral types, and then the int is cast to float or
396 * double.
397 * <p>
398 * @param srcRaster The Raster from which to copy pixels.
399 *
400 * @throws NullPointerException if srcRaster is null.
401 */
402 public void setRect(Raster srcRaster) {
403 setRect(0,0,srcRaster);
404 }
405
406 /**
407 * Copies pixels from Raster srcRaster to this WritableRaster.
408 * For each (x, y) address in srcRaster, the corresponding pixel
409 * is copied to address (x+dx, y+dy) in this WritableRaster,
410 * unless (x+dx, y+dy) falls outside the bounds of this raster.
411 * srcRaster must have the same number of bands as this WritableRaster.
412 * The copy is a simple copy of source samples to the corresponding
413 * destination samples. For details, see
414 * {@link WritableRaster#setRect(Raster)}.
415 *
416 * @param dx The X translation factor from src space to dst space
417 * of the copy.
418 * @param dy The Y translation factor from src space to dst space
419 * of the copy.
420 * @param srcRaster The Raster from which to copy pixels.
421 *
422 * @throws NullPointerException if srcRaster is null.
423 */
424 public void setRect(int dx, int dy, Raster srcRaster) {
425 int width = srcRaster.getWidth();
426 int height = srcRaster.getHeight();
427 int srcOffX = srcRaster.getMinX();
428 int srcOffY = srcRaster.getMinY();
429 int dstOffX = dx+srcOffX;
430 int dstOffY = dy+srcOffY;
431
432 // Clip to this raster
433 if (dstOffX < this.minX) {
434 int skipX = this.minX - dstOffX;
435 width -= skipX;
436 srcOffX += skipX;
437 dstOffX = this.minX;
438 }
439 if (dstOffY < this.minY) {
440 int skipY = this.minY - dstOffY;
441 height -= skipY;
442 srcOffY += skipY;
443 dstOffY = this.minY;
444 }
445 if (dstOffX+width > this.minX+this.width) {
446 width = this.minX + this.width - dstOffX;
447 }
448 if (dstOffY+height > this.minY+this.height) {
449 height = this.minY + this.height - dstOffY;
450 }
451
452 if (width <= 0 || height <= 0) {
453 return;
454 }
455
456 switch (srcRaster.getSampleModel().getDataType()) {
457 case DataBuffer.TYPE_BYTE:
458 case DataBuffer.TYPE_SHORT:
459 case DataBuffer.TYPE_USHORT:
460 case DataBuffer.TYPE_INT:
461 int[] iData = null;
462 for (int startY=0; startY < height; startY++) {
463 // Grab one scanline at a time
464 iData =
465 srcRaster.getPixels(srcOffX, srcOffY+startY, width, 1,
466 iData);
467 setPixels(dstOffX, dstOffY+startY, width, 1, iData);
468 }
469 break;
470
471 case DataBuffer.TYPE_FLOAT:
472 float[] fData = null;
473 for (int startY=0; startY < height; startY++) {
474 fData =
475 srcRaster.getPixels(srcOffX, srcOffY+startY, width, 1,
476 fData);
477 setPixels(dstOffX, dstOffY+startY, width, 1, fData);
478 }
479 break;
480
481 case DataBuffer.TYPE_DOUBLE:
482 double[] dData = null;
483 for (int startY=0; startY < height; startY++) {
484 // Grab one scanline at a time
485 dData =
486 srcRaster.getPixels(srcOffX, srcOffY+startY, width, 1,
487 dData);
488 setPixels(dstOffX, dstOffY+startY, width, 1, dData);
489 }
490 break;
491 }
492 }
493
494 /**
495 * Sets a pixel in the DataBuffer using an int array of samples for input.
496 * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
497 * not in bounds.
498 * However, explicit bounds checking is not guaranteed.
499 * @param x The X coordinate of the pixel location.
500 * @param y The Y coordinate of the pixel location.
501 * @param iArray The input samples in a int array.
502 *
503 * @throws NullPointerException if iArray is null.
504 * @throws ArrayIndexOutOfBoundsException if the coordinates are not
505 * in bounds, or if iArray is too small to hold the input.
506 */
507 public void setPixel(int x, int y, int iArray[]) {
508 sampleModel.setPixel(x-sampleModelTranslateX,y-sampleModelTranslateY,
509 iArray,dataBuffer);
510 }
511
512 /**
513 * Sets a pixel in the DataBuffer using a float array of samples for input.
514 * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
515 * not in bounds.
516 * However, explicit bounds checking is not guaranteed.
517 * @param x The X coordinate of the pixel location.
518 * @param y The Y coordinate of the pixel location.
519 * @param fArray The input samples in a float array.
520 *
521 * @throws NullPointerException if fArray is null.
522 * @throws ArrayIndexOutOfBoundsException if the coordinates are not
523 * in bounds, or if fArray is too small to hold the input.
524 */
525 public void setPixel(int x, int y, float fArray[]) {
526 sampleModel.setPixel(x-sampleModelTranslateX,y-sampleModelTranslateY,
527 fArray,dataBuffer);
528 }
529
530 /**
531 * Sets a pixel in the DataBuffer using a double array of samples for input.
532 * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
533 * not in bounds.
534 * However, explicit bounds checking is not guaranteed.
535 * @param x The X coordinate of the pixel location.
536 * @param y The Y coordinate of the pixel location.
537 * @param dArray The input samples in a double array.
538 *
539 * @throws NullPointerException if dArray is null.
540 * @throws ArrayIndexOutOfBoundsException if the coordinates are not
541 * in bounds, or if dArray is too small to hold the input.
542 */
543 public void setPixel(int x, int y, double dArray[]) {
544 sampleModel.setPixel(x-sampleModelTranslateX,y-sampleModelTranslateY,
545 dArray,dataBuffer);
546 }
547
548 /**
549 * Sets all samples for a rectangle of pixels from an int array containing
550 * one sample per array element.
551 * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
552 * not in bounds.
553 * However, explicit bounds checking is not guaranteed.
554 * @param x The X coordinate of the upper left pixel location.
555 * @param y The Y coordinate of the upper left pixel location.
556 * @param w Width of the pixel rectangle.
557 * @param h Height of the pixel rectangle.
558 * @param iArray The input int pixel array.
559 *
560 * @throws NullPointerException if iArray is null.
561 * @throws ArrayIndexOutOfBoundsException if the coordinates are not
562 * in bounds, or if iArray is too small to hold the input.
563 */
564 public void setPixels(int x, int y, int w, int h, int iArray[]) {
565 sampleModel.setPixels(x-sampleModelTranslateX,y-sampleModelTranslateY,
566 w,h,iArray,dataBuffer);
567 }
568
569 /**
570 * Sets all samples for a rectangle of pixels from a float array containing
571 * one sample per array element.
572 * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
573 * not in bounds.
574 * However, explicit bounds checking is not guaranteed.
575 * @param x The X coordinate of the upper left pixel location.
576 * @param y The Y coordinate of the upper left pixel location.
577 * @param w Width of the pixel rectangle.
578 * @param h Height of the pixel rectangle.
579 * @param fArray The input float pixel array.
580 *
581 * @throws NullPointerException if fArray is null.
582 * @throws ArrayIndexOutOfBoundsException if the coordinates are not
583 * in bounds, or if fArray is too small to hold the input.
584 */
585 public void setPixels(int x, int y, int w, int h, float fArray[]) {
586 sampleModel.setPixels(x-sampleModelTranslateX,y-sampleModelTranslateY,
587 w,h,fArray,dataBuffer);
588 }
589
590 /**
591 * Sets all samples for a rectangle of pixels from a double array containing
592 * one sample per array element.
593 * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
594 * not in bounds.
595 * However, explicit bounds checking is not guaranteed.
596 * @param x The X coordinate of the upper left pixel location.
597 * @param y The Y coordinate of the upper left pixel location.
598 * @param w Width of the pixel rectangle.
599 * @param h Height of the pixel rectangle.
600 * @param dArray The input double pixel array.
601 *
602 * @throws NullPointerException if dArray is null.
603 * @throws ArrayIndexOutOfBoundsException if the coordinates are not
604 * in bounds, or if dArray is too small to hold the input.
605 */
606 public void setPixels(int x, int y, int w, int h, double dArray[]) {
607 sampleModel.setPixels(x-sampleModelTranslateX,y-sampleModelTranslateY,
608 w,h,dArray,dataBuffer);
609 }
610
611 /**
612 * Sets a sample in the specified band for the pixel located at (x,y)
613 * in the DataBuffer using an int for input.
614 * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
615 * not in bounds.
616 * However, explicit bounds checking is not guaranteed.
617 * @param x The X coordinate of the pixel location.
618 * @param y The Y coordinate of the pixel location.
619 * @param b The band to set.
620 * @param s The input sample.
621 *
622 * @throws ArrayIndexOutOfBoundsException if the coordinates or
623 * the band index are not in bounds.
624 */
625 public void setSample(int x, int y, int b, int s) {
626 sampleModel.setSample(x-sampleModelTranslateX,
627 y-sampleModelTranslateY, b, s,
628 dataBuffer);
629 }
630
631 /**
632 * Sets a sample in the specified band for the pixel located at (x,y)
633 * in the DataBuffer using a float for input.
634 * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
635 * not in bounds.
636 * However, explicit bounds checking is not guaranteed.
637 * @param x The X coordinate of the pixel location.
638 * @param y The Y coordinate of the pixel location.
639 * @param b The band to set.
640 * @param s The input sample as a float.
641 *
642 * @throws ArrayIndexOutOfBoundsException if the coordinates or
643 * the band index are not in bounds.
644 */
645 public void setSample(int x, int y, int b, float s){
646 sampleModel.setSample(x-sampleModelTranslateX,y-sampleModelTranslateY,
647 b,s,dataBuffer);
648 }
649
650 /**
651 * Sets a sample in the specified band for the pixel located at (x,y)
652 * in the DataBuffer using a double for input.
653 * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
654 * not in bounds.
655 * However, explicit bounds checking is not guaranteed.
656 * @param x The X coordinate of the pixel location.
657 * @param y The Y coordinate of the pixel location.
658 * @param b The band to set.
659 * @param s The input sample as a double.
660 *
661 * @throws ArrayIndexOutOfBoundsException if the coordinates or
662 * the band index are not in bounds.
663 */
664 public void setSample(int x, int y, int b, double s){
665 sampleModel.setSample(x-sampleModelTranslateX,y-sampleModelTranslateY,
666 b,s,dataBuffer);
667 }
668
669 /**
670 * Sets the samples in the specified band for the specified rectangle
671 * of pixels from an int array containing one sample per array element.
672 * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
673 * not in bounds.
674 * However, explicit bounds checking is not guaranteed.
675 * @param x The X coordinate of the upper left pixel location.
676 * @param y The Y coordinate of the upper left pixel location.
677 * @param w Width of the pixel rectangle.
678 * @param h Height of the pixel rectangle.
679 * @param b The band to set.
680 * @param iArray The input int sample array.
681 *
682 * @throws NullPointerException if iArray is null.
683 * @throws ArrayIndexOutOfBoundsException if the coordinates or
684 * the band index are not in bounds, or if iArray is too small to
685 * hold the input.
686 */
687 public void setSamples(int x, int y, int w, int h, int b,
688 int iArray[]) {
689 sampleModel.setSamples(x-sampleModelTranslateX,y-sampleModelTranslateY,
690 w,h,b,iArray,dataBuffer);
691 }
692
693 /**
694 * Sets the samples in the specified band for the specified rectangle
695 * of pixels from a float array containing one sample per array element.
696 * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
697 * not in bounds.
698 * However, explicit bounds checking is not guaranteed.
699 * @param x The X coordinate of the upper left pixel location.
700 * @param y The Y coordinate of the upper left pixel location.
701 * @param w Width of the pixel rectangle.
702 * @param h Height of the pixel rectangle.
703 * @param b The band to set.
704 * @param fArray The input float sample array.
705 *
706 * @throws NullPointerException if fArray is null.
707 * @throws ArrayIndexOutOfBoundsException if the coordinates or
708 * the band index are not in bounds, or if fArray is too small to
709 * hold the input.
710 */
711 public void setSamples(int x, int y, int w, int h, int b,
712 float fArray[]) {
713 sampleModel.setSamples(x-sampleModelTranslateX,y-sampleModelTranslateY,
714 w,h,b,fArray,dataBuffer);
715 }
716
717 /**
718 * Sets the samples in the specified band for the specified rectangle
719 * of pixels from a double array containing one sample per array element.
720 * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
721 * not in bounds.
722 * However, explicit bounds checking is not guaranteed.
723 * @param x The X coordinate of the upper left pixel location.
724 * @param y The Y coordinate of the upper left pixel location.
725 * @param w Width of the pixel rectangle.
726 * @param h Height of the pixel rectangle.
727 * @param b The band to set.
728 * @param dArray The input double sample array.
729 *
730 * @throws NullPointerException if dArray is null.
731 * @throws ArrayIndexOutOfBoundsException if the coordinates or
732 * the band index are not in bounds, or if dArray is too small to
733 * hold the input.
734 */
735 public void setSamples(int x, int y, int w, int h, int b,
736 double dArray[]) {
737 sampleModel.setSamples(x-sampleModelTranslateX,y-sampleModelTranslateY,
738 w,h,b,dArray,dataBuffer);
739 }
740
741 }