Search in sources :

Example 6 with NITFException

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);
    }
}
Also used : NITFException(nitf.NITFException) ImageReader(javax.imageio.ImageReader) Reader(nitf.Reader) IIOException(javax.imageio.IIOException)

Example 7 with NITFException

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");
}
Also used : ImageSubheader(nitf.ImageSubheader) Raster(java.awt.image.Raster) WritableRaster(java.awt.image.WritableRaster) NITFException(nitf.NITFException) IIOException(javax.imageio.IIOException) IOException(java.io.IOException) Point(java.awt.Point) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier)

Example 8 with NITFException

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();
}
Also used : ImageSubheader(nitf.ImageSubheader) ColorSpace(java.awt.color.ColorSpace) NITFException(nitf.NITFException) ArrayList(java.util.ArrayList) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier) Point(java.awt.Point)

Aggregations

NITFException (nitf.NITFException)8 IIOException (javax.imageio.IIOException)6 Point (java.awt.Point)5 ImageSubheader (nitf.ImageSubheader)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)3 WritableRaster (java.awt.image.WritableRaster)2 ByteBuffer (java.nio.ByteBuffer)2 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)2 DownSampler (nitf.DownSampler)2 PixelSkipDownSampler (nitf.PixelSkipDownSampler)2 SubWindow (nitf.SubWindow)2 Rectangle (java.awt.Rectangle)1 ColorSpace (java.awt.color.ColorSpace)1 Raster (java.awt.image.Raster)1 DoubleBuffer (java.nio.DoubleBuffer)1 FloatBuffer (java.nio.FloatBuffer)1 ShortBuffer (java.nio.ShortBuffer)1 ImageReader (javax.imageio.ImageReader)1 DESegment (nitf.DESegment)1