CatalogOutputAdapter { @SuppressWarnings("UnnecessaryLocalVariable") Tre createIchipb( BufferedImage chip, int sourceX, int sourceY, float selectWidth, float selectHeight) { Tre ichipb = TreFactory.getDefault("ICHIPB", TreSource.ImageExtendedSubheaderData); ichipb.add(new TreEntryImpl("XFRM_FLAG", "00", UINT)); ichipb.add(new TreEntryImpl("SCALE_FACTOR", "0001.00000", REAL)); ichipb.add(new TreEntryImpl("ANAMRPH_CORR", "00", UINT)); ichipb.add(new TreEntryImpl("SCANBLK_NUM", "01", UINT)); float halfPixel = 0.5f; float chipX0 = halfPixel; float chipY0 = halfPixel; float chipX1 = (float) chip.getWidth() - halfPixel; float chipY1 = (float) chip.getHeight() - halfPixel; ichipb.add(new TreEntryImpl("OP_ROW_11", formatCoord(chipY0), REAL)); ichipb.add(new TreEntryImpl("OP_COL_11", formatCoord(chipX0), REAL)); ichipb.add(new TreEntryImpl("OP_ROW_12", formatCoord(chipY0), REAL)); ichipb.add(new TreEntryImpl("OP_COL_12", formatCoord(chipX1), REAL)); ichipb.add(new TreEntryImpl("OP_ROW_21", formatCoord(chipY1), REAL)); ichipb.add(new TreEntryImpl("OP_COL_21", formatCoord(chipX0), REAL)); ichipb.add(new TreEntryImpl("OP_ROW_22", formatCoord(chipY1), REAL)); ichipb.add(new TreEntryImpl("OP_COL_22", formatCoord(chipX1), REAL)); float origX0 = sourceX + halfPixel; float origY0 = sourceY + halfPixel; float origX1 = sourceX + selectWidth - halfPixel; float origY1 = sourceY + selectHeight - halfPixel; ichipb.add(new TreEntryImpl("FI_ROW_11", formatCoord(origY0), REAL)); ichipb.add(new TreEntryImpl("FI_COL_11", formatCoord(origX0), REAL)); ichipb.add(new TreEntryImpl("FI_ROW_12", formatCoord(origY0), REAL)); ichipb.add(new TreEntryImpl("FI_COL_12", formatCoord(origX1), REAL)); ichipb.add(new TreEntryImpl("FI_ROW_21", formatCoord(origY1), REAL)); ichipb.add(new TreEntryImpl("FI_COL_21", formatCoord(origX0), REAL)); ichipb.add(new TreEntryImpl("FI_ROW_22", formatCoord(origY1), REAL)); ichipb.add(new TreEntryImpl("FI_COL_22", formatCoord(origX1), REAL)); ichipb.add(new TreEntryImpl("FI_ROW", "00000000", UINT)); ichipb.add(new TreEntryImpl("FI_COL", "00000000", UINT)); return ichipb; } 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 testCreateIchipb() throws NitfFormatException { BufferedImage bufferedImage = mock(BufferedImage.class); int originalWidth = 200; int originalHeight = 100; when(bufferedImage.getWidth()).thenReturn(originalWidth); when(bufferedImage.getHeight()).thenReturn(originalHeight); int chipX = 20; int chipY = 10; Tre tre = catalogOutputAdapter.createIchipb(bufferedImage, chipX, chipY, 160, 80); assertTreEntry(tre, "XFRM_FLAG", TWO_DIGIT_REGEX, UINT); assertTreEntry(tre, "SCALE_FACTOR", Pattern.compile("^[0-9]{4}\\.[0-9]{5}$"), REAL); assertTreEntry(tre, "ANAMRPH_CORR", TWO_DIGIT_REGEX, UINT); assertTreEntry(tre, "SCANBLK_NUM", TWO_DIGIT_REGEX, UINT); assertTreEntry(tre, "OP_ROW_11", COORD_REGEX, REAL); assertTreEntry(tre, "OP_COL_11", COORD_REGEX, REAL); assertTreEntry(tre, "OP_ROW_12", COORD_REGEX, REAL); assertTreEntry(tre, "OP_COL_12", COORD_REGEX, REAL); assertTreEntry(tre, "OP_ROW_21", COORD_REGEX, REAL); assertTreEntry(tre, "OP_COL_21", COORD_REGEX, REAL); assertTreEntry(tre, "OP_ROW_22", COORD_REGEX, REAL); assertTreEntry(tre, "OP_COL_22", COORD_REGEX, REAL); assertTreEntry(tre, "FI_ROW_11", COORD_REGEX, REAL); assertTreEntry(tre, "FI_COL_11", COORD_REGEX, REAL); assertTreEntry(tre, "FI_ROW_12", COORD_REGEX, REAL); assertTreEntry(tre, "FI_COL_12", COORD_REGEX, REAL); assertTreEntry(tre, "FI_ROW_21", COORD_REGEX, REAL); assertTreEntry(tre, "FI_COL_21", COORD_REGEX, REAL); assertTreEntry(tre, "FI_ROW_22", COORD_REGEX, REAL); assertTreEntry(tre, "FI_COL_22", COORD_REGEX, REAL); assertTreEntry(tre, "FI_ROW", EIGHT_DIGIT_REGEX, UINT); assertTreEntry(tre, "FI_COL", EIGHT_DIGIT_REGEX, UINT); assertThat(tre.getDoubleValue("OP_ROW_11"), closeTo(0.5, 0.01)); assertThat(tre.getDoubleValue("OP_COL_11"), closeTo(0.5, 0.01)); assertThat(tre.getDoubleValue("OP_ROW_12"), closeTo(0.5, 0.01)); assertThat(tre.getDoubleValue("OP_COL_12"), closeTo(originalWidth - 0.5, 0.01)); assertThat(tre.getDoubleValue("OP_ROW_21"), closeTo(originalHeight - 0.5, 0.01)); assertThat(tre.getDoubleValue("OP_COL_21"), closeTo(0.5, 0.01)); assertThat(tre.getDoubleValue("OP_ROW_22"), closeTo(originalHeight - 0.5, 0.01)); assertThat(tre.getDoubleValue("OP_COL_22"), closeTo(originalWidth - 0.5, 0.01)); assertThat(tre.getDoubleValue("FI_ROW_11"), closeTo(chipY + 0.5, 0.01)); assertThat(tre.getDoubleValue("FI_COL_11"), closeTo(chipX + 0.5, 0.01)); assertThat(tre.getDoubleValue("FI_ROW_12"), closeTo(chipY + 0.5, 0.01)); assertThat(tre.getDoubleValue("FI_COL_12"), closeTo(originalWidth - chipX - 0.5, 0.01)); assertThat(tre.getDoubleValue("FI_ROW_21"), closeTo(originalHeight - chipY - 0.5, 0.01)); assertThat(tre.getDoubleValue("FI_COL_21"), closeTo(chipX + 0.5, 0.01)); assertThat(tre.getDoubleValue("FI_ROW_22"), closeTo(originalHeight - chipY - 0.5, 0.01)); assertThat(tre.getDoubleValue("FI_COL_22"), closeTo(originalWidth - chipX - 0.5, 0.01)); }