use of nitf.NITFException in project imageio-ext by geosolutions-it.
the class NITFReader method readHeader.
public synchronized void readHeader() throws IOException {
if (reader != null)
return;
if (handle == null) {
throw new IllegalStateException("No input handle");
}
try {
reader = new Reader();
record = reader.read(handle);
} catch (NITFException e) {
LOGGER.severe(e.getLocalizedMessage());
throw new IIOException("NITF Exception", e);
}
}
use of nitf.NITFException in project imageio-ext by geosolutions-it.
the class NITFReader method read.
@Override
public BufferedImage read(int imageIndex, ImageReadParam param) throws IOException {
readHeader();
Raster raster = readRaster(imageIndex, param);
// get the requested number of destination bands (or 0 for all)
int numDestBands = param != null ? (param.getDestinationBands() != null ? param.getDestinationBands().length : param.getSourceBands() != null ? param.getSourceBands().length : 0) : 0;
// try to find a good match for the specifier
ImageTypeSpecifier imageType = null, firstType = null;
Iterator<ImageTypeSpecifier> imageTypes = getImageTypes(imageIndex);
while (imageTypes.hasNext() && imageType == null) {
ImageTypeSpecifier currentImageType = imageTypes.next();
if (firstType == null)
firstType = currentImageType;
if (currentImageType.getNumBands() == numDestBands)
imageType = currentImageType;
}
if (imageType == null) {
if (firstType == null)
throw new IOException("Unable to determine the ImageTypeSpecifier");
else
imageType = firstType;
}
try {
ImageSubheader subheader = record.getImages()[imageIndex].getSubheader();
String pvType = subheader.getPixelValueType().getStringData().trim();
int nbpp = subheader.getNumBitsPerPixel().getIntData();
int nBytes = ((nbpp - 1) / 8) + 1;
if (nBytes == 1 || nBytes == 2 || (nBytes == 4 && pvType.equals("R")) || (nBytes == 8 && pvType.equals("R"))) {
return ImageIOUtils.rasterToBufferedImage(raster, imageType);
}
} catch (NITFException e) {
throw new IOException(e);
}
throw new UnsupportedOperationException("Image pixel type or bits per pixel not yet supported");
}
use of nitf.NITFException in project imageio-ext by geosolutions-it.
the class NITFReader method getImageTypes.
@Override
public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex) throws IOException {
checkIndex(imageIndex);
List<ImageTypeSpecifier> l = new ArrayList<ImageTypeSpecifier>();
try {
ImageSubheader subheader = record.getImages()[imageIndex].getSubheader();
String irep = subheader.getImageRepresentation().getStringData().trim();
String pvType = subheader.getPixelValueType().getStringData().trim();
int bandCount = subheader.getBandCount();
int nbpp = subheader.getNumBitsPerPixel().getIntData();
// if (NITFUtils.isCompressed(record, imageIndex))
// {
// throw new NotImplementedException(
// "Only uncompressed imagery is currently supported");
// }
int nBytes = ((nbpp - 1) / 8) + 1;
if (nBytes == 1 || nBytes == 2 || (nBytes == 4 && pvType.equals("R")) || (nBytes == 8 && pvType.equals("R"))) {
if (nBytes == 1 && bandCount == 3 && irep.equals("RGB")) {
ColorSpace rgb = ColorSpace.getInstance(ColorSpace.CS_sRGB);
int[] bandOffsets = new int[3];
for (int i = 0; i < bandOffsets.length; ++i) bandOffsets[i] = i;
l.add(ImageTypeSpecifier.createInterleaved(rgb, bandOffsets, DataBuffer.TYPE_BYTE, false, false));
}
l.add(ImageTypeSpecifier.createGrayscale(8, DataBuffer.TYPE_BYTE, false));
} else {
throw new UnsupportedOperationException("Support for pixels of size " + nbpp + " bytes has not been implemented yet");
}
} catch (NITFException e) {
LOGGER.severe(e.getLocalizedMessage());
}
return l.iterator();
}
Aggregations