ImageStyleUtils { public static float getScale(float imageWidth, float imageHeight, ImageStyle style) { float scale = 1.0f; float scaleX = style.getWidth() / imageWidth; float scaleY = style.getHeight() / imageHeight; switch (style.getScalingMode()) { case Box: scale = Math.min(scaleX, scaleY); if (imageWidth <= style.getWidth() && imageHeight <= style.getHeight()) scale = 1.0f; break; case Cover: if (scaleX >= 1f || scaleY >= 1f) scale = Math.max(scaleX, scaleY); else if (scaleX < 0f || scaleY < 1f) scale = Math.max(scaleX, scaleY); else scale = Math.min(scaleX, scaleY); break; case Fill: scale = Math.max(scaleX, scaleY); break; case Height: scale = scaleY; break; case None: scale = 1.0f; break; case Width: scale = scaleX; break; default: throw new IllegalStateException("Image style " + style + " contains an unknown scaling mode '" + style.getScalingMode() + "'"); } return scale; } private  ImageStyleUtils(); static int getStyledWidth(ImageContent image, ImageStyle style); static int getStyledHeight(ImageContent image, ImageStyle style); static float getScale(float imageWidth, float imageHeight,
      ImageStyle style); static int getCropX(int imageWidth, int imageHeight, ImageStyle style); static int getCropY(int imageWidth, int imageHeight, ImageStyle style); static int getStyledWidth(int imageWidth, int imageHeight,
      ImageStyle style); static int getStyledHeight(int imageWidth, int imageHeight,
      ImageStyle style); static ImageStyle findStyle(String styleId, Site site); static ImageStyle[] findStyles(String regex, boolean composeableOnly,
      Site site); static File createScaledFile(Resource<?> resource, Language language,
      ImageStyle style); static File createScaledFile(Resource<?> resource, String filename,
      Language language, ImageStyle style); static File getScaledFile(Resource<?> resource, Language language,
      ImageStyle style); static File getUnscaledFile(Resource<?> resource, Language language); static File getScaledFile(Resource<?> resource, String filename,
      Language language, ImageStyle style); static File getUnscaledFile(Resource<?> resource, String filename,
      Language language); static File getDirectory(Site site); static File getDirectory(Site site, ImageStyle style); static final String DEFAULT_PREVIEW_FORMAT; }
@Test public void testGetScale() { for (ImageStyle style : styles) { switch (style.getScalingMode()) { case Box: float[] expectedBoxValues = { 0.75f, 0.75f, 0.75f, 0.75f, 1, 1, 0.75f, 1, 1 }; testGetScale(style, expectedBoxValues); break; case Fill: float[] expectedFillValues = { 0.75f, 1, 1.5f, 1, 1, 1.5f, 1.5f, 1.5f, 1.5f }; testGetScale(style, expectedFillValues); break; case Cover: float[] expectedCoverValues = { 0.75f, 1, 1.5f, 1, 1, 1.5f, 1.5f, 1.5f, 1.5f }; testGetScale(style, expectedCoverValues); break; case Width: float[] expectedWidthValues = { 0.75f, 0.75f, 0.75f, 1, 1, 1, 1.5f, 1.5f, 1.5f }; testGetScale(style, expectedWidthValues); break; case Height: float[] expectedHeightValues = { 0.75f, 1, 1.5f, 0.75f, 1, 1.5f, 0.75f, 1, 1.5f }; testGetScale(style, expectedHeightValues); break; case None: break; default: fail("Unknown scaling mode " + style.getScalingMode()); } } }