Java Code Examples for com.badlogic.gdx.graphics.Pixmap#getHeight()
The following examples show how to use
com.badlogic.gdx.graphics.Pixmap#getHeight() .
These examples are extracted from open source projects.
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 Project: Mundus File: TerrainBrush.java License: Apache License 2.0 | 6 votes |
private void paint() { Terrain terrain = terrainAsset.getTerrain(); SplatMap sm = terrain.getTerrainTexture().getSplatmap(); if (sm == null) return; Vector3 terrainPos = terrain.getPosition(tVec1); final float splatX = ((brushPos.x - terrainPos.x) / (float) terrain.terrainWidth) * sm.getWidth(); final float splatY = ((brushPos.z - terrainPos.z) / (float) terrain.terrainDepth) * sm.getHeight(); final float splatRad = (radius / terrain.terrainWidth) * sm.getWidth(); final Pixmap pixmap = sm.getPixmap(); for (int smX = 0; smX < pixmap.getWidth(); smX++) { for (int smY = 0; smY < pixmap.getHeight(); smY++) { final float dst = MathUtils.dst(splatX, splatY, smX, smY); if (dst <= splatRad) { final float opacity = getValueOfBrushPixmap(splatX, splatY, smX, smY, splatRad) * 0.5f * strength; int newPixelColor = sm.additiveBlend(pixmap.getPixel(smX, smY), paintChannel, opacity); pixmap.drawPixel(smX, smY, newPixelColor); } } } sm.updateTexture(); splatmapModified = true; getProjectManager().current().assetManager.addDirtyAsset(terrainAsset); }
Example 2
Source Project: seventh File: TextureUtil.java License: GNU General Public License v2.0 | 6 votes |
public static Pixmap toWhite(Pixmap img) { Pixmap alpha = new Pixmap(img.getWidth(), img.getHeight(), Format.RGBA8888); //alpha.drawPixmap(img, 0, 0); int width = alpha.getWidth(); int height = alpha.getHeight(); //alpha.setColor(0xff00009f); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int col = img.getPixel(x, y); Color color = new Color(col); if ( color.a > 0.2f ) { alpha.drawPixel(x, y, Color.WHITE.toIntBits()); } } } img.dispose(); return alpha; }
Example 3
Source Project: seventh File: TextureUtil.java License: GNU General Public License v2.0 | 6 votes |
/** * Applying mask into image using specified masking color. Any Color in the * image that matches the masking color will be converted to transparent. * * @param img The source image * @param keyColor Masking color * @return Masked image */ public static Pixmap applyMask(Pixmap img, Color keyColor) { Pixmap alpha = new Pixmap(img.getWidth(), img.getHeight(), Format.RGBA8888); //alpha.drawPixmap(img, 0, 0); int width = alpha.getWidth(); int height = alpha.getHeight(); int colorMask = Color.rgba8888(keyColor); //alpha.setColor(0xff00009f); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int col = img.getPixel(x, y); if ( col != colorMask ) { alpha.drawPixel(x, y, img.getPixel(x, y)); } } } return alpha; }
Example 4
Source Project: shattered-pixel-dungeon File: BitmapFilm.java License: GNU General Public License v3.0 | 5 votes |
public BitmapFilm( Pixmap bitmap, int width, int height ) { this.bitmap = bitmap; int cols = bitmap.getWidth() / width; int rows = bitmap.getHeight() / height; for (int i=0; i < rows; i++) { for (int j=0; j < cols; j++) { Rect rect = new Rect( j * width, i * height, (j+1) * width, (i+1) * height ); add( i * cols + j, rect ); } } }
Example 5
Source Project: uracer-kotd File: DebugStatistics.java License: Apache License 2.0 | 5 votes |
private void init (int width, int height, float updateHz) { // assert (width < 256 && height < 256); final float oneOnUpdHz = 1f / updateHz; PanelWidth = width; PanelHeight = height; intervalNs = (long)(1000000000L * oneOnUpdHz); pixels = new Pixmap(PanelWidth, PanelHeight, Format.RGBA8888); texture = new Texture(width, height, Format.RGBA8888); texture.setFilter(TextureFilter.Nearest, TextureFilter.Nearest); region = new TextureRegion(texture, 0, 0, pixels.getWidth(), pixels.getHeight()); // create data dataRenderTime = new float[PanelWidth]; dataFps = new float[PanelWidth]; dataPhysicsTime = new float[PanelWidth]; dataTimeAliasing = new float[PanelWidth]; // precompute constants ratio_rtime = ((float)PanelHeight / 2f) * Config.Physics.TimestepHz; ratio_ptime = ((float)PanelHeight / 2f) * Config.Physics.TimestepHz; ratio_fps = ((float)PanelHeight / 2f) * oneOnUpdHz; reset(); }
Example 6
Source Project: shattered-pixel-dungeon File: SmartTexture.java License: GNU General Public License v3.0 | 5 votes |
public SmartTexture( Pixmap bitmap, int filtering, int wrapping, boolean premultiplied ) { this.bitmap = bitmap; width = bitmap.getWidth(); height = bitmap.getHeight(); this.fModeMin = this.fModeMax = filtering; this.wModeH = this.wModeV = wrapping; this.premultiplied = premultiplied; }
Example 7
Source Project: gdx-fireapp File: ImageHelper.java License: Apache License 2.0 | 5 votes |
/** * Transforms byte[] to Texture Region. * <p> * If you are going to call this method inside firebase callback remember to wrap it<p> * into {@code Gdx.app.postRunnable(Runnable)}. * The texture will be changed so that it has sides with length of power of 2. * * @param bytes Byte array with image description * @return Texture region representation of given byte array */ public TextureRegion createTextureFromBytes(byte[] bytes) { Pixmap pixmap = new Pixmap(bytes, 0, bytes.length); final int orgWidth = pixmap.getWidth(); final int orgHeight = pixmap.getHeight(); int width = MathUtils.nextPowerOfTwo(orgWidth); int height = MathUtils.nextPowerOfTwo(orgHeight); final Pixmap potPixmap = new Pixmap(width, height, pixmap.getFormat()); potPixmap.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight()); pixmap.dispose(); TextureRegion region = new TextureRegion(new Texture(potPixmap), 0, 0, orgWidth, orgHeight); potPixmap.dispose(); return region; }
Example 8
Source Project: skin-composer File: Utils.java License: MIT License | 5 votes |
public static Vector2 imageDimensions(FileHandle file) { Vector2 vector = new Vector2(); Pixmap pixmap = new Pixmap(file); vector.x = pixmap.getWidth(); vector.y = pixmap.getHeight(); if (file.name().matches("(?i).*\\.9\\.png$")) { vector.x = MathUtils.clamp(vector.x - 2, 0.0f, vector.x); vector.y = MathUtils.clamp(vector.y - 2, 0.0f, vector.y); } pixmap.dispose(); return vector; }
Example 9
Source Project: Cubes File: AOTextureGenerator.java License: MIT License | 5 votes |
private static void pixmapToDouble(Pixmap in, double[][] out) { Color c = new Color(); for (int x = 0; x < in.getWidth(); x++) { for (int y = 0; y < in.getHeight(); y++) { c.set(in.getPixel(x, y)); out[x][y] = c.r; } } }
Example 10
Source Project: mini2Dx File: Lwjgl3Mini2DxCursor.java License: Apache License 2.0 | 5 votes |
Lwjgl3Mini2DxCursor(Lwjgl3Mini2DxWindow window, Pixmap pixmap, int xHotspot, int yHotspot) { this.window = window; if (pixmap.getFormat() != Pixmap.Format.RGBA8888) { throw new GdxRuntimeException("Cursor image pixmap is not in RGBA8888 format."); } if ((pixmap.getWidth() & (pixmap.getWidth() - 1)) != 0) { throw new GdxRuntimeException( "Cursor image pixmap width of " + pixmap.getWidth() + " is not a power-of-two greater than zero."); } if ((pixmap.getHeight() & (pixmap.getHeight() - 1)) != 0) { throw new GdxRuntimeException("Cursor image pixmap height of " + pixmap.getHeight() + " is not a power-of-two greater than zero."); } if (xHotspot < 0 || xHotspot >= pixmap.getWidth()) { throw new GdxRuntimeException("xHotspot coordinate of " + xHotspot + " is not within image width bounds: [0, " + pixmap.getWidth() + ")."); } if (yHotspot < 0 || yHotspot >= pixmap.getHeight()) { throw new GdxRuntimeException("yHotspot coordinate of " + yHotspot + " is not within image height bounds: [0, " + pixmap.getHeight() + ")."); } this.pixmapCopy = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), Pixmap.Format.RGBA8888); this.pixmapCopy.setBlending(Pixmap.Blending.None); this.pixmapCopy.drawPixmap(pixmap, 0, 0); glfwImage = GLFWImage.malloc(); glfwImage.width(pixmapCopy.getWidth()); glfwImage.height(pixmapCopy.getHeight()); glfwImage.pixels(pixmapCopy.getPixels()); glfwCursor = GLFW.glfwCreateCursor(glfwImage, xHotspot, yHotspot); cursors.add(this); }
Example 11
Source Project: libgdx-snippets File: PixmapTransform.java License: MIT License | 5 votes |
public static void copyToMirrored(Pixmap source, Pixmap target, Mirror mirror){ for(int y=0; y<target.getHeight(); y++){ for(int x=0; x<target.getWidth(); x++){ int rgba = PixmapTransform.getPixelMirrored(source, x, y, mirror); target.drawPixel(x, y, rgba); } } }
Example 12
Source Project: shattered-pixel-dungeon-gdx File: SmartTexture.java License: GNU General Public License v3.0 | 5 votes |
public SmartTexture( Pixmap bitmap, int filtering, int wrapping ) { this.bitmap = bitmap; width = bitmap.getWidth(); height = bitmap.getHeight(); this.fModeMin = this.fModeMax = filtering; this.wModeH = this.wModeV = wrapping; }
Example 13
Source Project: Cubes File: AOTextureGenerator.java License: MIT License | 5 votes |
private static void gaussianPixmap(Pixmap in, double[][] doubleOut) { double[][] doubleIn = new double[in.getWidth()][in.getHeight()]; pixmapToDouble(in, doubleIn); for (int i = 0; i < doubleOut.length; i++) { for (int j = 0; j < doubleOut[i].length; j++) { doubleOut[i][j] = 0; } } Pixmap out = gaussianLocal.get(); int offsetX = (in.getWidth() - out.getWidth()) / 2; int offsetY = (in.getHeight() - out.getHeight()) / 2; for (int x = 0; x < out.getWidth(); x++) { for (int y = 0; y < out.getHeight(); y++) { double d = 0; for (int ox = -gaussianRadius; ox <= gaussianRadius; ox++) { for (int oy = -gaussianRadius; oy <= gaussianRadius; oy++) { d += doubleIn[x + ox + offsetX][y + oy + offsetY] * gwm[ox + gaussianRadius][oy + gaussianRadius]; } } doubleOut[x][y] = d; } } }
Example 14
Source Project: libgdx-snippets File: PixmapTransform.java License: MIT License | 5 votes |
public static void copyToRotated(Pixmap source, Pixmap target, Rotate rotate){ for(int y=0; y<target.getHeight(); y++){ for(int x=0; x<target.getWidth(); x++){ int rgba = PixmapTransform.getPixelRotated(source, x, y, rotate); target.drawPixel(x, y, rgba); } } }
Example 15
Source Project: shattered-pixel-dungeon-gdx File: BitmapText.java License: GNU General Public License v3.0 | 4 votes |
protected void splitBy( Pixmap bitmap, int height, int color, String chars ) { int length = chars.length(); int width = bitmap.getWidth(); float vHeight = (float)height / bitmap.getHeight(); int pos; int line = 0; spaceMeasuring: for (pos=0; pos < width; pos++) { for (int j=0; j < height; j++) { if (colorNotMatch(bitmap, pos, j, color)) break spaceMeasuring; } } add( ' ', new RectF( 0, 0, (float)pos / width, vHeight-0.01f ) ); int separator = pos; for (int i=0; i < length; i++) { char ch = chars.charAt( i ); if (ch == ' ') { continue; } else { boolean found; do{ if (separator >= width) { line += height; separator = 0; } found = false; for (int j=line; j < line + height; j++) { if (colorNotMatch( bitmap, separator, j, color)) { found = true; break; } } if (!found) separator++; } while (!found); int start = separator; do { if (++separator >= width) { line += height; separator = start = 0; if (line + height >= bitmap.getHeight()) break; } found = true; for (int j=line; j < line + height; j++) { if (colorNotMatch(bitmap, separator, j, color)) { found = false; break; } } } while (!found); add( ch, new RectF( (float)start / width, (float)line / bitmap.getHeight(), (float)separator / width, (float)line / bitmap.getHeight() + vHeight) ); separator++; } } lineHeight = baseLine = height( frames.get( chars.charAt( 0 ) ) ); }
Example 16
Source Project: shattered-pixel-dungeon-gdx File: BitmapFilm.java License: GNU General Public License v3.0 | 4 votes |
public BitmapFilm( Pixmap bitmap, int width ) { this( bitmap, width, bitmap.getHeight() ); }
Example 17
Source Project: skin-composer File: Utils.java License: MIT License | 4 votes |
/** * Does not dispose pixmap. * @param pixmap * @param ninePatch * @return */ public static Color averageEdgeColor(Pixmap pixmap, boolean ninePatch) { int border = 0; if (ninePatch) { border = 1; } Color temp = new Color(); float sumR = 0.0f; float sumG = 0.0f; float sumB = 0.0f; int count = 0; //left edge for (int y = border; y < pixmap.getHeight() - border; y++) { for (int x = border; x < pixmap.getWidth() - border; x++) { temp.set(pixmap.getPixel(x, y)); if (temp.a > 0) { sumR += temp.r; sumG += temp.g; sumB += temp.b; count++; break; } } } //right edge for (int y = border; y < pixmap.getHeight() - border; y++) { for (int x = pixmap.getWidth() - 1 - border; x > border; x--) { temp.set(pixmap.getPixel(x, y)); if (temp.a > 0) { sumR += temp.r; sumG += temp.g; sumB += temp.b; count++; break; } } } //top edge for (int x = border; x < pixmap.getWidth() - border; x++) { for (int y = border; y < pixmap.getHeight() - border; y++) { temp.set(pixmap.getPixel(x, y)); if (temp.a > 0) { sumR += temp.r; sumG += temp.g; sumB += temp.b; count++; break; } } } //bottom edge for (int x = border; x < pixmap.getWidth() - border; x++) { for (int y = pixmap.getHeight() - 1 - border; y > border; y--) { temp.set(pixmap.getPixel(x, y)); if (temp.a > 0) { sumR += temp.r; sumG += temp.g; sumB += temp.b; count++; break; } } } if (count == 0) { return new Color(Color.BLACK); } else { return new Color(sumR / count, sumG / count, sumB / count, 1.0f); } }
Example 18
Source Project: libgdx-snippets File: PixmapRegion.java License: MIT License | 4 votes |
public PixmapRegion(Pixmap pixmap) { this(pixmap, 0, 0, pixmap.getWidth(), pixmap.getHeight()); }
Example 19
Source Project: libgdx-snippets File: PixmapTransform.java License: MIT License | 4 votes |
/** * Read pixel from {@link Pixmap}, using back-transformed flipped and rotated pixel coordinates. */ public static int getPixel(Pixmap pixmap, int x, int y, Mirror mirror, Rotate rotate) { int widthMinusOne = pixmap.getWidth() - 1; int heightMinusOne = pixmap.getHeight() - 1; int px = x, py = y; int outX, outY; // mirror if (mirror == Mirror.X || mirror == Mirror.XY) { px = widthMinusOne - x; } if (mirror == Mirror.Y || mirror == Mirror.XY) { py = heightMinusOne - y; } // rotate switch (rotate) { case _90: outX = py; outY = heightMinusOne - px; break; case _180: outX = widthMinusOne - px; outY = heightMinusOne - py; break; case _270: outX = widthMinusOne - py; outY = px; break; default: case None: outX = px; outY = py; break; } return pixmap.getPixel(outX, outY); }
Example 20
Source Project: libgdx-snippets File: PixmapUtils.java License: MIT License | 3 votes |
/** * Horizontally mirrors the {@link Pixmap} content, in place, line by line. */ public static void flipX(Pixmap pixmap) { int width = pixmap.getWidth(); int height = pixmap.getHeight(); int bytesPerPixel = getPixelStride(pixmap.getFormat()); int pitch = width * bytesPerPixel; ByteBuffer pixels = pixmap.getPixels(); byte[] buffer = new byte[pitch]; for (int y = 0; y < height; y++) { pixels.position(y * pitch); pixels.get(buffer, 0, pitch); pixels.position(y * pitch); for (int x = 0, offs = pitch - bytesPerPixel; x < width; x++, offs -= bytesPerPixel) { pixels.put(buffer, offs, bytesPerPixel); } } pixels.position(0); }