1 /*
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
255 * location.
256 * An ArrayIndexOutOfBounds exception will be thrown at runtime
257 * if the pixel coordinate is out of bounds.
258 * A ClassCastException will be thrown if the input object is non null
259 * and references anything other than an array of transferType.
260 * @param x The X coordinate of the pixel location.
261 * @param y The Y coordinate of the pixel location.
262 * @param obj An object reference to an array of type defined by
263 * getTransferType() and length getNumDataElements().
264 * If null an array of appropriate type and size will be
265 * allocated.
266 * @return An object reference to an array of type defined by
267 * getTransferType() with the request pixel data.
268 */
269 public Object getDataElements(int x, int y, Object obj) {
270 if ((x < this.minX) || (y < this.minY) ||
271 (x >= this.maxX) || (y >= this.maxY)) {
272 throw new ArrayIndexOutOfBoundsException
273 ("Coordinate out of bounds!");
274 }
275 int outData[];
276 if (obj == null) {
277 outData = new int[numDataElements];
278 } else {
279 outData = (int[])obj;
280 }
281 int off = (y-minY)*scanlineStride +
282 (x-minX)*pixelStride;
283 for (int band = 0; band < numDataElements; band++) {
284 outData[band] = data[dataOffsets[band] + off];
285 }
286
287 return outData;
288 }
289
290
291 /**
292 * Returns an array of data elements from the specified rectangular
293 * region.
294 * An ArrayIndexOutOfBounds exception will be thrown at runtime
295 * if the pixel coordinates are out of bounds.
303 * System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
304 * pixel, 0, numDataElements);
305 * </pre>
306 * @param x The X coordinate of the upper left pixel location.
307 * @param y The Y coordinate of the upper left pixel location.
308 * @param w Width of the pixel rectangle.
309 * @param h Height of the pixel rectangle.
310 * @param obj An object reference to an array of type defined by
311 * getTransferType() and length w*h*getNumDataElements().
312 * If null an array of appropriate type and size will be
313 * allocated.
314 * @return An object reference to an array of type defined by
315 * getTransferType() with the request pixel data.
316 */
317 public Object getDataElements(int x, int y, int w, int h, Object obj) {
318 if ((x < this.minX) || (y < this.minY) ||
319 (x + w > this.maxX) || (y + h > this.maxY)) {
320 throw new ArrayIndexOutOfBoundsException
321 ("Coordinate out of bounds!");
322 }
323 int outData[];
324 if (obj instanceof int[]) {
325 outData = (int[])obj;
326 } else {
327 outData = new int[numDataElements*w*h];
328 }
329 int yoff = (y-minY)*scanlineStride +
330 (x-minX)*pixelStride;
331 int xoff;
332 int off = 0;
333 int xstart;
334 int ystart;
335
336 for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
337 xoff = yoff;
338 for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
339 for (int c = 0; c < numDataElements; c++) {
340 outData[off++] = data[dataOffsets[c] + xoff];
341 }
342 }
343 }
347
348
349 /**
350 * Stores the data elements for all bands at the specified location.
351 * An ArrayIndexOutOfBounds exception will be thrown at runtime
352 * if the pixel coordinate is out of bounds.
353 * A ClassCastException will be thrown if the input object is non null
354 * and references anything other than an array of transferType.
355 * @param x The X coordinate of the pixel location.
356 * @param y The Y coordinate of the pixel location.
357 * @param obj An object reference to an array of type defined by
358 * getTransferType() and length getNumDataElements()
359 * containing the pixel data to place at x,y.
360 */
361 public void setDataElements(int x, int y, Object obj) {
362 if ((x < this.minX) || (y < this.minY) ||
363 (x >= this.maxX) || (y >= this.maxY)) {
364 throw new ArrayIndexOutOfBoundsException
365 ("Coordinate out of bounds!");
366 }
367 int inData[] = (int[])obj;
368
369 int off = (y-minY)*scanlineStride +
370 (x-minX)*pixelStride;
371
372 for (int i = 0; i < numDataElements; i++) {
373 data[dataOffsets[i] + off] = inData[i];
374 }
375
376 markDirty();
377 }
378
379
380 /**
381 * Stores the Raster data at the specified location.
382 * The transferType of the inputRaster must match this raster.
383 * An ArrayIndexOutOfBoundsException will be thrown at runtime
384 * if the pixel coordinates are out of bounds.
385 * @param x The X coordinate of the pixel location.
386 * @param y The Y coordinate of the pixel location.
387 * @param inRaster Raster of data to place at x,y location.
406 * inRaster
407 * @param dstY The absolute Y coordinate of the destination pixel
408 * that will receive a copy of the upper-left pixel of the
409 * inRaster
410 * @param width The number of pixels to store horizontally
411 * @param height The number of pixels to store vertically
412 * @param inRaster Raster of data to place at x,y location.
413 */
414 private void setDataElements(int dstX, int dstY,
415 int width, int height,
416 Raster inRaster) {
417 // Assume bounds checking has been performed previously
418 if (width <= 0 || height <= 0) {
419 return;
420 }
421
422 // Write inRaster (minX, minY) to (dstX, dstY)
423
424 int srcOffX = inRaster.getMinX();
425 int srcOffY = inRaster.getMinY();
426 int tdata[] = null;
427
428 if (inRaster instanceof IntegerComponentRaster &&
429 (pixelStride == 1) && (numDataElements == 1)) {
430 IntegerComponentRaster ict = (IntegerComponentRaster) inRaster;
431 if (ict.getNumDataElements() != 1) {
432 throw new ArrayIndexOutOfBoundsException("Number of bands"+
433 " does not match");
434 }
435
436 // Extract the raster parameters
437 tdata = ict.getDataStorage();
438 int tss = ict.getScanlineStride();
439 int toff = ict.getDataOffset(0);
440
441 int srcOffset = toff;
442
443 int dstOffset = dataOffsets[0]+(dstY-minY)*scanlineStride+
444 (dstX-minX);
445
446
479 * data array are assumed to be packed. That is, a data element
480 * for the nth band at location (x2, y2) would be found at:
481 * <pre>
482 * inData[((y2-y)*w + (x2-x))*numDataElements + n]
483 * </pre>
484 * @param x The X coordinate of the upper left pixel location.
485 * @param y The Y coordinate of the upper left pixel location.
486 * @param w Width of the pixel rectangle.
487 * @param h Height of the pixel rectangle.
488 * @param obj An object reference to an array of type defined by
489 * getTransferType() and length w*h*getNumDataElements()
490 * containing the pixel data to place between x,y and
491 * x+h, y+h.
492 */
493 public void setDataElements(int x, int y, int w, int h, Object obj) {
494 if ((x < this.minX) || (y < this.minY) ||
495 (x + w > this.maxX) || (y + h > this.maxY)) {
496 throw new ArrayIndexOutOfBoundsException
497 ("Coordinate out of bounds!");
498 }
499 int inData[] = (int[])obj;
500
501 int yoff = (y-minY)*scanlineStride +
502 (x-minX)*pixelStride;
503 int xoff;
504 int off = 0;
505 int xstart;
506 int ystart;
507
508 for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
509 xoff = yoff;
510 for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
511 for (int c = 0; c < numDataElements; c++) {
512 data[dataOffsets[c] + xoff] = inData[off++];
513 }
514 }
515 }
516
517 markDirty();
518 }
519
523 * coordinates specify the horizontal and vertical offsets
524 * from the upper-left corner of this raster to the upper-left corner
525 * of the subraster. A subset of the bands of the parent Raster may
526 * be specified. If this is null, then all the bands are present in the
527 * subRaster. A translation to the subRaster may also be specified.
528 * Note that the subraster will reference the same
529 * DataBuffer as the parent raster, but using different offsets.
530 * @param x X offset.
531 * @param y Y offset.
532 * @param width Width (in pixels) of the subraster.
533 * @param height Height (in pixels) of the subraster.
534 * @param x0 Translated X origin of the subraster.
535 * @param y0 Translated Y origin of the subraster.
536 * @param bandList Array of band indices.
537 * @exception RasterFormatException
538 * if the specified bounding box is outside of the parent raster.
539 */
540 public WritableRaster createWritableChild (int x, int y,
541 int width, int height,
542 int x0, int y0,
543 int bandList[]) {
544 if (x < this.minX) {
545 throw new RasterFormatException("x lies outside raster");
546 }
547 if (y < this.minY) {
548 throw new RasterFormatException("y lies outside raster");
549 }
550 if ((x+width < x) || (x+width > this.minX + this.width)) {
551 throw new RasterFormatException("(x + width) is outside raster");
552 }
553 if ((y+height < y) || (y+height > this.minY + this.height)) {
554 throw new RasterFormatException("(y + height) is outside raster");
555 }
556
557 SampleModel sm;
558
559 if (bandList != null)
560 sm = sampleModel.createSubsetSampleModel(bandList);
561 else
562 sm = sampleModel;
563
577 * Creates a subraster given a region of the raster. The x and y
578 * coordinates specify the horizontal and vertical offsets
579 * from the upper-left corner of this raster to the upper-left corner
580 * of the subraster. A subset of the bands of the parent raster may
581 * be specified. If this is null, then all the bands are present in the
582 * subRaster. Note that the subraster will reference the same
583 * DataBuffer as the parent raster, but using different offsets.
584 * @param x X offset.
585 * @param y Y offset.
586 * @param width Width (in pixels) of the subraster.
587 * @param height Height (in pixels) of the subraster.
588 * @param x0 Translated X origin of the subRaster.
589 * @param y0 Translated Y origin of the subRaster.
590 * @param bandList Array of band indices.
591 * @exception RasterFormatException
592 * if the specified bounding box is outside of the parent raster.
593 */
594 public Raster createChild (int x, int y,
595 int width, int height,
596 int x0, int y0,
597 int bandList[]) {
598 return createWritableChild(x, y, width, height, x0, y0, bandList);
599 }
600
601
602 /**
603 * Creates a raster with the same band layout but using a different
604 * width and height, and with new zeroed data arrays.
605 */
606 public WritableRaster createCompatibleWritableRaster(int w, int h) {
607 if (w <= 0 || h <=0) {
608 throw new RasterFormatException("negative "+
609 ((w <= 0) ? "width" : "height"));
610 }
611
612 SampleModel sm = sampleModel.createCompatibleSampleModel(w,h);
613
614 return new IntegerComponentRaster(sm, new Point(0,0));
615 }
616
617 /**
|
1 /*
2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
255 * location.
256 * An ArrayIndexOutOfBounds exception will be thrown at runtime
257 * if the pixel coordinate is out of bounds.
258 * A ClassCastException will be thrown if the input object is non null
259 * and references anything other than an array of transferType.
260 * @param x The X coordinate of the pixel location.
261 * @param y The Y coordinate of the pixel location.
262 * @param obj An object reference to an array of type defined by
263 * getTransferType() and length getNumDataElements().
264 * If null an array of appropriate type and size will be
265 * allocated.
266 * @return An object reference to an array of type defined by
267 * getTransferType() with the request pixel data.
268 */
269 public Object getDataElements(int x, int y, Object obj) {
270 if ((x < this.minX) || (y < this.minY) ||
271 (x >= this.maxX) || (y >= this.maxY)) {
272 throw new ArrayIndexOutOfBoundsException
273 ("Coordinate out of bounds!");
274 }
275 int[] outData;
276 if (obj == null) {
277 outData = new int[numDataElements];
278 } else {
279 outData = (int[])obj;
280 }
281 int off = (y-minY)*scanlineStride +
282 (x-minX)*pixelStride;
283 for (int band = 0; band < numDataElements; band++) {
284 outData[band] = data[dataOffsets[band] + off];
285 }
286
287 return outData;
288 }
289
290
291 /**
292 * Returns an array of data elements from the specified rectangular
293 * region.
294 * An ArrayIndexOutOfBounds exception will be thrown at runtime
295 * if the pixel coordinates are out of bounds.
303 * System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
304 * pixel, 0, numDataElements);
305 * </pre>
306 * @param x The X coordinate of the upper left pixel location.
307 * @param y The Y coordinate of the upper left pixel location.
308 * @param w Width of the pixel rectangle.
309 * @param h Height of the pixel rectangle.
310 * @param obj An object reference to an array of type defined by
311 * getTransferType() and length w*h*getNumDataElements().
312 * If null an array of appropriate type and size will be
313 * allocated.
314 * @return An object reference to an array of type defined by
315 * getTransferType() with the request pixel data.
316 */
317 public Object getDataElements(int x, int y, int w, int h, Object obj) {
318 if ((x < this.minX) || (y < this.minY) ||
319 (x + w > this.maxX) || (y + h > this.maxY)) {
320 throw new ArrayIndexOutOfBoundsException
321 ("Coordinate out of bounds!");
322 }
323 int[] outData;
324 if (obj instanceof int[]) {
325 outData = (int[])obj;
326 } else {
327 outData = new int[numDataElements*w*h];
328 }
329 int yoff = (y-minY)*scanlineStride +
330 (x-minX)*pixelStride;
331 int xoff;
332 int off = 0;
333 int xstart;
334 int ystart;
335
336 for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
337 xoff = yoff;
338 for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
339 for (int c = 0; c < numDataElements; c++) {
340 outData[off++] = data[dataOffsets[c] + xoff];
341 }
342 }
343 }
347
348
349 /**
350 * Stores the data elements for all bands at the specified location.
351 * An ArrayIndexOutOfBounds exception will be thrown at runtime
352 * if the pixel coordinate is out of bounds.
353 * A ClassCastException will be thrown if the input object is non null
354 * and references anything other than an array of transferType.
355 * @param x The X coordinate of the pixel location.
356 * @param y The Y coordinate of the pixel location.
357 * @param obj An object reference to an array of type defined by
358 * getTransferType() and length getNumDataElements()
359 * containing the pixel data to place at x,y.
360 */
361 public void setDataElements(int x, int y, Object obj) {
362 if ((x < this.minX) || (y < this.minY) ||
363 (x >= this.maxX) || (y >= this.maxY)) {
364 throw new ArrayIndexOutOfBoundsException
365 ("Coordinate out of bounds!");
366 }
367 int[] inData = (int[])obj;
368
369 int off = (y-minY)*scanlineStride +
370 (x-minX)*pixelStride;
371
372 for (int i = 0; i < numDataElements; i++) {
373 data[dataOffsets[i] + off] = inData[i];
374 }
375
376 markDirty();
377 }
378
379
380 /**
381 * Stores the Raster data at the specified location.
382 * The transferType of the inputRaster must match this raster.
383 * An ArrayIndexOutOfBoundsException will be thrown at runtime
384 * if the pixel coordinates are out of bounds.
385 * @param x The X coordinate of the pixel location.
386 * @param y The Y coordinate of the pixel location.
387 * @param inRaster Raster of data to place at x,y location.
406 * inRaster
407 * @param dstY The absolute Y coordinate of the destination pixel
408 * that will receive a copy of the upper-left pixel of the
409 * inRaster
410 * @param width The number of pixels to store horizontally
411 * @param height The number of pixels to store vertically
412 * @param inRaster Raster of data to place at x,y location.
413 */
414 private void setDataElements(int dstX, int dstY,
415 int width, int height,
416 Raster inRaster) {
417 // Assume bounds checking has been performed previously
418 if (width <= 0 || height <= 0) {
419 return;
420 }
421
422 // Write inRaster (minX, minY) to (dstX, dstY)
423
424 int srcOffX = inRaster.getMinX();
425 int srcOffY = inRaster.getMinY();
426 int[] tdata = null;
427
428 if (inRaster instanceof IntegerComponentRaster &&
429 (pixelStride == 1) && (numDataElements == 1)) {
430 IntegerComponentRaster ict = (IntegerComponentRaster) inRaster;
431 if (ict.getNumDataElements() != 1) {
432 throw new ArrayIndexOutOfBoundsException("Number of bands"+
433 " does not match");
434 }
435
436 // Extract the raster parameters
437 tdata = ict.getDataStorage();
438 int tss = ict.getScanlineStride();
439 int toff = ict.getDataOffset(0);
440
441 int srcOffset = toff;
442
443 int dstOffset = dataOffsets[0]+(dstY-minY)*scanlineStride+
444 (dstX-minX);
445
446
479 * data array are assumed to be packed. That is, a data element
480 * for the nth band at location (x2, y2) would be found at:
481 * <pre>
482 * inData[((y2-y)*w + (x2-x))*numDataElements + n]
483 * </pre>
484 * @param x The X coordinate of the upper left pixel location.
485 * @param y The Y coordinate of the upper left pixel location.
486 * @param w Width of the pixel rectangle.
487 * @param h Height of the pixel rectangle.
488 * @param obj An object reference to an array of type defined by
489 * getTransferType() and length w*h*getNumDataElements()
490 * containing the pixel data to place between x,y and
491 * x+h, y+h.
492 */
493 public void setDataElements(int x, int y, int w, int h, Object obj) {
494 if ((x < this.minX) || (y < this.minY) ||
495 (x + w > this.maxX) || (y + h > this.maxY)) {
496 throw new ArrayIndexOutOfBoundsException
497 ("Coordinate out of bounds!");
498 }
499 int[] inData = (int[])obj;
500
501 int yoff = (y-minY)*scanlineStride +
502 (x-minX)*pixelStride;
503 int xoff;
504 int off = 0;
505 int xstart;
506 int ystart;
507
508 for (ystart=0; ystart < h; ystart++, yoff += scanlineStride) {
509 xoff = yoff;
510 for (xstart=0; xstart < w; xstart++, xoff += pixelStride) {
511 for (int c = 0; c < numDataElements; c++) {
512 data[dataOffsets[c] + xoff] = inData[off++];
513 }
514 }
515 }
516
517 markDirty();
518 }
519
523 * coordinates specify the horizontal and vertical offsets
524 * from the upper-left corner of this raster to the upper-left corner
525 * of the subraster. A subset of the bands of the parent Raster may
526 * be specified. If this is null, then all the bands are present in the
527 * subRaster. A translation to the subRaster may also be specified.
528 * Note that the subraster will reference the same
529 * DataBuffer as the parent raster, but using different offsets.
530 * @param x X offset.
531 * @param y Y offset.
532 * @param width Width (in pixels) of the subraster.
533 * @param height Height (in pixels) of the subraster.
534 * @param x0 Translated X origin of the subraster.
535 * @param y0 Translated Y origin of the subraster.
536 * @param bandList Array of band indices.
537 * @exception RasterFormatException
538 * if the specified bounding box is outside of the parent raster.
539 */
540 public WritableRaster createWritableChild (int x, int y,
541 int width, int height,
542 int x0, int y0,
543 int[] bandList) {
544 if (x < this.minX) {
545 throw new RasterFormatException("x lies outside raster");
546 }
547 if (y < this.minY) {
548 throw new RasterFormatException("y lies outside raster");
549 }
550 if ((x+width < x) || (x+width > this.minX + this.width)) {
551 throw new RasterFormatException("(x + width) is outside raster");
552 }
553 if ((y+height < y) || (y+height > this.minY + this.height)) {
554 throw new RasterFormatException("(y + height) is outside raster");
555 }
556
557 SampleModel sm;
558
559 if (bandList != null)
560 sm = sampleModel.createSubsetSampleModel(bandList);
561 else
562 sm = sampleModel;
563
577 * Creates a subraster given a region of the raster. The x and y
578 * coordinates specify the horizontal and vertical offsets
579 * from the upper-left corner of this raster to the upper-left corner
580 * of the subraster. A subset of the bands of the parent raster may
581 * be specified. If this is null, then all the bands are present in the
582 * subRaster. Note that the subraster will reference the same
583 * DataBuffer as the parent raster, but using different offsets.
584 * @param x X offset.
585 * @param y Y offset.
586 * @param width Width (in pixels) of the subraster.
587 * @param height Height (in pixels) of the subraster.
588 * @param x0 Translated X origin of the subRaster.
589 * @param y0 Translated Y origin of the subRaster.
590 * @param bandList Array of band indices.
591 * @exception RasterFormatException
592 * if the specified bounding box is outside of the parent raster.
593 */
594 public Raster createChild (int x, int y,
595 int width, int height,
596 int x0, int y0,
597 int[] bandList) {
598 return createWritableChild(x, y, width, height, x0, y0, bandList);
599 }
600
601
602 /**
603 * Creates a raster with the same band layout but using a different
604 * width and height, and with new zeroed data arrays.
605 */
606 public WritableRaster createCompatibleWritableRaster(int w, int h) {
607 if (w <= 0 || h <=0) {
608 throw new RasterFormatException("negative "+
609 ((w <= 0) ? "width" : "height"));
610 }
611
612 SampleModel sm = sampleModel.createCompatibleSampleModel(w,h);
613
614 return new IntegerComponentRaster(sm, new Point(0,0));
615 }
616
617 /**
|