Search in sources :

Example 11 with ImageSegment

use of org.codice.imaging.nitf.core.image.ImageSegment in project alliance by codice.

the class ImageInputTransformerTest method createNitfWithPiaprd.

private static Map<NitfAttribute, NitfValue> createNitfWithPiaprd(File file) throws NitfFormatException {
    String accessId = "THIS IS AN IPA FILE.                                       -END-";
    String keyword = "FIRST                                                             " + "                                                        " + "                                                        " + "                                                        " + "                -END-";
    Tre piaprd = TreFactory.getDefault("PIAPRD", TreSource.ImageExtendedSubheaderData);
    piaprd.add(new TreEntryImpl("ACCESSID", accessId, "string"));
    piaprd.add(new TreEntryImpl("FMCONTROL", "PXX                        -END-", "string"));
    piaprd.add(new TreEntryImpl("SUBDET", "P", "string"));
    piaprd.add(new TreEntryImpl("PRODCODE", "YY", "string"));
    piaprd.add(new TreEntryImpl("PRODUCERSE", "UNKNOW", "string"));
    piaprd.add(new TreEntryImpl("PRODIDNO", "X211           -END-", "string"));
    piaprd.add(new TreEntryImpl("PRODSNME", "JUNK FILE.", "string"));
    piaprd.add(new TreEntryImpl("PRODUCERCD", "27", "string"));
    piaprd.add(new TreEntryImpl("PRODCRTIME", "26081023ZOCT95", "string"));
    piaprd.add(new TreEntryImpl("MAPID", "132                                -END-", "string"));
    piaprd.add(new TreEntryImpl("SECTITLEREP", "01", "UINT"));
    TreEntryImpl secTitleEntry = new TreEntryImpl("SECTITLE", null, "string");
    TreGroup secTitleGroup = TreFactory.getDefault("SECTITLE", TreSource.ImageExtendedSubheaderData);
    secTitleGroup.getEntries().add(0, new TreEntryImpl("SECTITLE", "                                   -END-", "string"));
    secTitleGroup.getEntries().add(1, new TreEntryImpl("PPNUM", "32/47", "string"));
    secTitleGroup.getEntries().add(2, new TreEntryImpl("TPP", "001", "UINT"));
    secTitleEntry.initGroups();
    secTitleEntry.addGroup(secTitleGroup);
    piaprd.add(secTitleEntry);
    piaprd.add(new TreEntryImpl("REQORGREP", "01", "UINT"));
    TreEntryImpl reqorgEntry = new TreEntryImpl("REQORG", null, "string");
    TreGroup reqorgGroup = TreFactory.getDefault("REQORG", TreSource.ImageExtendedSubheaderData);
    reqorgGroup.getEntries().add(0, new TreEntryImpl("REQORG", "FIRST                                                      -END-", "string"));
    reqorgEntry.initGroups();
    reqorgEntry.addGroup(reqorgGroup);
    piaprd.add(reqorgEntry);
    piaprd.add(new TreEntryImpl("KEYWORDREP", "01", "UINT"));
    TreEntryImpl keywordEntry = new TreEntryImpl("KEYWORD", null, "string");
    TreGroup keywordGroup = TreFactory.getDefault("KEYWORD", TreSource.ImageExtendedSubheaderData);
    keywordGroup.getEntries().add(0, new TreEntryImpl("KEYWORD", keyword, "string"));
    keywordEntry.initGroups();
    keywordEntry.addGroup(keywordGroup);
    piaprd.add(keywordEntry);
    piaprd.add(new TreEntryImpl("ASSRPTREP", "01", "UNIT"));
    TreEntryImpl assrptEntry = new TreEntryImpl("ASSRPT", null, "string");
    TreGroup asserptGroup = TreFactory.getDefault("ASSRPT", TreSource.ImageExtendedSubheaderData);
    asserptGroup.getEntries().add(0, new TreEntryImpl("ASSRPT", "FIRST          -END-", "string"));
    assrptEntry.initGroups();
    assrptEntry.addGroup(asserptGroup);
    piaprd.add(assrptEntry);
    piaprd.add(new TreEntryImpl("ATEXTREP", "01", "UINT"));
    TreEntryImpl atextEntry = new TreEntryImpl("ATEXT", null, "string");
    TreGroup atextGroup = TreFactory.getDefault("ATEXT", TreSource.ImageExtendedSubheaderData);
    atextGroup.getEntries().add(0, new TreEntryImpl("ATEXT", "FIRST                                                             " + "                                                        " + "                                                        " + "                                                        " + "                -END-", "string"));
    atextEntry.initGroups();
    atextEntry.addGroup(atextGroup);
    piaprd.add(atextEntry);
    ImageSegment imageSegment = TreUtilityTest.createImageSegment();
    imageSegment.getTREsRawStructure().add(piaprd);
    new NitfCreationFlowImpl().fileHeader(() -> TreUtilityTest.createFileHeader()).imageSegment(() -> imageSegment).write(file.getAbsolutePath());
    // key value pair of nitf attributes and expected getAttributes
    Map<NitfAttribute, NitfValue> assertMap = new HashMap<>();
    assertMap.put(PiaprdAttribute.ACCESS_ID_ATTRIBUTE, new NitfValue(accessId));
    assertMap.put(IndexedPiaprdAttribute.KEYWORD_ATTRIBUTE, new NitfValue(keyword));
    return assertMap;
}
Also used : TreUtilityTest.createImageSegment(org.codice.alliance.transformer.nitf.TreUtilityTest.createImageSegment) ImageSegment(org.codice.imaging.nitf.core.image.ImageSegment) NitfCreationFlowImpl(org.codice.imaging.nitf.fluent.impl.NitfCreationFlowImpl) HashMap(java.util.HashMap) Tre(org.codice.imaging.nitf.core.tre.Tre) TreGroup(org.codice.imaging.nitf.core.tre.TreGroup) NitfAttribute(org.codice.alliance.transformer.nitf.common.NitfAttribute) TreEntryImpl(org.codice.imaging.nitf.core.tre.impl.TreEntryImpl)

Example 12 with ImageSegment

use of org.codice.imaging.nitf.core.image.ImageSegment in project alliance by codice.

the class ImageInputTransformerTest method createNitfWithExpltb.

private static Map<NitfAttribute, NitfValue> createNitfWithExpltb(File file) {
    String angleToNorth = "150.001";
    String angleToNorthAccuracy = "03.001";
    String mode = "LBM";
    String primeId = "aaaaaaaaaaaa";
    Tre expltb = TreFactory.getDefault("EXPLTB", TreSource.ImageExtendedSubheaderData);
    expltb.add(new TreEntryImpl("ANGLE_TO_NORTH", angleToNorth, "float"));
    expltb.add(new TreEntryImpl("ANGLE_TO_NORTH_ACCY", angleToNorthAccuracy, "float"));
    expltb.add(new TreEntryImpl("SQUINT_ANGLE", "-59.002", "float"));
    expltb.add(new TreEntryImpl("SQUINT_ANGLE_ACCY", "44.002", "float"));
    expltb.add(new TreEntryImpl("MODE", mode, "string"));
    expltb.add(new TreEntryImpl("GRAZE_ANG", "50.00", "float"));
    expltb.add(new TreEntryImpl("GRAZE_ANG_ACCY", "00.01", "float"));
    expltb.add(new TreEntryImpl("SLOPE_ANG", "24.00", "float"));
    expltb.add(new TreEntryImpl("POLAR", "HH", "UINT"));
    expltb.add(new TreEntryImpl("NSAMP", "03333", "UINT"));
    expltb.add(new TreEntryImpl("SEQ_NUM", "4", "string"));
    expltb.add(new TreEntryImpl("PRIME_ID", primeId, "string"));
    expltb.add(new TreEntryImpl("PRIME_BE", "bbbbbbbbbbbbbbb", "string"));
    expltb.add(new TreEntryImpl("N_SEC", "11", "UINT"));
    expltb.add(new TreEntryImpl("IPR", "22", "UINT"));
    ImageSegment imageSegment = TreUtilityTest.createImageSegment();
    imageSegment.getTREsRawStructure().add(expltb);
    new NitfCreationFlowImpl().fileHeader(() -> TreUtilityTest.createFileHeader()).imageSegment(() -> imageSegment).write(file.getAbsolutePath());
    // key value pair of nitf attributes and expected getAttributes
    Map<NitfAttribute, NitfValue> assertMap = new HashMap<>();
    assertMap.put(ExpltbAttribute.ANGLE_TO_NORTH_ATTRIBUTE, new NitfValue(Float.parseFloat(angleToNorth)));
    assertMap.put(ExpltbAttribute.ANGLE_TO_NORTH_ACCURACY_ATTRIBUTE, new NitfValue(Float.parseFloat(angleToNorthAccuracy)));
    assertMap.put(ExpltbAttribute.MODE_ATTRIBUTE, new NitfValue(mode));
    assertMap.put(ExpltbAttribute.PRIME_ID_ATTRIBUTE, new NitfValue(primeId));
    return assertMap;
}
Also used : TreUtilityTest.createImageSegment(org.codice.alliance.transformer.nitf.TreUtilityTest.createImageSegment) ImageSegment(org.codice.imaging.nitf.core.image.ImageSegment) NitfCreationFlowImpl(org.codice.imaging.nitf.fluent.impl.NitfCreationFlowImpl) HashMap(java.util.HashMap) Tre(org.codice.imaging.nitf.core.tre.Tre) NitfAttribute(org.codice.alliance.transformer.nitf.common.NitfAttribute) TreEntryImpl(org.codice.imaging.nitf.core.tre.impl.TreEntryImpl)

Example 13 with ImageSegment

use of org.codice.imaging.nitf.core.image.ImageSegment in project alliance by codice.

the class ImageInputTransformerTest method createNitfWithPiatgb.

private static void createNitfWithPiatgb(File file) {
    NitfHeader header = NitfHeaderFactory.getDefault(FileType.NITF_TWO_ONE);
    Tre piatgb = TreFactory.getDefault("PIATGB", TreSource.ImageExtendedSubheaderData);
    piatgb.add(new TreEntryImpl("TGTUTM", "55HFA9359093610", "string"));
    piatgb.add(new TreEntryImpl("PIATGAID", "ABCDEFGHIJUVWXY", "string"));
    piatgb.add(new TreEntryImpl("PIACTRY", "AS", "string"));
    piatgb.add(new TreEntryImpl("PIACAT", "702XX", "string"));
    piatgb.add(new TreEntryImpl("TGTGEO", "351655S1490742E", "string"));
    piatgb.add(new TreEntryImpl("DATUM", "WGE", "string"));
    piatgb.add(new TreEntryImpl("TGTNAME", "Canberra Hill                         ", "string"));
    piatgb.add(new TreEntryImpl("PERCOVER", "57", "UINT"));
    piatgb.add(new TreEntryImpl("TGTLAT", "-35.30812 ", "float"));
    piatgb.add(new TreEntryImpl("TGTLON", "+149.12447 ", "float"));
    ImageSegment imageSegment = ImageSegmentFactory.getDefault(FileType.NITF_TWO_ONE);
    imageSegment.addImageBand(TreUtilityTest.createImageBand());
    imageSegment.getTREsRawStructure().add(piatgb);
    new NitfCreationFlowImpl().fileHeader(() -> header).imageSegment(() -> imageSegment).write(file.getAbsolutePath());
}
Also used : TreUtilityTest.createImageSegment(org.codice.alliance.transformer.nitf.TreUtilityTest.createImageSegment) ImageSegment(org.codice.imaging.nitf.core.image.ImageSegment) NitfCreationFlowImpl(org.codice.imaging.nitf.fluent.impl.NitfCreationFlowImpl) NitfHeader(org.codice.imaging.nitf.core.header.NitfHeader) Tre(org.codice.imaging.nitf.core.tre.Tre) TreEntryImpl(org.codice.imaging.nitf.core.tre.impl.TreEntryImpl)

Example 14 with ImageSegment

use of org.codice.imaging.nitf.core.image.ImageSegment 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 15 with ImageSegment

use of org.codice.imaging.nitf.core.image.ImageSegment 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

ImageSegment (org.codice.imaging.nitf.core.image.ImageSegment)15 NitfHeader (org.codice.imaging.nitf.core.header.NitfHeader)7 TreUtilityTest.createImageSegment (org.codice.alliance.transformer.nitf.TreUtilityTest.createImageSegment)6 Tre (org.codice.imaging.nitf.core.tre.Tre)6 TreEntryImpl (org.codice.imaging.nitf.core.tre.impl.TreEntryImpl)6 NitfCreationFlowImpl (org.codice.imaging.nitf.fluent.impl.NitfCreationFlowImpl)6 TargetIdImpl (org.codice.imaging.nitf.core.image.impl.TargetIdImpl)4 FileSecurityMetadata (org.codice.imaging.nitf.core.security.FileSecurityMetadata)4 SecurityMetadata (org.codice.imaging.nitf.core.security.SecurityMetadata)4 NitfParserInputFlowImpl (org.codice.imaging.nitf.fluent.impl.NitfParserInputFlowImpl)4 BufferedImage (java.awt.image.BufferedImage)3 HashMap (java.util.HashMap)3 NitfAttribute (org.codice.alliance.transformer.nitf.common.NitfAttribute)3 NitfFormatException (org.codice.imaging.nitf.core.common.NitfFormatException)3 NitfSegmentsFlow (org.codice.imaging.nitf.fluent.NitfSegmentsFlow)3 Test (org.junit.Test)3 BinaryContent (ddf.catalog.data.BinaryContent)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 DataSource (org.codice.imaging.nitf.core.DataSource)2