236 public int getPixelStride() {
237 return pixelStride;
238 }
239
240 /**
241 * Returns a reference to the data array.
242 */
243 public byte[] getDataStorage() {
244 return data;
245 }
246
247 /**
248 * Returns the data elements for all bands at the specified
249 * location.
250 * An ArrayIndexOutOfBounds exception will be thrown at runtime
251 * if the pixel coordinate is out of bounds.
252 * A ClassCastException will be thrown if the input object is non null
253 * and references anything other than an array of transferType.
254 * @param x The X coordinate of the pixel location.
255 * @param y The Y coordinate of the pixel location.
256 * @param outData An object reference to an array of type defined by
257 * getTransferType() and length getNumDataElements().
258 * If null an array of appropriate type and size will be
259 * allocated.
260 * @return An object reference to an array of type defined by
261 * getTransferType() with the request pixel data.
262 */
263 public Object getDataElements(int x, int y, Object obj) {
264 if ((x < this.minX) || (y < this.minY) ||
265 (x >= this.maxX) || (y >= this.maxY)) {
266 throw new ArrayIndexOutOfBoundsException
267 ("Coordinate out of bounds!");
268 }
269 byte outData[];
270 if (obj == null) {
271 outData = new byte[numDataElements];
272 } else {
273 outData = (byte[])obj;
274 }
275 int off = (y-minY)*scanlineStride +
276 (x-minX)*pixelStride;
282 return outData;
283 }
284
285 /**
286 * Returns an array of data elements from the specified rectangular
287 * region.
288 * An ArrayIndexOutOfBounds exception will be thrown at runtime
289 * if the pixel coordinates are out of bounds.
290 * A ClassCastException will be thrown if the input object is non null
291 * and references anything other than an array of transferType.
292 * <pre>
293 * byte[] bandData = (byte[])raster.getDataElements(x, y, w, h, null);
294 * int numDataElements = raster.getNumDataElements();
295 * byte[] pixel = new byte[numDataElements];
296 * // To find a data element at location (x2, y2)
297 * System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
298 * pixel, 0, numDataElements);
299 * </pre>
300 * @param x The X coordinate of the upper left pixel location.
301 * @param y The Y coordinate of the upper left pixel location.
302 * @param width Width of the pixel rectangle.
303 * @param height Height of the pixel rectangle.
304 * @param outData An object reference to an array of type defined by
305 * getTransferType() and length w*h*getNumDataElements().
306 * If null an array of appropriate type and size will be
307 * allocated.
308 * @return An object reference to an array of type defined by
309 * getTransferType() with the request pixel data.
310 */
311 public Object getDataElements(int x, int y, int w, int h, Object obj) {
312 if ((x < this.minX) || (y < this.minY) ||
313 (x + w > this.maxX) || (y + h > this.maxY)) {
314 throw new ArrayIndexOutOfBoundsException
315 ("Coordinate out of bounds!");
316 }
317 byte outData[];
318 if (obj == null) {
319 outData = new byte[w*h*numDataElements];
320 } else {
321 outData = (byte[])obj;
322 }
323
324 int yoff = (y-minY)*scanlineStride +
335 outData[off++] = data[dataOffsets[c] + xoff];
336 }
337 }
338 }
339
340 return outData;
341 }
342
343 /**
344 * Returns a byte array of data elements from the specified rectangular
345 * region for the specified band.
346 * An ArrayIndexOutOfBounds exception will be thrown at runtime
347 * if the pixel coordinates are out of bounds.
348 * <pre>
349 * byte[] bandData = raster.getByteData(x, y, w, h, null);
350 * // To find the data element at location (x2, y2)
351 * byte bandElement = bandData[((y2-y)*w + (x2-x))];
352 * </pre>
353 * @param x The X coordinate of the upper left pixel location.
354 * @param y The Y coordinate of the upper left pixel location.
355 * @param width Width of the pixel rectangle.
356 * @param height Height of the pixel rectangle.
357 * @param band The band to return.
358 * @param outData If non-null, data elements for all bands
359 * at the specified location are returned in this array.
360 * @return Data array with data elements for all bands.
361 */
362 public byte[] getByteData(int x, int y, int w, int h,
363 int band, byte[] outData) {
364 // Bounds check for 'band' will be performed automatically
365 if ((x < this.minX) || (y < this.minY) ||
366 (x + w > this.maxX) || (y + h > this.maxY)) {
367 throw new ArrayIndexOutOfBoundsException
368 ("Coordinate out of bounds!");
369 }
370 if (outData == null) {
371 outData = new byte[scanlineStride*h];
372 }
373 int yoff = (y-minY)*scanlineStride +
374 (x-minX)*pixelStride + dataOffsets[band];
375 int xoff;
376 int off = 0;
398 }
399
400 return outData;
401 }
402
403 /**
404 * Returns a byte array of data elements from the specified rectangular
405 * region.
406 * An ArrayIndexOutOfBounds exception will be thrown at runtime
407 * if the pixel coordinates are out of bounds.
408 * <pre>
409 * byte[] bandData = raster.getByteData(x, y, w, h, null);
410 * int numDataElements = raster.getnumDataElements();
411 * byte[] pixel = new byte[numDataElements];
412 * // To find a data element at location (x2, y2)
413 * System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
414 * pixel, 0, numDataElements);
415 * </pre>
416 * @param x The X coordinate of the upper left pixel location.
417 * @param y The Y coordinate of the upper left pixel location.
418 * @param width Width of the pixel rectangle.
419 * @param height Height of the pixel rectangle.
420 * @param outData If non-null, data elements for all bands
421 * at the specified location are returned in this array.
422 * @return Data array with data elements for all bands.
423 */
424 public byte[] getByteData(int x, int y, int w, int h, byte[] outData) {
425 if ((x < this.minX) || (y < this.minY) ||
426 (x + w > this.maxX) || (y + h > this.maxY)) {
427 throw new ArrayIndexOutOfBoundsException
428 ("Coordinate out of bounds!");
429 }
430 if (outData == null) {
431 outData = new byte[numDataElements*scanlineStride*h];
432 }
433 int yoff = (y-minY)*scanlineStride +
434 (x-minX)*pixelStride;
435 int xoff;
436 int off = 0;
437 int xstart;
438 int ystart;
439
441 for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
442 xoff = yoff;
443 for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
444 for (int c = 0; c < numDataElements; c++) {
445 outData[off++] = data[dataOffsets[c] + xoff];
446 }
447 }
448 }
449
450 return outData;
451 }
452
453 /**
454 * Stores the data elements for all bands at the specified location.
455 * An ArrayIndexOutOfBounds exception will be thrown at runtime
456 * if the pixel coordinate is out of bounds.
457 * A ClassCastException will be thrown if the input object is non null
458 * and references anything other than an array of transferType.
459 * @param x The X coordinate of the pixel location.
460 * @param y The Y coordinate of the pixel location.
461 * @param inData An object reference to an array of type defined by
462 * getTransferType() and length getNumDataElements()
463 * containing the pixel data to place at x,y.
464 */
465 public void setDataElements(int x, int y, Object obj) {
466 if ((x < this.minX) || (y < this.minY) ||
467 (x >= this.maxX) || (y >= this.maxY)) {
468 throw new ArrayIndexOutOfBoundsException
469 ("Coordinate out of bounds!");
470 }
471 byte inData[] = (byte[])obj;
472 int off = (y-minY)*scanlineStride +
473 (x-minX)*pixelStride;
474
475 for (int i = 0; i < numDataElements; i++) {
476 data[dataOffsets[i] + off] = inData[i];
477 }
478
479 markDirty();
480 }
481
560 }
561 }
562
563 /**
564 * Stores an array of data elements into the specified rectangular
565 * region.
566 * An ArrayIndexOutOfBounds exception will be thrown at runtime
567 * if the pixel coordinates are out of bounds.
568 * A ClassCastException will be thrown if the input object is non null
569 * and references anything other than an array of transferType.
570 * The data elements in the
571 * data array are assumed to be packed. That is, a data element
572 * for the nth band at location (x2, y2) would be found at:
573 * <pre>
574 * inData[((y2-y)*w + (x2-x))*numDataElements + n]
575 * </pre>
576 * @param x The X coordinate of the upper left pixel location.
577 * @param y The Y coordinate of the upper left pixel location.
578 * @param w Width of the pixel rectangle.
579 * @param h Height of the pixel rectangle.
580 * @param inData An object reference to an array of type defined by
581 * getTransferType() and length w*h*getNumDataElements()
582 * containing the pixel data to place between x,y and
583 * x+h, y+h.
584 */
585 public void setDataElements(int x, int y, int w, int h, Object obj) {
586 if ((x < this.minX) || (y < this.minY) ||
587 (x + w > this.maxX) || (y + h > this.maxY)) {
588 throw new ArrayIndexOutOfBoundsException
589 ("Coordinate out of bounds!");
590 }
591 byte inData[] = (byte[])obj;
592 int yoff = (y-minY)*scanlineStride +
593 (x-minX)*pixelStride;
594 int xoff;
595 int off = 0;
596 int xstart;
597 int ystart;
598
599 if (numDataElements == 1) {
600 int srcOffset = 0;
|
236 public int getPixelStride() {
237 return pixelStride;
238 }
239
240 /**
241 * Returns a reference to the data array.
242 */
243 public byte[] getDataStorage() {
244 return data;
245 }
246
247 /**
248 * Returns the data elements for all bands at the specified
249 * location.
250 * An ArrayIndexOutOfBounds exception will be thrown at runtime
251 * if the pixel coordinate is out of bounds.
252 * A ClassCastException will be thrown if the input object is non null
253 * and references anything other than an array of transferType.
254 * @param x The X coordinate of the pixel location.
255 * @param y The Y coordinate of the pixel location.
256 * @param obj An object reference to an array of type defined by
257 * getTransferType() and length getNumDataElements().
258 * If null an array of appropriate type and size will be
259 * allocated.
260 * @return An object reference to an array of type defined by
261 * getTransferType() with the request pixel data.
262 */
263 public Object getDataElements(int x, int y, Object obj) {
264 if ((x < this.minX) || (y < this.minY) ||
265 (x >= this.maxX) || (y >= this.maxY)) {
266 throw new ArrayIndexOutOfBoundsException
267 ("Coordinate out of bounds!");
268 }
269 byte outData[];
270 if (obj == null) {
271 outData = new byte[numDataElements];
272 } else {
273 outData = (byte[])obj;
274 }
275 int off = (y-minY)*scanlineStride +
276 (x-minX)*pixelStride;
282 return outData;
283 }
284
285 /**
286 * Returns an array of data elements from the specified rectangular
287 * region.
288 * An ArrayIndexOutOfBounds exception will be thrown at runtime
289 * if the pixel coordinates are out of bounds.
290 * A ClassCastException will be thrown if the input object is non null
291 * and references anything other than an array of transferType.
292 * <pre>
293 * byte[] bandData = (byte[])raster.getDataElements(x, y, w, h, null);
294 * int numDataElements = raster.getNumDataElements();
295 * byte[] pixel = new byte[numDataElements];
296 * // To find a data element at location (x2, y2)
297 * System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
298 * pixel, 0, numDataElements);
299 * </pre>
300 * @param x The X coordinate of the upper left pixel location.
301 * @param y The Y coordinate of the upper left pixel location.
302 * @param w Width of the pixel rectangle.
303 * @param h Height of the pixel rectangle.
304 * @param obj An object reference to an array of type defined by
305 * getTransferType() and length w*h*getNumDataElements().
306 * If null an array of appropriate type and size will be
307 * allocated.
308 * @return An object reference to an array of type defined by
309 * getTransferType() with the request pixel data.
310 */
311 public Object getDataElements(int x, int y, int w, int h, Object obj) {
312 if ((x < this.minX) || (y < this.minY) ||
313 (x + w > this.maxX) || (y + h > this.maxY)) {
314 throw new ArrayIndexOutOfBoundsException
315 ("Coordinate out of bounds!");
316 }
317 byte outData[];
318 if (obj == null) {
319 outData = new byte[w*h*numDataElements];
320 } else {
321 outData = (byte[])obj;
322 }
323
324 int yoff = (y-minY)*scanlineStride +
335 outData[off++] = data[dataOffsets[c] + xoff];
336 }
337 }
338 }
339
340 return outData;
341 }
342
343 /**
344 * Returns a byte array of data elements from the specified rectangular
345 * region for the specified band.
346 * An ArrayIndexOutOfBounds exception will be thrown at runtime
347 * if the pixel coordinates are out of bounds.
348 * <pre>
349 * byte[] bandData = raster.getByteData(x, y, w, h, null);
350 * // To find the data element at location (x2, y2)
351 * byte bandElement = bandData[((y2-y)*w + (x2-x))];
352 * </pre>
353 * @param x The X coordinate of the upper left pixel location.
354 * @param y The Y coordinate of the upper left pixel location.
355 * @param w Width of the pixel rectangle.
356 * @param h Height of the pixel rectangle.
357 * @param band The band to return.
358 * @param outData If non-null, data elements for all bands
359 * at the specified location are returned in this array.
360 * @return Data array with data elements for all bands.
361 */
362 public byte[] getByteData(int x, int y, int w, int h,
363 int band, byte[] outData) {
364 // Bounds check for 'band' will be performed automatically
365 if ((x < this.minX) || (y < this.minY) ||
366 (x + w > this.maxX) || (y + h > this.maxY)) {
367 throw new ArrayIndexOutOfBoundsException
368 ("Coordinate out of bounds!");
369 }
370 if (outData == null) {
371 outData = new byte[scanlineStride*h];
372 }
373 int yoff = (y-minY)*scanlineStride +
374 (x-minX)*pixelStride + dataOffsets[band];
375 int xoff;
376 int off = 0;
398 }
399
400 return outData;
401 }
402
403 /**
404 * Returns a byte array of data elements from the specified rectangular
405 * region.
406 * An ArrayIndexOutOfBounds exception will be thrown at runtime
407 * if the pixel coordinates are out of bounds.
408 * <pre>
409 * byte[] bandData = raster.getByteData(x, y, w, h, null);
410 * int numDataElements = raster.getnumDataElements();
411 * byte[] pixel = new byte[numDataElements];
412 * // To find a data element at location (x2, y2)
413 * System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
414 * pixel, 0, numDataElements);
415 * </pre>
416 * @param x The X coordinate of the upper left pixel location.
417 * @param y The Y coordinate of the upper left pixel location.
418 * @param w Width of the pixel rectangle.
419 * @param h Height of the pixel rectangle.
420 * @param outData If non-null, data elements for all bands
421 * at the specified location are returned in this array.
422 * @return Data array with data elements for all bands.
423 */
424 public byte[] getByteData(int x, int y, int w, int h, byte[] outData) {
425 if ((x < this.minX) || (y < this.minY) ||
426 (x + w > this.maxX) || (y + h > this.maxY)) {
427 throw new ArrayIndexOutOfBoundsException
428 ("Coordinate out of bounds!");
429 }
430 if (outData == null) {
431 outData = new byte[numDataElements*scanlineStride*h];
432 }
433 int yoff = (y-minY)*scanlineStride +
434 (x-minX)*pixelStride;
435 int xoff;
436 int off = 0;
437 int xstart;
438 int ystart;
439
441 for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
442 xoff = yoff;
443 for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
444 for (int c = 0; c < numDataElements; c++) {
445 outData[off++] = data[dataOffsets[c] + xoff];
446 }
447 }
448 }
449
450 return outData;
451 }
452
453 /**
454 * Stores the data elements for all bands at the specified location.
455 * An ArrayIndexOutOfBounds exception will be thrown at runtime
456 * if the pixel coordinate is out of bounds.
457 * A ClassCastException will be thrown if the input object is non null
458 * and references anything other than an array of transferType.
459 * @param x The X coordinate of the pixel location.
460 * @param y The Y coordinate of the pixel location.
461 * @param obj An object reference to an array of type defined by
462 * getTransferType() and length getNumDataElements()
463 * containing the pixel data to place at x,y.
464 */
465 public void setDataElements(int x, int y, Object obj) {
466 if ((x < this.minX) || (y < this.minY) ||
467 (x >= this.maxX) || (y >= this.maxY)) {
468 throw new ArrayIndexOutOfBoundsException
469 ("Coordinate out of bounds!");
470 }
471 byte inData[] = (byte[])obj;
472 int off = (y-minY)*scanlineStride +
473 (x-minX)*pixelStride;
474
475 for (int i = 0; i < numDataElements; i++) {
476 data[dataOffsets[i] + off] = inData[i];
477 }
478
479 markDirty();
480 }
481
560 }
561 }
562
563 /**
564 * Stores an array of data elements into the specified rectangular
565 * region.
566 * An ArrayIndexOutOfBounds exception will be thrown at runtime
567 * if the pixel coordinates are out of bounds.
568 * A ClassCastException will be thrown if the input object is non null
569 * and references anything other than an array of transferType.
570 * The data elements in the
571 * data array are assumed to be packed. That is, a data element
572 * for the nth band at location (x2, y2) would be found at:
573 * <pre>
574 * inData[((y2-y)*w + (x2-x))*numDataElements + n]
575 * </pre>
576 * @param x The X coordinate of the upper left pixel location.
577 * @param y The Y coordinate of the upper left pixel location.
578 * @param w Width of the pixel rectangle.
579 * @param h Height of the pixel rectangle.
580 * @param obj An object reference to an array of type defined by
581 * getTransferType() and length w*h*getNumDataElements()
582 * containing the pixel data to place between x,y and
583 * x+h, y+h.
584 */
585 public void setDataElements(int x, int y, int w, int h, Object obj) {
586 if ((x < this.minX) || (y < this.minY) ||
587 (x + w > this.maxX) || (y + h > this.maxY)) {
588 throw new ArrayIndexOutOfBoundsException
589 ("Coordinate out of bounds!");
590 }
591 byte inData[] = (byte[])obj;
592 int yoff = (y-minY)*scanlineStride +
593 (x-minX)*pixelStride;
594 int xoff;
595 int off = 0;
596 int xstart;
597 int ystart;
598
599 if (numDataElements == 1) {
600 int srcOffset = 0;
|