[gdal-dev] GDAL, Java and UINT16
Mike O'Malley
mike.omalley at nextcentury.com
Thu Oct 27 14:14:32 EDT 2011
Hi-
I've built GDAL 1.8.1 on Windows and used SWIG to produce the Java
bindings. I've tried to run Worldwind's GDALTest application
(http://worldwind31.arc.nasa.gov/svn/trunk/GDAL/GDAL-1.7.2/swig/java/app
s/GDALtest.java) against a known good NITF image, but with no success.
Initially, I got an exception because the image's single band is of
type UINT16, and the Worldwind code didn't have a case for that type. I
shoehorned it into the INT16 clause, producing this:
else if ((buf_type ==
gdalconstConstants.GDT_Int16)||(buf_type==gdalconstConstants.GDT_UInt16)
)
{
System.out.println("Int16/Uint16");
short[][] shorts = new short[bandCount][];
for (int i = 0; i < bandCount; i++)
{
shorts[i] = new short[pixels];
bands[i].asShortBuffer().get(shorts[i]);
}
imgBuffer = new DataBufferShort(shorts, pixels);
buffer_type = DataBuffer.TYPE_USHORT;
sampleModel = new BandedSampleModel(buffer_type,
xsize, ysize, xsize, banks, offsets);
data_type = BufferedImage.TYPE_USHORT_GRAY;
}
I knew it wasn't quite correct, but it turns out that it's not at all
correct. The Worldwind function returns a BufferedImage object
constructed from the NITF file. Java's ImageIO object refuses to write
the BufferedImage created for the UINT16 image using the code above.
There's no exception, the function ImageIO.write() simply returns false
and no file is created.
The problem isn't the image; the GDAL command line applications work
very well with it, as does FWTools.
I don't think this is a Java bindings problem; I just think I'm not
handling UINT16 images correctly. Given the difference in sign between
Java and C, what's the best way to proceed? There has to be a
straightforward answer for this, but I can't find it. The Worldwind
code handles bytes, signed int16s, and signed int32s.
Thanks,
Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20111027/836a5ebf/attachment.html
More information about the gdal-dev
mailing list