Java Code Examples for com.jme3.math.FastMath#nearestPowerOfTwo()
The following examples show how to use
com.jme3.math.FastMath#nearestPowerOfTwo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MipMapGenerator.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
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); }
Example 2
Source File: MipMapGenerator.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
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); }
Example 3
Source File: TextureUtil.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * <code>uploadTextureBitmap</code> uploads a native android bitmap * @param target * @param bitmap * @param generateMips * @param powerOf2 */ private static void uploadTextureBitmap2(final int target, Bitmap bitmap, boolean generateMips, boolean powerOf2) { if (bitmap.isRecycled()) { throw new RuntimeException("bitmap is recycled."); } if (!powerOf2) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); if (!FastMath.isPowerOfTwo(width) || !FastMath.isPowerOfTwo(height) /*|| width >= 512 || height >= 512*/) { // scale to power of two width = FastMath.nearestPowerOfTwo(width); height = FastMath.nearestPowerOfTwo(height); // while(width >= 512) { // width = width / 2; // } // while(height >= 512) { // height = height / 2; // } Logger.getLogger(TextureUtil.class.getName()).warning("texture size changed."); Bitmap bitmap2 = Bitmap.createScaledBitmap(bitmap, width, height, true); bitmap.recycle(); bitmap = bitmap2; } } if (generateMips) { buildMipmap(bitmap); } else { GLUtils.texImage2D(target, 0, bitmap, 0); //checkGLError(); //bitmap.recycle(); } }
Example 4
Source File: MipMapGenerator.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static Image resizeToPowerOf2(Image original){ int potWidth = FastMath.nearestPowerOfTwo(original.getWidth()); int potHeight = FastMath.nearestPowerOfTwo(original.getHeight()); return scaleImage(original, potWidth, potHeight); }