@Override public void create () { Pixmap pixmap = new Pixmap(512, 512, Format.RGBA8888); pixmap.setColor(Color.WHITE); Bresenham2 bresenham = new Bresenham2(); for (GridPoint2 point : bresenham.line(0, 0, 512, 512)) pixmap.drawPixel(point.x, point.y); for (GridPoint2 point : bresenham.line(512, 0, 0, 512)) pixmap.drawPixel(point.x, point.y); for (GridPoint2 point : bresenham.line(0, 0, 512, 256)) pixmap.drawPixel(point.x, point.y); for (GridPoint2 point : bresenham.line(512, 0, 0, 256)) pixmap.drawPixel(point.x, point.y); result = new Texture(pixmap); batch = new SpriteBatch(); }
float depth = MathUtils.clamp(buffer.get(x + y * bufferWidth), 0, Float.POSITIVE_INFINITY); float c = depth * extent; debugPixmap.drawPixel(x, y, Color.rgba8888(c, c, c, 1));
for (int x = 0; x < w; x++) { int alpha = (levelPixmap.getPixel(x, y)) & 0x0FF; pm.drawPixel(x, y + h, (alpha << 24) | (alpha << 16) | (alpha << 8) | 0x0FF);
for (int x = 0; x < w; x++) { int alpha = (levelPixmap.getPixel(x, y)) & 0x0FF; pm.drawPixel(x, y + h, (alpha << 24) | (alpha << 16) | (alpha << 8) | 0x0FF);
for (int w = 0; w < (glyph.width + glyph.xoffset); w++) { int bit = (buf.get(idx + (w / 8)) >>> (7 - (w % 8))) & 1; mainPixmap.drawPixel(w, h, ((bit == 1) ? whiteIntBits : clearIntBits));
for (int w = 0; w < (glyph.width + glyph.xoffset); w++) { int bit = (buf.get(idx + (w / 8)) >>> (7 - (w % 8))) & 1; mainPixmap.drawPixel(w, h, ((bit == 1) ? whiteIntBits : clearIntBits));
private void drawTitle(Pixmap outPixmap, String[] str_titles, int titleWidth, int titleHeight , int px, int py, boolean isFlipX, boolean isFlipY, boolean isRote90) { for (int x = 0; x < titleWidth; x++) { int xx = isFlipX ? titleWidth - 1 - x : x; for (int y = 0; y < titleHeight; y++) { int yy = isFlipY ? titleHeight - 1 - y : y; int color = Integer.parseInt(str_titles[xx * titleHeight + yy]); if (isRote90) { outPixmap.drawPixel(y + px, x + py, color); } else { outPixmap.drawPixel(x + px, y + py, color); } } } }
private void drawAngle(Pixmap outPixmap, String[] str_angles, int angleSize, int px, int py, boolean isFlipX, boolean isFlipY) { for (int x = 0; x < angleSize; x++) { int xx = isFlipX ? angleSize - 1 - x : x; for (int y = 0; y < angleSize; y++) { int yy = isFlipY ? angleSize - 1 - y : y; int color = Integer.parseInt(str_angles[yy * angleSize + xx]); outPixmap.drawPixel(x + px, y + py, color); } } }
private void drawHome(Pixmap outPixmap, String[] str_homes, int homeWidth, int homeHeight, int px, int py, boolean isFlipX, boolean isFlipY) { for (int x = 0; x < homeWidth; x++) { int xx = isFlipX ? homeWidth - 1 - x : x; for (int y = 0; y < homeHeight; y++) { int yy = isFlipY ? homeHeight - 1 - y : y; int color = Integer.parseInt(str_homes[xx * homeHeight + yy]); outPixmap.drawPixel(x + px, y + py, color); } } }
Pixmap pixmap = new Pixmap( colors.length, colors[0].length, Format.RGBA8888 ); for (int i = 0; i < colors.length; i++) { for (int i = 0; i < colors.length; i++) { pixmap.setColor( 0, 1, 0, 0.75f ); //Set to color r,g,b,a pixmap.drawPixel(i,j); //Draw the pixel } } Texture pixmaptex = new Texture(pixmap); //Create new texture from the Pixmap pixmap.dispose();
public synchronized static SmartTexture createGradient( int... colors ) { final String key = "" + colors; if (all.containsKey( key )) { return all.get( key ); } else { Pixmap pixmap = new Pixmap( colors.length, 1, Pixmap.Format.RGBA8888); for (int i=0; i < colors.length; i++) { // In the rest of the code ARGB is used pixmap.drawPixel( i, 0, (colors[i] << 8) | (colors[i] >>> 24) ); } SmartTexture tx = new SmartTexture( pixmap ); tx.filter( Texture.LINEAR, Texture.LINEAR ); tx.wrap( Texture.CLAMP, Texture.CLAMP ); all.put( key, tx ); return tx; } }
public Pixmap flipPixmap(Pixmap src) { final int width = src.getWidth(); final int height = src.getHeight(); Pixmap flipped = new Pixmap(width, height, src.getFormat()); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { flipped.drawPixel(x, y, src.getPixel(width - x - 1, y)); } } return flipped; }
/** * Given a Pixmap and a 2D float array, uses each float in the array as an encoded color for a pixel in the Pixmap * at a location determined by the float's position in the array. This is meant to be used to draw backgrounds that * will be stretched by the {@link #actualCellWidth} and {@link #actualCellHeight} of this TextCellFactory. * <br> * Oddly, this doesn't seem to be very fast compared to {@link #draw(Batch, float[][], float, float)}, so if you * need to draw backgrounds then prefer that method (as SparseLayers does). It also doesn't work with a FilterBatch, * so if you want to use FloatFilter to adjust colors, you would need to use the other draw method for backgrounds. * @param pixmap a non-null Pixmap that will be modified * @param encodedColors a 2D float array that must be non-null and non-empty, and contains packed colors */ @Beta public void draw(Pixmap pixmap, float[][] encodedColors) { final int w = Math.min(pixmap.getWidth(), encodedColors.length), h = Math.min(pixmap.getHeight(), encodedColors[0].length); for (int i = 0; i < w; i++) { for (int j = h - 1; j >= 0; j--) { if (encodedColors[i][j] == 0f) continue; pixmap.drawPixel(i, j, NumberTools.floatToReversedIntBits(encodedColors[i][j])); } } }
private Pixmap rotatePixmap (Pixmap srcPix){ final int width = srcPix.getWidth(); final int height = srcPix.getHeight(); Pixmap rotatedPix = new Pixmap(height, width, srcPix.getFormat()); for (int x = 0; x < height; x++) { for (int y = 0; y < width; y++) { rotatedPix.drawPixel(x, y, srcPix.getPixel(y, x)); } } srcPix.dispose(); return rotatedPix; }
public void pixmapMask(Pixmap pixmap, Pixmap mask, Pixmap result, boolean invertMaskAlpha){ int pixmapWidth = pixmap.getWidth(); int pixmapHeight = pixmap.getHeight(); Color pixelColor = new Color(); Color maskPixelColor = new Color(); Pixmap.Blending blending = Pixmap.getBlending(); Pixmap.setBlending(Blending.None); for (int x=0; x<pixmapWidth; x++){ for (int y=0; y<pixmapHeight; y++){ Color.rgba8888ToColor(pixelColor, pixmap.getPixel(x, y)); // get pixel color Color.rgba8888ToColor(maskPixelColor, mask.getPixel(x, y)); // get mask color maskPixelColor.a = (invertMaskAlpha) ? 1.0f-maskPixelColor.a : maskPixelColor.a; // IF invert mask pixelColor.a = pixelColor.a * maskPixelColor.a; // multiply pixel alpha * mask alpha result.setColor(pixelColor); result.drawPixel(x, y); } } Pixmap.setBlending(blending); }
color = pixmap.getPixel(px, y); if ((color & 0x80) == 0 && hasTransparent) pixmap.drawPixel(px, y, 0); else { int rr = ((color >>> 24) ); int gg = ((color >>> 16) & 0xFF); int bb = ((color >>> 8) & 0xFF); pixmap.drawPixel(px, y, paletteArray[ paletteMapping[((rr << 7) & 0x7C00) | ((gg << 2) & 0x3E0)
public void floodFillShape(Pixmap shapePixmap, int x, int y){ Array<Vector2> queue = new Array<Vector2>(Vector2.class); Color tempColor = new Color(); Vector2 point; queue.add(new Vector2(x, y)); while (queue.size > 0){ point = queue.pop(); if (tempColor.set(shapePixmap.getPixel((int)point.x, (int)point.y)).a == 0){ shapePixmap.drawPixel((int)point.x, (int)point.y); queue.add(new Vector2((int)point.x+1, (int)point.y)); queue.add(new Vector2((int)point.x-1, (int)point.y)); queue.add(new Vector2((int)point.x, (int)point.y+1)); queue.add(new Vector2((int)point.x, (int)point.y-1)); } } }
/** @return original image pixmap with 1-pixel border 9-patch markup. */ public Pixmap prepareNinePatchPixmap() { Pixmap patchPixmap = new Pixmap(this.pixmap.getWidth() + 2, this.pixmap.getHeight() + 2, this.pixmap.getFormat()); patchPixmap.setBlending(Pixmap.Blending.None); patchPixmap.drawPixmap(pixmap, 1, 1); patchPixmap.setColor(0x000000ff); if (patchValues.left.get() != 0 && patchValues.right.get() != 0) { for (int x = patchValues.left.get(); x < (pixmap.getWidth() - patchValues.right.get()); x++) { patchPixmap.drawPixel(x+1, 0); } } if (patchValues.top.get() != 0 && patchValues.bottom.get() != 0) { for (int y = patchValues.top.get(); y < (pixmap.getHeight() - patchValues.bottom.get()); y++) { patchPixmap.drawPixel(0, y+1); } } if (contentValues.left.get() != 0 && contentValues.right.get() != 0) { for (int x = contentValues.left.get(); x < (pixmap.getWidth() - contentValues.right.get()); x++) { patchPixmap.drawPixel(x+1, pixmap.getHeight()+1); } } if (contentValues.top.get() != 0 && contentValues.bottom.get() != 0) { for (int y = contentValues.top.get(); y < (pixmap.getHeight() - contentValues.bottom.get()); y++) { patchPixmap.drawPixel(pixmap.getWidth()+1, y+1); } } return patchPixmap; } //endregion
public void clearChannel(SplatTexture.Channel channel) { Pixmap pixmap = getPixmap(); for (int smX = 0; smX < pixmap.getWidth(); smX++) { for (int smY = 0; smY < pixmap.getHeight(); smY++) { c0.set(pixmap.getPixel(smX, smY)); if (channel == SplatTexture.Channel.R) { c0.set(0, c0.g, c0.b, c0.a); } else if (channel == SplatTexture.Channel.G) { c0.set(c0.r, 0, c0.b, c0.a); } else if (channel == SplatTexture.Channel.B) { c0.set(c0.r, c0.g, 0, c0.a); } else if (channel == SplatTexture.Channel.A) { c0.set(c0.r, c0.g, c0.b, 0); } pixmap.drawPixel(smX, smY, Color.rgba8888(c0)); } } }
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); }