KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > image > WritableRaster


1 /*
2  * @(#)WritableRaster.java 1.48 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 /* ****************************************************************
9  ******************************************************************
10  ******************************************************************
11  *** COPYRIGHT (c) Eastman Kodak Company, 1997
12  *** As an unpublished work pursuant to Title 17 of the United
13  *** States Code. All rights reserved.
14  ******************************************************************
15  ******************************************************************
16  ******************************************************************/

17
18 package java.awt.image;
19 import java.awt.Rectangle JavaDoc;
20 import java.awt.Point JavaDoc;
21
22 /**
23  * This class extends Raster to provide pixel writing capabilities.
24  * Refer to the class comment for Raster for descriptions of how
25  * a Raster stores pixels.
26  *
27  * <p> The constructors of this class are protected. To instantiate
28  * a WritableRaster, use one of the createWritableRaster factory methods
29  * in the Raster class.
30  */

31 public class WritableRaster extends Raster JavaDoc {
32
33     /**
34      * Constructs a WritableRaster with the given SampleModel. The
35      * WritableRaster's upper left corner is origin and it is the
36      * same size as the SampleModel. A DataBuffer large enough to
37      * describe the WritableRaster is automatically created.
38      * @param sampleModel The SampleModel that specifies the layout.
39      * @param origin The Point that specifies the origin.
40      * @throws RasterFormatException if computing either
41      * <code>origin.x + sampleModel.getWidth()</code> or
42      * <code>origin.y + sampleModel.getHeight()</code> results
43      * in integer overflow
44      */

45     protected WritableRaster(SampleModel JavaDoc sampleModel,
46                              Point JavaDoc origin) {
47         this(sampleModel,
48              sampleModel.createDataBuffer(),
49              new Rectangle JavaDoc(origin.x,
50                            origin.y,
51                            sampleModel.getWidth(),
52                            sampleModel.getHeight()),
53              origin,
54              null);
55     }
56
57     /**
58      * Constructs a WritableRaster with the given SampleModel and DataBuffer.
59      * The WritableRaster's upper left corner is origin and it is the same
60      * size as the SampleModel. The DataBuffer is not initialized and must
61      * be compatible with SampleModel.
62      * @param sampleModel The SampleModel that specifies the layout.
63      * @param dataBuffer The DataBuffer that contains the image data.
64      * @param origin The Point that specifies the origin.
65      * @throws RasterFormatException if computing either
66      * <code>origin.x + sampleModel.getWidth()</code> or
67      * <code>origin.y + sampleModel.getHeight()</code> results
68      * in integer overflow
69      */

70     protected WritableRaster(SampleModel JavaDoc sampleModel,
71                              DataBuffer JavaDoc dataBuffer,
72                              Point JavaDoc origin) {
73         this(sampleModel,
74              dataBuffer,
75              new Rectangle JavaDoc(origin.x,
76                            origin.y,
77                            sampleModel.getWidth(),
78                            sampleModel.getHeight()),
79              origin,
80              null);
81     }
82
83     /**
84      * Constructs a WritableRaster with the given SampleModel, DataBuffer,
85      * and parent. aRegion specifies the bounding rectangle of the new
86      * Raster. When translated into the base Raster's coordinate
87      * system, aRegion must be contained by the base Raster.
88      * (The base Raster is the Raster's ancestor which has no parent.)
89      * sampleModelTranslate specifies the sampleModelTranslateX and
90      * sampleModelTranslateY values of the new Raster.
91      *
92      * Note that this constructor should generally be called by other
93      * constructors or create methods, it should not be used directly.
94      * @param sampleModel The SampleModel that specifies the layout.
95      * @param dataBuffer The DataBuffer that contains the image data.
96      * @param aRegion The Rectangle that specifies the image area.
97      * @param sampleModelTranslate The Point that specifies the translation
98      * from SampleModel to Raster coordinates.
99      * @param parent The parent (if any) of this raster.
100      * @throws RasterFormatException if <code>aRegion</code> has width
101      * or height less than or equal to zero, or computing either
102      * <code>aRegion.x + aRegion.width</code> or
103      * <code>aRegion.y + aRegion.height</code> results in integer
104      * overflow
105      */

106     protected WritableRaster(SampleModel JavaDoc sampleModel,
107                              DataBuffer JavaDoc dataBuffer,
108                              Rectangle JavaDoc aRegion,
109                              Point JavaDoc sampleModelTranslate,
110                              WritableRaster JavaDoc parent){
111         super(sampleModel,dataBuffer,aRegion,sampleModelTranslate,parent);
112     }
113
114     /** Returns the parent WritableRaster (if any) of this WritableRaster,
115      * or else null.
116      * @return the parent of this <code>WritableRaster</code>, or
117      * <code>null</code>.
118      */

119     public WritableRaster JavaDoc getWritableParent() {
120         return (WritableRaster JavaDoc)parent;
121     }
122
123     /**
124      * Create a WritableRaster with the same size, SampleModel and DataBuffer
125      * as this one, but with a different location. The new WritableRaster
126      * will possess a reference to the current WritableRaster, accessible
127      * through its getParent() and getWritableParent() methods.
128      *
129      * @param childMinX X coord of the upper left corner of the new Raster.
130      * @param childMinY Y coord of the upper left corner of the new Raster.
131      * @return a <code>WritableRaster</code> the same as this one except
132      * for the specified location.
133      * @throws RasterFormatException if computing either
134      * <code>childMinX + this.getWidth()</code> or
135      * <code>childMinY + this.getHeight()</code> results in integer
136      * overflow
137      */

138     public WritableRaster JavaDoc createWritableTranslatedChild(int childMinX,
139                                                         int childMinY) {
140         return createWritableChild(minX,minY,width,height,
141                                    childMinX,childMinY,null);
142     }
143
144     /**
145      * Returns a new WritableRaster which shares all or part of this
146      * WritableRaster's DataBuffer. The new WritableRaster will
147      * possess a reference to the current WritableRaster, accessible
148      * through its getParent() and getWritableParent() methods.
149      *
150      * <p> The parentX, parentY, width and height parameters form a
151      * Rectangle in this WritableRaster's coordinate space, indicating
152      * the area of pixels to be shared. An error will be thrown if
153      * this Rectangle is not contained with the bounds of the current
154      * WritableRaster.
155      *
156      * <p> The new WritableRaster may additionally be translated to a
157      * different coordinate system for the plane than that used by the current
158      * WritableRaster. The childMinX and childMinY parameters give
159      * the new (x, y) coordinate of the upper-left pixel of the
160      * returned WritableRaster; the coordinate (childMinX, childMinY)
161      * in the new WritableRaster will map to the same pixel as the
162      * coordinate (parentX, parentY) in the current WritableRaster.
163      *
164      * <p> The new WritableRaster may be defined to contain only a
165      * subset of the bands of the current WritableRaster, possibly
166      * reordered, by means of the bandList parameter. If bandList is
167      * null, it is taken to include all of the bands of the current
168      * WritableRaster in their current order.
169      *
170      * <p> To create a new WritableRaster that contains a subregion of
171      * the current WritableRaster, but shares its coordinate system
172      * and bands, this method should be called with childMinX equal to
173      * parentX, childMinY equal to parentY, and bandList equal to
174      * null.
175      *
176      * @param parentX X coordinate of the upper left corner in this
177      * WritableRaster's coordinates.
178      * @param parentY Y coordinate of the upper left corner in this
179      * WritableRaster's coordinates.
180      * @param w Width of the region starting at (parentX, parentY).
181      * @param h Height of the region starting at (parentX, parentY).
182      * @param childMinX X coordinate of the upper left corner of
183      * the returned WritableRaster.
184      * @param childMinY Y coordinate of the upper left corner of
185      * the returned WritableRaster.
186      * @param bandList Array of band indices, or null to use all bands.
187      * @return a <code>WritableRaster</code> sharing all or part of the
188      * <code>DataBuffer</code> of this <code>WritableRaster</code>.
189      * @exception RasterFormatException if the subregion is outside of the
190      * raster bounds.
191      * @throws RasterFormatException if <code>w</code> or
192      * <code>h</code>
193      * is less than or equal to zero, or computing any of
194      * <code>parentX + w</code>, <code>parentY + h</code>,
195      * <code>childMinX + w</code>, or
196      * <code>childMinY + h</code> results in integer
197      * overflow
198      */

199     public WritableRaster JavaDoc createWritableChild(int parentX, int parentY,
200                                               int w, int h,
201                                               int childMinX, int childMinY,
202                                               int bandList[]) {
203         if (parentX < this.minX) {
204             throw new RasterFormatException JavaDoc("parentX lies outside raster");
205         }
206         if (parentY < this.minY) {
207             throw new RasterFormatException JavaDoc("parentY lies outside raster");
208         }
209         if ((parentX+w < parentX) || (parentX+w > this.width + this.minX)) {
210             throw new RasterFormatException JavaDoc("(parentX + width) is outside raster");
211         }
212         if ((parentY+h < parentY) || (parentY+h > this.height + this.minY)) {
213             throw new RasterFormatException JavaDoc("(parentY + height) is outside raster");
214         }
215
216         SampleModel JavaDoc sm;
217         // Note: the SampleModel for the child Raster should have the same
218
// width and height as that for the parent, since it represents
219
// the physical layout of the pixel data. The child Raster's width
220
// and height represent a "virtual" view of the pixel data, so
221
// they may be different than those of the SampleModel.
222
if (bandList != null) {
223             sm = sampleModel.createSubsetSampleModel(bandList);
224         }
225         else {
226             sm = sampleModel;
227         }
228
229         int deltaX = childMinX - parentX;
230         int deltaY = childMinY - parentY;
231
232         // we use getDataBuffer() here, which will ensure that notifyStolen()
233
// is invoked if this is a SunWritableRaster, thus disabling future
234
// acceleration of this WritableRaster
235
return new WritableRaster JavaDoc(sm,
236                                   getDataBuffer(),
237                                   new Rectangle JavaDoc(childMinX,childMinY,
238                                                 w, h),
239                                   new Point JavaDoc(sampleModelTranslateX+deltaX,
240                                             sampleModelTranslateY+deltaY),
241                                   this);
242     }
243
244     /**
245      * Sets the data for a single pixel from a
246      * primitive array of type TransferType. For image data supported by
247      * the Java 2D(tm) API, this will be one of DataBuffer.TYPE_BYTE,
248      * DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT,
249      * DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE. Data in the array
250      * may be in a packed format, thus increasing efficiency for data
251      * transfers.
252      * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
253      * not in bounds, or if inData is not large enough to hold the pixel data.
254      * However, explicit bounds checking is not guaranteed.
255      * A ClassCastException will be thrown if the input object is not null
256      * and references anything other than an array of TransferType.
257      * @see java.awt.image.SampleModel#setDataElements(int, int, Object, DataBuffer)
258      * @param x The X coordinate of the pixel location.
259      * @param y The Y coordinate of the pixel location.
260      * @param inData An object reference to an array of type defined by
261      * getTransferType() and length getNumDataElements()
262      * containing the pixel data to place at x,y.
263      *
264      * @throws ArrayIndexOutOfBoundsException if the coordinates are not
265      * in bounds, or if inData is too small to hold the input.
266      */

267     public void setDataElements(int x, int y, Object JavaDoc inData) {
268         sampleModel.setDataElements(x-sampleModelTranslateX,
269                                     y-sampleModelTranslateY,
270                                     inData, dataBuffer);
271     }
272
273     /**
274      * Sets the data for a rectangle of pixels from an input Raster.
275      * The input Raster must be compatible with this WritableRaster
276      * in that they must have the same number of bands, corresponding bands
277      * must have the same number of bits per sample, the TransferTypes
278      * and NumDataElements must be the same, and the packing used by
279      * the getDataElements/setDataElements must be identical.
280      * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
281      * not in bounds.
282      * However, explicit bounds checking is not guaranteed.
283      * @param x The X coordinate of the pixel location.
284      * @param y The Y coordinate of the pixel location.
285      * @param inRaster Raster containing data to place at x,y.
286      *
287      * @throws NullPointerException if inRaster is null.
288      * @throws ArrayIndexOutOfBoundsException if the coordinates are not
289      * in bounds.
290      */

291     public void setDataElements(int x, int y, Raster JavaDoc inRaster) {
292         int dstOffX = x+inRaster.getMinX();
293         int dstOffY = y+inRaster.getMinY();
294         int width = inRaster.getWidth();
295         int height = inRaster.getHeight();
296         if ((dstOffX < this.minX) || (dstOffY < this.minY) ||
297             (dstOffX + width > this.minX + this.width) ||
298             (dstOffY + height > this.minY + this.height)) {
299             throw new ArrayIndexOutOfBoundsException JavaDoc
300                 ("Coordinate out of bounds!");
301         }
302
303         int srcOffX = inRaster.getMinX();
304         int srcOffY = inRaster.getMinY();
305         Object JavaDoc tdata = null;
306
307         for (int startY=0; startY < height; startY++) {
308             tdata = inRaster.getDataElements(srcOffX, srcOffY+startY,
309                                              width, 1, tdata);
310             setDataElements(dstOffX, dstOffY+startY,
311                             width, 1, tdata);
312         }
313     }
314
315     /**
316      * Sets the data for a rectangle of pixels from a
317      * primitive array of type TransferType. For image data supported by
318      * the Java 2D API, this will be one of DataBuffer.TYPE_BYTE,
319      * DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT,
320      * DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE. Data in the array
321      * may be in a packed format, thus increasing efficiency for data
322      * transfers.
323      * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
324      * not in bounds, or if inData is not large enough to hold the pixel data.
325      * However, explicit bounds checking is not guaranteed.
326      * A ClassCastException will be thrown if the input object is not null
327      * and references anything other than an array of TransferType.
328      * @see java.awt.image.SampleModel#setDataElements(int, int, int, int, Object, DataBuffer)
329      * @param x The X coordinate of the upper left pixel location.
330      * @param y The Y coordinate of the upper left pixel location.
331      * @param w Width of the pixel rectangle.
332      * @param h Height of the pixel rectangle.
333      * @param inData An object reference to an array of type defined by
334      * getTransferType() and length w*h*getNumDataElements()
335      * containing the pixel data to place between x,y and
336      * x+w-1, y+h-1.
337      *
338      * @throws NullPointerException if inData is null.
339      * @throws ArrayIndexOutOfBoundsException if the coordinates are not
340      * in bounds, or if inData is too small to hold the input.
341      */

342     public void setDataElements(int x, int y, int w, int h, Object JavaDoc inData) {
343         sampleModel.setDataElements(x-sampleModelTranslateX,
344                                     y-sampleModelTranslateY,
345                                     w,h,inData,dataBuffer);
346     }
347
348     /**
349      * Copies pixels from Raster srcRaster to this WritableRaster. Each pixel
350      * in srcRaster is copied to the same x,y address in this raster, unless
351      * the address falls outside the bounds of this raster. srcRaster
352      * must have the same number of bands as this WritableRaster. The
353      * copy is a simple copy of source samples to the corresponding destination
354      * samples.
355      * <p>
356      * If all samples of both source and destination Rasters are of
357      * integral type and less than or equal to 32 bits in size, then calling
358      * this method is equivalent to executing the following code for all
359      * <code>x,y</code> addresses valid in both Rasters.
360      * <pre>
361      * Raster srcRaster;
362      * WritableRaster dstRaster;
363      * for (int b = 0; b < srcRaster.getNumBands(); b++) {
364      * dstRaster.setSample(x, y, b, srcRaster.getSample(x, y, b));
365      * }
366      * </pre>
367      * Thus, when copying an integral type source to an integral type
368      * destination, if the source sample size is greater than the destination
369      * sample size for a particular band, the high order bits of the source
370      * sample are truncated. If the source sample size is less than the
371      * destination size for a particular band, the high order bits of the
372      * destination are zero-extended or sign-extended depending on whether
373      * srcRaster's SampleModel treats the sample as a signed or unsigned
374      * quantity.
375      * <p>
376      * When copying a float or double source to an integral type destination,
377      * each source sample is cast to the destination type. When copying an
378      * integral type source to a float or double destination, the source
379      * is first converted to a 32-bit int (if necessary), using the above
380      * rules for integral types, and then the int is cast to float or
381      * double.
382      * <p>
383      * @param srcRaster The Raster from which to copy pixels.
384      *
385      * @throws NullPointerException if srcRaster is null.
386      */

387     public void setRect(Raster JavaDoc srcRaster) {
388         setRect(0,0,srcRaster);
389     }
390
391     /**
392      * Copies pixels from Raster srcRaster to this WritableRaster.
393      * For each (x, y) address in srcRaster, the corresponding pixel
394      * is copied to address (x+dx, y+dy) in this WritableRaster,
395      * unless (x+dx, y+dy) falls outside the bounds of this raster.
396      * srcRaster must have the same number of bands as this WritableRaster.
397      * The copy is a simple copy of source samples to the corresponding
398      * destination samples. For details, see
399      * {@link WritableRaster#setRect(Raster)}.
400      *
401      * @param dx The X translation factor from src space to dst space
402      * of the copy.
403      * @param dy The Y translation factor from src space to dst space
404      * of the copy.
405      * @param srcRaster The Raster from which to copy pixels.
406      *
407      * @throws NullPointerException if srcRaster is null.
408      */

409     public void setRect(int dx, int dy, Raster JavaDoc srcRaster) {
410         int width = srcRaster.getWidth();
411         int height = srcRaster.getHeight();
412         int srcOffX = srcRaster.getMinX();
413         int srcOffY = srcRaster.getMinY();
414         int dstOffX = dx+srcOffX;
415         int dstOffY = dy+srcOffY;
416
417         // Clip to this raster
418
if (dstOffX < this.minX) {
419             int skipX = this.minX - dstOffX;
420             width -= skipX;
421             srcOffX += skipX;
422             dstOffX = this.minX;
423         }
424         if (dstOffY < this.minY) {
425             int skipY = this.minY - dstOffY;
426             height -= skipY;
427             srcOffY += skipY;
428             dstOffY = this.minY;
429         }
430         if (dstOffX+width > this.minX+this.width) {
431             width = this.minX + this.width - dstOffX;
432         }
433         if (dstOffY+height > this.minY+this.height) {
434             height = this.minY + this.height - dstOffY;
435         }
436
437         if (width <= 0 || height <= 0) {
438             return;
439         }
440
441         switch (srcRaster.getSampleModel().getDataType()) {
442         case DataBuffer.TYPE_BYTE:
443         case DataBuffer.TYPE_SHORT:
444         case DataBuffer.TYPE_USHORT:
445         case DataBuffer.TYPE_INT:
446             int[] iData = null;
447             for (int startY=0; startY < height; startY++) {
448                 // Grab one scanline at a time
449
iData =
450                     srcRaster.getPixels(srcOffX, srcOffY+startY, width, 1,
451                                         iData);
452                 setPixels(dstOffX, dstOffY+startY, width, 1, iData);
453             }
454             break;
455
456         case DataBuffer.TYPE_FLOAT:
457             float[] fData = null;
458             for (int startY=0; startY < height; startY++) {
459                 fData =
460                     srcRaster.getPixels(srcOffX, srcOffY+startY, width, 1,
461                                         fData);
462                 setPixels(dstOffX, dstOffY+startY, width, 1, fData);
463             }
464             break;
465
466         case DataBuffer.TYPE_DOUBLE:
467             double[] dData = null;
468             for (int startY=0; startY < height; startY++) {
469                 // Grab one scanline at a time
470
dData =
471                     srcRaster.getPixels(srcOffX, srcOffY+startY, width, 1,
472                                         dData);
473                 setPixels(dstOffX, dstOffY+startY, width, 1, dData);
474             }
475             break;
476         }
477     }
478
479     /**
480      * Sets a pixel in the DataBuffer using an int array of samples for input.
481      * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
482      * not in bounds.
483      * However, explicit bounds checking is not guaranteed.
484      * @param x The X coordinate of the pixel location.
485      * @param y The Y coordinate of the pixel location.
486      * @param iArray The input samples in a int array.
487      *
488      * @throws NullPointerException if iArray is null.
489      * @throws ArrayIndexOutOfBoundsException if the coordinates are not
490      * in bounds, or if iArray is too small to hold the input.
491      */

492     public void setPixel(int x, int y, int iArray[]) {
493         sampleModel.setPixel(x-sampleModelTranslateX,y-sampleModelTranslateY,
494                              iArray,dataBuffer);
495     }
496
497     /**
498      * Sets a pixel in the DataBuffer using a float array of samples for input.
499      * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
500      * not in bounds.
501      * However, explicit bounds checking is not guaranteed.
502      * @param x The X coordinate of the pixel location.
503      * @param y The Y coordinate of the pixel location.
504      * @param fArray The input samples in a float array.
505      *
506      * @throws NullPointerException if fArray is null.
507      * @throws ArrayIndexOutOfBoundsException if the coordinates are not
508      * in bounds, or if fArray is too small to hold the input.
509      */

510     public void setPixel(int x, int y, float fArray[]) {
511         sampleModel.setPixel(x-sampleModelTranslateX,y-sampleModelTranslateY,
512                  fArray,dataBuffer);
513     }
514
515     /**
516      * Sets a pixel in the DataBuffer using a double array of samples for input.
517      * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
518      * not in bounds.
519      * However, explicit bounds checking is not guaranteed.
520      * @param x The X coordinate of the pixel location.
521      * @param y The Y coordinate of the pixel location.
522      * @param dArray The input samples in a double array.
523      *
524      * @throws NullPointerException if dArray is null.
525      * @throws ArrayIndexOutOfBoundsException if the coordinates are not
526      * in bounds, or if dArray is too small to hold the input.
527      */

528     public void setPixel(int x, int y, double dArray[]) {
529         sampleModel.setPixel(x-sampleModelTranslateX,y-sampleModelTranslateY,
530                  dArray,dataBuffer);
531     }
532
533     /**
534      * Sets all samples for a rectangle of pixels from an int array containing
535      * one sample per array element.
536      * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
537      * not in bounds.
538      * However, explicit bounds checking is not guaranteed.
539      * @param x The X coordinate of the upper left pixel location.
540      * @param y The Y coordinate of the upper left pixel location.
541      * @param w Width of the pixel rectangle.
542      * @param h Height of the pixel rectangle.
543      * @param iArray The input int pixel array.
544      *
545      * @throws NullPointerException if iArray is null.
546      * @throws ArrayIndexOutOfBoundsException if the coordinates are not
547      * in bounds, or if iArray is too small to hold the input.
548      */

549     public void setPixels(int x, int y, int w, int h, int iArray[]) {
550         sampleModel.setPixels(x-sampleModelTranslateX,y-sampleModelTranslateY,
551                               w,h,iArray,dataBuffer);
552     }
553
554     /**
555      * Sets all samples for a rectangle of pixels from a float array containing
556      * one sample per array element.
557      * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
558      * not in bounds.
559      * However, explicit bounds checking is not guaranteed.
560      * @param x The X coordinate of the upper left pixel location.
561      * @param y The Y coordinate of the upper left pixel location.
562      * @param w Width of the pixel rectangle.
563      * @param h Height of the pixel rectangle.
564      * @param fArray The input float pixel array.
565      *
566      * @throws NullPointerException if fArray is null.
567      * @throws ArrayIndexOutOfBoundsException if the coordinates are not
568      * in bounds, or if fArray is too small to hold the input.
569      */

570     public void setPixels(int x, int y, int w, int h, float fArray[]) {
571         sampleModel.setPixels(x-sampleModelTranslateX,y-sampleModelTranslateY,
572                               w,h,fArray,dataBuffer);
573     }
574
575     /**
576      * Sets all samples for a rectangle of pixels from a double array containing
577      * one sample per array element.
578      * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
579      * not in bounds.
580      * However, explicit bounds checking is not guaranteed.
581      * @param x The X coordinate of the upper left pixel location.
582      * @param y The Y coordinate of the upper left pixel location.
583      * @param w Width of the pixel rectangle.
584      * @param h Height of the pixel rectangle.
585      * @param dArray The input double pixel array.
586      *
587      * @throws NullPointerException if dArray is null.
588      * @throws ArrayIndexOutOfBoundsException if the coordinates are not
589      * in bounds, or if dArray is too small to hold the input.
590      */

591     public void setPixels(int x, int y, int w, int h, double dArray[]) {
592         sampleModel.setPixels(x-sampleModelTranslateX,y-sampleModelTranslateY,
593                               w,h,dArray,dataBuffer);
594     }
595
596     /**
597      * Sets a sample in the specified band for the pixel located at (x,y)
598      * in the DataBuffer using an int for input.
599      * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
600      * not in bounds.
601      * However, explicit bounds checking is not guaranteed.
602      * @param x The X coordinate of the pixel location.
603      * @param y The Y coordinate of the pixel location.
604      * @param b The band to set.
605      * @param s The input sample.
606      *
607      * @throws ArrayIndexOutOfBoundsException if the coordinates or
608      * the band index are not in bounds.
609      */

610     public void setSample(int x, int y, int b, int s) {
611         sampleModel.setSample(x-sampleModelTranslateX,
612                               y-sampleModelTranslateY, b, s,
613                               dataBuffer);
614     }
615
616     /**
617      * Sets a sample in the specified band for the pixel located at (x,y)
618      * in the DataBuffer using a float for input.
619      * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
620      * not in bounds.
621      * However, explicit bounds checking is not guaranteed.
622      * @param x The X coordinate of the pixel location.
623      * @param y The Y coordinate of the pixel location.
624      * @param b The band to set.
625      * @param s The input sample as a float.
626      *
627      * @throws ArrayIndexOutOfBoundsException if the coordinates or
628      * the band index are not in bounds.
629      */

630     public void setSample(int x, int y, int b, float s){
631         sampleModel.setSample(x-sampleModelTranslateX,y-sampleModelTranslateY,
632                   b,s,dataBuffer);
633     }
634
635     /**
636      * Sets a sample in the specified band for the pixel located at (x,y)
637      * in the DataBuffer using a double for input.
638      * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
639      * not in bounds.
640      * However, explicit bounds checking is not guaranteed.
641      * @param x The X coordinate of the pixel location.
642      * @param y The Y coordinate of the pixel location.
643      * @param b The band to set.
644      * @param s The input sample as a double.
645      *
646      * @throws ArrayIndexOutOfBoundsException if the coordinates or
647      * the band index are not in bounds.
648      */

649     public void setSample(int x, int y, int b, double s){
650         sampleModel.setSample(x-sampleModelTranslateX,y-sampleModelTranslateY,
651                                     b,s,dataBuffer);
652     }
653
654     /**
655      * Sets the samples in the specified band for the specified rectangle
656      * of pixels from an int array containing one sample per array element.
657      * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
658      * not in bounds.
659      * However, explicit bounds checking is not guaranteed.
660      * @param x The X coordinate of the upper left pixel location.
661      * @param y The Y coordinate of the upper left pixel location.
662      * @param w Width of the pixel rectangle.
663      * @param h Height of the pixel rectangle.
664      * @param b The band to set.
665      * @param iArray The input int sample array.
666      *
667      * @throws NullPointerException if iArray is null.
668      * @throws ArrayIndexOutOfBoundsException if the coordinates or
669      * the band index are not in bounds, or if iArray is too small to
670      * hold the input.
671      */

672     public void setSamples(int x, int y, int w, int h, int b,
673                            int iArray[]) {
674         sampleModel.setSamples(x-sampleModelTranslateX,y-sampleModelTranslateY,
675                                w,h,b,iArray,dataBuffer);
676     }
677
678     /**
679      * Sets the samples in the specified band for the specified rectangle
680      * of pixels from a float array containing one sample per array element.
681      * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
682      * not in bounds.
683      * However, explicit bounds checking is not guaranteed.
684      * @param x The X coordinate of the upper left pixel location.
685      * @param y The Y coordinate of the upper left pixel location.
686      * @param w Width of the pixel rectangle.
687      * @param h Height of the pixel rectangle.
688      * @param b The band to set.
689      * @param fArray The input float sample array.
690      *
691      * @throws NullPointerException if fArray is null.
692      * @throws ArrayIndexOutOfBoundsException if the coordinates or
693      * the band index are not in bounds, or if fArray is too small to
694      * hold the input.
695      */

696     public void setSamples(int x, int y, int w, int h, int b,
697                            float fArray[]) {
698         sampleModel.setSamples(x-sampleModelTranslateX,y-sampleModelTranslateY,
699                                w,h,b,fArray,dataBuffer);
700     }
701
702     /**
703      * Sets the samples in the specified band for the specified rectangle
704      * of pixels from a double array containing one sample per array element.
705      * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
706      * not in bounds.
707      * However, explicit bounds checking is not guaranteed.
708      * @param x The X coordinate of the upper left pixel location.
709      * @param y The Y coordinate of the upper left pixel location.
710      * @param w Width of the pixel rectangle.
711      * @param h Height of the pixel rectangle.
712      * @param b The band to set.
713      * @param dArray The input double sample array.
714      *
715      * @throws NullPointerException if dArray is null.
716      * @throws ArrayIndexOutOfBoundsException if the coordinates or
717      * the band index are not in bounds, or if dArray is too small to
718      * hold the input.
719      */

720     public void setSamples(int x, int y, int w, int h, int b,
721                            double dArray[]) {
722         sampleModel.setSamples(x-sampleModelTranslateX,y-sampleModelTranslateY,
723                   w,h,b,dArray,dataBuffer);
724     }
725
726 }
727
Popular Tags