Java Code Examples for java.awt.image.DataBufferUShort#getData()

The following examples show how to use java.awt.image.DataBufferUShort#getData() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: mochadoom   File: MenuMisc.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void WritePNGfile(String imagename, short[] linear, int width, int height) {
    BufferedImage buf = new BufferedImage(width, height, BufferedImage.TYPE_USHORT_555_RGB);
    DataBufferUShort sh = (DataBufferUShort) buf.getRaster().getDataBuffer();
    short[] shd = sh.getData();
    System.arraycopy(linear, 0, shd, 0, Math.min(linear.length, shd.length));
    try {
        ImageIO.write(buf, "PNG", new File(imagename));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 2
private Object extractImageData(BufferedImage img){
    DataBuffer buf = img.getRaster().getDataBuffer();
    switch (buf.getDataType()){
        case DataBuffer.TYPE_BYTE:
            DataBufferByte byteBuf = (DataBufferByte) buf;
            return byteBuf.getData();
        case DataBuffer.TYPE_USHORT:
            DataBufferUShort shortBuf = (DataBufferUShort) buf;
            return shortBuf.getData();
    }
    return null;
}
 
Example 3
Source Project: gcs   File: JPXFilter.java    License: Mozilla Public License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public DecodeResult decode(InputStream encoded, OutputStream decoded, COSDictionary
        parameters, int index, DecodeOptions options) throws IOException
{
    DecodeResult result = new DecodeResult(new COSDictionary());
    result.getParameters().addAll(parameters);
    BufferedImage image = readJPX(encoded, options, result);

    Raster raster = image.getRaster();
    switch (raster.getDataBuffer().getDataType())
    {
        case DataBuffer.TYPE_BYTE:
            DataBufferByte byteBuffer = (DataBufferByte) raster.getDataBuffer();
            decoded.write(byteBuffer.getData());
            return result;

        case DataBuffer.TYPE_USHORT:
            DataBufferUShort wordBuffer = (DataBufferUShort) raster.getDataBuffer();
            for (short w : wordBuffer.getData())
            {
                decoded.write(w >> 8);
                decoded.write(w);
            }
            return result;

        case DataBuffer.TYPE_INT:
            // not yet used (as of October 2018) but works as fallback
            // if we decide to convert to BufferedImage.TYPE_INT_RGB
            int[] ar = new int[raster.getNumBands()];
            for (int y = 0; y < image.getHeight(); ++y)
            {
                for (int x = 0; x < image.getWidth(); ++x)
                {
                    raster.getPixel(x, y, ar);
                    for (int i = 0; i < ar.length; ++i)
                    {
                        decoded.write(ar[i]);
                    }
                }
            }
            return result;

        default:
            throw new IOException("Data type " + raster.getDataBuffer().getDataType() + " not implemented");
    }
}
 
Example 4
Source Project: geopackage-java   File: CoverageDataPng.java    License: MIT License 2 votes vote down vote up
/**
 * Get the pixel values of the raster as "unsigned shorts"
 * 
 * @param raster
 *            image raster
 * @return "unsigned short" pixel values
 */
public short[] getPixelValues(WritableRaster raster) {
	DataBufferUShort buffer = (DataBufferUShort) raster.getDataBuffer();
	short[] pixelValues = buffer.getData();
	return pixelValues;
}