109 * Constructs a SampleModel with the specified parameters. |
109 * Constructs a SampleModel with the specified parameters. |
110 * @param dataType The data type of the DataBuffer storing the pixel data. |
110 * @param dataType The data type of the DataBuffer storing the pixel data. |
111 * @param w The width (in pixels) of the region of image data. |
111 * @param w The width (in pixels) of the region of image data. |
112 * @param h The height (in pixels) of the region of image data. |
112 * @param h The height (in pixels) of the region of image data. |
113 * @param numBands The number of bands of the image data. |
113 * @param numBands The number of bands of the image data. |
114 * @throws IllegalArgumentException if <code>w</code> or <code>h</code> |
114 * @throws IllegalArgumentException if {@code w} or {@code h} |
115 * is not greater than 0 |
115 * is not greater than 0 |
116 * @throws IllegalArgumentException if the product of <code>w</code> |
116 * @throws IllegalArgumentException if the product of {@code w} |
117 * and <code>h</code> is greater than |
117 * and {@code h} is greater than |
118 * <code>Integer.MAX_VALUE</code> |
118 * {@code Integer.MAX_VALUE} |
119 * @throws IllegalArgumentException if <code>dataType</code> is not |
119 * @throws IllegalArgumentException if {@code dataType} is not |
120 * one of the supported data types |
120 * one of the supported data types |
121 */ |
121 */ |
122 public SampleModel(int dataType, int w, int h, int numBands) |
122 public SampleModel(int dataType, int w, int h, int numBands) |
123 { |
123 { |
124 long size = (long)w * h; |
124 long size = (long)w * h; |
149 this.numBands = numBands; |
149 this.numBands = numBands; |
150 } |
150 } |
151 |
151 |
152 /** Returns the width in pixels. |
152 /** Returns the width in pixels. |
153 * @return the width in pixels of the region of image data |
153 * @return the width in pixels of the region of image data |
154 * that this <code>SampleModel</code> describes. |
154 * that this {@code SampleModel} describes. |
155 */ |
155 */ |
156 public final int getWidth() { |
156 public final int getWidth() { |
157 return width; |
157 return width; |
158 } |
158 } |
159 |
159 |
160 /** Returns the height in pixels. |
160 /** Returns the height in pixels. |
161 * @return the height in pixels of the region of image data |
161 * @return the height in pixels of the region of image data |
162 * that this <code>SampleModel</code> describes. |
162 * that this {@code SampleModel} describes. |
163 */ |
163 */ |
164 public final int getHeight() { |
164 public final int getHeight() { |
165 return height; |
165 return height; |
166 } |
166 } |
167 |
167 |
168 /** Returns the total number of bands of image data. |
168 /** Returns the total number of bands of image data. |
169 * @return the number of bands of image data that this |
169 * @return the number of bands of image data that this |
170 * <code>SampleModel</code> describes. |
170 * {@code SampleModel} describes. |
171 */ |
171 */ |
172 public final int getNumBands() { |
172 public final int getNumBands() { |
173 return numBands; |
173 return numBands; |
174 } |
174 } |
175 |
175 |
259 * thus increasing efficiency for data transfers. Generally, obj |
259 * thus increasing efficiency for data transfers. Generally, obj |
260 * should be passed in as null, so that the Object will be created |
260 * should be passed in as null, so that the Object will be created |
261 * automatically and will be of the right primitive data type. |
261 * automatically and will be of the right primitive data type. |
262 * <p> |
262 * <p> |
263 * The following code illustrates transferring data for one pixel from |
263 * The following code illustrates transferring data for one pixel from |
264 * DataBuffer <code>db1</code>, whose storage layout is described by |
264 * DataBuffer {@code db1}, whose storage layout is described by |
265 * SampleModel <code>sm1</code>, to DataBuffer <code>db2</code>, whose |
265 * SampleModel {@code sm1}, to DataBuffer {@code db2}, whose |
266 * storage layout is described by SampleModel <code>sm2</code>. |
266 * storage layout is described by SampleModel {@code sm2}. |
267 * The transfer will generally be more efficient than using |
267 * The transfer will generally be more efficient than using |
268 * getPixel/setPixel. |
268 * getPixel/setPixel. |
269 * <pre> |
269 * <pre> |
270 * SampleModel sm1, sm2; |
270 * SampleModel sm1, sm2; |
271 * DataBuffer db1, db2; |
271 * DataBuffer db1, db2; |
310 * should be passed in as null, so that the Object will be created |
310 * should be passed in as null, so that the Object will be created |
311 * automatically and will be of the right primitive data type. |
311 * automatically and will be of the right primitive data type. |
312 * <p> |
312 * <p> |
313 * The following code illustrates transferring data for a rectangular |
313 * The following code illustrates transferring data for a rectangular |
314 * region of pixels from |
314 * region of pixels from |
315 * DataBuffer <code>db1</code>, whose storage layout is described by |
315 * DataBuffer {@code db1}, whose storage layout is described by |
316 * SampleModel <code>sm1</code>, to DataBuffer <code>db2</code>, whose |
316 * SampleModel {@code sm1}, to DataBuffer {@code db2}, whose |
317 * storage layout is described by SampleModel <code>sm2</code>. |
317 * storage layout is described by SampleModel {@code sm2}. |
318 * The transfer will generally be more efficient than using |
318 * The transfer will generally be more efficient than using |
319 * getPixels/setPixels. |
319 * getPixels/setPixels. |
320 * <pre> |
320 * <pre> |
321 * SampleModel sm1, sm2; |
321 * SampleModel sm1, sm2; |
322 * DataBuffer db1, db2; |
322 * DataBuffer db1, db2; |
496 * DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE. Data in the array |
496 * DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE. Data in the array |
497 * may be in a packed format, thus increasing efficiency for data |
497 * may be in a packed format, thus increasing efficiency for data |
498 * transfers. |
498 * transfers. |
499 * <p> |
499 * <p> |
500 * The following code illustrates transferring data for one pixel from |
500 * The following code illustrates transferring data for one pixel from |
501 * DataBuffer <code>db1</code>, whose storage layout is described by |
501 * DataBuffer {@code db1}, whose storage layout is described by |
502 * SampleModel <code>sm1</code>, to DataBuffer <code>db2</code>, whose |
502 * SampleModel {@code sm1}, to DataBuffer {@code db2}, whose |
503 * storage layout is described by SampleModel <code>sm2</code>. |
503 * storage layout is described by SampleModel {@code sm2}. |
504 * The transfer will generally be more efficient than using |
504 * The transfer will generally be more efficient than using |
505 * getPixel/setPixel. |
505 * getPixel/setPixel. |
506 * <pre> |
506 * <pre> |
507 * SampleModel sm1, sm2; |
507 * SampleModel sm1, sm2; |
508 * DataBuffer db1, db2; |
508 * DataBuffer db1, db2; |
543 * may be in a packed format, thus increasing efficiency for data |
543 * may be in a packed format, thus increasing efficiency for data |
544 * transfers. |
544 * transfers. |
545 * <p> |
545 * <p> |
546 * The following code illustrates transferring data for a rectangular |
546 * The following code illustrates transferring data for a rectangular |
547 * region of pixels from |
547 * region of pixels from |
548 * DataBuffer <code>db1</code>, whose storage layout is described by |
548 * DataBuffer {@code db1}, whose storage layout is described by |
549 * SampleModel <code>sm1</code>, to DataBuffer <code>db2</code>, whose |
549 * SampleModel {@code sm1}, to DataBuffer {@code db2}, whose |
550 * storage layout is described by SampleModel <code>sm2</code>. |
550 * storage layout is described by SampleModel {@code sm2}. |
551 * The transfer will generally be more efficient than using |
551 * The transfer will generally be more efficient than using |
552 * getPixels/setPixels. |
552 * getPixels/setPixels. |
553 * <pre> |
553 * <pre> |
554 * SampleModel sm1, sm2; |
554 * SampleModel sm1, sm2; |
555 * DataBuffer db1, db2; |
555 * DataBuffer db1, db2; |
1296 /** |
1296 /** |
1297 * Sets a sample in the specified band for the pixel located at (x,y) |
1297 * Sets a sample in the specified band for the pixel located at (x,y) |
1298 * in the DataBuffer using a float for input. |
1298 * in the DataBuffer using a float for input. |
1299 * The default implementation of this method casts the input |
1299 * The default implementation of this method casts the input |
1300 * float sample to an int and then calls the |
1300 * float sample to an int and then calls the |
1301 * <code>setSample(int, int, int, DataBuffer)</code> method using |
1301 * {@code setSample(int, int, int, DataBuffer)} method using |
1302 * that int value. |
1302 * that int value. |
1303 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are |
1303 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are |
1304 * not in bounds. |
1304 * not in bounds. |
1305 * @param x The X coordinate of the pixel location. |
1305 * @param x The X coordinate of the pixel location. |
1306 * @param y The Y coordinate of the pixel location. |
1306 * @param y The Y coordinate of the pixel location. |
1324 /** |
1324 /** |
1325 * Sets a sample in the specified band for the pixel located at (x,y) |
1325 * Sets a sample in the specified band for the pixel located at (x,y) |
1326 * in the DataBuffer using a double for input. |
1326 * in the DataBuffer using a double for input. |
1327 * The default implementation of this method casts the input |
1327 * The default implementation of this method casts the input |
1328 * double sample to an int and then calls the |
1328 * double sample to an int and then calls the |
1329 * <code>setSample(int, int, int, DataBuffer)</code> method using |
1329 * {@code setSample(int, int, int, DataBuffer)} method using |
1330 * that int value. |
1330 * that int value. |
1331 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are |
1331 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are |
1332 * not in bounds. |
1332 * not in bounds. |
1333 * @param x The X coordinate of the pixel location. |
1333 * @param x The X coordinate of the pixel location. |
1334 * @param y The Y coordinate of the pixel location. |
1334 * @param y The Y coordinate of the pixel location. |
1467 /** |
1467 /** |
1468 * Creates a SampleModel which describes data in this SampleModel's |
1468 * Creates a SampleModel which describes data in this SampleModel's |
1469 * format, but with a different width and height. |
1469 * format, but with a different width and height. |
1470 * @param w the width of the image data |
1470 * @param w the width of the image data |
1471 * @param h the height of the image data |
1471 * @param h the height of the image data |
1472 * @return a <code>SampleModel</code> describing the same image |
1472 * @return a {@code SampleModel} describing the same image |
1473 * data as this <code>SampleModel</code>, but with a |
1473 * data as this {@code SampleModel}, but with a |
1474 * different size. |
1474 * different size. |
1475 */ |
1475 */ |
1476 public abstract SampleModel createCompatibleSampleModel(int w, int h); |
1476 public abstract SampleModel createCompatibleSampleModel(int w, int h); |
1477 |
1477 |
1478 /** |
1478 /** |
1479 * Creates a new SampleModel |
1479 * Creates a new SampleModel |
1480 * with a subset of the bands of this |
1480 * with a subset of the bands of this |
1481 * SampleModel. |
1481 * SampleModel. |
1482 * @param bands the subset of bands of this <code>SampleModel</code> |
1482 * @param bands the subset of bands of this {@code SampleModel} |
1483 * @return a <code>SampleModel</code> with a subset of bands of this |
1483 * @return a {@code SampleModel} with a subset of bands of this |
1484 * <code>SampleModel</code>. |
1484 * {@code SampleModel}. |
1485 */ |
1485 */ |
1486 public abstract SampleModel createSubsetSampleModel(int bands[]); |
1486 public abstract SampleModel createSubsetSampleModel(int bands[]); |
1487 |
1487 |
1488 /** |
1488 /** |
1489 * Creates a DataBuffer that corresponds to this SampleModel. |
1489 * Creates a DataBuffer that corresponds to this SampleModel. |
1490 * The DataBuffer's width and height will match this SampleModel's. |
1490 * The DataBuffer's width and height will match this SampleModel's. |
1491 * @return a <code>DataBuffer</code> corresponding to this |
1491 * @return a {@code DataBuffer} corresponding to this |
1492 * <code>SampleModel</code>. |
1492 * {@code SampleModel}. |
1493 */ |
1493 */ |
1494 public abstract DataBuffer createDataBuffer(); |
1494 public abstract DataBuffer createDataBuffer(); |
1495 |
1495 |
1496 /** Returns the size in bits of samples for all bands. |
1496 /** Returns the size in bits of samples for all bands. |
1497 * @return the size of samples for all bands. |
1497 * @return the size of samples for all bands. |