List of usage examples for com.badlogic.gdx.graphics Pixmap Pixmap
public Pixmap(byte[] encodedData, int offset, int len)
From source file:com.o2d.pkayjava.editor.utils.poly.TextureUtils.java
License:Apache License
public static Pixmap getPOTPixmap(Texture texture) { if (texture == null) return null; texture.getTextureData().prepare();/*from www .j a v a2 s. c o m*/ Pixmap pixmap = texture.getTextureData().consumePixmap(); int origW = pixmap.getWidth(); int origH = pixmap.getHeight(); int w = getNearestPOT(origW); int h = getNearestPOT(origH); int len = Math.max(w, h); Pixmap potPixmap = new Pixmap(len, len, pixmap.getFormat()); potPixmap.drawPixmap(pixmap, 0, 0, 0, 0, origW, origH); pixmap.dispose(); return potPixmap; }
From source file:com.o2d.pkayjava.editor.utils.poly.TextureUtils.java
License:Apache License
public static TextureRegion getPOTTexture(Texture texture) { if (texture == null) return null; texture.getTextureData().prepare();// w w w . ja va 2 s . c o m Pixmap pixmap = texture.getTextureData().consumePixmap(); int origW = pixmap.getWidth(); int origH = pixmap.getHeight(); int w = getNearestPOT(origW); int h = getNearestPOT(origH); int len = Math.max(w, h); Pixmap potPixmap = new Pixmap(len, len, pixmap.getFormat()); potPixmap.drawPixmap(pixmap, 0, 0, 0, 0, origW, origH); pixmap.dispose(); Texture otherTexture = new Texture(potPixmap); otherTexture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); return new TextureRegion(otherTexture, 0, 0, origW, origH); }
From source file:com.o2d.pkayjava.editor.view.ui.widget.components.color.ColorChannelWidget.java
License:Apache License
public ColorChannelWidget(String label, int maxValue, boolean useAlpha, final ColorChannelWidgetListener drawer) { super(true);//w ww.ja v a 2s. co m this.value = 0; this.maxValue = maxValue; this.drawer = drawer; this.useAlpha = useAlpha; barListener = new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { value = bar.getValue(); drawer.updateFields(); inputField.setValue(value); } }; if (useAlpha) pixmap = new Pixmap(maxValue, 1, Pixmap.Format.RGBA8888); else pixmap = new Pixmap(maxValue, 1, Pixmap.Format.RGB888); texture = new Texture(pixmap); add(new VisLabel(label)).width(10).center(); add(inputField = new ColorInputField(maxValue, new ColorInputField.ColorInputFieldListener() { @Override public void changed(int newValue) { value = newValue; drawer.updateFields(); bar.setValue(newValue); } })).width(CustomColorPicker.FIELD_WIDTH); add(bar = createBarImage()).size(CustomColorPicker.BAR_WIDTH, CustomColorPicker.BAR_HEIGHT); inputField.setValue(0); }
From source file:com.o2d.pkayjava.editor.view.ui.widget.components.color.CustomColorPicker.java
License:Apache License
private void createColorWidgets() { palettePixmap = new Pixmap(100, 100, Pixmap.Format.RGB888); paletteTexture = new Texture(palettePixmap); barPixmap = new Pixmap(1, 360, Pixmap.Format.RGB888); for (int h = 0; h < 360; h++) { ColorUtils.HSVtoRGB(360 - h, 100, 100, tmpColor); barPixmap.drawPixel(0, h, Color.rgba8888(tmpColor)); }//from ww w . ja va 2 s . c o m barTexture = new Texture(barPixmap); palette = new Palette(VisUI.getSkin().get(ColorPickerStyle.class), VisUI.getSkin().get(com.kotcrab.vis.ui.Sizes.class), paletteTexture, 0, 0, 100, new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { //S ans V are flipped because the plate is flipped as well! sBar.setValue(palette.getV()); vBar.setValue(palette.getS()); updateHSVValuesFromFields(); updatePixmaps(); } }); verticalBar = new VerticalChannelBar(VisUI.getSkin().get(ColorPickerStyle.class), VisUI.getSkin().get(com.kotcrab.vis.ui.Sizes.class), barTexture, 0, 360, new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { hBar.setValue(verticalBar.getValue()); updateHSVValuesFromFields(); updatePixmaps(); } }); hBar = new ColorChannelWidget("H", 360, new ColorChannelWidget.ColorChannelWidgetListener() { @Override public void updateFields() { verticalBar.setValue(hBar.getValue()); updateHSVValuesFromFields(); updatePixmaps(); } @Override public void draw(Pixmap pixmap) { for (int h = 0; h < 360; h++) { ColorUtils.HSVtoRGB(h, sBar.getValue(), vBar.getValue(), tmpColor); pixmap.drawPixel(h, 0, Color.rgba8888(tmpColor)); } } }); sBar = new ColorChannelWidget("S", 100, new ColorChannelWidget.ColorChannelWidgetListener() { @Override public void updateFields() { palette.setValue(vBar.getValue(), sBar.getValue()); updateHSVValuesFromFields(); updatePixmaps(); } @Override public void draw(Pixmap pixmap) { for (int s = 0; s < 100; s++) { ColorUtils.HSVtoRGB(hBar.getValue(), s, vBar.getValue(), tmpColor); pixmap.drawPixel(s, 0, Color.rgba8888(tmpColor)); } } }); vBar = new ColorChannelWidget("V", 100, new ColorChannelWidget.ColorChannelWidgetListener() { @Override public void updateFields() { palette.setValue(vBar.getValue(), sBar.getValue()); updateHSVValuesFromFields(); updatePixmaps(); } @Override public void draw(Pixmap pixmap) { for (int v = 0; v < 100; v++) { ColorUtils.HSVtoRGB(hBar.getValue(), sBar.getValue(), v, tmpColor); pixmap.drawPixel(v, 0, Color.rgba8888(tmpColor)); } } }); rBar = new ColorChannelWidget("R", 255, new ColorChannelWidget.ColorChannelWidgetListener() { @Override public void updateFields() { updateRGBValuesFromFields(); updatePixmaps(); } @Override public void draw(Pixmap pixmap) { for (int r = 0; r < 255; r++) { tmpColor.set(r / 255.0f, color.g, color.b, 1); pixmap.drawPixel(r, 0, Color.rgba8888(tmpColor)); } } }); gBar = new ColorChannelWidget("G", 255, new ColorChannelWidget.ColorChannelWidgetListener() { @Override public void updateFields() { updateRGBValuesFromFields(); updatePixmaps(); } @Override public void draw(Pixmap pixmap) { for (int g = 0; g < 255; g++) { tmpColor.set(color.r, g / 255.0f, color.b, 1); pixmap.drawPixel(g, 0, Color.rgba8888(tmpColor)); } } }); bBar = new ColorChannelWidget("B", 255, new ColorChannelWidget.ColorChannelWidgetListener() { @Override public void updateFields() { updateRGBValuesFromFields(); updatePixmaps(); } @Override public void draw(Pixmap pixmap) { for (int b = 0; b < 255; b++) { tmpColor.set(color.r, color.g, b / 255.0f, 1); pixmap.drawPixel(b, 0, Color.rgba8888(tmpColor)); } } }); aBar = new ColorChannelWidget("A", 255, true, new ColorChannelWidget.ColorChannelWidgetListener() { @Override public void updateFields() { if (aBar.isInputValid()) color.a = aBar.getValue() / 255.0f; updatePixmaps(); } @Override public void draw(Pixmap pixmap) { pixmap.fill(); for (int i = 0; i < 255; i++) { tmpColor.set(color.r, color.g, color.b, i / 255.0f); pixmap.drawPixel(i, 0, Color.rgba8888(tmpColor)); } } }); }
From source file:com.quadbits.gdxhelper.actors.ScreenDimActor.java
License:Apache License
@Inject public ScreenDimActor() { super();//from w w w. ja v a2 s .c om // Create a 1x1 black pixmap and send it to the graphics card (create texture) Pixmap dimPixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888); dimPixmap.drawPixel(0, 0, Color.rgba8888(0, 0, 0, 1)); dimTexture = new Texture(dimPixmap); dimPixmap.dispose(); this.dimSprite = new Sprite(dimTexture); setSize(dimSprite.getWidth(), dimSprite.getHeight()); alpha = 0; }
From source file:com.quadbits.gdxhelper.actors.SkyActor.java
License:Apache License
@Override public void setSize(float width, float height) { super.setSize(width, height); Pixmap vgradientPixmap;/*from w w w . j a va2 s. c om*/ // Read any previously existing pixmap from file String vgradientPixmapFilenameSize = String.format("vgradient_%d_%d.cim", (int) width, (int) height); FileHandle dataFile = Gdx.files.local(vgradientPixmapFilenameSize); if (dataFile.exists()) { vgradientPixmap = PixmapIO.readCIM(dataFile); } else { vgradientPixmap = new Pixmap((int) width, (int) height, Pixmap.Format.RGBA8888); // Create an array of viewportWidth integers indicating the shift in alpha for a certain // horizontal pixel value float[] alphaShifts = new float[(int) width]; float maxAlphaShift = 3f / 255f; for (int i = 0; i < alphaShifts.length; i++) { alphaShifts[i] = maxAlphaShift * (2 * random.nextFloat() - 1); } // Pixmaps' (0,0) is at the top-left corner float deltaAlpha = 1f / vgradientPixmap.getHeight(); float alpha = 0; int startAlphaShiftIndex = 0; tmpColor.set(0xffffffff); // initialize to white for (int y = 0; y < vgradientPixmap.getHeight(); y++, alpha += deltaAlpha) { // select a (wrapped) starting point in the alphaShift array startAlphaShiftIndex += random.nextInt(alphaShifts.length / 2); startAlphaShiftIndex = startAlphaShiftIndex % alphaShifts.length; for (int x = 0; x < vgradientPixmap.getWidth(); x++) { int alphaShiftIndex = startAlphaShiftIndex + x; alphaShiftIndex = alphaShiftIndex % alphaShifts.length; tmpColor.a = alpha + alphaShifts[alphaShiftIndex]; tmpColor.clamp(); vgradientPixmap.drawPixel(x, y, Color.rgba8888(tmpColor)); } } // Write pixmap to file PixmapIO.writeCIM(dataFile, vgradientPixmap); } // Free any previously existing texture if (vgradient != null && vgradient.getTexture() != null) { vgradient.getTexture().dispose(); } vgradient = new Sprite(new Texture(vgradientPixmap)); vgradient.setPosition(0, 0); vgradient.setSize(width, height); // Dispose pixmap vgradientPixmap.dispose(); }
From source file:com.ray3k.skincomposer.data.AtlasData.java
License:Open Source License
public void readAtlas(FileHandle fileHandle) throws Exception { if (fileHandle.exists()) { FileHandle saveFile = main.getProjectData().getSaveFile(); FileHandle targetDirectory;//from ww w . j a v a2 s .co m if (saveFile != null) { targetDirectory = saveFile.sibling(saveFile.nameWithoutExtension() + "_data/"); } else { targetDirectory = Gdx.files.local("temp/" + main.getProjectData().getId() + "_data/"); } targetDirectory.mkdirs(); TextureAtlas atlas = new TextureAtlas(fileHandle); Array<AtlasRegion> regions = atlas.getRegions(); for (AtlasRegion region : regions) { Texture texture = region.getTexture(); if (!texture.getTextureData().isPrepared()) { texture.getTextureData().prepare(); } Pixmap.setBlending(Pixmap.Blending.None); Pixmap pixmap = texture.getTextureData().consumePixmap(); Pixmap savePixmap; String name; if (region.splits == null && region.pads == null) { name = region.name + ".png"; savePixmap = new Pixmap(region.getRegionWidth(), region.getRegionHeight(), Pixmap.Format.RGBA8888); for (int x = 0; x < region.getRegionWidth(); x++) { for (int y = 0; y < region.getRegionHeight(); y++) { int colorInt = pixmap.getPixel(region.getRegionX() + x, region.getRegionY() + y); savePixmap.drawPixel(x, y, colorInt); } } } else { name = region.name + ".9.png"; savePixmap = new Pixmap(region.getRegionWidth() + 2, region.getRegionHeight() + 2, pixmap.getFormat()); int x; int y; //draw 9 patch lines savePixmap.setColor(Color.BLACK); if (region.splits != null) { x = 0; for (y = region.splits[2] + 1; y < savePixmap.getHeight() - region.splits[3] - 1; y++) { savePixmap.drawPixel(x, y); } y = 0; for (x = region.splits[0] + 1; x < savePixmap.getWidth() - region.splits[1] - 1; x++) { savePixmap.drawPixel(x, y); } } if (region.pads != null) { x = savePixmap.getWidth() - 1; for (y = region.pads[2] + 1; y < savePixmap.getHeight() - region.pads[3] - 1; y++) { savePixmap.drawPixel(x, y); } y = savePixmap.getHeight() - 1; for (x = region.pads[0] + 1; x < savePixmap.getWidth() - region.pads[1] - 1; x++) { savePixmap.drawPixel(x, y); } } for (x = 0; x < region.getRegionWidth(); x++) { for (y = 0; y < region.getRegionHeight(); y++) { int colorInt = pixmap.getPixel(region.getRegionX() + x, region.getRegionY() + y); savePixmap.drawPixel(x + 1, y + 1, colorInt); } } } FileHandle outputFile = targetDirectory.child(name); PixmapIO.writePNG(outputFile, savePixmap); DrawableData drawable = new DrawableData(outputFile); //delete drawables with the same name for (DrawableData originalData : new Array<>(main.getProjectData().getAtlasData().getDrawables())) { if (originalData.name.equals(drawable.name)) { main.getProjectData().getAtlasData().getDrawables().removeValue(originalData, true); } } drawables.add(drawable); } } else { throw new FileNotFoundException(); } }
From source file:com.ridiculousRPG.GameBase.java
License:Apache License
/** * Takes a screenshot from the current frame buffer. The screenshot will be * stretched to fit into the Rectangle specified by dstW and dstH * //from ww w .j av a 2 s . c om * @param srcX * @param srcY * @param srcW * @param srcH * @param dstW * @param dstH * @return A Pixmap containing the screenshot. The screenshot will be * flipped at the y-axis. * @throws IOException */ public Pixmap takeScreenshot(int srcX, int srcY, int srcW, int srcH, int dstW, int dstH) throws IOException { Gdx.gl.glPixelStorei(GL10.GL_PACK_ALIGNMENT, 1); Pixmap pixmap = new Pixmap(srcW, srcH, Format.RGBA8888); Gdx.gl.glReadPixels(srcX, srcY, srcW, srcH, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, pixmap.getPixels()); // scale the picture if (srcW != dstW || srcH != dstH) { Pixmap scale = new Pixmap(dstW, dstH, Format.RGBA8888); Blending old = Pixmap.getBlending(); Pixmap.setBlending(Blending.None); scale.drawPixmap(pixmap, 0, 0, srcW, srcH, 0, 0, dstW, dstH); Pixmap.setBlending(old); pixmap.dispose(); pixmap = scale; } return pixmap; }
From source file:com.ridiculousRPG.util.TextureRegionLoader.java
License:Apache License
/** * Obtains a texture region for drawing {@link Pixmap}s on it.<br> * This method creates a texture region with an underlying texture (which is * sized with the next powers of two) for drawing. * /* www . jav a 2 s .c om*/ * @param width * the width of the texture region * @param height * the height of the texture region * @param format * the format for drawing {@link Pixmap}s onto this TextureRegion * @return A texture region with the specified width and height for drawing * on it. */ public static TextureRegionRef obtainEmptyRegion(int width, int height, final Format format) { final int safeWidth = MathUtils.nextPowerOfTwo(width); final int safeHeight = MathUtils.nextPowerOfTwo(height); final PixmapTextureData ptd = new PixmapTextureData(new Pixmap(safeWidth, safeHeight, format), null, false, true); TextureCache tCache; if (GameBase.$().isGlContextThread()) { tCache = new TextureCache(ptd); } else { final TextureCacheContainer tCC = new TextureCacheContainer(); new ExecWithGlContext() { @Override public void exec() { tCC.tCache = new TextureCache(ptd); } }.runWait(); tCache = tCC.tCache; } return tCache.obtainRegion(0, 0, width, height); }
From source file:com.ridiculousRPG.video.cortado.CortadoPlayerAppletWrapper.java
License:Open Source License
/** * Instantiates a new video player. Don't forget to dispose the player! * /*w w w . java 2 s . c om*/ * @param url * url to ogg / ogv file * @param screenBounds * the screen position, width and height * @param projectToMap * Defines whether to project the video onto the map or onto the * screen coordinates * @param withAudio * if false, the audio channel will be disabled. */ public CortadoPlayerAppletWrapper(URL url, Rectangle screenBounds, boolean projectToMap, boolean withAudio, boolean drawPlaceholder) { this.screenBounds = new Rectangle(screenBounds); this.projectToMap = projectToMap; if (!projectToMap) { GameBase gb = GameBase.$(); this.screenBounds.width /= gb.getScreen().width; this.screenBounds.height /= gb.getScreen().height; this.screenBounds.x /= gb.getScreen().width; this.screenBounds.y /= gb.getScreen().height; } int width = (int) screenBounds.width; int height = (int) screenBounds.height; textureRef = TextureRegionLoader.obtainEmptyRegion(width, height, Format.RGBA8888); if (drawPlaceholder) { Pixmap placeholder = new Pixmap(width, height, Format.RGBA8888); placeholder.setColor(0, 0, 0, 1); placeholder.fillRectangle(0, 0, width, height); placeholder.setColor(.7f, .7f, .7f, 1); placeholder.fillCircle(width / 2, height / 2, Math.min(width, height) / 3); placeholder.setColor(.4f, .4f, .4f, 1); placeholder.drawRectangle(0, 0, width, height); placeholder.drawRectangle(2, 2, width - 4, height - 4); placeholder.drawLine(1, 0, width, height - 1); placeholder.drawLine(0, 1, width - 1, height); placeholder.drawLine(1, height, width, 1); placeholder.drawLine(0, height - 1, width - 1, 0); textureRef.draw(placeholder); placeholder.dispose(); } graphicsPixmap = new VideoARGBintPixmapWrapper(); player = new CortadoPlayerApplet(graphicsPixmap); initPlayer(); player.setParam("url", url.toString()); player.setParam("audio", String.valueOf(withAudio)); player.setSize(width, height); player.setStub(this); player.init(); player.start(); }