public static Image resizeToPowerOf2(Image original){ int potWidth = FastMath.nearestPowerOfTwo(original.getWidth()); int potHeight = FastMath.nearestPowerOfTwo(original.getHeight()); return scaleImage(original, potWidth, potHeight); }
@Test public void testNearestPowerOfTwo() { for (int i = -100; i < 1; i++) { assert FastMath.nearestPowerOfTwo(i) == 1; } for (int i = 1; i < 10000; i++) { int nextPowerOf2 = FastMath.nearestPowerOfTwo(i); assert i <= nextPowerOf2; assert FastMath.isPowerOfTwo(nextPowerOf2); assert nextPowerOf2 == nearestPowerOfTwoSlow(i); } }
public static void resizeToPowerOf2(Image image){ BufferedImage original = ImageToAwt.convert(image, false, true, 0); int potWidth = FastMath.nearestPowerOfTwo(image.getWidth()); int potHeight = FastMath.nearestPowerOfTwo(image.getHeight()); int potSize = Math.max(potWidth, potHeight); BufferedImage scaled = scaleDown(original, potSize, potSize); AWTLoader loader = new AWTLoader(); Image output = loader.load(scaled, false); image.setWidth(potSize); image.setHeight(potSize); image.setDepth(0); image.setData(output.getData(0)); image.setFormat(output.getFormat()); image.setMipMapSizes(null); }
@Override public void setTexture(int unit, Texture tex) { Image image = tex.getImage(); if (image.isUpdateNeeded() || (image.isGeneratedMipmapsRequired() && !image.isMipmapsGenerated())) { // Check NPOT requirements boolean scaleToPot = false; try { checkNonPowerOfTwo(tex); } catch (RendererException ex) { if (logger.isLoggable(Level.WARNING)) { int nextWidth = FastMath.nearestPowerOfTwo(tex.getImage().getWidth()); int nextHeight = FastMath.nearestPowerOfTwo(tex.getImage().getHeight()); logger.log(Level.WARNING, "Non-power-of-2 textures are not supported! Scaling texture '" + tex.getName() + "' of size " + tex.getImage().getWidth() + "x" + tex.getImage().getHeight() + " to " + nextWidth + "x" + nextHeight); } scaleToPot = true; } updateTexImageData(image, tex.getType(), unit, scaleToPot); } int texId = image.getId(); assert texId != -1; setupTextureParams(unit, tex); }
public static Image resizeToPowerOf2(Image original){ int potWidth = FastMath.nearestPowerOfTwo(original.getWidth()); int potHeight = FastMath.nearestPowerOfTwo(original.getHeight()); return scaleImage(original, potWidth, potHeight); }
public static void resizeToPowerOf2(Image image){ BufferedImage original = ImageToAwt.convert(image, false, true, 0); int potWidth = FastMath.nearestPowerOfTwo(image.getWidth()); int potHeight = FastMath.nearestPowerOfTwo(image.getHeight()); int potSize = Math.max(potWidth, potHeight); BufferedImage scaled = scaleDown(original, potSize, potSize); AWTLoader loader = new AWTLoader(); Image output = loader.load(scaled, false); image.setWidth(potSize); image.setHeight(potSize); image.setDepth(0); image.setData(output.getData(0)); image.setFormat(output.getFormat()); image.setMipMapSizes(null); }
public static void resizeToPowerOf2(Image image){ BufferedImage original = ImageToAwt.convert(image, false, true, 0); int potWidth = FastMath.nearestPowerOfTwo(image.getWidth()); int potHeight = FastMath.nearestPowerOfTwo(image.getHeight()); int potSize = Math.max(potWidth, potHeight); BufferedImage scaled = scaleDown(original, potSize, potSize); AWTLoader loader = new AWTLoader(); Image output = loader.load(scaled, false); image.setWidth(potSize); image.setHeight(potSize); image.setDepth(0); image.setData(output.getData(0)); image.setFormat(output.getFormat()); image.setMipMapSizes(null); }
@Override public void setTexture(int unit, Texture tex) { Image image = tex.getImage(); if (image.isUpdateNeeded() || (image.isGeneratedMipmapsRequired() && !image.isMipmapsGenerated())) { // Check NPOT requirements boolean scaleToPot = false; try { checkNonPowerOfTwo(tex); } catch (RendererException ex) { if (logger.isLoggable(Level.WARNING)) { int nextWidth = FastMath.nearestPowerOfTwo(tex.getImage().getWidth()); int nextHeight = FastMath.nearestPowerOfTwo(tex.getImage().getHeight()); logger.log(Level.WARNING, "Non-power-of-2 textures are not supported! Scaling texture '" + tex.getName() + "' of size " + tex.getImage().getWidth() + "x" + tex.getImage().getHeight() + " to " + nextWidth + "x" + nextHeight); } scaleToPot = true; } updateTexImageData(image, tex.getType(), unit, scaleToPot); } int texId = image.getId(); assert texId != -1; setupTextureParams(unit, tex); }