Java Code Examples for java.awt.image.DataBuffer#TYPE_FLOAT
The following examples show how to use
java.awt.image.DataBuffer#TYPE_FLOAT .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TIFFDecompressor.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Return the number of bits occupied by {@code dataType} * which must be one of the {@code DataBuffer} {@code TYPE}s. */ private static int getDataTypeSize(int dataType) throws IIOException { int dataTypeSize = 0; switch(dataType) { case DataBuffer.TYPE_BYTE: dataTypeSize = 8; break; case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_USHORT: dataTypeSize = 16; break; case DataBuffer.TYPE_INT: case DataBuffer.TYPE_FLOAT: dataTypeSize = 32; break; case DataBuffer.TYPE_DOUBLE: dataTypeSize = 64; break; default: throw new IIOException("Unknown data type "+dataType); } return dataTypeSize; }
Example 2
Source File: ColConvTest.java From hottub with GNU General Public License v2.0 | 6 votes |
static String getDTName(int dType) { switch(dType) { case DataBuffer.TYPE_BYTE: return "TYPE_BYTE"; case DataBuffer.TYPE_DOUBLE: return "TYPE_DOUBLE"; case DataBuffer.TYPE_FLOAT: return "TYPE_FLOAT"; case DataBuffer.TYPE_INT: return "TYPE_INT"; case DataBuffer.TYPE_SHORT: return "TYPE_SHORT"; case DataBuffer.TYPE_USHORT: return "TYPE_USHORT"; case DataBuffer.TYPE_UNDEFINED: return "TYPE_UNDEFINED"; } return "UNKNOWN"; }
Example 3
Source File: ColConvTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
static String getDTName(int dType) { switch(dType) { case DataBuffer.TYPE_BYTE: return "TYPE_BYTE"; case DataBuffer.TYPE_DOUBLE: return "TYPE_DOUBLE"; case DataBuffer.TYPE_FLOAT: return "TYPE_FLOAT"; case DataBuffer.TYPE_INT: return "TYPE_INT"; case DataBuffer.TYPE_SHORT: return "TYPE_SHORT"; case DataBuffer.TYPE_USHORT: return "TYPE_USHORT"; case DataBuffer.TYPE_UNDEFINED: return "TYPE_UNDEFINED"; } return "UNKNOWN"; }
Example 4
Source File: ColConvTest.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
static String getDTName(int dType) { switch(dType) { case DataBuffer.TYPE_BYTE: return "TYPE_BYTE"; case DataBuffer.TYPE_DOUBLE: return "TYPE_DOUBLE"; case DataBuffer.TYPE_FLOAT: return "TYPE_FLOAT"; case DataBuffer.TYPE_INT: return "TYPE_INT"; case DataBuffer.TYPE_SHORT: return "TYPE_SHORT"; case DataBuffer.TYPE_USHORT: return "TYPE_USHORT"; case DataBuffer.TYPE_UNDEFINED: return "TYPE_UNDEFINED"; } return "UNKNOWN"; }
Example 5
Source File: GeneralRenderer.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
static PixelWriter createXorPixelWriter(SunGraphics2D sg2d, SurfaceData sData) { ColorModel dstCM = sData.getColorModel(); Object srcPixel = dstCM.getDataElements(sg2d.eargb, null); XORComposite comp = (XORComposite)sg2d.getComposite(); int xorrgb = comp.getXorColor().getRGB(); Object xorPixel = dstCM.getDataElements(xorrgb, null); switch (dstCM.getTransferType()) { case DataBuffer.TYPE_BYTE: return new XorPixelWriter.ByteData(srcPixel, xorPixel); case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_USHORT: return new XorPixelWriter.ShortData(srcPixel, xorPixel); case DataBuffer.TYPE_INT: return new XorPixelWriter.IntData(srcPixel, xorPixel); case DataBuffer.TYPE_FLOAT: return new XorPixelWriter.FloatData(srcPixel, xorPixel); case DataBuffer.TYPE_DOUBLE: return new XorPixelWriter.DoubleData(srcPixel, xorPixel); default: throw new InternalError("Unsupported XOR pixel type"); } }
Example 6
Source File: RenderToCustomBufferTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static BufferedImage createCustomBuffer() { ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); ColorModel cm = new ComponentColorModel(cs, false, false, Transparency.OPAQUE, DataBuffer.TYPE_FLOAT); WritableRaster wr = cm.createCompatibleWritableRaster(width, height); return new BufferedImage(cm, wr, false, null); }
Example 7
Source File: GeneralRenderer.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
static PixelWriter createXorPixelWriter(SunGraphics2D sg2d, SurfaceData sData) { ColorModel dstCM = sData.getColorModel(); Object srcPixel = dstCM.getDataElements(sg2d.eargb, null); XORComposite comp = (XORComposite)sg2d.getComposite(); int xorrgb = comp.getXorColor().getRGB(); Object xorPixel = dstCM.getDataElements(xorrgb, null); switch (dstCM.getTransferType()) { case DataBuffer.TYPE_BYTE: return new XorPixelWriter.ByteData(srcPixel, xorPixel); case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_USHORT: return new XorPixelWriter.ShortData(srcPixel, xorPixel); case DataBuffer.TYPE_INT: return new XorPixelWriter.IntData(srcPixel, xorPixel); case DataBuffer.TYPE_FLOAT: return new XorPixelWriter.FloatData(srcPixel, xorPixel); case DataBuffer.TYPE_DOUBLE: return new XorPixelWriter.DoubleData(srcPixel, xorPixel); default: throw new InternalError("Unsupported XOR pixel type"); } }
Example 8
Source File: GeneralRenderer.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
static PixelWriter createXorPixelWriter(SunGraphics2D sg2d, SurfaceData sData) { ColorModel dstCM = sData.getColorModel(); Object srcPixel = dstCM.getDataElements(sg2d.eargb, null); XORComposite comp = (XORComposite)sg2d.getComposite(); int xorrgb = comp.getXorColor().getRGB(); Object xorPixel = dstCM.getDataElements(xorrgb, null); switch (dstCM.getTransferType()) { case DataBuffer.TYPE_BYTE: return new XorPixelWriter.ByteData(srcPixel, xorPixel); case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_USHORT: return new XorPixelWriter.ShortData(srcPixel, xorPixel); case DataBuffer.TYPE_INT: return new XorPixelWriter.IntData(srcPixel, xorPixel); case DataBuffer.TYPE_FLOAT: return new XorPixelWriter.FloatData(srcPixel, xorPixel); case DataBuffer.TYPE_DOUBLE: return new XorPixelWriter.DoubleData(srcPixel, xorPixel); default: throw new InternalError("Unsupported XOR pixel type"); } }
Example 9
Source File: ImageTypeSpecifier.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public Banded(ColorSpace colorSpace, int[] bankIndices, int[] bandOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied) { if (colorSpace == null) { throw new IllegalArgumentException("colorSpace == null!"); } if (bankIndices == null) { throw new IllegalArgumentException("bankIndices == null!"); } if (bandOffsets == null) { throw new IllegalArgumentException("bandOffsets == null!"); } if (bankIndices.length != bandOffsets.length) { throw new IllegalArgumentException ("bankIndices.length != bandOffsets.length!"); } if (dataType != DataBuffer.TYPE_BYTE && dataType != DataBuffer.TYPE_SHORT && dataType != DataBuffer.TYPE_USHORT && dataType != DataBuffer.TYPE_INT && dataType != DataBuffer.TYPE_FLOAT && dataType != DataBuffer.TYPE_DOUBLE) { throw new IllegalArgumentException ("Bad value for dataType!"); } int numBands = colorSpace.getNumComponents() + (hasAlpha ? 1 : 0); if (bandOffsets.length != numBands) { throw new IllegalArgumentException ("bandOffsets.length is wrong!"); } this.colorSpace = colorSpace; this.bankIndices = (int[])bankIndices.clone(); this.bandOffsets = (int[])bandOffsets.clone(); this.dataType = dataType; this.hasAlpha = hasAlpha; this.isAlphaPremultiplied = isAlphaPremultiplied; this.colorModel = ImageTypeSpecifier.createComponentCM(colorSpace, bankIndices.length, dataType, hasAlpha, isAlphaPremultiplied); int w = 1; int h = 1; this.sampleModel = new BandedSampleModel(dataType, w, h, w, bankIndices, bandOffsets); }
Example 10
Source File: BufferedImageTools.java From scifio with BSD 2-Clause "Simplified" License | 4 votes |
/** * Gets the pixel type of the given image. * * @return One of the following types: * <ul> * <li>FormatReader.INT8</li> * <li>FormatReader.UINT8</li> * <li>FormatReader.INT16</li> * <li>FormatReader.UINT16</li> * <li>FormatReader.INT32</li> * <li>FormatReader.UINT32</li> * <li>FormatReader.FLOAT</li> * <li>FormatReader.DOUBLE</li> * <li>-1 (unknown type)</li> * </ul> */ public static int getPixelType(final BufferedImage image) { final Raster raster = image.getRaster(); if (raster == null) return -1; final DataBuffer buffer = raster.getDataBuffer(); if (buffer == null) return -1; if (buffer instanceof SignedByteBuffer) { return FormatTools.INT8; } else if (buffer instanceof SignedShortBuffer) { return FormatTools.INT16; } else if (buffer instanceof UnsignedIntBuffer) { return FormatTools.UINT32; } final int type = buffer.getDataType(); final int imageType = image.getType(); switch (type) { case DataBuffer.TYPE_BYTE: return FormatTools.UINT8; case DataBuffer.TYPE_DOUBLE: return FormatTools.DOUBLE; case DataBuffer.TYPE_FLOAT: return FormatTools.FLOAT; case DataBuffer.TYPE_INT: if (imageType == BufferedImage.TYPE_INT_RGB || imageType == BufferedImage.TYPE_INT_BGR || imageType == BufferedImage.TYPE_INT_ARGB) { return FormatTools.UINT8; } if (buffer instanceof UnsignedIntBuffer) { return FormatTools.UINT32; } return FormatTools.INT32; case DataBuffer.TYPE_SHORT: return FormatTools.INT16; case DataBuffer.TYPE_USHORT: if (imageType == BufferedImage.TYPE_USHORT_555_RGB || imageType == BufferedImage.TYPE_USHORT_565_RGB) { return FormatTools.UINT8; } return FormatTools.UINT16; default: return -1; } }
Example 11
Source File: SampleModelPersistenceUtils.java From geowave with Apache License 2.0 | 4 votes |
/** * Sets the data for a single pixel in the specified <code>DataBuffer</code> from a primitive * array of type TransferType. For a <code>ComponentSampleModel</code>, this will be the same as * the data type, and samples are transferred one per array element. * * <p> The following code illustrates transferring data for one pixel from <code>DataBuffer * </code> <code>db1</code>, whose storage layout is described by <code>ComponentSampleModel * </code> <code>csm1</code>, to <code>DataBuffer</code> <code>db2</code>, whose storage layout * is described by <code>ComponentSampleModel</code> <code>csm2</code>. The transfer will * generally be more efficient than using getPixel/setPixel. * * <pre> * ComponentSampleModel csm1, csm2; * DataBufferInt db1, db2; * csm2.setDataElements(x, y, csm1.getDataElements(x, y, null, db1), db2); * </pre> * * Using getDataElements/setDataElements to transfer between two <code>DataBuffer</code> * /SampleModel pairs is legitimate if the <code>SampleModel</code>s have the same number of * bands, corresponding bands have the same number of bits per sample, and the TransferTypes are * the same. * * <p> * * @param x The X coordinate of the pixel location. * @param y The Y coordinate of the pixel location. * @param obj A primitive array containing pixel data. * @param data The <code>DataBuffer</code> containing the image data. * @throws <code>ClassCastException</code> if obj is non-null and is not a primitive array of * type TransferType. * @throws <code>ArrayIndexOutOfBoundsException</code> if the coordinates are not in bounds, or * if obj is non-null and is not large enough to hold the pixel data. */ @Override public void setDataElements(final int x, final int y, final Object obj, final DataBuffer data) { final int type = getTransferType(); final int numDataElems = getNumDataElements(); final int pixelOffset = (y * scanlineStride) + (x * pixelStride); switch (type) { case DataBuffer.TYPE_BYTE: final byte[] barray = (byte[]) obj; for (int i = 0; i < numDataElems; i++) { data.setElem(bankIndices[i], pixelOffset + bandOffsets[i], (barray[i]) & 0xff); } break; case DataBuffer.TYPE_USHORT: final short[] usarray = (short[]) obj; for (int i = 0; i < numDataElems; i++) { data.setElem(bankIndices[i], pixelOffset + bandOffsets[i], (usarray[i]) & 0xffff); } break; case DataBuffer.TYPE_INT: final int[] iarray = (int[]) obj; for (int i = 0; i < numDataElems; i++) { data.setElem(bankIndices[i], pixelOffset + bandOffsets[i], iarray[i]); } break; case DataBuffer.TYPE_SHORT: final short[] sarray = (short[]) obj; for (int i = 0; i < numDataElems; i++) { data.setElem(bankIndices[i], pixelOffset + bandOffsets[i], sarray[i]); } break; case DataBuffer.TYPE_FLOAT: final float[] farray = (float[]) obj; for (int i = 0; i < numDataElems; i++) { data.setElemFloat(bankIndices[i], pixelOffset + bandOffsets[i], farray[i]); } break; case DataBuffer.TYPE_DOUBLE: final double[] darray = (double[]) obj; for (int i = 0; i < numDataElems; i++) { data.setElemDouble(bankIndices[i], pixelOffset + bandOffsets[i], darray[i]); } break; default: throw new RuntimeException("Unsupported data buffer type " + type); } }
Example 12
Source File: ImageTypeSpecifier.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public Interleaved(ColorSpace colorSpace, int[] bandOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied) { if (colorSpace == null) { throw new IllegalArgumentException("colorSpace == null!"); } if (bandOffsets == null) { throw new IllegalArgumentException("bandOffsets == null!"); } int numBands = colorSpace.getNumComponents() + (hasAlpha ? 1 : 0); if (bandOffsets.length != numBands) { throw new IllegalArgumentException ("bandOffsets.length is wrong!"); } if (dataType != DataBuffer.TYPE_BYTE && dataType != DataBuffer.TYPE_SHORT && dataType != DataBuffer.TYPE_USHORT && dataType != DataBuffer.TYPE_INT && dataType != DataBuffer.TYPE_FLOAT && dataType != DataBuffer.TYPE_DOUBLE) { throw new IllegalArgumentException ("Bad value for dataType!"); } this.colorSpace = colorSpace; this.bandOffsets = (int[])bandOffsets.clone(); this.dataType = dataType; this.hasAlpha = hasAlpha; this.isAlphaPremultiplied = isAlphaPremultiplied; this.colorModel = ImageTypeSpecifier.createComponentCM(colorSpace, bandOffsets.length, dataType, hasAlpha, isAlphaPremultiplied); int minBandOffset = bandOffsets[0]; int maxBandOffset = minBandOffset; for (int i = 0; i < bandOffsets.length; i++) { int offset = bandOffsets[i]; minBandOffset = Math.min(offset, minBandOffset); maxBandOffset = Math.max(offset, maxBandOffset); } int pixelStride = maxBandOffset - minBandOffset + 1; int w = 1; int h = 1; this.sampleModel = new PixelInterleavedSampleModel(dataType, w, h, pixelStride, w*pixelStride, bandOffsets); }
Example 13
Source File: ImageTypeSpecifier.java From hottub with GNU General Public License v2.0 | 4 votes |
public Banded(ColorSpace colorSpace, int[] bankIndices, int[] bandOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied) { if (colorSpace == null) { throw new IllegalArgumentException("colorSpace == null!"); } if (bankIndices == null) { throw new IllegalArgumentException("bankIndices == null!"); } if (bandOffsets == null) { throw new IllegalArgumentException("bandOffsets == null!"); } if (bankIndices.length != bandOffsets.length) { throw new IllegalArgumentException ("bankIndices.length != bandOffsets.length!"); } if (dataType != DataBuffer.TYPE_BYTE && dataType != DataBuffer.TYPE_SHORT && dataType != DataBuffer.TYPE_USHORT && dataType != DataBuffer.TYPE_INT && dataType != DataBuffer.TYPE_FLOAT && dataType != DataBuffer.TYPE_DOUBLE) { throw new IllegalArgumentException ("Bad value for dataType!"); } int numBands = colorSpace.getNumComponents() + (hasAlpha ? 1 : 0); if (bandOffsets.length != numBands) { throw new IllegalArgumentException ("bandOffsets.length is wrong!"); } this.colorSpace = colorSpace; this.bankIndices = (int[])bankIndices.clone(); this.bandOffsets = (int[])bandOffsets.clone(); this.dataType = dataType; this.hasAlpha = hasAlpha; this.isAlphaPremultiplied = isAlphaPremultiplied; this.colorModel = ImageTypeSpecifier.createComponentCM(colorSpace, bankIndices.length, dataType, hasAlpha, isAlphaPremultiplied); int w = 1; int h = 1; this.sampleModel = new BandedSampleModel(dataType, w, h, w, bankIndices, bandOffsets); }
Example 14
Source File: ImageTypeSpecifier.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public Interleaved(ColorSpace colorSpace, int[] bandOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied) { if (colorSpace == null) { throw new IllegalArgumentException("colorSpace == null!"); } if (bandOffsets == null) { throw new IllegalArgumentException("bandOffsets == null!"); } int numBands = colorSpace.getNumComponents() + (hasAlpha ? 1 : 0); if (bandOffsets.length != numBands) { throw new IllegalArgumentException ("bandOffsets.length is wrong!"); } if (dataType != DataBuffer.TYPE_BYTE && dataType != DataBuffer.TYPE_SHORT && dataType != DataBuffer.TYPE_USHORT && dataType != DataBuffer.TYPE_INT && dataType != DataBuffer.TYPE_FLOAT && dataType != DataBuffer.TYPE_DOUBLE) { throw new IllegalArgumentException ("Bad value for dataType!"); } this.colorSpace = colorSpace; this.bandOffsets = (int[])bandOffsets.clone(); this.dataType = dataType; this.hasAlpha = hasAlpha; this.isAlphaPremultiplied = isAlphaPremultiplied; this.colorModel = ImageTypeSpecifier.createComponentCM(colorSpace, bandOffsets.length, dataType, hasAlpha, isAlphaPremultiplied); int minBandOffset = bandOffsets[0]; int maxBandOffset = minBandOffset; for (int i = 0; i < bandOffsets.length; i++) { int offset = bandOffsets[i]; minBandOffset = Math.min(offset, minBandOffset); maxBandOffset = Math.max(offset, maxBandOffset); } int pixelStride = maxBandOffset - minBandOffset + 1; int w = 1; int h = 1; this.sampleModel = new PixelInterleavedSampleModel(dataType, w, h, pixelStride, w*pixelStride, bandOffsets); }
Example 15
Source File: ImageTypeSpecifier.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public Banded(ColorSpace colorSpace, int[] bankIndices, int[] bandOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied) { if (colorSpace == null) { throw new IllegalArgumentException("colorSpace == null!"); } if (bankIndices == null) { throw new IllegalArgumentException("bankIndices == null!"); } if (bandOffsets == null) { throw new IllegalArgumentException("bandOffsets == null!"); } if (bankIndices.length != bandOffsets.length) { throw new IllegalArgumentException ("bankIndices.length != bandOffsets.length!"); } if (dataType != DataBuffer.TYPE_BYTE && dataType != DataBuffer.TYPE_SHORT && dataType != DataBuffer.TYPE_USHORT && dataType != DataBuffer.TYPE_INT && dataType != DataBuffer.TYPE_FLOAT && dataType != DataBuffer.TYPE_DOUBLE) { throw new IllegalArgumentException ("Bad value for dataType!"); } int numBands = colorSpace.getNumComponents() + (hasAlpha ? 1 : 0); if (bandOffsets.length != numBands) { throw new IllegalArgumentException ("bandOffsets.length is wrong!"); } this.colorSpace = colorSpace; this.bankIndices = (int[])bankIndices.clone(); this.bandOffsets = (int[])bandOffsets.clone(); this.dataType = dataType; this.hasAlpha = hasAlpha; this.isAlphaPremultiplied = isAlphaPremultiplied; this.colorModel = ImageTypeSpecifier.createComponentCM(colorSpace, bankIndices.length, dataType, hasAlpha, isAlphaPremultiplied); int w = 1; int h = 1; this.sampleModel = new BandedSampleModel(dataType, w, h, w, bankIndices, bandOffsets); }
Example 16
Source File: ImageTypeSpecifier.java From JDKSourceCode1.8 with MIT License | 4 votes |
public Interleaved(ColorSpace colorSpace, int[] bandOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied) { if (colorSpace == null) { throw new IllegalArgumentException("colorSpace == null!"); } if (bandOffsets == null) { throw new IllegalArgumentException("bandOffsets == null!"); } int numBands = colorSpace.getNumComponents() + (hasAlpha ? 1 : 0); if (bandOffsets.length != numBands) { throw new IllegalArgumentException ("bandOffsets.length is wrong!"); } if (dataType != DataBuffer.TYPE_BYTE && dataType != DataBuffer.TYPE_SHORT && dataType != DataBuffer.TYPE_USHORT && dataType != DataBuffer.TYPE_INT && dataType != DataBuffer.TYPE_FLOAT && dataType != DataBuffer.TYPE_DOUBLE) { throw new IllegalArgumentException ("Bad value for dataType!"); } this.colorSpace = colorSpace; this.bandOffsets = (int[])bandOffsets.clone(); this.dataType = dataType; this.hasAlpha = hasAlpha; this.isAlphaPremultiplied = isAlphaPremultiplied; this.colorModel = ImageTypeSpecifier.createComponentCM(colorSpace, bandOffsets.length, dataType, hasAlpha, isAlphaPremultiplied); int minBandOffset = bandOffsets[0]; int maxBandOffset = minBandOffset; for (int i = 0; i < bandOffsets.length; i++) { int offset = bandOffsets[i]; minBandOffset = Math.min(offset, minBandOffset); maxBandOffset = Math.max(offset, maxBandOffset); } int pixelStride = maxBandOffset - minBandOffset + 1; int w = 1; int h = 1; this.sampleModel = new PixelInterleavedSampleModel(dataType, w, h, pixelStride, w*pixelStride, bandOffsets); }
Example 17
Source File: DataBufferPersistenceUtils.java From geowave with Apache License 2.0 | 4 votes |
public static byte[] getDataBufferBinary(final DataBuffer dataBuffer) { final DataBufferProtos.DataBuffer.Builder bldr = DataBufferProtos.DataBuffer.newBuilder(); bldr.setType(dataBuffer.getDataType()); bldr.addAllOffsets(Ints.asList(dataBuffer.getOffsets())); bldr.setSize(dataBuffer.getSize()); switch (dataBuffer.getDataType()) { case DataBuffer.TYPE_BYTE: final ByteDataBuffer.Builder byteBldr = ByteDataBuffer.newBuilder(); final byte[][] byteBank = ((DataBufferByte) dataBuffer).getBankData(); final Iterable<ByteString> byteIt = () -> new Iterator<ByteString>() { private int index = 0; @Override public boolean hasNext() { return byteBank.length > index; } @Override public ByteString next() { if (!hasNext()) { throw new NoSuchElementException(); } return ByteString.copyFrom(byteBank[index++]); } }; byteBldr.addAllBanks(byteIt); bldr.setByteDb(byteBldr.build()); break; case DataBuffer.TYPE_SHORT: setBuilder(shortToInt(((DataBufferShort) dataBuffer).getBankData()), bldr); break; case DataBuffer.TYPE_USHORT: setBuilder(shortToInt(((DataBufferUShort) dataBuffer).getBankData()), bldr); break; case DataBuffer.TYPE_INT: setBuilder(((DataBufferInt) dataBuffer).getBankData(), bldr); break; case DataBuffer.TYPE_FLOAT: final FloatDataBuffer.Builder fltBldr = FloatDataBuffer.newBuilder(); final float[][] fltBank = ((DataBufferFloat) dataBuffer).getBankData(); final Iterable<FloatArray> floatIt = () -> new Iterator<FloatArray>() { private int index = 0; @Override public boolean hasNext() { return fltBank.length > index; } @Override public FloatArray next() { return FloatArray.newBuilder().addAllSamples(Floats.asList(fltBank[index++])).build(); } }; fltBldr.addAllBanks(floatIt); bldr.setFlt(fltBldr); break; case DataBuffer.TYPE_DOUBLE: final DoubleDataBuffer.Builder dblBldr = DoubleDataBuffer.newBuilder(); final double[][] dblBank = ((DataBufferDouble) dataBuffer).getBankData(); final Iterable<DoubleArray> dblIt = () -> new Iterator<DoubleArray>() { private int index = 0; @Override public boolean hasNext() { return dblBank.length > index; } @Override public DoubleArray next() { return DoubleArray.newBuilder().addAllSamples(Doubles.asList(dblBank[index++])).build(); } }; dblBldr.addAllBanks(dblIt); bldr.setDbl(dblBldr); break; default: throw new RuntimeException( "Unsupported DataBuffer type for serialization " + dataBuffer.getDataType()); } return bldr.build().toByteArray(); }
Example 18
Source File: ImageTypeSpecifier.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public Interleaved(ColorSpace colorSpace, int[] bandOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied) { if (colorSpace == null) { throw new IllegalArgumentException("colorSpace == null!"); } if (bandOffsets == null) { throw new IllegalArgumentException("bandOffsets == null!"); } int numBands = colorSpace.getNumComponents() + (hasAlpha ? 1 : 0); if (bandOffsets.length != numBands) { throw new IllegalArgumentException ("bandOffsets.length is wrong!"); } if (dataType != DataBuffer.TYPE_BYTE && dataType != DataBuffer.TYPE_SHORT && dataType != DataBuffer.TYPE_USHORT && dataType != DataBuffer.TYPE_INT && dataType != DataBuffer.TYPE_FLOAT && dataType != DataBuffer.TYPE_DOUBLE) { throw new IllegalArgumentException ("Bad value for dataType!"); } this.colorSpace = colorSpace; this.bandOffsets = (int[])bandOffsets.clone(); this.dataType = dataType; this.hasAlpha = hasAlpha; this.isAlphaPremultiplied = isAlphaPremultiplied; this.colorModel = ImageTypeSpecifier.createComponentCM(colorSpace, bandOffsets.length, dataType, hasAlpha, isAlphaPremultiplied); int minBandOffset = bandOffsets[0]; int maxBandOffset = minBandOffset; for (int i = 0; i < bandOffsets.length; i++) { int offset = bandOffsets[i]; minBandOffset = Math.min(offset, minBandOffset); maxBandOffset = Math.max(offset, maxBandOffset); } int pixelStride = maxBandOffset - minBandOffset + 1; int w = 1; int h = 1; this.sampleModel = new PixelInterleavedSampleModel(dataType, w, h, pixelStride, w*pixelStride, bandOffsets); }
Example 19
Source File: AWTImageTools.java From scifio with BSD 2-Clause "Simplified" License | 3 votes |
/** * Creates an image from the given float data. * * @param data Array containing image data. * @param w Width of image plane. * @param h Height of image plane. * @param c Number of channels. * @param interleaved If set, the channels are assumed to be interleaved; * otherwise they are assumed to be sequential. For example, for RGB * data, the pattern "RGBRGBRGB..." is interleaved, while * "RRR...GGG...BBB..." is sequential. */ public static BufferedImage makeImage(final float[] data, final int w, final int h, final int c, final boolean interleaved) { if (c == 1) return makeImage(data, w, h); final int dataType = DataBuffer.TYPE_FLOAT; final DataBuffer buffer = new DataBufferFloat(data, c * w * h); return constructImage(c, dataType, w, h, interleaved, false, buffer); }
Example 20
Source File: AWTImageTools.java From scifio with BSD 2-Clause "Simplified" License | 3 votes |
/** * Creates an image from the given single-precision floating point data. * * @param data Array containing image data. It is assumed that each channel * corresponds to one element of the array. For example, for RGB * data, data[0] is R, data[1] is G, and data[2] is B. * @param w Width of image plane. * @param h Height of image plane. */ public static BufferedImage makeImage(final float[][] data, final int w, final int h) { final int dataType = DataBuffer.TYPE_FLOAT; final DataBuffer buffer = new DataBufferFloat(data, data[0].length); return constructImage(data.length, dataType, w, h, false, true, buffer); }