155 } else {
156 throw new RasterFormatException("ShortBandedRasters must have "+
157 "BandedSampleModels");
158 }
159 verify();
160 }
161
162 /**
163 * Returns a copy of the data offsets array. For each band the data offset
164 * is the index into the band's data array, of the first sample of the
165 * band.
166 */
167 public int[] getDataOffsets() {
168 return dataOffsets.clone();
169 }
170
171 /**
172 * Returns the data offset for the specified band. The data offset
173 * is the index into the band's data array
174 * in which the first sample of the first scanline is stored.
175 * @param The band whose offset is returned.
176 */
177 public int getDataOffset(int band) {
178 return dataOffsets[band];
179 }
180
181 /**
182 * Returns the scanline stride -- the number of data array elements between
183 * a given sample and the sample in the same column
184 * of the next row in the same band.
185 */
186 public int getScanlineStride() {
187 return scanlineStride;
188 }
189
190 /**
191 * Returns the pixel stride, which is always equal to one for
192 * a Raster with a BandedSampleModel.
193 */
194 public int getPixelStride() {
195 return 1;
201 public short[][] getDataStorage() {
202 return data;
203 }
204
205 /**
206 * Returns a reference to the specific band data array.
207 */
208 public short[] getDataStorage(int band) {
209 return data[band];
210 }
211
212 /**
213 * Returns the data elements for all bands at the specified
214 * location.
215 * An ArrayIndexOutOfBounds exception will be thrown at runtime
216 * if the pixel coordinate is out of bounds.
217 * A ClassCastException will be thrown if the input object is non null
218 * and references anything other than an array of transferType.
219 * @param x The X coordinate of the pixel location.
220 * @param y The Y coordinate of the pixel location.
221 * @param outData An object reference to an array of type defined by
222 * getTransferType() and length getNumDataElements().
223 * If null an array of appropriate type and size will be
224 * allocated.
225 * @return An object reference to an array of type defined by
226 * getTransferType() with the request pixel data.
227 */
228 public Object getDataElements(int x, int y, Object obj) {
229 if ((x < this.minX) || (y < this.minY) ||
230 (x >= this.maxX) || (y >= this.maxY)) {
231 throw new ArrayIndexOutOfBoundsException
232 ("Coordinate out of bounds!");
233 }
234 short outData[];
235 if (obj == null) {
236 outData = new short[numDataElements];
237 } else {
238 outData = (short[])obj;
239 }
240
241 int off = (y-minY)*scanlineStride + (x-minX);
245 }
246
247 return outData;
248 }
249
250 /**
251 * Returns an array of data elements from the specified rectangular
252 * region.
253 * An ArrayIndexOutOfBounds exception will be thrown at runtime
254 * if the pixel coordinates are out of bounds.
255 * <pre>
256 * short[] bandData = (short[])Raster.getDataElements(x, y, w, h, null);
257 * int numDataElements = Raster.getnumDataElements();
258 * short[] pixel = new short[numDataElements];
259 * // To find a data element at location (x2, y2)
260 * System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
261 * pixel, 0, numDataElements);
262 * </pre>
263 * @param x The X coordinate of the upper left pixel location.
264 * @param y The Y coordinate of the upper left pixel location.
265 * @param width Width of the pixel rectangle.
266 * @param height Height of the pixel rectangle.
267 * @param outData An object reference to an array of type defined by
268 * getTransferType() and length w*h*getNumDataElements().
269 * If null an array of appropriate type and size will be
270 * allocated.
271 * @return An object reference to an array of type defined by
272 * getTransferType() with the request pixel data.
273 */
274 public Object getDataElements(int x, int y, int w, int h, Object obj) {
275 if ((x < this.minX) || (y < this.minY) ||
276 (x + w > this.maxX) || (y + h > this.maxY)) {
277 throw new ArrayIndexOutOfBoundsException
278 ("Coordinate out of bounds!");
279 }
280 short outData[];
281 if (obj == null) {
282 outData = new short[numDataElements*w*h];
283 } else {
284 outData = (short[])obj;
285 }
286 int yoff = (y-minY)*scanlineStride + (x-minX);
287
298 off += numDataElements;
299 }
300 }
301 }
302
303 return outData;
304 }
305
306 /**
307 * Returns a short array of data elements from the specified rectangular
308 * region for the specified band.
309 * An ArrayIndexOutOfBounds exception will be thrown at runtime
310 * if the pixel coordinates are out of bounds.
311 * <pre>
312 * short[] bandData = Raster.getShortData(x, y, w, h, null);
313 * // To find the data element at location (x2, y2)
314 * short bandElement = bandData[((y2-y)*w + (x2-x))];
315 * </pre>
316 * @param x The X coordinate of the upper left pixel location.
317 * @param y The Y coordinate of the upper left pixel location.
318 * @param width Width of the pixel rectangle.
319 * @param height Height of the pixel rectangle.
320 * @param band The band to return.
321 * @param outData If non-null, data elements for all bands
322 * at the specified location are returned in this array.
323 * @return Data array with data elements for all bands.
324 */
325 public short[] getShortData(int x, int y, int w, int h,
326 int band, short[] outData) {
327 // Bounds check for 'band' will be performed automatically
328 if ((x < this.minX) || (y < this.minY) ||
329 (x + w > this.maxX) || (y + h > this.maxY)) {
330 throw new ArrayIndexOutOfBoundsException
331 ("Coordinate out of bounds!");
332 }
333 if (outData == null) {
334 outData = new short[scanlineStride*h];
335 }
336 int yoff = (y-minY)*scanlineStride + (x-minX) + dataOffsets[band];
337
338 if (scanlineStride == w) {
339 System.arraycopy(data[band], yoff, outData, 0, w*h);
346 }
347
348 return outData;
349 }
350
351 /**
352 * Returns a short array of data elements from the specified rectangular
353 * region.
354 * An ArrayIndexOutOfBounds exception will be thrown at runtime
355 * if the pixel coordinates are out of bounds.
356 * <pre>
357 * short[] bandData = Raster.getShortData(x, y, w, h, null);
358 * int numDataElements = Raster.getnumDataElements();
359 * short[] pixel = new short[numDataElements];
360 * // To find a data element at location (x2, y2)
361 * System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
362 * pixel, 0, numDataElements);
363 * </pre>
364 * @param x The X coordinate of the upper left pixel location.
365 * @param y The Y coordinate of the upper left pixel location.
366 * @param width Width of the pixel rectangle.
367 * @param height Height of the pixel rectangle.
368 * @param outData If non-null, data elements for all bands
369 * at the specified location are returned in this array.
370 * @return Data array with data elements for all bands.
371 */
372 public short[] getShortData(int x, int y, int w, int h,
373 short[] outData) {
374 if ((x < this.minX) || (y < this.minY) ||
375 (x + w > this.maxX) || (y + h > this.maxY)) {
376 throw new ArrayIndexOutOfBoundsException
377 ("Coordinate out of bounds!");
378 }
379 if (outData == null) {
380 outData = new short[numDataElements*scanlineStride*h];
381 }
382 int yoff = (y-minY)*scanlineStride + (x-minX);
383
384 for (int c = 0; c < numDataElements; c++) {
385 int off = c;
386 short[] bank = data[c];
387 int dataOffset = dataOffsets[c];
390 for (int ystart=0; ystart < h; ystart++, yoff2 += scanlineStride) {
391 int xoff = dataOffset + yoff2;
392 for (int xstart=0; xstart < w; xstart++) {
393 outData[off] = bank[xoff++];
394 off += numDataElements;
395 }
396 }
397 }
398
399 return outData;
400 }
401
402 /**
403 * Stores the data element for all bands at the specified location.
404 * An ArrayIndexOutOfBounds exception will be thrown at runtime
405 * if the pixel coordinate is out of bounds.
406 * A ClassCastException will be thrown if the input object is non null
407 * and references anything other than an array of transferType.
408 * @param x The X coordinate of the pixel location.
409 * @param y The Y coordinate of the pixel location.
410 * @param inData An object reference to an array of type defined by
411 * getTransferType() and length getNumDataElements()
412 * containing the pixel data to place at x,y.
413 */
414 public void setDataElements(int x, int y, Object obj) {
415 if ((x < this.minX) || (y < this.minY) ||
416 (x >= this.maxX) || (y >= this.maxY)) {
417 throw new ArrayIndexOutOfBoundsException
418 ("Coordinate out of bounds!");
419 }
420 short inData[] = (short[])obj;
421 int off = (y-minY)*scanlineStride + (x-minX);
422 for (int i = 0; i < numDataElements; i++) {
423 data[i][dataOffsets[i] + off] = inData[i];
424 }
425
426 markDirty();
427 }
428
429 /**
430 * Stores the Raster data at the specified location.
486 }
487 }
488
489 /**
490 * Stores an array of data elements into the specified rectangular
491 * region.
492 * An ArrayIndexOutOfBounds exception will be thrown at runtime
493 * if the pixel coordinates are out of bounds.
494 * A ClassCastException will be thrown if the input object is non null
495 * and references anything other than an array of transferType.
496 * The data elements in the
497 * data array are assumed to be packed. That is, a data element
498 * for the nth band at location (x2, y2) would be found at:
499 * <pre>
500 * inData[((y2-y)*w + (x2-x))*numDataElements + n]
501 * </pre>
502 * @param x The X coordinate of the upper left pixel location.
503 * @param y The Y coordinate of the upper left pixel location.
504 * @param w Width of the pixel rectangle.
505 * @param h Height of the pixel rectangle.
506 * @param inData An object reference to an array of type defined by
507 * getTransferType() and length w*h*getNumDataElements()
508 * containing the pixel data to place between x,y and
509 * x+h, y+h.
510 */
511 public void setDataElements(int x, int y, int w, int h, Object obj) {
512 if ((x < this.minX) || (y < this.minY) ||
513 (x + w > this.maxX) || (y + h > this.maxY)) {
514 throw new ArrayIndexOutOfBoundsException
515 ("Coordinate out of bounds!");
516 }
517 short inData[] = (short[])obj;
518 int yoff = (y-minY)*scanlineStride + (x-minX);
519
520 for (int c = 0; c < numDataElements; c++) {
521 int off = c;
522 short[] bank = data[c];
523 int dataOffset = dataOffsets[c];
524
525 int yoff2 = yoff;
526 for (int ystart=0; ystart < h; ystart++, yoff2 += scanlineStride) {
|
155 } else {
156 throw new RasterFormatException("ShortBandedRasters must have "+
157 "BandedSampleModels");
158 }
159 verify();
160 }
161
162 /**
163 * Returns a copy of the data offsets array. For each band the data offset
164 * is the index into the band's data array, of the first sample of the
165 * band.
166 */
167 public int[] getDataOffsets() {
168 return dataOffsets.clone();
169 }
170
171 /**
172 * Returns the data offset for the specified band. The data offset
173 * is the index into the band's data array
174 * in which the first sample of the first scanline is stored.
175 * @param band The band whose offset is returned.
176 */
177 public int getDataOffset(int band) {
178 return dataOffsets[band];
179 }
180
181 /**
182 * Returns the scanline stride -- the number of data array elements between
183 * a given sample and the sample in the same column
184 * of the next row in the same band.
185 */
186 public int getScanlineStride() {
187 return scanlineStride;
188 }
189
190 /**
191 * Returns the pixel stride, which is always equal to one for
192 * a Raster with a BandedSampleModel.
193 */
194 public int getPixelStride() {
195 return 1;
201 public short[][] getDataStorage() {
202 return data;
203 }
204
205 /**
206 * Returns a reference to the specific band data array.
207 */
208 public short[] getDataStorage(int band) {
209 return data[band];
210 }
211
212 /**
213 * Returns the data elements for all bands at the specified
214 * location.
215 * An ArrayIndexOutOfBounds exception will be thrown at runtime
216 * if the pixel coordinate is out of bounds.
217 * A ClassCastException will be thrown if the input object is non null
218 * and references anything other than an array of transferType.
219 * @param x The X coordinate of the pixel location.
220 * @param y The Y coordinate of the pixel location.
221 * @param obj An object reference to an array of type defined by
222 * getTransferType() and length getNumDataElements().
223 * If null an array of appropriate type and size will be
224 * allocated.
225 * @return An object reference to an array of type defined by
226 * getTransferType() with the request pixel data.
227 */
228 public Object getDataElements(int x, int y, Object obj) {
229 if ((x < this.minX) || (y < this.minY) ||
230 (x >= this.maxX) || (y >= this.maxY)) {
231 throw new ArrayIndexOutOfBoundsException
232 ("Coordinate out of bounds!");
233 }
234 short outData[];
235 if (obj == null) {
236 outData = new short[numDataElements];
237 } else {
238 outData = (short[])obj;
239 }
240
241 int off = (y-minY)*scanlineStride + (x-minX);
245 }
246
247 return outData;
248 }
249
250 /**
251 * Returns an array of data elements from the specified rectangular
252 * region.
253 * An ArrayIndexOutOfBounds exception will be thrown at runtime
254 * if the pixel coordinates are out of bounds.
255 * <pre>
256 * short[] bandData = (short[])Raster.getDataElements(x, y, w, h, null);
257 * int numDataElements = Raster.getnumDataElements();
258 * short[] pixel = new short[numDataElements];
259 * // To find a data element at location (x2, y2)
260 * System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
261 * pixel, 0, numDataElements);
262 * </pre>
263 * @param x The X coordinate of the upper left pixel location.
264 * @param y The Y coordinate of the upper left pixel location.
265 * @param w Width of the pixel rectangle.
266 * @param h Height of the pixel rectangle.
267 * @param obj An object reference to an array of type defined by
268 * getTransferType() and length w*h*getNumDataElements().
269 * If null an array of appropriate type and size will be
270 * allocated.
271 * @return An object reference to an array of type defined by
272 * getTransferType() with the request pixel data.
273 */
274 public Object getDataElements(int x, int y, int w, int h, Object obj) {
275 if ((x < this.minX) || (y < this.minY) ||
276 (x + w > this.maxX) || (y + h > this.maxY)) {
277 throw new ArrayIndexOutOfBoundsException
278 ("Coordinate out of bounds!");
279 }
280 short outData[];
281 if (obj == null) {
282 outData = new short[numDataElements*w*h];
283 } else {
284 outData = (short[])obj;
285 }
286 int yoff = (y-minY)*scanlineStride + (x-minX);
287
298 off += numDataElements;
299 }
300 }
301 }
302
303 return outData;
304 }
305
306 /**
307 * Returns a short array of data elements from the specified rectangular
308 * region for the specified band.
309 * An ArrayIndexOutOfBounds exception will be thrown at runtime
310 * if the pixel coordinates are out of bounds.
311 * <pre>
312 * short[] bandData = Raster.getShortData(x, y, w, h, null);
313 * // To find the data element at location (x2, y2)
314 * short bandElement = bandData[((y2-y)*w + (x2-x))];
315 * </pre>
316 * @param x The X coordinate of the upper left pixel location.
317 * @param y The Y coordinate of the upper left pixel location.
318 * @param w Width of the pixel rectangle.
319 * @param h Height of the pixel rectangle.
320 * @param band The band to return.
321 * @param outData If non-null, data elements for all bands
322 * at the specified location are returned in this array.
323 * @return Data array with data elements for all bands.
324 */
325 public short[] getShortData(int x, int y, int w, int h,
326 int band, short[] outData) {
327 // Bounds check for 'band' will be performed automatically
328 if ((x < this.minX) || (y < this.minY) ||
329 (x + w > this.maxX) || (y + h > this.maxY)) {
330 throw new ArrayIndexOutOfBoundsException
331 ("Coordinate out of bounds!");
332 }
333 if (outData == null) {
334 outData = new short[scanlineStride*h];
335 }
336 int yoff = (y-minY)*scanlineStride + (x-minX) + dataOffsets[band];
337
338 if (scanlineStride == w) {
339 System.arraycopy(data[band], yoff, outData, 0, w*h);
346 }
347
348 return outData;
349 }
350
351 /**
352 * Returns a short array of data elements from the specified rectangular
353 * region.
354 * An ArrayIndexOutOfBounds exception will be thrown at runtime
355 * if the pixel coordinates are out of bounds.
356 * <pre>
357 * short[] bandData = Raster.getShortData(x, y, w, h, null);
358 * int numDataElements = Raster.getnumDataElements();
359 * short[] pixel = new short[numDataElements];
360 * // To find a data element at location (x2, y2)
361 * System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
362 * pixel, 0, numDataElements);
363 * </pre>
364 * @param x The X coordinate of the upper left pixel location.
365 * @param y The Y coordinate of the upper left pixel location.
366 * @param w Width of the pixel rectangle.
367 * @param h Height of the pixel rectangle.
368 * @param outData If non-null, data elements for all bands
369 * at the specified location are returned in this array.
370 * @return Data array with data elements for all bands.
371 */
372 public short[] getShortData(int x, int y, int w, int h,
373 short[] outData) {
374 if ((x < this.minX) || (y < this.minY) ||
375 (x + w > this.maxX) || (y + h > this.maxY)) {
376 throw new ArrayIndexOutOfBoundsException
377 ("Coordinate out of bounds!");
378 }
379 if (outData == null) {
380 outData = new short[numDataElements*scanlineStride*h];
381 }
382 int yoff = (y-minY)*scanlineStride + (x-minX);
383
384 for (int c = 0; c < numDataElements; c++) {
385 int off = c;
386 short[] bank = data[c];
387 int dataOffset = dataOffsets[c];
390 for (int ystart=0; ystart < h; ystart++, yoff2 += scanlineStride) {
391 int xoff = dataOffset + yoff2;
392 for (int xstart=0; xstart < w; xstart++) {
393 outData[off] = bank[xoff++];
394 off += numDataElements;
395 }
396 }
397 }
398
399 return outData;
400 }
401
402 /**
403 * Stores the data element for all bands at the specified location.
404 * An ArrayIndexOutOfBounds exception will be thrown at runtime
405 * if the pixel coordinate is out of bounds.
406 * A ClassCastException will be thrown if the input object is non null
407 * and references anything other than an array of transferType.
408 * @param x The X coordinate of the pixel location.
409 * @param y The Y coordinate of the pixel location.
410 * @param obj An object reference to an array of type defined by
411 * getTransferType() and length getNumDataElements()
412 * containing the pixel data to place at x,y.
413 */
414 public void setDataElements(int x, int y, Object obj) {
415 if ((x < this.minX) || (y < this.minY) ||
416 (x >= this.maxX) || (y >= this.maxY)) {
417 throw new ArrayIndexOutOfBoundsException
418 ("Coordinate out of bounds!");
419 }
420 short inData[] = (short[])obj;
421 int off = (y-minY)*scanlineStride + (x-minX);
422 for (int i = 0; i < numDataElements; i++) {
423 data[i][dataOffsets[i] + off] = inData[i];
424 }
425
426 markDirty();
427 }
428
429 /**
430 * Stores the Raster data at the specified location.
486 }
487 }
488
489 /**
490 * Stores an array of data elements into the specified rectangular
491 * region.
492 * An ArrayIndexOutOfBounds exception will be thrown at runtime
493 * if the pixel coordinates are out of bounds.
494 * A ClassCastException will be thrown if the input object is non null
495 * and references anything other than an array of transferType.
496 * The data elements in the
497 * data array are assumed to be packed. That is, a data element
498 * for the nth band at location (x2, y2) would be found at:
499 * <pre>
500 * inData[((y2-y)*w + (x2-x))*numDataElements + n]
501 * </pre>
502 * @param x The X coordinate of the upper left pixel location.
503 * @param y The Y coordinate of the upper left pixel location.
504 * @param w Width of the pixel rectangle.
505 * @param h Height of the pixel rectangle.
506 * @param obj An object reference to an array of type defined by
507 * getTransferType() and length w*h*getNumDataElements()
508 * containing the pixel data to place between x,y and
509 * x+h, y+h.
510 */
511 public void setDataElements(int x, int y, int w, int h, Object obj) {
512 if ((x < this.minX) || (y < this.minY) ||
513 (x + w > this.maxX) || (y + h > this.maxY)) {
514 throw new ArrayIndexOutOfBoundsException
515 ("Coordinate out of bounds!");
516 }
517 short inData[] = (short[])obj;
518 int yoff = (y-minY)*scanlineStride + (x-minX);
519
520 for (int c = 0; c < numDataElements; c++) {
521 int off = c;
522 short[] bank = data[c];
523 int dataOffset = dataOffsets[c];
524
525 int yoff2 = yoff;
526 for (int ystart=0; ystart < h; ystart++, yoff2 += scanlineStride) {
|