Java Code Examples for com.badlogic.gdx.graphics.Pixmap#getFormat()

The following examples show how to use com.badlogic.gdx.graphics.Pixmap#getFormat() . 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: FacedMultiCubemapData.java    From gdx-gltf with Apache License 2.0 6 votes vote down vote up
@Override
public void consumeCubemapData () {
	for(int level = 0 ; level<levels ; level++){
		for (int i = 0; i < 6; i++) {
			int index = level * 6 + i;
			if (data[index].getType() == TextureData.TextureDataType.Custom) {
				data[index].consumeCustomData(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i);
			} else {
				Pixmap pixmap = data[index].consumePixmap();
				boolean disposePixmap = data[index].disposePixmap();
				if (data[index].getFormat() != pixmap.getFormat()) {
					Pixmap tmp = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), data[index].getFormat());
					tmp.setBlending(Blending.None);
					tmp.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight());
					if (data[index].disposePixmap()) pixmap.dispose();
					pixmap = tmp;
					disposePixmap = true;
				}
				Gdx.gl.glPixelStorei(GL20.GL_UNPACK_ALIGNMENT, 1);
				Gdx.gl.glTexImage2D(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, level, pixmap.getGLInternalFormat(), pixmap.getWidth(),
					pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels());
				if (disposePixmap) pixmap.dispose();
			}
		}
	}
}
 
Example 2
Source File: TextureUtil.java    From seventh with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Splits the image 
 * @param image
 * @param width
 * @param height
 * @param row
 * @param col
 * @return
 */
public static Pixmap[] splitPixmap(Pixmap image, int width, int height, int row, int col) {                
    int total = col * row; // total returned images
    int frame = 0; // frame counter

    int w = width / col;
    int h = height / row;

    Pixmap[] images = new Pixmap[total];

    for (int j = 0; j < row; j++) {
        for (int i = 0; i < col; i++) {                
            Pixmap region = new Pixmap(w, h, image.getFormat());
            region.drawPixmap(image, 0, 0, i * w, j * h, w, h);
            
            images[frame++] = region;
        }
    }

    return images;
}
 
Example 3
Source File: ImageHelper.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
/**
 * 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 4
Source File: PixmapUtils.java    From libgdx-snippets with MIT License 5 votes vote down vote up
/**
 * Returns a copy of the given pixmap, cropped about the given dimensions.
 */
public static Pixmap crop(Pixmap pixmap, int left, int bottom, int width, int height) {

	Pixmap result = new Pixmap(width, height, pixmap.getFormat());
	result.drawPixmap(pixmap, 0, 0, left, bottom, width, height);

	return result;
}
 
Example 5
Source File: AOTextureGenerator.java    From Cubes with MIT License 5 votes vote down vote up
protected static void generate(FileHandle file) {
  final long startTime = System.currentTimeMillis();
  startExecutor();
  Pixmap weak = generate(0.5f);
  Pixmap strong = generate(0.1f);

  Pixmap out = new Pixmap(weak.getWidth(), weak.getHeight(), weak.getFormat());
  Color outColor = new Color();
  Color tempColor = new Color();
  for (int x = 0; x < out.getWidth(); x++) {
    for (int y = 0; y < out.getHeight(); y++) {
      outColor.r = tempColor.set(weak.getPixel(x, y)).r;
      outColor.g = tempColor.set(strong.getPixel(x, y)).r;
      outColor.b = 1f;
      outColor.a = 1f;
      out.drawPixel(x, y, Color.rgba8888(outColor));
    }
  }
  weak.dispose();
  strong.dispose();

  System.out.println("Took " + ((System.currentTimeMillis() - startTime) / 1000 / 60) + " minutes");
  System.out.println("Writing to: " + file.path());
  System.out.println();

  PixmapIO.writePNG(file, out);
  out.dispose();
}
 
Example 6
Source File: HeightMap.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param file 8-bit PNG file heightmap data
 * @param heightScale vertical scaling (y axis)
 * @param widthScale width on the x-z plane (distance between points)
 * @param whiteHigh height is represented by white (instead of black)
 */
public HeightMap(FileHandle file, float heightScale, float widthScale, boolean whiteHigh, int smoothingPasses) {
	// TODO whiteHigh seems to breaking the normals
	this.heightScale = heightScale;
	this.widthScale = widthScale;

	Pixmap pix = new Pixmap(file);
	if (pix.getFormat() != Pixmap.Format.Alpha) {
		throw new GdxRuntimeException("Pixmap must be format Pixmap.Alpha (8-bit Grayscale), not: " + pix.getFormat());
	}
	int pixWidth = pix.getWidth();
	int pixHeight = pix.getHeight();
	int w = pixWidth;
	int h = pixHeight;
	System.out.println("w,h: " + w + ", " + h);
	heights = new float[h][w];

	boolean countWidth = true;
	for (int z = 0; z < pixHeight; z ++) {
		depth++;
		for (int x = 0; x < pixWidth; x ++) {
			if (countWidth) width++;
			//System.out.printf("pix value: (%d, %d): %d\n", x, z,  pix.getPixel(x, z));
			int height;
			if (whiteHigh) {
				height = 256 - (-1 * pix.getPixel(x, z));
			} else {
				height = -1 * pix.getPixel(x, z);
			}
			heights[z][x] = height;
			numPoints++;
		}
		countWidth = false;
	}
	smoothVertexPositions(smoothingPasses);
	updateDimensions();
}
 
Example 7
Source File: Lwjgl3Mini2DxCursor.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
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 8
Source File: PixmapTransform.java    From libgdx-snippets with MIT License 4 votes vote down vote up
public static Pixmap getRotatedMirroredCopy(Pixmap pixmap, Mirror mirror, Rotate rotate){

		Pixmap mirrored = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), pixmap.getFormat());
		copyToMirrored(pixmap, mirrored, mirror);

		int newWidth = PixmapTransform.getWidth(pixmap, rotate);
		int newHeight = PixmapTransform.getHeight(pixmap, rotate);

		Pixmap copy = new Pixmap(newWidth, newHeight, pixmap.getFormat());
		copyToRotated(mirrored, copy, rotate);

		/** Only temp for copying around */
		mirrored.dispose();

		return copy;
	}
 
Example 9
Source File: TextureUtil.java    From seventh with GNU General Public License v2.0 4 votes vote down vote up
public static Pixmap subPixmap(Pixmap pix, int x, int y, int width, int height) {
    Pixmap sub = new Pixmap(width, height, pix.getFormat());
    sub.drawPixmap(pix, x, y, width, height, 0, 0, width, height);
    return sub;
}
 
Example 10
Source File: TextureUtil.java    From seventh with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Resizes the image
 *
 * @param image
 * @param width
 * @param height
 * @return
 */
public static Pixmap resizePixmap(Pixmap image, int width, int height) {
    Pixmap pix = new Pixmap(width, height, image.getFormat());
    pix.drawPixmap(image, 0, 0, width, height, // destination
             0, 0, image.getWidth(), image.getHeight()); // source                         
    return pix;
}