Search in sources :

Example 21 with NitfParserInputFlowImpl

use of org.codice.imaging.nitf.fluent.impl.NitfParserInputFlowImpl in project alliance by codice.

the class ImageInputTransformerTest method testPiatgb.

@Test
public void testPiatgb() throws IOException, NitfFormatException {
    File nitfFile = File.createTempFile("nitf-", ".ntf");
    try {
        createNitfWithPiatgb(nitfFile);
        try (InputStream inputStream = new FileInputStream(nitfFile)) {
            Metacard metacard = metacardFactory.createMetacard("piatgbTest");
            NitfSegmentsFlow nitfSegmentsFlow = new NitfParserInputFlowImpl().inputStream(inputStream).headerOnly();
            transformer.transform(nitfSegmentsFlow, metacard);
            assertThat(metacard.getAttribute(PiatgbAttribute.TARGET_NAME_ATTRIBUTE.getLongName()).getValue(), is("Canberra Hill"));
        }
    } finally {
        nitfFile.delete();
    }
}
Also used : Metacard(ddf.catalog.data.Metacard) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) NitfSegmentsFlow(org.codice.imaging.nitf.fluent.NitfSegmentsFlow) NitfParserInputFlowImpl(org.codice.imaging.nitf.fluent.impl.NitfParserInputFlowImpl) File(java.io.File) FileInputStream(java.io.FileInputStream) TreUtilityTest(org.codice.alliance.transformer.nitf.TreUtilityTest) Test(org.junit.Test)

Example 22 with NitfParserInputFlowImpl

use of org.codice.imaging.nitf.fluent.impl.NitfParserInputFlowImpl 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 23 with NitfParserInputFlowImpl

use of org.codice.imaging.nitf.fluent.impl.NitfParserInputFlowImpl in project alliance by codice.

the class ImagingTest method testImageNitfChipCreationNitf.

@Test
public void testImageNitfChipCreationNitf() throws Exception {
    String id = ingestNitfFile(TEST_IMAGE_NITF);
    String chippingUrl = SECURE_ROOT + HTTPS_PORT.getPort() + "/chipping/chipping.html?id=" + id + "&source=Alliance";
    given().get(chippingUrl).then().assertThat().statusCode(HttpStatus.SC_OK);
    final int width = 350;
    final int height = 240;
    String chippedImageUrl = SERVICE_ROOT + "/catalog/" + id + "?transform=nitf-chip&qualifier=overview&x=" + 300 + "&y=" + 200 + "&w=" + width + "&h=" + height;
    InputStream chippedImageStream = given().get(chippedImageUrl).asInputStream();
    List<ImageSegment> imageSegments = new LinkedList<>();
    try (TemporaryFileBackedOutputStream tfbos = new TemporaryFileBackedOutputStream()) {
        IOUtils.copyLarge(chippedImageStream, tfbos);
        NitfSegmentsFlow nitfSegmentsFlow = new NitfParserInputFlowImpl().inputStream(tfbos.asByteSource().openBufferedStream()).allData();
        nitfSegmentsFlow.forEachImageSegment(imageSegments::add);
    }
    assertThat(imageSegments, hasSize(1));
    assertThat(imageSegments.get(0).getNumberOfColumns(), is((long) width));
    assertThat(imageSegments.get(0).getNumberOfRows(), is((long) height));
}
Also used : ImageSegment(org.codice.imaging.nitf.core.image.ImageSegment) TemporaryFileBackedOutputStream(org.codice.ddf.platform.util.TemporaryFileBackedOutputStream) InputStream(java.io.InputStream) NitfSegmentsFlow(org.codice.imaging.nitf.fluent.NitfSegmentsFlow) NitfParserInputFlowImpl(org.codice.imaging.nitf.fluent.impl.NitfParserInputFlowImpl) LinkedList(java.util.LinkedList) AbstractAllianceIntegrationTest(org.codice.alliance.test.itests.common.AbstractAllianceIntegrationTest) Test(org.junit.Test)

Aggregations

NitfParserInputFlowImpl (org.codice.imaging.nitf.fluent.impl.NitfParserInputFlowImpl)23 NitfSegmentsFlow (org.codice.imaging.nitf.fluent.NitfSegmentsFlow)22 Test (org.junit.Test)20 File (java.io.File)13 Metacard (ddf.catalog.data.Metacard)12 InputStream (java.io.InputStream)12 FileInputStream (java.io.FileInputStream)10 TreUtilityTest (org.codice.alliance.transformer.nitf.TreUtilityTest)10 BufferedImage (java.awt.image.BufferedImage)6 BinaryContent (ddf.catalog.data.BinaryContent)5 NitfAttribute (org.codice.alliance.transformer.nitf.common.NitfAttribute)5 ImageSegment (org.codice.imaging.nitf.core.image.ImageSegment)4 DateTime (org.codice.imaging.nitf.core.common.DateTime)3 NitfFormatException (org.codice.imaging.nitf.core.common.NitfFormatException)3 NitfHeader (org.codice.imaging.nitf.core.header.NitfHeader)3 FileSecurityMetadata (org.codice.imaging.nitf.core.security.FileSecurityMetadata)3 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