CatalogOutputAdapter { @SuppressWarnings("unused") public BinaryContent getNitfBinaryContent( BufferedImage chip, NitfSegmentsFlow nitfSegmentsFlow, int sourceX, int sourceY) throws IOException, MimeTypeParseException, NitfFormatException { try { lock.acquire(); try { NitfHeader chipHeader = createChipHeader(nitfSegmentsFlow); nitfSegmentsFlow.fileHeader(nitfHeader -> copySDEs(nitfHeader, chipHeader)); ImageSegment chipImageSegment = createChipImageSegment(chip, sourceX, sourceY, nitfSegmentsFlow); addIchipbTre(chip, sourceX, sourceY, chipImageSegment); List<ImageSegment> imageSegments = getImageSegments(nitfSegmentsFlow); if (!imageSegments.isEmpty()) { copySDEs(imageSegments.get(0), chipImageSegment); } return nitfToBinaryContent(chipHeader, chipImageSegment); } finally { lock.release(); nitfSegmentsFlow.end(); } } catch (InterruptedException e) { LOGGER.debug("Interrupt received while doing image processing.", e); Thread.currentThread().interrupt(); } return null; } CatalogOutputAdapter(Semaphore lock); @SuppressWarnings("WeakerAccess") BufferedImage getImage(ResourceResponse resourceResponse); @SuppressWarnings("WeakerAccess") BinaryContent getBinaryContent(BufferedImage image); @SuppressWarnings("unused") NitfSegmentsFlow getNitfSegmentsFlow(ResourceResponse resourceResponse); @SuppressWarnings("unused") BinaryContent getNitfBinaryContent(
      BufferedImage chip, NitfSegmentsFlow nitfSegmentsFlow, int sourceX, int sourceY); @SuppressWarnings("unused") void wrapException(Exception exception);  }
@Test public void testGrayscale() throws MimeTypeParseException, NitfFormatException, IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { int originalWidth = 200; int originalHeight = 100; int chipWidth = 160; int chipHeight = 80; NitfSegmentsFlow nitfSegmentsFlow = createGenericNitfSegmentFlow(originalWidth, originalHeight); BufferedImage chipImage = new BufferedImage(chipWidth, chipHeight, BufferedImage.TYPE_BYTE_GRAY); BinaryContent binaryContent = catalogOutputAdapter.getNitfBinaryContent(chipImage, nitfSegmentsFlow, 0, 0); NitfSegmentsFlow chipNitfSegmentFlow = new NitfParserInputFlowImpl().inputStream(binaryContent.getInputStream()).allData(); chipNitfSegmentFlow.forEachImageSegment( imageSegment1 -> { assertThat(imageSegment1.getPixelValueType(), is(PixelValueType.INTEGER)); assertThat(imageSegment1.getImageRepresentation(), is(ImageRepresentation.MONOCHROME)); assertThat(imageSegment1.getActualBitsPerPixelPerBand(), is(8)); assertThat(imageSegment1.getNumberOfBitsPerPixelPerBand(), is(8)); assertThat(imageSegment1.getImageBand(1).getImageRepresentation(), is("M")); }); }
@Test public void testByteIndexed() throws MimeTypeParseException, NitfFormatException, IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { int originalWidth = 200; int originalHeight = 100; int chipWidth = 160; int chipHeight = 80; NitfSegmentsFlow nitfSegmentsFlow = createGenericNitfSegmentFlow(originalWidth, originalHeight); BufferedImage chipImage = new BufferedImage(chipWidth, chipHeight, BufferedImage.TYPE_BYTE_INDEXED); BinaryContent binaryContent = catalogOutputAdapter.getNitfBinaryContent(chipImage, nitfSegmentsFlow, 0, 0); NitfSegmentsFlow chipNitfSegmentFlow = new NitfParserInputFlowImpl().inputStream(binaryContent.getInputStream()).allData(); chipNitfSegmentFlow.forEachImageSegment( imageSegment1 -> { assertThat(imageSegment1.getPixelValueType(), is(PixelValueType.INTEGER)); assertThat(imageSegment1.getImageRepresentation(), is(ImageRepresentation.RGBLUT)); assertThat(imageSegment1.getActualBitsPerPixelPerBand(), is(8)); assertThat(imageSegment1.getNumberOfBitsPerPixelPerBand(), is(8)); assertThat(imageSegment1.getImageBand(1).getImageRepresentation(), is("LU")); }); }
@Test public void testIntARGB() throws MimeTypeParseException, NitfFormatException, IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { int originalWidth = 200; int originalHeight = 100; int chipWidth = 160; int chipHeight = 80; NitfSegmentsFlow nitfSegmentsFlow = createGenericNitfSegmentFlow(originalWidth, originalHeight); BufferedImage chipImage = new BufferedImage(chipWidth, chipHeight, BufferedImage.TYPE_INT_ARGB); BinaryContent binaryContent = catalogOutputAdapter.getNitfBinaryContent(chipImage, nitfSegmentsFlow, 0, 0); NitfSegmentsFlow chipNitfSegmentFlow = new NitfParserInputFlowImpl().inputStream(binaryContent.getInputStream()).allData(); chipNitfSegmentFlow.forEachImageSegment( imageSegment1 -> { assertThat(imageSegment1.getPixelValueType(), is(PixelValueType.INTEGER)); assertThat(imageSegment1.getImageRepresentation(), is(ImageRepresentation.RGBTRUECOLOUR)); assertThat(imageSegment1.getActualBitsPerPixelPerBand(), is(8)); assertThat(imageSegment1.getNumberOfBitsPerPixelPerBand(), is(8)); assertThat(imageSegment1.getImageBand(1).getImageRepresentation(), is("R")); assertThat(imageSegment1.getImageBand(2).getImageRepresentation(), is("G")); assertThat(imageSegment1.getImageBand(3).getImageRepresentation(), is("B")); }); }
@Test public void testGetNitfBinaryContent() throws MimeTypeParseException, NitfFormatException, IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, InterruptedException { int originalWidth = 200; int originalHeight = 100; int chipX = 20; int chipY = 10; int chipWidth = 160; int chipHeight = 80; BufferedImage chipImage = new BufferedImage(chipWidth, chipHeight, BufferedImage.TYPE_3BYTE_BGR); FileSecurityMetadata fileSecurityMetadata = createFileSecurityMetadata(); DateTime dateTime = DateTimeImpl.getNitfDateTimeForNow(); NitfHeader nitfHeader = getNitfHeader(fileSecurityMetadata, dateTime); ImageCoordinates imageCoordinates = getImageCoordinates(); SecurityMetadata imageSecurityMetadata = getImageSecurityMetadata(); ImageSegment imageSegment = getImageSegment( originalWidth, originalHeight, dateTime, imageCoordinates, imageSecurityMetadata); DataSource dataSource = getDataSource(nitfHeader, Collections.singletonList(imageSegment)); Constructor<NitfSegmentsFlowImpl> constructor; constructor = NitfSegmentsFlowImpl.class.getDeclaredConstructor(DataSource.class, Runnable.class); constructor.setAccessible(true); NitfSegmentsFlow nitfSegmentsFlow = constructor.newInstance(dataSource, (Runnable) () -> {}); BinaryContent binaryContent = catalogOutputAdapter.getNitfBinaryContent(chipImage, nitfSegmentsFlow, chipX, chipY); NitfSegmentsFlow chipNitfSegmentFlow = new NitfParserInputFlowImpl().inputStream(binaryContent.getInputStream()).allData(); assertThat(chipNitfSegmentFlow, notNullValue()); chipNitfSegmentFlow.fileHeader( nh -> { assertThat(nh.getFileType(), is(FileType.NITF_TWO_ONE)); assertThat(nh.getFileTitle(), is("FileTitle")); assertThat(nh.getStandardType(), is("BF01")); assertThat(nh.getOriginatingStationId(), is("U21SOO90")); assertThat(nh.getFileBackgroundColour().getRed(), is((byte) 0)); assertThat(nh.getFileBackgroundColour().getGreen(), is((byte) 0)); assertThat(nh.getFileBackgroundColour().getBlue(), is((byte) 0)); assertThat(nh.getFileDateTime(), notNullValue()); assertThat(nh.getOriginatorsName(), is("W.TEMPEL")); assertThat(nh.getOriginatorsPhoneNumber(), is("44 1480 84 5611")); assertThat( nh.getFileSecurityMetadata().getSecurityClassification(), is(SecurityClassification.UNCLASSIFIED)); assertThat(nh.getFileSecurityMetadata().getSecurityClassificationSystem(), is("AB")); assertThat(nh.getFileSecurityMetadata().getCodewords(), is("ABCDEFGHIJK")); assertThat(nh.getFileSecurityMetadata().getControlAndHandling(), is("AB")); assertThat( nh.getFileSecurityMetadata().getReleaseInstructions(), is("01234567890123456789")); assertThat(nh.getFileSecurityMetadata().getDeclassificationType(), is("DD")); assertThat(nh.getFileSecurityMetadata().getDeclassificationDate(), is("20160101")); assertThat(nh.getFileSecurityMetadata().getDeclassificationExemption(), is("abcd")); assertThat(nh.getFileSecurityMetadata().getDowngrade(), is("S")); assertThat(nh.getFileSecurityMetadata().getDowngradeDate(), is("20160202")); assertThat(nh.getFileSecurityMetadata().getClassificationText(), is("classtext")); assertThat(nh.getFileSecurityMetadata().getClassificationAuthorityType(), is("O")); assertThat(nh.getFileSecurityMetadata().getClassificationAuthority(), is("MyAuthority")); assertThat(nh.getFileSecurityMetadata().getClassificationReason(), is("A")); assertThat(nh.getFileSecurityMetadata().getSecuritySourceDate(), is("20160303")); assertThat( nh.getFileSecurityMetadata().getSecurityControlNumber(), is("012345678901234")); assertThat(nh.getFileSecurityMetadata().getFileCopyNumber(), is("99999")); assertThat(nh.getFileSecurityMetadata().getFileNumberOfCopies(), is("99999")); }); chipNitfSegmentFlow.forEachImageSegment( imageSegment1 -> { assertThat( imageSegment1.getImageCoordinates().getCoordinate00().getLongitude(), closeTo(22, 0.01)); assertThat( imageSegment1.getImageCoordinates().getCoordinate00().getLatitude(), closeTo(18, 0.01)); assertThat( imageSegment1.getImageCoordinates().getCoordinate0MaxCol().getLongitude(), closeTo(38, 0.01)); assertThat( imageSegment1.getImageCoordinates().getCoordinate0MaxCol().getLatitude(), closeTo(18, 0.01)); assertThat( imageSegment1.getImageCoordinates().getCoordinateMaxRowMaxCol().getLongitude(), closeTo(38, 0.01)); assertThat( imageSegment1.getImageCoordinates().getCoordinateMaxRowMaxCol().getLatitude(), closeTo(2, 0.01)); assertThat( imageSegment1.getImageCoordinates().getCoordinateMaxRow0().getLongitude(), closeTo(22, 0.01)); assertThat( imageSegment1.getImageCoordinates().getCoordinateMaxRow0().getLatitude(), closeTo(2, 0.01)); assertThat(imageSegment1.getNumberOfColumns(), is((long) chipWidth)); assertThat(imageSegment1.getNumberOfRows(), is((long) chipHeight)); assertThat(imageSegment1.getImageCategory(), is(ImageCategory.UNKNOWN)); assertThat(imageSegment1.getImageComments(), is(Collections.singletonList("MyComment"))); assertThat(imageSegment1.getIdentifier(), is("0123456789")); assertThat(imageSegment1.getImageIdentifier2(), is("abc")); assertThat(imageSegment1.getImageMagnification(), is("1.0 ")); try { assertThat( imageSegment1.getImageTargetId().textValue(), is(new TargetIdImpl(" ").textValue())); } catch (NitfFormatException e) { fail(e.getMessage()); } assertThat(imageSegment1.getImageSource(), is("")); assertThat( imageSegment1.getImageDateTime().getSourceString(), is(dateTime.getSourceString())); assertThat(imageSegment1.getImageRepresentation(), is(ImageRepresentation.RGBTRUECOLOUR)); }); verify(lock).acquire(); verify(lock).release(); }