List of usage examples for com.badlogic.gdx.graphics Pixmap getFormat
public Format getFormat()
From source file:at.tugraz.ist.catroid.content.Costume.java
License:Open Source License
protected Pixmap adjustBrightness(Pixmap currentPixmap) { Pixmap newPixmap = new Pixmap(currentPixmap.getWidth(), currentPixmap.getHeight(), currentPixmap.getFormat()); for (int y = 0; y < currentPixmap.getHeight(); y++) { for (int x = 0; x < currentPixmap.getWidth(); x++) { int pixel = currentPixmap.getPixel(x, y); int r = (int) (((pixel >> 24) & 0xff) + (255 * (brightnessValue - 1))); int g = (int) (((pixel >> 16) & 0xff) + (255 * (brightnessValue - 1))); int b = (int) (((pixel >> 8) & 0xff) + (255 * (brightnessValue - 1))); int a = pixel & 0xff; if (r > 255) { r = 255;//from w w w . ja va2s. c o m } else if (r < 0) { r = 0; } if (g > 255) { g = 255; } else if (g < 0) { g = 0; } if (b > 255) { b = 255; } else if (b < 0) { b = 0; } newPixmap.setColor(r / 255f, g / 255f, b / 255f, a / 255f); newPixmap.drawPixel(x, y); } } currentPixmap.dispose(); return newPixmap; }
From source file:CB_UI_Base.graphics.Images.BitmapDrawable.java
License:Open Source License
private void createData() { Pixmap pix; try {// w w w.j a va 2 s .c om pix = new Pixmap(buffer, 0, buffer.length); } catch (Exception e) { // Can't create e.printStackTrace(); return; } // scale? if (this.scaleFactor != 1) { int w = (int) (pix.getWidth() * this.scaleFactor); int h = (int) (pix.getHeight() * this.scaleFactor); Pixmap tmpPixmap = new Pixmap(w, h, pix.getFormat()); Pixmap.setFilter(Pixmap.Filter.NearestNeighbour); tmpPixmap.drawPixmap(pix, 0, 0, pix.getWidth(), pix.getHeight(), 0, 0, w, h); pix.dispose(); pix = tmpPixmap; } try { Packer.pack(AtlasHashString, pix); } catch (Exception e) { e.printStackTrace(); } if (Atlas == null) { Atlas = Packer.generateTextureAtlas(TextureFilter.Linear, TextureFilter.Linear, false); } else { Packer.updateTextureAtlas(Atlas, TextureFilter.Linear, TextureFilter.Linear, false); } pix.dispose(); buffer = null; }
From source file:com.agateau.pixelwheels.tools.MapScreenshotGenerator.java
License:Apache License
private static Pixmap scaleScreenshot(Pixmap src) { int srcW = src.getWidth(); int srcH = src.getHeight(); float ratio = (float) SHOT_SIZE / Math.min(srcW, srcH); int dstW = (int) (srcW * ratio); int dstH = (int) (srcH * ratio); Pixmap dst = new Pixmap(SHOT_SIZE, SHOT_SIZE, src.getFormat()); dst.setFilter(Pixmap.Filter.BiLinear); dst.drawPixmap(src, 0, 0, srcW, srcH, (SHOT_SIZE - dstW) / 2, (SHOT_SIZE - dstH) / 2, dstW, dstH); return dst;//w ww . j a v a2 s .c om }
From source file:com.austinerb.project0.engine.SpriterLoader.java
License:Apache License
@Override /**/*from w ww . j ava2 s . co m*/ * This method is now responsible for creating the pixmaps and textures. */ public void finishLoading() { final Reference[] refs = super.getRefs(); for (int i = 0; i < refs.length; i++) { final Pixmap image; Pixmap pix = this.pixmaps.get(refs[i]); if (!Gdx.graphics.isGL20Available()) { Pixmap temp = pix; image = new Pixmap(MathUtils.nextPowerOfTwo(temp.getWidth()), MathUtils.nextPowerOfTwo(temp.getHeight()), temp.getFormat()); image.drawPixmap(temp, 0, 0); this.pixmapsToDispose.put(temp, true); } else image = pix; final int index = i; this.pixmapsToDispose.put(image, false); this.createSprite(refs[index], image); if (this.packer != null) packer.pack(refs[i].fileName, image); } if (this.pack) generatePackedSprites(); this.disposePixmaps(); }
From source file:com.badlogic.gdx.tests.g3d.HeightField.java
public void set(final Pixmap map) { if (map.getWidth() != width || map.getHeight() != height) throw new GdxRuntimeException("Incorrect map size"); set(map.getPixels(), map.getFormat()); }
From source file:com.digitale.screens.MissionScreen.java
License:Open Source License
public Texture generateDynamicTexture(String iconFilename, String category, int quality) { Pixmap baseImage; if (category.equals("blueprint")) { FileHandle baseFile = Gdx.files.internal("data/blueprint.png"); baseImage = new Pixmap(baseFile); } else {// ww w . java 2s. c o m baseImage = new Pixmap(64, 64, Format.RGBA8888); } FileHandle iconFile = Gdx.files.internal(iconFilename); FileHandle iconGlowFile = Gdx.files.internal(iconFilename); if (Stardust3d.DEEPDEBUG) System.out.println("base format" + baseImage.getFormat()); Pixmap imgA = new Pixmap(iconGlowFile); if (Stardust3d.DEEPDEBUG) System.out.println("a format" + imgA.getFormat()); Pixmap imgB = new Pixmap(iconFile); if (Stardust3d.DEEPDEBUG) System.out.println("b " + iconFilename + " format" + imgB.getFormat()); // overdraw rectangle to tint icon where needed // if(tintcolour !null){imgB.SetColor(tintcolour); imgB.fillRectangle(0, 0, 64, 64); // set colour for quality marker switch (quality) { case 0: imgB.setColor(.5f, .5f, .5f, 1f); break; case 1: imgB.setColor(.75f, .75f, .75f, 1f); break; case 2: imgB.setColor(1f, 1f, 1f, 1f); break; case 3: imgB.setColor(0f, .5f, 0f, 1f); break; case 4: imgB.setColor(0f, 1f, 0f, 1f); break; case 5: imgB.setColor(0f, 0f, 1f, 1f); break; case 6: imgB.setColor(0f, 0f, .5f, 1f); break; case 7: imgB.setColor(.5f, 0f, 1f, 1f); break; case 8: imgB.setColor(1f, .5f, 0f, 1f); break; case 9: imgB.setColor(1f, 0.5f, 0f, 1f); break; } // draw quality indicator imgB.fillRectangle(0, 54, 10, 10); baseImage.setColor(0f, 1f, 0f, .2f); // baseImage.drawPixmap(imgA, 0, 0, 64, 64, 0, 0, 64, 64); // superimpose item's icon baseImage.drawPixmap(imgB, 0, 0, 64, 64, 0, 0, 64, 64); Texture dynamicTexture = new Texture(baseImage); baseImage.dispose(); imgA.dispose(); imgB.dispose(); return dynamicTexture; }
From source file:com.mbrlabs.mundus.history.commands.TerrainPaintCommand.java
License:Apache License
public void setAfter(Pixmap data) { after = new Pixmap(data.getWidth(), data.getHeight(), data.getFormat()); after.drawPixmap(data, 0, 0); }
From source file:com.mbrlabs.mundus.history.commands.TerrainPaintCommand.java
License:Apache License
public void setBefore(Pixmap data) { before = new Pixmap(data.getWidth(), data.getHeight(), data.getFormat()); before.drawPixmap(data, 0, 0); }
From source file:com.mbrlabs.mundus.ui.modules.inspector.terrain.TerrainGenTab.java
License:Apache License
private void loadHeightMap(FileHandle heightMap) { Terrain terrain = parent.component.getTerrain().getTerrain(); TerrainHeightCommand command = new TerrainHeightCommand(terrain); command.setHeightDataBefore(terrain.heightData); Pixmap originalMap = new Pixmap(heightMap); // scale pixmap if it doesn't fit the terrain if (originalMap.getWidth() != terrain.vertexResolution || originalMap.getHeight() != terrain.vertexResolution) { Pixmap scaledPixmap = new Pixmap(terrain.vertexResolution, terrain.vertexResolution, originalMap.getFormat()); scaledPixmap.drawPixmap(originalMap, 0, 0, originalMap.getWidth(), originalMap.getHeight(), 0, 0, scaledPixmap.getWidth(), scaledPixmap.getHeight()); originalMap.dispose();/*from www . j a v a 2 s . c o m*/ Terraformer.heightMap(terrain).maxHeight(terrain.terrainWidth * 0.17f).map(scaledPixmap).terraform(); scaledPixmap.dispose(); } else { Terraformer.heightMap(terrain).maxHeight(terrain.terrainWidth * 0.17f).map(originalMap).terraform(); originalMap.dispose(); } command.setHeightDataAfter(terrain.heightData); history.add(command); }
From source file:com.mygdx.java.utils.ImageUtils.java
License:Apache License
public static void setScreenTextureRegion(TextureRegion textureRegion, byte[] bytes) { if (textureRegion == null) { throw new IllegalArgumentException("Input the TextureRegion is null."); }//w w w . j av a2 s .c om Texture tempTexture = textureRegion.getTexture(); if (tempTexture != null) { tempTexture.dispose(); tempTexture = null; } Pixmap pixmap = new Pixmap(bytes, 0, bytes.length); int width = pixmap.getWidth(); int height = pixmap.getHeight(); Texture texture = new Texture(width, height, pixmap.getFormat()); texture.draw(pixmap, 0, 0); textureRegion.setTexture(texture); textureRegion.setRegion(0, 0, width, height); pixmap.dispose(); }