Java Code Examples for com.jme3.texture.Image#setFormat()
The following examples show how to use
com.jme3.texture.Image#setFormat() .
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: CombinedTexture.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * This method scales the given texture to the given size. * * @param texture * the texture to be scaled * @param width * new width of the texture * @param height * new height of the texture */ private void scale(Texture2D texture, int width, int height) { // first determine if scaling is required boolean scaleRequired = texture.getImage().getWidth() != width || texture.getImage().getHeight() != height; if (scaleRequired) { Image image = texture.getImage(); BufferedImage sourceImage = ImageToAwt.convert(image, false, true, 0); int sourceWidth = sourceImage.getWidth(); int sourceHeight = sourceImage.getHeight(); BufferedImage targetImage = new BufferedImage(width, height, sourceImage.getType()); Graphics2D g = targetImage.createGraphics(); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.drawImage(sourceImage, 0, 0, width, height, 0, 0, sourceWidth, sourceHeight, null); g.dispose(); Image output = new ImageLoader().load(targetImage, false); image.setWidth(width); image.setHeight(height); image.setData(output.getData(0)); image.setFormat(output.getFormat()); } }
Example 4
Source File: MipMapGenerator.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static void generateMipMaps(Image image){ BufferedImage original = ImageToAwt.convert(image, false, true, 0); int width = original.getWidth(); int height = original.getHeight(); int level = 0; BufferedImage current = original; AWTLoader loader = new AWTLoader(); ArrayList<ByteBuffer> output = new ArrayList<ByteBuffer>(); int totalSize = 0; Format format = null; while (height >= 1 || width >= 1){ Image converted = loader.load(current, false); format = converted.getFormat(); output.add(converted.getData(0)); totalSize += converted.getData(0).capacity(); if(height == 1 || width == 1) { break; } level++; height /= 2; width /= 2; current = scaleDown(current, width, height); } ByteBuffer combinedData = BufferUtils.createByteBuffer(totalSize); int[] mipSizes = new int[output.size()]; for (int i = 0; i < output.size(); i++){ ByteBuffer data = output.get(i); data.clear(); combinedData.put(data); mipSizes[i] = data.capacity(); } combinedData.flip(); // insert mip data into image image.setData(0, combinedData); image.setMipMapSizes(mipSizes); image.setFormat(format); }
Example 5
Source File: MipMapGenerator.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public static void generateMipMaps(Image image){ BufferedImage original = ImageToAwt.convert(image, false, true, 0); int width = original.getWidth(); int height = original.getHeight(); int level = 0; BufferedImage current = original; AWTLoader loader = new AWTLoader(); ArrayList<ByteBuffer> output = new ArrayList<ByteBuffer>(); int totalSize = 0; Format format = null; while (height >= 1 || width >= 1){ Image converted = loader.load(current, false); format = converted.getFormat(); output.add(converted.getData(0)); totalSize += converted.getData(0).capacity(); if(height == 1 || width == 1) { break; } level++; height /= 2; width /= 2; current = scaleDown(current, width, height); } ByteBuffer combinedData = BufferUtils.createByteBuffer(totalSize); int[] mipSizes = new int[output.size()]; for (int i = 0; i < output.size(); i++){ ByteBuffer data = output.get(i); data.clear(); combinedData.put(data); mipSizes[i] = data.capacity(); } combinedData.flip(); // insert mip data into image image.setData(0, combinedData); image.setMipMapSizes(mipSizes); image.setFormat(format); }