List of usage examples for java.awt.image DataBuffer TYPE_FLOAT
int TYPE_FLOAT
To view the source code for java.awt.image DataBuffer TYPE_FLOAT.
Click Source Link
From source file:it.geosolutions.imageio.plugins.nitronitf.ImageIOUtils.java
public static boolean canDisplay(BufferedImage image) { log.info("Data Type: " + image.getSampleModel().getDataType()); log.info("Pixel Size: " + image.getColorModel().getPixelSize()); if (image.getSampleModel().getDataType() == DataBuffer.TYPE_FLOAT && image.getColorModel().getPixelSize() == 64) return false; return !GraphicsEnvironment.isHeadless(); }
From source file:com.bc.ceres.jai.opimage.ReinterpretOpImage.java
private void rescale(Raster sourceRaster, WritableRaster targetRaster, Rectangle targetRectangle) { final int sourceDataType = sourceRaster.getSampleModel().getDataType(); final int targetDataType = targetRaster.getSampleModel().getDataType(); final PixelAccessor sourceAcc = new PixelAccessor(getSourceImage(0)); final PixelAccessor targetAcc = new PixelAccessor(this); final UnpackedImageData sourcePixels; final UnpackedImageData targetPixels; sourcePixels = sourceAcc.getPixels(sourceRaster, targetRectangle, sourceDataType, false); targetPixels = targetAcc.getPixels(targetRaster, targetRectangle, targetDataType, true); switch (sourceDataType) { case DataBuffer.TYPE_BYTE: if (interpretationType == ReinterpretDescriptor.INTERPRET_BYTE_SIGNED) { rescaleSByte(sourcePixels, targetPixels, targetRectangle); } else {// w ww .j av a2 s . c o m rescaleByte(sourcePixels, targetPixels, targetRectangle); } break; case DataBuffer.TYPE_USHORT: rescaleUShort(sourcePixels, targetPixels, targetRectangle); break; case DataBuffer.TYPE_SHORT: rescaleShort(sourcePixels, targetPixels, targetRectangle); break; case DataBuffer.TYPE_INT: if (interpretationType == ReinterpretDescriptor.INTERPRET_INT_UNSIGNED) { rescaleUInt(sourcePixels, targetPixels, targetRectangle); } else { rescaleInt(sourcePixels, targetPixels, targetRectangle); } break; case DataBuffer.TYPE_FLOAT: rescaleFloat(sourcePixels, targetPixels, targetRectangle); break; case DataBuffer.TYPE_DOUBLE: rescaleDouble(sourcePixels, targetPixels, targetRectangle); break; } targetAcc.setPixels(targetPixels); }
From source file:it.geosolutions.imageio.plugins.nitronitf.ImageIOUtils.java
/** * Returns a generic banded WritableRaster * //from w ww . ja v a 2 s .c o m * @param numElems * @param numLines * @param bandOffsets * @param dataType * @return */ public static WritableRaster makeGenericBandedWritableRaster(int numElems, int numLines, int numBands, int dataType) { int[] bandOffsets = new int[numBands]; for (int i = 0; i < numBands; ++i) bandOffsets[i] = i; DataBuffer d = null; if (dataType == DataBuffer.TYPE_BYTE) d = new DataBufferByte(numElems * numLines * numBands); else if (dataType == DataBuffer.TYPE_FLOAT) d = new DataBufferFloat(numElems * numLines * numBands); else throw new IllegalArgumentException("Invalid datatype: " + dataType); BandedSampleModel bsm = new BandedSampleModel(dataType, numElems, numLines, bandOffsets.length, bandOffsets, bandOffsets); SunWritableRaster ras = new SunWritableRaster(bsm, d, new Point(0, 0)); return ras; }
From source file:it.geosolutions.imageio.plugins.nitronitf.ImageIOUtils.java
/** * Returns a generic pixel interleaved WritableRaster * /*from ww w . java2 s. co m*/ * @param numElems * @param numLines * @param bandOffsets * @param dataType * @return */ public static WritableRaster makeGenericPixelInterleavedWritableRaster(int numElems, int numLines, int numBands, int dataType) { int[] bandOffsets = new int[numBands]; for (int i = 0; i < numBands; ++i) bandOffsets[i] = i; DataBuffer d = null; if (dataType == DataBuffer.TYPE_BYTE) d = new DataBufferByte(numElems * numLines * numBands); else if (dataType == DataBuffer.TYPE_SHORT) d = new DataBufferShort(numElems * numLines * numBands); else if (dataType == DataBuffer.TYPE_USHORT) d = new DataBufferUShort(numElems * numLines * numBands); else if (dataType == DataBuffer.TYPE_FLOAT) d = new DataBufferFloat(numElems * numLines * numBands); else if (dataType == DataBuffer.TYPE_DOUBLE) d = new DataBufferDouble(numElems * numLines * numBands); else throw new IllegalArgumentException("Invalid datatype: " + dataType); PixelInterleavedSampleModel pism = new PixelInterleavedSampleModel(dataType, numElems, numLines, bandOffsets.length, numElems * bandOffsets.length, bandOffsets); SunWritableRaster ras = new SunWritableRaster(pism, d, new Point(0, 0)); return ras; }
From source file:omr.jai.TestImage3.java
public static void print(PlanarImage pi) { // Show the image dimensions and coordinates. System.out.print("Image Dimensions: "); System.out.print(pi.getWidth() + "x" + pi.getHeight() + " pixels"); // Remember getMaxX and getMaxY return the coordinate of the next point! System.out.println(" (from " + pi.getMinX() + "," + pi.getMinY() + " to " + (pi.getMaxX() - 1) + "," + (pi.getMaxY() - 1) + ")"); if ((pi.getNumXTiles() != 1) || (pi.getNumYTiles() != 1)) { // Is it tiled? // Tiles number, dimensions and coordinates. System.out.print("Tiles: "); System.out.print(pi.getTileWidth() + "x" + pi.getTileHeight() + " pixels" + " (" + pi.getNumXTiles() + "x" + pi.getNumYTiles() + " tiles)"); System.out.print(" (from " + pi.getMinTileX() + "," + pi.getMinTileY() + " to " + pi.getMaxTileX() + "," + pi.getMaxTileY() + ")"); System.out.println(" offset: " + pi.getTileGridXOffset() + "," + pi.getTileGridXOffset()); }/*from w w w .j a va 2s .c o m*/ // Display info about the SampleModel of the image. SampleModel sm = pi.getSampleModel(); System.out.println("Number of bands: " + sm.getNumBands()); System.out.print("Data type: "); switch (sm.getDataType()) { case DataBuffer.TYPE_BYTE: System.out.println("byte"); break; case DataBuffer.TYPE_SHORT: System.out.println("short"); break; case DataBuffer.TYPE_USHORT: System.out.println("ushort"); break; case DataBuffer.TYPE_INT: System.out.println("int"); break; case DataBuffer.TYPE_FLOAT: System.out.println("float"); break; case DataBuffer.TYPE_DOUBLE: System.out.println("double"); break; case DataBuffer.TYPE_UNDEFINED: System.out.println("undefined"); break; } // Display info about the ColorModel of the image. ColorModel cm = pi.getColorModel(); if (cm != null) { System.out.println("Number of color components: " + cm.getNumComponents()); System.out.println("Bits per pixel: " + cm.getPixelSize()); System.out.print("Image Transparency: "); switch (cm.getTransparency()) { case Transparency.OPAQUE: System.out.println("opaque"); break; case Transparency.BITMASK: System.out.println("bitmask"); break; case Transparency.TRANSLUCENT: System.out.println("translucent"); break; } } else System.out.println("No color model."); }
From source file:it.geosolutions.imageio.plugins.nitronitf.ImageIOUtils.java
/** * Utility method for creating a BufferedImage from a source raster Currently only Float->Byte and Byte->Byte are supported. Will throw an * {@link UnsupportedOperationException} if the conversion is not supported. * //from w ww .j a v a 2 s .c o m * @param raster * @param imageType * @return */ public static BufferedImage rasterToBufferedImage(Raster raster, ImageTypeSpecifier imageType) { if (imageType == null) { if (raster.getDataBuffer().getDataType() == DataBuffer.TYPE_BYTE) imageType = ImageTypeSpecifier.createGrayscale(8, DataBuffer.TYPE_BYTE, false); else throw new IllegalArgumentException("unable to dynamically determine the imageType"); } // create a new buffered image, for display BufferedImage bufImage = imageType.createBufferedImage(raster.getWidth(), raster.getHeight()); if (raster.getDataBuffer().getDataType() == DataBuffer.TYPE_USHORT && bufImage.getRaster().getDataBuffer().getDataType() == DataBuffer.TYPE_BYTE) { // convert short pixels to bytes short[] shortData = ((DataBufferUShort) raster.getDataBuffer()).getData(); byte[] byteData = ((DataBufferByte) bufImage.getWritableTile(0, 0).getDataBuffer()).getData(); ImageIOUtils.shortToByteBuffer(shortData, byteData, 1, raster.getNumBands()); } else if (raster.getDataBuffer().getDataType() == DataBuffer.TYPE_FLOAT && bufImage.getRaster().getDataBuffer().getDataType() == DataBuffer.TYPE_BYTE) { // convert float pixels to bytes float[] floatData = ((DataBufferFloat) raster.getDataBuffer()).getData(); byte[] byteData = ((DataBufferByte) bufImage.getWritableTile(0, 0).getDataBuffer()).getData(); ImageIOUtils.floatToByteBuffer(floatData, byteData, 1, raster.getNumBands()); } else if (raster.getDataBuffer().getDataType() == DataBuffer.TYPE_DOUBLE && bufImage.getRaster().getDataBuffer().getDataType() == DataBuffer.TYPE_BYTE) { // convert double pixels to bytes double[] doubleData = ((DataBufferDouble) raster.getDataBuffer()).getData(); byte[] byteData = ((DataBufferByte) bufImage.getWritableTile(0, 0).getDataBuffer()).getData(); ImageIOUtils.doubleToByteBuffer(doubleData, byteData, 1, raster.getNumBands()); } else if ((raster.getDataBuffer().getDataType() == DataBuffer.TYPE_BYTE && bufImage.getRaster().getDataBuffer().getDataType() == DataBuffer.TYPE_BYTE) || (raster.getDataBuffer().getDataType() == DataBuffer.TYPE_USHORT && bufImage.getRaster().getDataBuffer().getDataType() == DataBuffer.TYPE_USHORT) || (raster.getDataBuffer().getDataType() == DataBuffer.TYPE_SHORT && bufImage.getRaster().getDataBuffer().getDataType() == DataBuffer.TYPE_SHORT)) { bufImage.setData(raster); } else { throw new UnsupportedOperationException( "Unable to convert raster type to bufferedImage type: " + raster.getDataBuffer().getDataType() + " ==> " + bufImage.getRaster().getDataBuffer().getDataType()); } return bufImage; }
From source file:it.geosolutions.jaiext.range.RangeTest.java
@Test public void testRangeTimeByte1or2Points() { if (!SINGLE_POINT) { switch (TEST_SELECTOR) { case DataBuffer.TYPE_BYTE: testRangeTimeByte(rangeB2bounds, SINGLE_POINT); break; case DataBuffer.TYPE_SHORT: testRangeTimeShort(rangeS2bounds, SINGLE_POINT); break; case DataBuffer.TYPE_INT: testRangeTimeInteger(rangeI2bounds, SINGLE_POINT); break; case DataBuffer.TYPE_FLOAT: testRangeTimeFloat(rangeF2bounds, SINGLE_POINT); break; case DataBuffer.TYPE_DOUBLE: testRangeTimeDouble(rangeD2bounds, SINGLE_POINT); break; default://w ww . j av a 2 s .com throw new IllegalArgumentException("Wrong data type"); } } else { switch (TEST_SELECTOR) { case DataBuffer.TYPE_BYTE: testRangeTimeByte(rangeBpoint, SINGLE_POINT); break; case DataBuffer.TYPE_SHORT: testRangeTimeShort(rangeSpoint, SINGLE_POINT); break; case DataBuffer.TYPE_INT: testRangeTimeInteger(rangeIpoint, SINGLE_POINT); break; case DataBuffer.TYPE_FLOAT: testRangeTimeFloat(rangeFpoint, SINGLE_POINT); break; case DataBuffer.TYPE_DOUBLE: testRangeTimeDouble(rangeDpoint, SINGLE_POINT); break; default: throw new IllegalArgumentException("Wrong data type"); } } }
From source file:it.geosolutions.jaiext.range.RangeTest.java
@Test public void testJaiToolsRangeTimeByte1or2Points() { if (!SINGLE_POINT) { switch (TEST_SELECTOR) { case DataBuffer.TYPE_BYTE: testJaiToolsRangeTime(rangeJTB, SINGLE_POINT, arrayBtest); break; case DataBuffer.TYPE_SHORT: testJaiToolsRangeTime(rangeJTS, SINGLE_POINT, arrayStest); break; case DataBuffer.TYPE_INT: testJaiToolsRangeTime(rangeJTI, SINGLE_POINT, arrayItest); break; case DataBuffer.TYPE_FLOAT: testJaiToolsRangeTime(rangeJTF, SINGLE_POINT, arrayFtest); break; case DataBuffer.TYPE_DOUBLE: testJaiToolsRangeTime(rangeJTD, SINGLE_POINT, arrayDtest); break; default://from w w w . j a v a2 s .co m throw new IllegalArgumentException("Wrong data type"); } } else { switch (TEST_SELECTOR) { case DataBuffer.TYPE_BYTE: testJaiToolsRangeTime(rangeJTBpoint, SINGLE_POINT, arrayBtest); break; case DataBuffer.TYPE_SHORT: testJaiToolsRangeTime(rangeJTSpoint, SINGLE_POINT, arrayStest); break; case DataBuffer.TYPE_INT: testJaiToolsRangeTime(rangeJTIpoint, SINGLE_POINT, arrayItest); break; case DataBuffer.TYPE_FLOAT: testJaiToolsRangeTime(rangeJTFpoint, SINGLE_POINT, arrayFtest); break; case DataBuffer.TYPE_DOUBLE: testJaiToolsRangeTime(rangeJTDpoint, SINGLE_POINT, arrayDtest); break; default: throw new IllegalArgumentException("Wrong data type"); } } }
From source file:it.geosolutions.jaiext.range.RangeTest.java
@Test public void testJAIRangeTimeByte1or2Points() { if (!SINGLE_POINT) { switch (TEST_SELECTOR) { case DataBuffer.TYPE_BYTE: testJAIRangeTime(rangeJAIB, SINGLE_POINT, arrayBtest); break; case DataBuffer.TYPE_SHORT: testJAIRangeTime(rangeJAIS, SINGLE_POINT, arrayStest); break; case DataBuffer.TYPE_INT: testJAIRangeTime(rangeJAII, SINGLE_POINT, arrayItest); break; case DataBuffer.TYPE_FLOAT: testJAIRangeTime(rangeJAIF, SINGLE_POINT, arrayFtest); break; case DataBuffer.TYPE_DOUBLE: testJAIRangeTime(rangeJAID, SINGLE_POINT, arrayDtest); break; default://from w w w .j a v a 2 s . co m throw new IllegalArgumentException("Wrong data type"); } } else { switch (TEST_SELECTOR) { case DataBuffer.TYPE_BYTE: testJAIRangeTime(rangeJAIBpoint, SINGLE_POINT, arrayBtest); break; case DataBuffer.TYPE_SHORT: testJAIRangeTime(rangeJAISpoint, SINGLE_POINT, arrayStest); break; case DataBuffer.TYPE_INT: testJAIRangeTime(rangeJAIIpoint, SINGLE_POINT, arrayItest); break; case DataBuffer.TYPE_FLOAT: testJAIRangeTime(rangeJAIFpoint, SINGLE_POINT, arrayFtest); break; case DataBuffer.TYPE_DOUBLE: testJAIRangeTime(rangeJAIDpoint, SINGLE_POINT, arrayDtest); break; default: throw new IllegalArgumentException("Wrong data type"); } } }
From source file:it.geosolutions.jaiext.range.RangeTest.java
@Test public void testApacheCommonRangeTimeByte1or2Points() { if (!SINGLE_POINT) { switch (TEST_SELECTOR) { case DataBuffer.TYPE_BYTE: testApacheCommonsRangeTime(rangeCommonsB, SINGLE_POINT, arrayBtest); break; case DataBuffer.TYPE_SHORT: testApacheCommonsRangeTime(rangeCommonsS, SINGLE_POINT, arrayStest); break; case DataBuffer.TYPE_INT: testApacheCommonsRangeTime(rangeCommonsI, SINGLE_POINT, arrayItest); break; case DataBuffer.TYPE_FLOAT: testApacheCommonsRangeTime(rangeCommonsF, SINGLE_POINT, arrayFtest); break; case DataBuffer.TYPE_DOUBLE: testApacheCommonsRangeTime(rangeCommonsD, SINGLE_POINT, arrayDtest); break; default://from ww w . j av a 2 s.com throw new IllegalArgumentException("Wrong data type"); } } else { switch (TEST_SELECTOR) { case DataBuffer.TYPE_BYTE: testApacheCommonsRangeTime(rangeCommonsBpoint, SINGLE_POINT, arrayBtest); break; case DataBuffer.TYPE_SHORT: testApacheCommonsRangeTime(rangeCommonsSpoint, SINGLE_POINT, arrayStest); break; case DataBuffer.TYPE_INT: testApacheCommonsRangeTime(rangeCommonsIpoint, SINGLE_POINT, arrayItest); break; case DataBuffer.TYPE_FLOAT: testApacheCommonsRangeTime(rangeCommonsFpoint, SINGLE_POINT, arrayFtest); break; case DataBuffer.TYPE_DOUBLE: testApacheCommonsRangeTime(rangeCommonsDpoint, SINGLE_POINT, arrayDtest); break; default: throw new IllegalArgumentException("Wrong data type"); } } }