ProcessingUtils { static float getScale(int orig_width, int orig_height, int width, int height) throws InconsistentImageScale { float orig_ratio=(float)orig_width/orig_height; float target_pix_number = (float)width*height; double target_height = Math.sqrt(target_pix_number/orig_ratio); double target_width = target_height * orig_ratio; if ((target_height < 1) || (target_width) < 1) { throw new InconsistentImageScale( String.format("Wrong image scale (%.2f,%.2f)", target_width, target_height)); } float scale = (float)(target_height/orig_height); return scale; } private  ProcessingUtils(); static RenderedImage resizeImage(RenderedImage image, int width, int height); static DrbNode getNodeFromPath(String location); static DrbCortexItemClass getClassFromNode(DrbNode node); static String getClassLabelFromNode(DrbNode node); static DrbCortexItemClass getClassFromUrl(URL url); static List<String> getSuperClass(String URI); static List<String> getSubClass(String URI); static String getItemClassUri(DrbCortexItemClass cl); static List<String> getAllClasses(); static boolean checkGMLFootprint(String footprint); static boolean checkJTSFootprint(String footprint); static List<MetadataIndex> getIndexesFrom(URL url); static final String THUMBNAIL_SUFFIX; static final String QUICKLOOK_SUFFIX; }
@Test public void getScale() throws InconsistentImageScale { float scale = ProcessingUtils.getScale(1217, 15100, 512, 512); Assert.assertEquals((int) (1217 * scale), 145); Assert.assertEquals((int) (15100 * scale), 1803); scale = ProcessingUtils.getScale(100, 1000000, 512, 512); Assert.assertEquals((int) (100 * scale), 5); Assert.assertEquals((int) (1000000 * scale), 51200); scale = ProcessingUtils.getScale(1000000, 100, 512, 512); Assert.assertEquals((int) (100 * scale), 5); Assert.assertEquals((int) (1000000 * scale), 51200); scale = ProcessingUtils.getScale(7, 1217, 64, 64); Assert.assertEquals((int) (7 * scale), 4); Assert.assertEquals((int) (1217 * scale), 843); scale = ProcessingUtils.getScale(7, 1217, 64, 64); Assert.assertEquals((int) (7 * scale), 4); Assert.assertEquals((int) (1217 * scale), 843); }
@Test(expectedExceptions = InconsistentImageScale.class) public void getScale_failure_issue_1125() throws InconsistentImageScale { ProcessingUtils.getScale(2, 10000, 64, 64); }