Search in sources :

Example 1 with NitfRenderer

use of org.codice.imaging.nitf.render.NitfRenderer in project alliance by codice.

the class NitfPreStoragePlugin method render.

private BufferedImage render(ContentItem contentItem, Function<Pair<ImageSegment, NitfRenderer>, BufferedImage> imageSegmentFunction) throws IOException, ParseException, NitfFormatException {
    final ThreadLocal<BufferedImage> bufferedImage = new ThreadLocal<>();
    if (contentItem != null) {
        InputStream inputStream = contentItem.getInputStream();
        if (inputStream != null) {
            try {
                NitfRenderer renderer = getNitfRenderer();
                new NitfParserInputFlowImpl().inputStream(inputStream).allData().forEachImageSegment(segment -> {
                    if (bufferedImage.get() == null) {
                        BufferedImage bi = imageSegmentFunction.apply(new ImmutablePair<>(segment, renderer));
                        if (bi != null) {
                            bufferedImage.set(bi);
                        }
                    }
                }).end();
            } finally {
                IOUtils.closeQuietly(inputStream);
            }
        }
    }
    return bufferedImage.get();
}
Also used : J2KImageWriter(com.github.jaiimageio.jpeg2000.impl.J2KImageWriter) IIOImage(javax.imageio.IIOImage) ImageSegment(org.codice.imaging.nitf.core.image.ImageSegment) StringUtils(org.apache.commons.lang.StringUtils) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) J2KImageReaderSpi(com.github.jaiimageio.jpeg2000.impl.J2KImageReaderSpi) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) NitfParserInputFlowImpl(org.codice.imaging.nitf.fluent.impl.NitfParserInputFlowImpl) LoggerFactory(org.slf4j.LoggerFactory) PreCreateStoragePlugin(ddf.catalog.content.plugin.PreCreateStoragePlugin) Thumbnails(net.coobird.thumbnailator.Thumbnails) Function(java.util.function.Function) J2KImageWriterSpi(com.github.jaiimageio.jpeg2000.impl.J2KImageWriterSpi) ArrayList(java.util.ArrayList) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) ImageWriteParam(javax.imageio.ImageWriteParam) ContentItem(ddf.catalog.content.data.ContentItem) PreUpdateStoragePlugin(ddf.catalog.content.plugin.PreUpdateStoragePlugin) Pair(org.apache.commons.lang3.tuple.Pair) Metacard(ddf.catalog.data.Metacard) Graphics2D(java.awt.Graphics2D) MimeType(javax.activation.MimeType) ImageIO(javax.imageio.ImageIO) ByteSource(com.google.common.io.ByteSource) ParseException(java.text.ParseException) Core(ddf.catalog.data.types.Core) NitfFormatException(org.codice.imaging.nitf.core.common.NitfFormatException) Logger(org.slf4j.Logger) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException) IIORegistry(javax.imageio.spi.IIORegistry) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ImageOutputStream(javax.imageio.stream.ImageOutputStream) MimeTypeParseException(javax.activation.MimeTypeParseException) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Attribute(ddf.catalog.data.Attribute) MemoryCacheImageOutputStream(javax.imageio.stream.MemoryCacheImageOutputStream) NitfRenderer(org.codice.imaging.nitf.render.NitfRenderer) J2KImageWriteParam(com.github.jaiimageio.jpeg2000.J2KImageWriteParam) FilenameUtils(org.apache.commons.io.FilenameUtils) InputStream(java.io.InputStream) NitfRenderer(org.codice.imaging.nitf.render.NitfRenderer) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) InputStream(java.io.InputStream) NitfParserInputFlowImpl(org.codice.imaging.nitf.fluent.impl.NitfParserInputFlowImpl) BufferedImage(java.awt.image.BufferedImage)

Example 2 with NitfRenderer

use of org.codice.imaging.nitf.render.NitfRenderer in project alliance by codice.

the class PreStoragePluginTest method testRunTimeException.

@Test
public void testRunTimeException() throws IOException, PluginExecutionException {
    NitfRenderer nitfRenderer = mock(NitfRenderer.class);
    NitfPreStoragePlugin nitfPreStoragePlugin = new NitfPreStoragePlugin() {

        @Override
        NitfRenderer getNitfRenderer() {
            return nitfRenderer;
        }
    };
    when(nitfRenderer.render(any(ImageSegment.class))).thenThrow(RuntimeException.class);
    CreateStorageRequest result = nitfPreStoragePlugin.process(createStorageRequest);
    assertThat(result.getContentItems(), is(createStorageRequest.getContentItems()));
}
Also used : ImageSegment(org.codice.imaging.nitf.core.image.ImageSegment) NitfRenderer(org.codice.imaging.nitf.render.NitfRenderer) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) Test(org.junit.Test)

Aggregations

CreateStorageRequest (ddf.catalog.content.operation.CreateStorageRequest)2 ImageSegment (org.codice.imaging.nitf.core.image.ImageSegment)2 NitfRenderer (org.codice.imaging.nitf.render.NitfRenderer)2 J2KImageWriteParam (com.github.jaiimageio.jpeg2000.J2KImageWriteParam)1 J2KImageReaderSpi (com.github.jaiimageio.jpeg2000.impl.J2KImageReaderSpi)1 J2KImageWriter (com.github.jaiimageio.jpeg2000.impl.J2KImageWriter)1 J2KImageWriterSpi (com.github.jaiimageio.jpeg2000.impl.J2KImageWriterSpi)1 ByteSource (com.google.common.io.ByteSource)1 ContentItem (ddf.catalog.content.data.ContentItem)1 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)1 UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)1 PreCreateStoragePlugin (ddf.catalog.content.plugin.PreCreateStoragePlugin)1 PreUpdateStoragePlugin (ddf.catalog.content.plugin.PreUpdateStoragePlugin)1 Attribute (ddf.catalog.data.Attribute)1 Metacard (ddf.catalog.data.Metacard)1 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)1 Core (ddf.catalog.data.types.Core)1 PluginExecutionException (ddf.catalog.plugin.PluginExecutionException)1 Graphics2D (java.awt.Graphics2D)1 BufferedImage (java.awt.image.BufferedImage)1