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
237 * @param pixelStride the pixel stride of the image data
238 * @param bandOffsets the offsets of all bands
239 * @param location the upper-left corner of the {@code Raster}
240 * @return a WritableRaster object with the specified data type,
241 * width, height, scanline stride, pixel stride and band
242 * offsets.
243 * @throws RasterFormatException if {@code w} or {@code h}
244 * is less than or equal to zero, or computing either
245 * {@code location.x + w} or
246 * {@code location.y + h} results in integer
247 * overflow
248 * @throws IllegalArgumentException if {@code dataType} is not
249 * one of the supported data types, which are
250 * {@code DataBuffer.TYPE_BYTE}, or
251 * {@code DataBuffer.TYPE_USHORT}.
252 */
253 public static WritableRaster createInterleavedRaster(int dataType,
254 int w, int h,
255 int scanlineStride,
256 int pixelStride,
257 int bandOffsets[],
258 Point location) {
259 DataBuffer d;
260
261 int size = scanlineStride * (h - 1) + // fisrt (h - 1) scans
262 pixelStride * w; // last scan
263
264 switch(dataType) {
265 case DataBuffer.TYPE_BYTE:
266 d = new DataBufferByte(size);
267 break;
268
269 case DataBuffer.TYPE_USHORT:
270 d = new DataBufferUShort(size);
271 break;
272
273 default:
274 throw new IllegalArgumentException("Unsupported data type " +
275 dataType);
276 }
277
348 * @param location the upper-left corner of the {@code Raster}
349 * @return a WritableRaster object with the specified data type,
350 * width, height, scanline stride, bank indices and band
351 * offsets.
352 * @throws RasterFormatException if {@code w} or {@code h}
353 * is less than or equal to zero, or computing either
354 * {@code location.x + w} or
355 * {@code location.y + h} results in integer
356 * overflow
357 * @throws IllegalArgumentException if {@code dataType} is not
358 * one of the supported data types, which are
359 * {@code DataBuffer.TYPE_BYTE},
360 * {@code DataBuffer.TYPE_USHORT}
361 * or {@code DataBuffer.TYPE_INT}
362 * @throws ArrayIndexOutOfBoundsException if {@code bankIndices}
363 * or {@code bandOffsets} is {@code null}
364 */
365 public static WritableRaster createBandedRaster(int dataType,
366 int w, int h,
367 int scanlineStride,
368 int bankIndices[],
369 int bandOffsets[],
370 Point location) {
371 DataBuffer d;
372 int bands = bandOffsets.length;
373
374 if (bankIndices == null) {
375 throw new
376 ArrayIndexOutOfBoundsException("Bank indices array is null");
377 }
378 if (bandOffsets == null) {
379 throw new
380 ArrayIndexOutOfBoundsException("Band offsets array is null");
381 }
382
383 // Figure out the #banks and the largest band offset
384 int maxBank = bankIndices[0];
385 int maxBandOff = bandOffsets[0];
386 for (int i = 1; i < bands; i++) {
387 if (bankIndices[i] > maxBank) {
388 maxBank = bankIndices[i];
389 }
433 * @param dataType the data type for storing samples
434 * @param w the width in pixels of the image data
435 * @param h the height in pixels of the image data
436 * @param bandMasks an array containing an entry for each band
437 * @param location the upper-left corner of the {@code Raster}
438 * @return a WritableRaster object with the specified data type,
439 * width, height, and band masks.
440 * @throws RasterFormatException if {@code w} or {@code h}
441 * is less than or equal to zero, or computing either
442 * {@code location.x + w} or
443 * {@code location.y + h} results in integer
444 * overflow
445 * @throws IllegalArgumentException if {@code dataType} is not
446 * one of the supported data types, which are
447 * {@code DataBuffer.TYPE_BYTE},
448 * {@code DataBuffer.TYPE_USHORT}
449 * or {@code DataBuffer.TYPE_INT}
450 */
451 public static WritableRaster createPackedRaster(int dataType,
452 int w, int h,
453 int bandMasks[],
454 Point location) {
455 DataBuffer d;
456
457 switch(dataType) {
458 case DataBuffer.TYPE_BYTE:
459 d = new DataBufferByte(w*h);
460 break;
461
462 case DataBuffer.TYPE_USHORT:
463 d = new DataBufferUShort(w*h);
464 break;
465
466 case DataBuffer.TYPE_INT:
467 d = new DataBufferInt(w*h);
468 break;
469
470 default:
471 throw new IllegalArgumentException("Unsupported data type " +
472 dataType);
473 }
611 * @return a WritableRaster object with the specified
612 * {@code DataBuffer}, width, height, scanline stride,
613 * pixel stride and band offsets.
614 * @throws RasterFormatException if {@code w} or {@code h}
615 * is less than or equal to zero, or computing either
616 * {@code location.x + w} or
617 * {@code location.y + h} results in integer
618 * overflow
619 * @throws IllegalArgumentException if {@code dataType} is not
620 * one of the supported data types, which are
621 * {@code DataBuffer.TYPE_BYTE},
622 * {@code DataBuffer.TYPE_USHORT}
623 * @throws RasterFormatException if {@code dataBuffer} has more
624 * than one bank.
625 * @throws NullPointerException if {@code dataBuffer} is null
626 */
627 public static WritableRaster createInterleavedRaster(DataBuffer dataBuffer,
628 int w, int h,
629 int scanlineStride,
630 int pixelStride,
631 int bandOffsets[],
632 Point location)
633 {
634 if (dataBuffer == null) {
635 throw new NullPointerException("DataBuffer cannot be null");
636 }
637 if (location == null) {
638 location = new Point(0, 0);
639 }
640 int dataType = dataBuffer.getDataType();
641
642 PixelInterleavedSampleModel csm =
643 new PixelInterleavedSampleModel(dataType, w, h,
644 pixelStride,
645 scanlineStride,
646 bandOffsets);
647 switch(dataType) {
648 case DataBuffer.TYPE_BYTE:
649 if (dataBuffer instanceof DataBufferByte) {
650 return new ByteInterleavedRaster(csm,
651 (DataBufferByte) dataBuffer, location);
684 * @param bandOffsets the offsets of all bands
685 * @param location the upper-left corner of the {@code Raster}
686 * @return a WritableRaster object with the specified
687 * {@code DataBuffer}, width, height, scanline stride,
688 * bank indices and band offsets.
689 * @throws RasterFormatException if {@code w} or {@code h}
690 * is less than or equal to zero, or computing either
691 * {@code location.x + w} or
692 * {@code location.y + h} results in integer
693 * overflow
694 * @throws IllegalArgumentException if {@code dataType} is not
695 * one of the supported data types, which are
696 * {@code DataBuffer.TYPE_BYTE},
697 * {@code DataBuffer.TYPE_USHORT}
698 * or {@code DataBuffer.TYPE_INT}
699 * @throws NullPointerException if {@code dataBuffer} is null
700 */
701 public static WritableRaster createBandedRaster(DataBuffer dataBuffer,
702 int w, int h,
703 int scanlineStride,
704 int bankIndices[],
705 int bandOffsets[],
706 Point location)
707 {
708 if (dataBuffer == null) {
709 throw new NullPointerException("DataBuffer cannot be null");
710 }
711 if (location == null) {
712 location = new Point(0,0);
713 }
714 int dataType = dataBuffer.getDataType();
715
716 int bands = bankIndices.length;
717 if (bandOffsets.length != bands) {
718 throw new IllegalArgumentException(
719 "bankIndices.length != bandOffsets.length");
720 }
721
722 BandedSampleModel bsm =
723 new BandedSampleModel(dataType, w, h,
724 scanlineStride,
725 bankIndices, bandOffsets);
767 * @return a WritableRaster object with the specified
768 * {@code DataBuffer}, width, height, scanline stride,
769 * and band masks.
770 * @throws RasterFormatException if {@code w} or {@code h}
771 * is less than or equal to zero, or computing either
772 * {@code location.x + w} or
773 * {@code location.y + h} results in integer
774 * overflow
775 * @throws IllegalArgumentException if {@code dataType} is not
776 * one of the supported data types, which are
777 * {@code DataBuffer.TYPE_BYTE},
778 * {@code DataBuffer.TYPE_USHORT}
779 * or {@code DataBuffer.TYPE_INT}
780 * @throws RasterFormatException if {@code dataBuffer} has more
781 * than one bank.
782 * @throws NullPointerException if {@code dataBuffer} is null
783 */
784 public static WritableRaster createPackedRaster(DataBuffer dataBuffer,
785 int w, int h,
786 int scanlineStride,
787 int bandMasks[],
788 Point location)
789 {
790 if (dataBuffer == null) {
791 throw new NullPointerException("DataBuffer cannot be null");
792 }
793 if (location == null) {
794 location = new Point(0,0);
795 }
796 int dataType = dataBuffer.getDataType();
797
798 SinglePixelPackedSampleModel sppsm =
799 new SinglePixelPackedSampleModel(dataType, w, h, scanlineStride,
800 bandMasks);
801
802 switch(dataType) {
803 case DataBuffer.TYPE_BYTE:
804 if (dataBuffer instanceof DataBufferByte) {
805 return new ByteInterleavedRaster(sppsm,
806 (DataBufferByte) dataBuffer, location);
807 }
1380 * @param height Height of the region starting at (parentX, parentY).
1381 * @param childMinX The X coordinate of the upper-left corner
1382 * of the returned Raster
1383 * @param childMinY The Y coordinate of the upper-left corner
1384 * of the returned Raster
1385 * @param bandList Array of band indices, or null to use all bands
1386 * @return a new {@code Raster}.
1387 * @exception RasterFormatException if the specified subregion is outside
1388 * of the raster bounds.
1389 * @throws RasterFormatException if {@code width} or
1390 * {@code height}
1391 * is less than or equal to zero, or computing any of
1392 * {@code parentX + width}, {@code parentY + height},
1393 * {@code childMinX + width}, or
1394 * {@code childMinY + height} results in integer
1395 * overflow
1396 */
1397 public Raster createChild(int parentX, int parentY,
1398 int width, int height,
1399 int childMinX, int childMinY,
1400 int bandList[]) {
1401 if (parentX < this.minX) {
1402 throw new RasterFormatException("parentX lies outside raster");
1403 }
1404 if (parentY < this.minY) {
1405 throw new RasterFormatException("parentY lies outside raster");
1406 }
1407 if ((parentX + width < parentX) ||
1408 (parentX + width > this.width + this.minX)) {
1409 throw new RasterFormatException("(parentX + width) is outside raster");
1410 }
1411 if ((parentY + height < parentY) ||
1412 (parentY + height > this.height + this.minY)) {
1413 throw new RasterFormatException("(parentY + height) is outside raster");
1414 }
1415
1416 SampleModel subSampleModel;
1417 // Note: the SampleModel for the child Raster should have the same
1418 // width and height as that for the parent, since it represents
1419 // the physical layout of the pixel data. The child Raster's width
1420 // and height represent a "virtual" view of the pixel data, so
1584 */
1585 public Object getDataElements(int x, int y, int w, int h, Object outData) {
1586 return sampleModel.getDataElements(x - sampleModelTranslateX,
1587 y - sampleModelTranslateY,
1588 w, h, outData, dataBuffer);
1589 }
1590
1591 /**
1592 * Returns the samples in an array of int for the specified pixel.
1593 * An ArrayIndexOutOfBoundsException may be thrown
1594 * if the coordinates are not in bounds. However, explicit bounds
1595 * checking is not guaranteed.
1596 * @param x The X coordinate of the pixel location
1597 * @param y The Y coordinate of the pixel location
1598 * @param iArray An optionally preallocated int array
1599 * @return the samples for the specified pixel.
1600 *
1601 * @throws ArrayIndexOutOfBoundsException if the coordinates are not
1602 * in bounds, or if iArray is too small to hold the output.
1603 */
1604 public int[] getPixel(int x, int y, int iArray[]) {
1605 return sampleModel.getPixel(x - sampleModelTranslateX,
1606 y - sampleModelTranslateY,
1607 iArray, dataBuffer);
1608 }
1609
1610 /**
1611 * Returns the samples in an array of float for the
1612 * specified pixel.
1613 * An ArrayIndexOutOfBoundsException may be thrown
1614 * if the coordinates are not in bounds. However, explicit bounds
1615 * checking is not guaranteed.
1616 * @param x The X coordinate of the pixel location
1617 * @param y The Y coordinate of the pixel location
1618 * @param fArray An optionally preallocated float array
1619 * @return the samples for the specified pixel.
1620 *
1621 * @throws ArrayIndexOutOfBoundsException if the coordinates are not
1622 * in bounds, or if fArray is too small to hold the output.
1623 */
1624 public float[] getPixel(int x, int y, float fArray[]) {
1625 return sampleModel.getPixel(x - sampleModelTranslateX,
1626 y - sampleModelTranslateY,
1627 fArray, dataBuffer);
1628 }
1629
1630 /**
1631 * Returns the samples in an array of double for the specified pixel.
1632 * An ArrayIndexOutOfBoundsException may be thrown
1633 * if the coordinates are not in bounds. However, explicit bounds
1634 * checking is not guaranteed.
1635 * @param x The X coordinate of the pixel location
1636 * @param y The Y coordinate of the pixel location
1637 * @param dArray An optionally preallocated double array
1638 * @return the samples for the specified pixel.
1639 *
1640 * @throws ArrayIndexOutOfBoundsException if the coordinates are not
1641 * in bounds, or if dArray is too small to hold the output.
1642 */
1643 public double[] getPixel(int x, int y, double dArray[]) {
1644 return sampleModel.getPixel(x - sampleModelTranslateX,
1645 y - sampleModelTranslateY,
1646 dArray, dataBuffer);
1647 }
1648
1649 /**
1650 * Returns an int array containing all samples for a rectangle of pixels,
1651 * one sample per array element.
1652 * An ArrayIndexOutOfBoundsException may be thrown
1653 * if the coordinates are not in bounds. However, explicit bounds
1654 * checking is not guaranteed.
1655 * @param x The X coordinate of the upper-left pixel location
1656 * @param y The Y coordinate of the upper-left pixel location
1657 * @param w Width of the pixel rectangle
1658 * @param h Height of the pixel rectangle
1659 * @param iArray An optionally pre-allocated int array
1660 * @return the samples for the specified rectangle of pixels.
1661 *
1662 * @throws ArrayIndexOutOfBoundsException if the coordinates are not
1663 * in bounds, or if iArray is too small to hold the output.
1664 */
1665 public int[] getPixels(int x, int y, int w, int h, int iArray[]) {
1666 return sampleModel.getPixels(x - sampleModelTranslateX,
1667 y - sampleModelTranslateY, w, h,
1668 iArray, dataBuffer);
1669 }
1670
1671 /**
1672 * Returns a float array containing all samples for a rectangle of pixels,
1673 * one sample per array element.
1674 * An ArrayIndexOutOfBoundsException may be thrown
1675 * if the coordinates are not in bounds. However, explicit bounds
1676 * checking is not guaranteed.
1677 * @param x The X coordinate of the pixel location
1678 * @param y The Y coordinate of the pixel location
1679 * @param w Width of the pixel rectangle
1680 * @param h Height of the pixel rectangle
1681 * @param fArray An optionally pre-allocated float array
1682 * @return the samples for the specified rectangle of pixels.
1683 *
1684 * @throws ArrayIndexOutOfBoundsException if the coordinates are not
1685 * in bounds, or if fArray is too small to hold the output.
1686 */
1687 public float[] getPixels(int x, int y, int w, int h,
1688 float fArray[]) {
1689 return sampleModel.getPixels(x - sampleModelTranslateX,
1690 y - sampleModelTranslateY, w, h,
1691 fArray, dataBuffer);
1692 }
1693
1694 /**
1695 * Returns a double array containing all samples for a rectangle of pixels,
1696 * one sample per array element.
1697 * An ArrayIndexOutOfBoundsException may be thrown
1698 * if the coordinates are not in bounds. However, explicit bounds
1699 * checking is not guaranteed.
1700 * @param x The X coordinate of the upper-left pixel location
1701 * @param y The Y coordinate of the upper-left pixel location
1702 * @param w Width of the pixel rectangle
1703 * @param h Height of the pixel rectangle
1704 * @param dArray An optionally pre-allocated double array
1705 * @return the samples for the specified rectangle of pixels.
1706 *
1707 * @throws ArrayIndexOutOfBoundsException if the coordinates are not
1708 * in bounds, or if dArray is too small to hold the output.
1709 */
1710 public double[] getPixels(int x, int y, int w, int h,
1711 double dArray[]) {
1712 return sampleModel.getPixels(x - sampleModelTranslateX,
1713 y - sampleModelTranslateY,
1714 w, h, dArray, dataBuffer);
1715 }
1716
1717
1718 /**
1719 * Returns the sample in a specified band for the pixel located
1720 * at (x,y) as an int.
1721 * An ArrayIndexOutOfBoundsException may be thrown
1722 * if the coordinates are not in bounds. However, explicit bounds
1723 * checking is not guaranteed.
1724 * @param x The X coordinate of the pixel location
1725 * @param y The Y coordinate of the pixel location
1726 * @param b The band to return
1727 * @return the sample in the specified band for the pixel at the
1728 * specified coordinate.
1729 *
1730 * @throws ArrayIndexOutOfBoundsException if the coordinates or
1731 * the band index are not in bounds.
1781 /**
1782 * Returns the samples for a specified band for the specified rectangle
1783 * of pixels in an int array, one sample per array element.
1784 * An ArrayIndexOutOfBoundsException may be thrown
1785 * if the coordinates are not in bounds. However, explicit bounds
1786 * checking is not guaranteed.
1787 * @param x The X coordinate of the upper-left pixel location
1788 * @param y The Y coordinate of the upper-left pixel location
1789 * @param w Width of the pixel rectangle
1790 * @param h Height of the pixel rectangle
1791 * @param b The band to return
1792 * @param iArray An optionally pre-allocated int array
1793 * @return the samples for the specified band for the specified
1794 * rectangle of pixels.
1795 *
1796 * @throws ArrayIndexOutOfBoundsException if the coordinates or
1797 * the band index are not in bounds, or if iArray is too small to
1798 * hold the output.
1799 */
1800 public int[] getSamples(int x, int y, int w, int h, int b,
1801 int iArray[]) {
1802 return sampleModel.getSamples(x - sampleModelTranslateX,
1803 y - sampleModelTranslateY,
1804 w, h, b, iArray,
1805 dataBuffer);
1806 }
1807
1808 /**
1809 * Returns the samples for a specified band for the specified rectangle
1810 * of pixels in a float array, one sample per array element.
1811 * An ArrayIndexOutOfBoundsException may be thrown
1812 * if the coordinates are not in bounds. However, explicit bounds
1813 * checking is not guaranteed.
1814 * @param x The X coordinate of the upper-left pixel location
1815 * @param y The Y coordinate of the upper-left pixel location
1816 * @param w Width of the pixel rectangle
1817 * @param h Height of the pixel rectangle
1818 * @param b The band to return
1819 * @param fArray An optionally pre-allocated float array
1820 * @return the samples for the specified band for the specified
1821 * rectangle of pixels.
1822 *
1823 * @throws ArrayIndexOutOfBoundsException if the coordinates or
1824 * the band index are not in bounds, or if fArray is too small to
1825 * hold the output.
1826 */
1827 public float[] getSamples(int x, int y, int w, int h, int b,
1828 float fArray[]) {
1829 return sampleModel.getSamples(x - sampleModelTranslateX,
1830 y - sampleModelTranslateY,
1831 w, h, b, fArray, dataBuffer);
1832 }
1833
1834 /**
1835 * Returns the samples for a specified band for a specified rectangle
1836 * of pixels in a double array, one sample per array element.
1837 * An ArrayIndexOutOfBoundsException may be thrown
1838 * if the coordinates are not in bounds. However, explicit bounds
1839 * checking is not guaranteed.
1840 * @param x The X coordinate of the upper-left pixel location
1841 * @param y The Y coordinate of the upper-left pixel location
1842 * @param w Width of the pixel rectangle
1843 * @param h Height of the pixel rectangle
1844 * @param b The band to return
1845 * @param dArray An optionally pre-allocated double array
1846 * @return the samples for the specified band for the specified
1847 * rectangle of pixels.
1848 *
1849 * @throws ArrayIndexOutOfBoundsException if the coordinates or
1850 * the band index are not in bounds, or if dArray is too small to
1851 * hold the output.
1852 */
1853 public double[] getSamples(int x, int y, int w, int h, int b,
1854 double dArray[]) {
1855 return sampleModel.getSamples(x - sampleModelTranslateX,
1856 y - sampleModelTranslateY,
1857 w, h, b, dArray, dataBuffer);
1858 }
1859
1860 }
|
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
237 * @param pixelStride the pixel stride of the image data
238 * @param bandOffsets the offsets of all bands
239 * @param location the upper-left corner of the {@code Raster}
240 * @return a WritableRaster object with the specified data type,
241 * width, height, scanline stride, pixel stride and band
242 * offsets.
243 * @throws RasterFormatException if {@code w} or {@code h}
244 * is less than or equal to zero, or computing either
245 * {@code location.x + w} or
246 * {@code location.y + h} results in integer
247 * overflow
248 * @throws IllegalArgumentException if {@code dataType} is not
249 * one of the supported data types, which are
250 * {@code DataBuffer.TYPE_BYTE}, or
251 * {@code DataBuffer.TYPE_USHORT}.
252 */
253 public static WritableRaster createInterleavedRaster(int dataType,
254 int w, int h,
255 int scanlineStride,
256 int pixelStride,
257 int[] bandOffsets,
258 Point location) {
259 DataBuffer d;
260
261 int size = scanlineStride * (h - 1) + // fisrt (h - 1) scans
262 pixelStride * w; // last scan
263
264 switch(dataType) {
265 case DataBuffer.TYPE_BYTE:
266 d = new DataBufferByte(size);
267 break;
268
269 case DataBuffer.TYPE_USHORT:
270 d = new DataBufferUShort(size);
271 break;
272
273 default:
274 throw new IllegalArgumentException("Unsupported data type " +
275 dataType);
276 }
277
348 * @param location the upper-left corner of the {@code Raster}
349 * @return a WritableRaster object with the specified data type,
350 * width, height, scanline stride, bank indices and band
351 * offsets.
352 * @throws RasterFormatException if {@code w} or {@code h}
353 * is less than or equal to zero, or computing either
354 * {@code location.x + w} or
355 * {@code location.y + h} results in integer
356 * overflow
357 * @throws IllegalArgumentException if {@code dataType} is not
358 * one of the supported data types, which are
359 * {@code DataBuffer.TYPE_BYTE},
360 * {@code DataBuffer.TYPE_USHORT}
361 * or {@code DataBuffer.TYPE_INT}
362 * @throws ArrayIndexOutOfBoundsException if {@code bankIndices}
363 * or {@code bandOffsets} is {@code null}
364 */
365 public static WritableRaster createBandedRaster(int dataType,
366 int w, int h,
367 int scanlineStride,
368 int[] bankIndices,
369 int[] bandOffsets,
370 Point location) {
371 DataBuffer d;
372 int bands = bandOffsets.length;
373
374 if (bankIndices == null) {
375 throw new
376 ArrayIndexOutOfBoundsException("Bank indices array is null");
377 }
378 if (bandOffsets == null) {
379 throw new
380 ArrayIndexOutOfBoundsException("Band offsets array is null");
381 }
382
383 // Figure out the #banks and the largest band offset
384 int maxBank = bankIndices[0];
385 int maxBandOff = bandOffsets[0];
386 for (int i = 1; i < bands; i++) {
387 if (bankIndices[i] > maxBank) {
388 maxBank = bankIndices[i];
389 }
433 * @param dataType the data type for storing samples
434 * @param w the width in pixels of the image data
435 * @param h the height in pixels of the image data
436 * @param bandMasks an array containing an entry for each band
437 * @param location the upper-left corner of the {@code Raster}
438 * @return a WritableRaster object with the specified data type,
439 * width, height, and band masks.
440 * @throws RasterFormatException if {@code w} or {@code h}
441 * is less than or equal to zero, or computing either
442 * {@code location.x + w} or
443 * {@code location.y + h} results in integer
444 * overflow
445 * @throws IllegalArgumentException if {@code dataType} is not
446 * one of the supported data types, which are
447 * {@code DataBuffer.TYPE_BYTE},
448 * {@code DataBuffer.TYPE_USHORT}
449 * or {@code DataBuffer.TYPE_INT}
450 */
451 public static WritableRaster createPackedRaster(int dataType,
452 int w, int h,
453 int[] bandMasks,
454 Point location) {
455 DataBuffer d;
456
457 switch(dataType) {
458 case DataBuffer.TYPE_BYTE:
459 d = new DataBufferByte(w*h);
460 break;
461
462 case DataBuffer.TYPE_USHORT:
463 d = new DataBufferUShort(w*h);
464 break;
465
466 case DataBuffer.TYPE_INT:
467 d = new DataBufferInt(w*h);
468 break;
469
470 default:
471 throw new IllegalArgumentException("Unsupported data type " +
472 dataType);
473 }
611 * @return a WritableRaster object with the specified
612 * {@code DataBuffer}, width, height, scanline stride,
613 * pixel stride and band offsets.
614 * @throws RasterFormatException if {@code w} or {@code h}
615 * is less than or equal to zero, or computing either
616 * {@code location.x + w} or
617 * {@code location.y + h} results in integer
618 * overflow
619 * @throws IllegalArgumentException if {@code dataType} is not
620 * one of the supported data types, which are
621 * {@code DataBuffer.TYPE_BYTE},
622 * {@code DataBuffer.TYPE_USHORT}
623 * @throws RasterFormatException if {@code dataBuffer} has more
624 * than one bank.
625 * @throws NullPointerException if {@code dataBuffer} is null
626 */
627 public static WritableRaster createInterleavedRaster(DataBuffer dataBuffer,
628 int w, int h,
629 int scanlineStride,
630 int pixelStride,
631 int[] bandOffsets,
632 Point location)
633 {
634 if (dataBuffer == null) {
635 throw new NullPointerException("DataBuffer cannot be null");
636 }
637 if (location == null) {
638 location = new Point(0, 0);
639 }
640 int dataType = dataBuffer.getDataType();
641
642 PixelInterleavedSampleModel csm =
643 new PixelInterleavedSampleModel(dataType, w, h,
644 pixelStride,
645 scanlineStride,
646 bandOffsets);
647 switch(dataType) {
648 case DataBuffer.TYPE_BYTE:
649 if (dataBuffer instanceof DataBufferByte) {
650 return new ByteInterleavedRaster(csm,
651 (DataBufferByte) dataBuffer, location);
684 * @param bandOffsets the offsets of all bands
685 * @param location the upper-left corner of the {@code Raster}
686 * @return a WritableRaster object with the specified
687 * {@code DataBuffer}, width, height, scanline stride,
688 * bank indices and band offsets.
689 * @throws RasterFormatException if {@code w} or {@code h}
690 * is less than or equal to zero, or computing either
691 * {@code location.x + w} or
692 * {@code location.y + h} results in integer
693 * overflow
694 * @throws IllegalArgumentException if {@code dataType} is not
695 * one of the supported data types, which are
696 * {@code DataBuffer.TYPE_BYTE},
697 * {@code DataBuffer.TYPE_USHORT}
698 * or {@code DataBuffer.TYPE_INT}
699 * @throws NullPointerException if {@code dataBuffer} is null
700 */
701 public static WritableRaster createBandedRaster(DataBuffer dataBuffer,
702 int w, int h,
703 int scanlineStride,
704 int[] bankIndices,
705 int[] bandOffsets,
706 Point location)
707 {
708 if (dataBuffer == null) {
709 throw new NullPointerException("DataBuffer cannot be null");
710 }
711 if (location == null) {
712 location = new Point(0,0);
713 }
714 int dataType = dataBuffer.getDataType();
715
716 int bands = bankIndices.length;
717 if (bandOffsets.length != bands) {
718 throw new IllegalArgumentException(
719 "bankIndices.length != bandOffsets.length");
720 }
721
722 BandedSampleModel bsm =
723 new BandedSampleModel(dataType, w, h,
724 scanlineStride,
725 bankIndices, bandOffsets);
767 * @return a WritableRaster object with the specified
768 * {@code DataBuffer}, width, height, scanline stride,
769 * and band masks.
770 * @throws RasterFormatException if {@code w} or {@code h}
771 * is less than or equal to zero, or computing either
772 * {@code location.x + w} or
773 * {@code location.y + h} results in integer
774 * overflow
775 * @throws IllegalArgumentException if {@code dataType} is not
776 * one of the supported data types, which are
777 * {@code DataBuffer.TYPE_BYTE},
778 * {@code DataBuffer.TYPE_USHORT}
779 * or {@code DataBuffer.TYPE_INT}
780 * @throws RasterFormatException if {@code dataBuffer} has more
781 * than one bank.
782 * @throws NullPointerException if {@code dataBuffer} is null
783 */
784 public static WritableRaster createPackedRaster(DataBuffer dataBuffer,
785 int w, int h,
786 int scanlineStride,
787 int[] bandMasks,
788 Point location)
789 {
790 if (dataBuffer == null) {
791 throw new NullPointerException("DataBuffer cannot be null");
792 }
793 if (location == null) {
794 location = new Point(0,0);
795 }
796 int dataType = dataBuffer.getDataType();
797
798 SinglePixelPackedSampleModel sppsm =
799 new SinglePixelPackedSampleModel(dataType, w, h, scanlineStride,
800 bandMasks);
801
802 switch(dataType) {
803 case DataBuffer.TYPE_BYTE:
804 if (dataBuffer instanceof DataBufferByte) {
805 return new ByteInterleavedRaster(sppsm,
806 (DataBufferByte) dataBuffer, location);
807 }
1380 * @param height Height of the region starting at (parentX, parentY).
1381 * @param childMinX The X coordinate of the upper-left corner
1382 * of the returned Raster
1383 * @param childMinY The Y coordinate of the upper-left corner
1384 * of the returned Raster
1385 * @param bandList Array of band indices, or null to use all bands
1386 * @return a new {@code Raster}.
1387 * @exception RasterFormatException if the specified subregion is outside
1388 * of the raster bounds.
1389 * @throws RasterFormatException if {@code width} or
1390 * {@code height}
1391 * is less than or equal to zero, or computing any of
1392 * {@code parentX + width}, {@code parentY + height},
1393 * {@code childMinX + width}, or
1394 * {@code childMinY + height} results in integer
1395 * overflow
1396 */
1397 public Raster createChild(int parentX, int parentY,
1398 int width, int height,
1399 int childMinX, int childMinY,
1400 int[] bandList) {
1401 if (parentX < this.minX) {
1402 throw new RasterFormatException("parentX lies outside raster");
1403 }
1404 if (parentY < this.minY) {
1405 throw new RasterFormatException("parentY lies outside raster");
1406 }
1407 if ((parentX + width < parentX) ||
1408 (parentX + width > this.width + this.minX)) {
1409 throw new RasterFormatException("(parentX + width) is outside raster");
1410 }
1411 if ((parentY + height < parentY) ||
1412 (parentY + height > this.height + this.minY)) {
1413 throw new RasterFormatException("(parentY + height) is outside raster");
1414 }
1415
1416 SampleModel subSampleModel;
1417 // Note: the SampleModel for the child Raster should have the same
1418 // width and height as that for the parent, since it represents
1419 // the physical layout of the pixel data. The child Raster's width
1420 // and height represent a "virtual" view of the pixel data, so
1584 */
1585 public Object getDataElements(int x, int y, int w, int h, Object outData) {
1586 return sampleModel.getDataElements(x - sampleModelTranslateX,
1587 y - sampleModelTranslateY,
1588 w, h, outData, dataBuffer);
1589 }
1590
1591 /**
1592 * Returns the samples in an array of int for the specified pixel.
1593 * An ArrayIndexOutOfBoundsException may be thrown
1594 * if the coordinates are not in bounds. However, explicit bounds
1595 * checking is not guaranteed.
1596 * @param x The X coordinate of the pixel location
1597 * @param y The Y coordinate of the pixel location
1598 * @param iArray An optionally preallocated int array
1599 * @return the samples for the specified pixel.
1600 *
1601 * @throws ArrayIndexOutOfBoundsException if the coordinates are not
1602 * in bounds, or if iArray is too small to hold the output.
1603 */
1604 public int[] getPixel(int x, int y, int[] iArray) {
1605 return sampleModel.getPixel(x - sampleModelTranslateX,
1606 y - sampleModelTranslateY,
1607 iArray, dataBuffer);
1608 }
1609
1610 /**
1611 * Returns the samples in an array of float for the
1612 * specified pixel.
1613 * An ArrayIndexOutOfBoundsException may be thrown
1614 * if the coordinates are not in bounds. However, explicit bounds
1615 * checking is not guaranteed.
1616 * @param x The X coordinate of the pixel location
1617 * @param y The Y coordinate of the pixel location
1618 * @param fArray An optionally preallocated float array
1619 * @return the samples for the specified pixel.
1620 *
1621 * @throws ArrayIndexOutOfBoundsException if the coordinates are not
1622 * in bounds, or if fArray is too small to hold the output.
1623 */
1624 public float[] getPixel(int x, int y, float[] fArray) {
1625 return sampleModel.getPixel(x - sampleModelTranslateX,
1626 y - sampleModelTranslateY,
1627 fArray, dataBuffer);
1628 }
1629
1630 /**
1631 * Returns the samples in an array of double for the specified pixel.
1632 * An ArrayIndexOutOfBoundsException may be thrown
1633 * if the coordinates are not in bounds. However, explicit bounds
1634 * checking is not guaranteed.
1635 * @param x The X coordinate of the pixel location
1636 * @param y The Y coordinate of the pixel location
1637 * @param dArray An optionally preallocated double array
1638 * @return the samples for the specified pixel.
1639 *
1640 * @throws ArrayIndexOutOfBoundsException if the coordinates are not
1641 * in bounds, or if dArray is too small to hold the output.
1642 */
1643 public double[] getPixel(int x, int y, double[] dArray) {
1644 return sampleModel.getPixel(x - sampleModelTranslateX,
1645 y - sampleModelTranslateY,
1646 dArray, dataBuffer);
1647 }
1648
1649 /**
1650 * Returns an int array containing all samples for a rectangle of pixels,
1651 * one sample per array element.
1652 * An ArrayIndexOutOfBoundsException may be thrown
1653 * if the coordinates are not in bounds. However, explicit bounds
1654 * checking is not guaranteed.
1655 * @param x The X coordinate of the upper-left pixel location
1656 * @param y The Y coordinate of the upper-left pixel location
1657 * @param w Width of the pixel rectangle
1658 * @param h Height of the pixel rectangle
1659 * @param iArray An optionally pre-allocated int array
1660 * @return the samples for the specified rectangle of pixels.
1661 *
1662 * @throws ArrayIndexOutOfBoundsException if the coordinates are not
1663 * in bounds, or if iArray is too small to hold the output.
1664 */
1665 public int[] getPixels(int x, int y, int w, int h, int[] iArray) {
1666 return sampleModel.getPixels(x - sampleModelTranslateX,
1667 y - sampleModelTranslateY, w, h,
1668 iArray, dataBuffer);
1669 }
1670
1671 /**
1672 * Returns a float array containing all samples for a rectangle of pixels,
1673 * one sample per array element.
1674 * An ArrayIndexOutOfBoundsException may be thrown
1675 * if the coordinates are not in bounds. However, explicit bounds
1676 * checking is not guaranteed.
1677 * @param x The X coordinate of the pixel location
1678 * @param y The Y coordinate of the pixel location
1679 * @param w Width of the pixel rectangle
1680 * @param h Height of the pixel rectangle
1681 * @param fArray An optionally pre-allocated float array
1682 * @return the samples for the specified rectangle of pixels.
1683 *
1684 * @throws ArrayIndexOutOfBoundsException if the coordinates are not
1685 * in bounds, or if fArray is too small to hold the output.
1686 */
1687 public float[] getPixels(int x, int y, int w, int h,
1688 float[] fArray) {
1689 return sampleModel.getPixels(x - sampleModelTranslateX,
1690 y - sampleModelTranslateY, w, h,
1691 fArray, dataBuffer);
1692 }
1693
1694 /**
1695 * Returns a double array containing all samples for a rectangle of pixels,
1696 * one sample per array element.
1697 * An ArrayIndexOutOfBoundsException may be thrown
1698 * if the coordinates are not in bounds. However, explicit bounds
1699 * checking is not guaranteed.
1700 * @param x The X coordinate of the upper-left pixel location
1701 * @param y The Y coordinate of the upper-left pixel location
1702 * @param w Width of the pixel rectangle
1703 * @param h Height of the pixel rectangle
1704 * @param dArray An optionally pre-allocated double array
1705 * @return the samples for the specified rectangle of pixels.
1706 *
1707 * @throws ArrayIndexOutOfBoundsException if the coordinates are not
1708 * in bounds, or if dArray is too small to hold the output.
1709 */
1710 public double[] getPixels(int x, int y, int w, int h,
1711 double[] dArray) {
1712 return sampleModel.getPixels(x - sampleModelTranslateX,
1713 y - sampleModelTranslateY,
1714 w, h, dArray, dataBuffer);
1715 }
1716
1717
1718 /**
1719 * Returns the sample in a specified band for the pixel located
1720 * at (x,y) as an int.
1721 * An ArrayIndexOutOfBoundsException may be thrown
1722 * if the coordinates are not in bounds. However, explicit bounds
1723 * checking is not guaranteed.
1724 * @param x The X coordinate of the pixel location
1725 * @param y The Y coordinate of the pixel location
1726 * @param b The band to return
1727 * @return the sample in the specified band for the pixel at the
1728 * specified coordinate.
1729 *
1730 * @throws ArrayIndexOutOfBoundsException if the coordinates or
1731 * the band index are not in bounds.
1781 /**
1782 * Returns the samples for a specified band for the specified rectangle
1783 * of pixels in an int array, one sample per array element.
1784 * An ArrayIndexOutOfBoundsException may be thrown
1785 * if the coordinates are not in bounds. However, explicit bounds
1786 * checking is not guaranteed.
1787 * @param x The X coordinate of the upper-left pixel location
1788 * @param y The Y coordinate of the upper-left pixel location
1789 * @param w Width of the pixel rectangle
1790 * @param h Height of the pixel rectangle
1791 * @param b The band to return
1792 * @param iArray An optionally pre-allocated int array
1793 * @return the samples for the specified band for the specified
1794 * rectangle of pixels.
1795 *
1796 * @throws ArrayIndexOutOfBoundsException if the coordinates or
1797 * the band index are not in bounds, or if iArray is too small to
1798 * hold the output.
1799 */
1800 public int[] getSamples(int x, int y, int w, int h, int b,
1801 int[] iArray) {
1802 return sampleModel.getSamples(x - sampleModelTranslateX,
1803 y - sampleModelTranslateY,
1804 w, h, b, iArray,
1805 dataBuffer);
1806 }
1807
1808 /**
1809 * Returns the samples for a specified band for the specified rectangle
1810 * of pixels in a float array, one sample per array element.
1811 * An ArrayIndexOutOfBoundsException may be thrown
1812 * if the coordinates are not in bounds. However, explicit bounds
1813 * checking is not guaranteed.
1814 * @param x The X coordinate of the upper-left pixel location
1815 * @param y The Y coordinate of the upper-left pixel location
1816 * @param w Width of the pixel rectangle
1817 * @param h Height of the pixel rectangle
1818 * @param b The band to return
1819 * @param fArray An optionally pre-allocated float array
1820 * @return the samples for the specified band for the specified
1821 * rectangle of pixels.
1822 *
1823 * @throws ArrayIndexOutOfBoundsException if the coordinates or
1824 * the band index are not in bounds, or if fArray is too small to
1825 * hold the output.
1826 */
1827 public float[] getSamples(int x, int y, int w, int h, int b,
1828 float[] fArray) {
1829 return sampleModel.getSamples(x - sampleModelTranslateX,
1830 y - sampleModelTranslateY,
1831 w, h, b, fArray, dataBuffer);
1832 }
1833
1834 /**
1835 * Returns the samples for a specified band for a specified rectangle
1836 * of pixels in a double array, one sample per array element.
1837 * An ArrayIndexOutOfBoundsException may be thrown
1838 * if the coordinates are not in bounds. However, explicit bounds
1839 * checking is not guaranteed.
1840 * @param x The X coordinate of the upper-left pixel location
1841 * @param y The Y coordinate of the upper-left pixel location
1842 * @param w Width of the pixel rectangle
1843 * @param h Height of the pixel rectangle
1844 * @param b The band to return
1845 * @param dArray An optionally pre-allocated double array
1846 * @return the samples for the specified band for the specified
1847 * rectangle of pixels.
1848 *
1849 * @throws ArrayIndexOutOfBoundsException if the coordinates or
1850 * the band index are not in bounds, or if dArray is too small to
1851 * hold the output.
1852 */
1853 public double[] getSamples(int x, int y, int w, int h, int b,
1854 double[] dArray) {
1855 return sampleModel.getSamples(x - sampleModelTranslateX,
1856 y - sampleModelTranslateY,
1857 w, h, b, dArray, dataBuffer);
1858 }
1859
1860 }
|