Arrays.fill(bankData[i], (short) 0); db = new DataBufferUShort(bankData, (int) size);
strideElementsAligned = strideBytesAligned / 2; cm = new DirectColorModel(16, 0x7C00, 0x3E0, 0x1F); buffer = new DataBufferUShort(strideElementsAligned * height); raster = Raster.createPackedRaster(buffer, bih.biWidth, height, strideElementsAligned, ((DirectColorModel) cm).getMasks(), null); break;
+ numElems + " elements per bank"); buff = new DataBufferUShort(numElems, numBanks); for (int elem = 0; elem < numElems; elem++) { for (int bank = 0; bank < numBanks; bank++) {
Arrays.fill(ushortDataArray[i], noDataValue.shortValue()); dataBuffer = new DataBufferUShort(ushortDataArray, dataBufferSize); break;
Arrays.fill(bankData[i], (short) 0); db = new DataBufferUShort(bankData, (int) size);
DataBuffer db = new DataBufferUShort(shortArray, shortArray.length); raster = Raster.createPackedRaster(db, srcRect.width, srcRect.height, srcRect.width, ((DirectColorModel) cm).getMasks(), null);
int w = 2; int h = 2; int stride = 1; byte[] rawBytes = {0x21, 0x27, 0x33, (byte) 0xF6, 0x28, (byte) 0xF3, (byte) 0x27, (byte) 0xF2}; short[] rawShorts = new short[rawBytes.length / 2]; ByteBuffer.wrap(rawBytes) .order(ByteOrder.LITTLE_ENDIAN) .asShortBuffer() .get(rawShorts); DataBuffer dataBuffer = new DataBufferUShort(rawShorts, rawShorts.length); WritableRaster raster = Raster.createInterleavedRaster(dataBuffer, w, h, w * stride, stride, new int[]{0}, null); ColorModel colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY), false, false, Transparency.OPAQUE, DataBuffer.TYPE_USHORT); BufferedImage image = new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null);
@Override protected DataBufferUShort createDataBuffer( final ShortArray data ) { final short[] sourceArray = data.getCurrentStorageArray(); return new DataBufferUShort( sourceArray, sourceArray.length ); }
@Override protected DataBufferUShort createDataBuffer( final ShortArray data ) { final short[] sourceArray = data.getCurrentStorageArray(); return new DataBufferUShort( sourceArray, sourceArray.length ); }
buffer = new DataBufferUShort(data, data.length); bands = data.length / (pWidth * pHeight);
public LookupTableCV(short[] data, int offset, boolean isUShort) { this.offsets = new int[1]; this.initOffsets(offset); if (isUShort) { this.data = new DataBufferUShort(Objects.requireNonNull(data), data.length); } else { this.data = new DataBufferShort(Objects.requireNonNull(data), data.length); } }
/** * Creates an image from the given short 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. * @param signed Whether the short values should be treated as signed * (-32768 to 32767) instead of unsigned (0 to 65535). */ public static BufferedImage makeImage(short[][] data, int w, int h, boolean signed) { int dataType; DataBuffer buffer; if (signed) { dataType = DataBuffer.TYPE_SHORT; buffer = new SignedShortBuffer(data, data[0].length); } else { dataType = DataBuffer.TYPE_USHORT; buffer = new DataBufferUShort(data, data[0].length); } return constructImage(data.length, dataType, w, h, false, true, buffer); }
/** * Creates an image from the given short 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. * @param signed Whether the short values should be treated as signed (-32768 * to 32767) instead of unsigned (0 to 65535). */ public static BufferedImage makeImage(final short[][] data, final int w, final int h, final boolean signed) { int dataType; DataBuffer buffer; if (signed) { dataType = DataBuffer.TYPE_SHORT; buffer = new SignedShortBuffer(data, data[0].length); } else { dataType = DataBuffer.TYPE_USHORT; buffer = new DataBufferUShort(data, data[0].length); } return constructImage(data.length, dataType, w, h, false, true, buffer); }
/** * Creates an image from the given short 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. * @param signed Whether the short values should be treated as signed * (-32768 to 32767) instead of unsigned (0 to 65535). */ public static BufferedImage makeImage(short[][] data, int w, int h, boolean signed) { int dataType; DataBuffer buffer; if (signed) { dataType = DataBuffer.TYPE_SHORT; buffer = new SignedShortBuffer(data, data[0].length); } else { dataType = DataBuffer.TYPE_USHORT; buffer = new DataBufferUShort(data, data[0].length); } return constructImage(data.length, dataType, w, h, false, true, buffer); }
/** * Creates an image from the given short 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. * @param signed Whether the short values should be treated as signed * (-32768 to 32767) instead of unsigned (0 to 65535). */ public static BufferedImage makeImage(short[][] data, int w, int h, boolean signed) { int dataType; DataBuffer buffer; if (signed) { dataType = DataBuffer.TYPE_SHORT; buffer = new SignedShortBuffer(data, data[0].length); } else { dataType = DataBuffer.TYPE_USHORT; buffer = new DataBufferUShort(data, data[0].length); } return constructImage(data.length, dataType, w, h, false, true, buffer); }
/** * Creates an image from the given short 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. * @param signed Whether the short values should be treated as signed (-32768 * to 32767) instead of unsigned (0 to 65535). */ public static BufferedImage makeImage(final short[][] data, final int w, final int h, final boolean signed) { int dataType; DataBuffer buffer; if (signed) { dataType = DataBuffer.TYPE_SHORT; buffer = new SignedShortBuffer(data, data[0].length); } else { dataType = DataBuffer.TYPE_USHORT; buffer = new DataBufferUShort(data, data[0].length); } return constructImage(data.length, dataType, w, h, false, true, buffer); }
private DataBuffer asDataBuffer() { if (depthPerPixel == 1 || depthPerPixel == 8) { byte[][] buffers = new byte[getFrames().size()][]; for (int i = 0; i < getFrames().size(); i++) { buffers[i] = getFrames().get(i).getData(); } return new DataBufferByte(buffers, getFrames().get(0).getData().length); } else { short[][] buffers = new short[getFrames().size()][]; int stride = Short.SIZE / Byte.SIZE; for (int i = 0; i < getFrames().size(); i++) { byte[] bank = getFrames().get(i).getData(); buffers[i] = new short[bank.length / stride]; for (int j = 0; j < buffers[i].length; j++) { buffers[i][j] = (short) ((bank[stride * j] & 0xFF) << Byte.SIZE); buffers[i][j] |= (short) (bank[stride * j + 1] & 0xFF); } } return new DataBufferUShort(buffers, getFrames().get(0).getData().length / stride); } }
origin); } else { dataBuffer = new DataBufferUShort(height * scanlineStride); ras = Raster.createInterleavedRaster(dataBuffer, width, height,
public static RenderedImage createRenderedImage(int width, int height, ProductData data) { final int dataBufferType = ImageManager.getDataBufferType(data.getType()); DataBuffer db; if (dataBufferType == DataBuffer.TYPE_BYTE) { db = new DataBufferByte((byte[]) data.getElems(), data.getNumElems()); } else if (dataBufferType == DataBuffer.TYPE_USHORT) { db = new DataBufferUShort((short[]) data.getElems(), data.getNumElems()); } else if (dataBufferType == DataBuffer.TYPE_SHORT) { db = new DataBufferShort((short[]) data.getElems(), data.getNumElems()); } else if (dataBufferType == DataBuffer.TYPE_INT) { db = new DataBufferInt((int[]) data.getElems(), data.getNumElems()); } else if (dataBufferType == DataBuffer.TYPE_FLOAT) { db = new DataBufferFloat((float[]) data.getElems(), data.getNumElems()); } else if (dataBufferType == DataBuffer.TYPE_DOUBLE) { db = new DataBufferDouble((double[]) data.getElems(), data.getNumElems()); } else { throw new IllegalStateException("illegal image data buffer type: " + dataBufferType); } SampleModel sampleModel = createSingleBandedSampleModel(dataBufferType, width, height); final ColorModel colorModel = PlanarImage.createColorModel(sampleModel); final WritableRaster raster = WritableRaster.createWritableRaster(sampleModel, db, new Point(0, 0)); // final TiledImage image = new TiledImage(0, 0, width, height, 512, 512, sampleModel, colorModel); // final BufferedImage image = new BufferedImage(colorModel, raster, false, null); // image. return new MyRenderedImage(raster, colorModel); }
@Test public void testAccumulateDataUShort() throws Exception { short[] data = new short[]{ (short) 65535, (short) 65534, (short) 65533, (short) 65532, (short) 65531, (short) 65530, (short) 65529, (short) 65528, (short) 65527, (short) 65526, (short) 65525 }; SummaryStxOp op = new SummaryStxOp(); op.accumulateData(getPixels(new DataBufferUShort(data, data.length)), null); assertEquals(65525.0, op.getMinimum(), 1.0e-8); assertEquals(65535.0, op.getMaximum(), 1.0e-8); assertEquals(65530.0, op.getMean(), 1.0e-8); assertEquals(11.0, op.getVariance(), 1.0e-8); assertEquals(3.31662479, op.getStandardDeviation(), 1.0e-8); }