com.badlogic.gdx.graphics.Pixmap Java Examples

The following examples show how to use com.badlogic.gdx.graphics.Pixmap. 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: SeparatedDataFileResolver.java    From gdx-gltf with Apache License 2.0 6 votes vote down vote up
@Override
public Pixmap load(GLTFImage glImage) {
	if(glImage.uri == null){
		throw new GLTFIllegalException("GLTF image URI cannot be null");
	}else if(glImage.uri.startsWith("data:")){
		// data:application/octet-stream;base64,
		String [] headerBody = glImage.uri.split(",", 2);
		String header = headerBody[0];
		System.out.println(header);
		String body = headerBody[1];
		byte [] data = Base64Coder.decode(body);
		return PixmapBinaryLoaderHack.load(data, 0, data.length);
	}else{
		return new Pixmap(path.child(glImage.uri));
	}
}
 
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: PixmapTransform.java    From libgdx-snippets with MIT License 6 votes vote down vote up
public static int getPixelMirrored(Pixmap pixmap, int x, int y, Mirror mirror) {
	int widthMinusOne = pixmap.getWidth() - 1;
	int heightMinusOne = pixmap.getHeight() - 1;

	int px = x, py = y;

	if (mirror == Mirror.X || mirror == Mirror.XY) {
		px = widthMinusOne - x;
	}

	if (mirror == Mirror.Y || mirror == Mirror.XY) {
		py = heightMinusOne - y;
	}

	return pixmap.getPixel(px, py);
}
 
Example #4
Source File: BGImageProcessor.java    From beatoraja with GNU General Public License v3.0 6 votes vote down vote up
public BGImageProcessor(int size, int maxgen) {
	bgacache = new Texture[size];
	bgacacheid = new int[size];
	cache = new PixmapResourcePool(maxgen) {

		protected Pixmap convert(Pixmap pixmap) {
			int bgasize = Math.max(pixmap.getHeight(), pixmap.getWidth());
			if ( bgasize <=256 ){
				final int fixx = (256 - pixmap.getWidth()) / 2;
				Pixmap fixpixmap = new Pixmap(256, 256, pixmap.getFormat());
				fixpixmap.drawPixmap(pixmap, 0, 0, pixmap.getWidth(), pixmap.getHeight(),
						fixx, 0, pixmap.getWidth(), pixmap.getHeight());
				pixmap.dispose();
				return fixpixmap;
			}
			return pixmap;
		}
	};
}
 
Example #5
Source File: TextureCache.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public synchronized static SmartTexture createSolid( int color ) {
	final String key = "1x1:" + color;
	
	if (all.containsKey( key )) {
		
		return all.get( key );
		
	} else {
		
		Pixmap pixmap =new Pixmap( 1, 1, Pixmap.Format.RGBA8888 );
		// In the rest of the code ARGB is used
		pixmap.setColor( (color << 8) | (color >>> 24) );
		pixmap.fill();
		
		SmartTexture tx = new SmartTexture( pixmap );
		all.put( key, tx );
		
		return tx;
	}
}
 
Example #6
Source File: ToolHandlePicker.java    From Mundus with Apache License 2.0 6 votes vote down vote up
public ToolHandle pick(ToolHandle[] handles, EditorScene scene, int screenX, int screenY) {
    begin(scene.viewport);
    renderPickableScene(handles, scene.sceneGraph.batch, scene.cam);
    end();
    Pixmap pm = getFrameBufferPixmap(scene.viewport);

    int x = screenX - scene.viewport.getScreenX();
    int y = screenY - (Gdx.graphics.getHeight() - (scene.viewport.getScreenY() + scene.viewport.getScreenHeight()));

    int id = PickerColorEncoder.decode(pm.getPixel(x, y));
    Log.trace("ToolHandlePicker", "Picking handle with id {}", id);
    for (ToolHandle handle : handles) {
        if (handle.getId() == id) {
            return handle;
        }
    }

    return null;
}
 
Example #7
Source File: DC6.java    From riiablo with Apache License 2.0 6 votes vote down vote up
@Override
public void loadDirection(int d, boolean combineFrames) {
  if (textures == null) textures = new Texture[header.directions][];
  else if (textures[d] != null) return;
  preloadDirection(d, combineFrames);

  Pixmap[] pixmaps = this.pixmaps[d];
  textures[d] = new Texture[pixmaps.length];
  for (int p = 0; p < pixmaps.length; p++) {
    Pixmap pixmap = pixmaps[p];
    Texture texture = new Texture(new PixmapTextureData(pixmap, null, false, false, false));
    //texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    texture.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge);
    textures[d][p] = texture;
  }

  regions[d] = new TextureRegion[pixmaps.length];
  for (int p = 0; p < pixmaps.length; p++) {
    regions[d][p] = new TextureRegion(textures[d][p]);
  }
}
 
Example #8
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 #9
Source File: MapLoader.java    From Bomberman_libGdx with MIT License 6 votes vote down vote up
public MapLoader(World b2dWorld, com.artemis.World world, int level) {
    this.b2dWorld = b2dWorld;
    this.world = world;
    this.level = level;
    assetManager = GameManager.getInstance().getAssetManager();

    pixmap = assetManager.get("maps/level_" + level + ".png", Pixmap.class);
    switch (level) {
        case 5:
            tileTextureAtlas = assetManager.get("maps/area_3_tiles.pack", TextureAtlas.class);
            break;
        case 4:
        case 3:
            tileTextureAtlas = assetManager.get("maps/area_2_tiles.pack", TextureAtlas.class);
            break;
        case 2:
        case 1:
        default:
            tileTextureAtlas = assetManager.get("maps/area_1_tiles.pack", TextureAtlas.class);
            break;
    }

    mapWidth = pixmap.getWidth();
    mapHeight = pixmap.getHeight();
}
 
Example #10
Source File: PL2.java    From riiablo with Apache License 2.0 6 votes vote down vote up
public Texture render() {
  Pixmap pl2Pixmap = new Pixmap(Palette.COLORS, size, Pixmap.Format.RGBA8888);
  ByteBuffer buffer = pl2Pixmap.getPixels();
  for (int i = 0, j = 0; i < size; i++) {
    //buffer.put(colormaps[i]);
    for (int k = 0; k < Palette.COLORS; k++, j += 4) {
      buffer.put(j, colormaps[i][k]);
    }
  }

  buffer.rewind();
  Texture texture = new Texture(pl2Pixmap);
  //texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
  texture.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge);
  pl2Pixmap.dispose();
  return texture;
}
 
Example #11
Source File: NoiseImage.java    From talos with Apache License 2.0 6 votes vote down vote up
/**
 * @deprecated
 *
 * WARNING THIS IS FOR TESTING PURPOSES ONLY,
 * DO NOT USE AS THIS HAS HORRIBLE PERFORMANCE
 *
 * @param batch
 * @param parentAlpha
 */
public void drawPixmap(Batch batch, float parentAlpha) {
    SimplexNoise simplexNoise = new SimplexNoise();
    pixmap.setColor(0, 0, 0, 1f);
    pixmap.fill();
    for(int x = 0; x < 165; x++) {
        for(int y = 0; y < 100; y++) {
            float v = simplexNoise.query(x/165f, y/100f, frequency) *0.5f + 0.5f;
            pixmap.setColor(v, v, v, 1f);
            pixmap.drawPixel(x, y);
        }
    }

    Texture texture = new Texture(pixmap, Pixmap.Format.RGB888, false);
    batch.draw(texture, getX(), getY());
}
 
Example #12
Source File: Cursor.java    From riiablo with Apache License 2.0 6 votes vote down vote up
public void setCursor(DC dc, Index colormap, int id) {
  if (cursor == null) {
    Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
    cursor = Gdx.graphics.newCursor(pixmap, 0, 0);
    Gdx.graphics.setCursor(cursor);
  }

  this.dc = dc;
  if (colormap != null) {
    transform = colormap;
    transformColor = id;
  } else {
    transform = null;
    transformColor = 0;
  }
}
 
Example #13
Source File: Halo.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
public Halo() {
	super();
	
	if (!TextureCache.contains( CACHE_KEY )) {
		Pixmap pixmap = new Pixmap(RADIUS * 2, RADIUS * 2, Pixmap.Format.RGBA8888);
		pixmap.setColor( 0xFFFFFF0A );
		for (int i = 0; i < 50; i++) {
			pixmap.fillCircle(RADIUS, RADIUS, (int)(RADIUS * (i+1)/50f));
		}
		TextureCache.add( CACHE_KEY, new SmartTexture( pixmap ) );
	}
	
	texture( CACHE_KEY );
}
 
Example #14
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 #15
Source File: ImageHelper.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
/**
 * Creates texture region from byte[].
 * <p>
 * GWT platform requires additional step (as far as i know) to deal with Pixmap. It is need to load Image element
 * and wait until it is loaded.
 *
 * @param bytes    Image byte[] representation, not null
 * @param consumer Consumer where you should deal with region, not null
 */
public static void createTextureFromBytes(byte[] bytes, final Consumer<TextureRegion> consumer) {
    String base64 = "data:image/png;base64," + new String(Base64Coder.encode(bytes));
    final Image image = new Image();
    image.setVisible(false);
    image.addLoadHandler(new LoadHandler() {
        @Override
        public void onLoad(LoadEvent event) {
            ImageElement imageElement = image.getElement().cast();
            Pixmap pixmap = new Pixmap(imageElement);
            GdxFIRLogger.log("Image loaded");
            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();
            RootPanel.get().remove(image);
            consumer.accept(region);
        }
    });
    image.setUrl(base64);
    RootPanel.get().add(image);
}
 
Example #16
Source File: Screenshot.java    From Cubes with MIT License 5 votes vote down vote up
@Override
public void frameEnd() {
  if (!state.compareAndSet(1,  2)) return;

  Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, screenshotWidth, screenshotHeight);
  frameBuffer.end();

  Adapter.getInterface().resize(oldWidth, oldHeight);

  writeScreenshot(pixmap);
}
 
Example #17
Source File: Utils.java    From skin-composer with MIT License 5 votes vote down vote up
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 #18
Source File: PixmapBinaryLoaderHack.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
public static Pixmap load(byte [] encodedData, int offset, int len){
	if(Gdx.app.getType() == ApplicationType.WebGL){
		throw new GdxRuntimeException("load pixmap from bytes not supported for WebGL");
	}else{
		// call new Pixmap(encodedData, offset, len); via reflection to
		// avoid compilation error with GWT.
		try {
			return (Pixmap)ClassReflection.getConstructor(Pixmap.class, byte[].class, int.class, int.class).newInstance(encodedData, offset, len);
		} catch (ReflectionException e) {
			throw new GdxRuntimeException(e);
		}
	}
}
 
Example #19
Source File: IBLBuilder.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an radiance map, to be used with {@link net.mgsx.gltf.scene3d.attributes.PBRCubemapAttribute#SpecularEnv}
 * generated cubemap contains mipmaps in order to perform roughness in PBR shading
 * @param levels mipMapLevels how many mipmaps level, eg. 10 levels produce a 1024x1024 cubemap with mipmaps.
 * @return generated cubemap, caller is responsible to dispose it when no longer used.
 */
public Cubemap buildRadianceMap(final int mipMapLevels){
	Pixmap[] maps = new Pixmap[mipMapLevels * 6];
	int index = 0;
	for(int level=0 ; level<mipMapLevels ; level++){
		int size = 1 << (mipMapLevels - level - 1);
		FrameBuffer fbo = new FrameBuffer(Format.RGBA8888, size, size, false);
		fbo.begin();
		for(int s=0 ; s<6 ; s++){
			Gdx.gl.glClearColor(0, 0, 0, 0);
			Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
			
			CubemapSide side = CubemapSide.values()[s];
			
			float blur = (float)level / (float)mipMapLevels;
			
			renderGradient(side, blur);
			renderLights(side, false);
			
			maps[index] = ScreenUtils.getFrameBufferPixmap(0, 0, size, size);
			index++;
		}
		fbo.end();
		fbo.dispose();
	}
	FacedMultiCubemapData data = new FacedMultiCubemapData(maps, mipMapLevels);
	Cubemap map = new Cubemap(data);
	map.setFilter(TextureFilter.MipMap, TextureFilter.Linear);
	return map;
}
 
Example #20
Source File: AOTextureGenerator.java    From Cubes with MIT License 5 votes vote down vote up
private static void setupPixmap(Pixmap p, int i, Color c) {
  p.setColor(c);

  if ((i & AmbientOcclusion.A) == AmbientOcclusion.A) p.fillRectangle(0, 0, AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE);
  if ((i & AmbientOcclusion.B) == AmbientOcclusion.B) p.fillRectangle(AmbientOcclusion.INDIVIDUAL_SIZE, 0, AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE);
  if ((i & AmbientOcclusion.C) == AmbientOcclusion.C) p.fillRectangle(AmbientOcclusion.INDIVIDUAL_SIZE * 2, 0, AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE);

  if ((i & AmbientOcclusion.D) == AmbientOcclusion.D) p.fillRectangle(0, AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE);
  if ((i & AmbientOcclusion.E) == AmbientOcclusion.E) p.fillRectangle(AmbientOcclusion.INDIVIDUAL_SIZE * 2, AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE);

  if ((i & AmbientOcclusion.F) == AmbientOcclusion.F) p.fillRectangle(0, AmbientOcclusion.INDIVIDUAL_SIZE * 2, AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE);
  if ((i & AmbientOcclusion.G) == AmbientOcclusion.G) p.fillRectangle(AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE * 2, AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE);
  if ((i & AmbientOcclusion.H) == AmbientOcclusion.H) p.fillRectangle(AmbientOcclusion.INDIVIDUAL_SIZE * 2, AmbientOcclusion.INDIVIDUAL_SIZE * 2, AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE);
}
 
Example #21
Source File: DialogTenPatch.java    From skin-composer with MIT License 5 votes vote down vote up
private Pixmap loadPixmapFile(FileHandle fileHandle) {
    if (!fileHandle.name().matches("(?i:.*\\.9\\.png)")) {
        return new Pixmap(fileHandle);
    } else {
        var pixmap = new Pixmap(fileHandle);
        var returnValue = new Pixmap(Math.max(pixmap.getWidth() - 2, 1), Math.max(pixmap.getHeight() - 2, 1), pixmap.getFormat());
        returnValue.setBlending(Pixmap.Blending.None);
        returnValue.drawPixmap(pixmap, -1, -1);
        pixmap.dispose();
        return returnValue;
    }
}
 
Example #22
Source File: DialogTenPatch.java    From skin-composer with MIT License 5 votes vote down vote up
private void saveToImageFile(FileHandle fileHandle) {
    var source = loadPixmapFile(this.fileHandle);
    var pixmap = new Pixmap(source.getWidth() + 2, source.getHeight() + 2, source.getFormat());
    pixmap.setBlending(Pixmap.Blending.None);
    
    pixmap.drawPixmap(source, 1, 1);
    source.dispose();
    
    var tenPatchData = drawableData.tenPatchData;
    
    pixmap.setColor(Color.BLACK);
    var stretchAreas = tenPatchData.horizontalStretchAreas;
    for (var i = 0; i + 1 < stretchAreas.size; i += 2) {
        pixmap.drawRectangle(stretchAreas.get(i) + 1, 0, stretchAreas.get(i + 1) - stretchAreas.get(i) + 1, 1);
    }
    
    stretchAreas = tenPatchData.verticalStretchAreas;
    for (var i = 0; i + 1 < stretchAreas.size; i += 2) {
        pixmap.drawRectangle(0, pixmap.getHeight() - stretchAreas.get(i + 1) - 2, 1, stretchAreas.get(i + 1) - stretchAreas.get(i) + 1);
    }
    
    pixmap.drawRectangle(tenPatchData.contentLeft, pixmap.getHeight() - 1, (pixmap.getWidth() - tenPatchData.contentRight) - tenPatchData.contentLeft, 1);
    
    pixmap.drawRectangle(pixmap.getWidth() - 1, tenPatchData.contentTop, 1, (pixmap.getHeight() - tenPatchData.contentBottom) - tenPatchData.contentTop);
    
    PixmapIO.writePNG(fileHandle, pixmap);
    pixmap.dispose();
}
 
Example #23
Source File: GifDecoder.java    From Norii with Apache License 2.0 5 votes vote down vote up
DixieMap(final int[] data, final int w, final int h, final Pixmap.Format f) {
	super(w, h, f);

	int x, y;

	for (y = 0; y < h; y++) {
		for (x = 0; x < w; x++) {
			final int pxl_ARGB8888 = data[x + y * w];
			final int pxl_RGBA8888 = ((pxl_ARGB8888 >> 24) & 0x000000ff) | ((pxl_ARGB8888 << 8) & 0xffffff00);
			// convert ARGB8888 > RGBA8888
			drawPixel(x, y, pxl_RGBA8888);
		}
	}
}
 
Example #24
Source File: PaletteReducer.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Modifies the given Pixmap so it only uses colors present in this PaletteReducer, without dithering. This produces
 * blocky solid sections of color in most images where the palette isn't exact, instead of checkerboard-like
 * dithering patterns. If you want to reduce the colors in a Pixmap based on what it currently contains, call
 * {@link #analyze(Pixmap)} with {@code pixmap} as its argument, then call this method with the same
 * Pixmap. You may instead want to use a known palette instead of one computed from a Pixmap;
 * {@link #exact(int[])} is the tool for that job.
 * @param pixmap a Pixmap that will be modified in place
 * @return the given Pixmap, for chaining
 */
public Pixmap reduceSolid (Pixmap pixmap) {
    boolean hasTransparent = (paletteArray[0] == 0);
    final int lineLen = pixmap.getWidth(), h = pixmap.getHeight();
    Pixmap.Blending blending = pixmap.getBlending();
    pixmap.setBlending(Pixmap.Blending.None);
    int color;
    for (int y = 0; y < h; y++) {
        for (int px = 0; px < lineLen; px++) {
            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)
                                | ((bb >>> 3))] & 0xFF]);
            }
        }

    }
    pixmap.setBlending(blending);
    return pixmap;
}
 
Example #25
Source File: ShadeTiles.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
private void drawSouth(Pixmap image) {
    int currentAlpha = startAlpha;
    for (int i = 0; i < tileHeight; i++) {
        int color = (currentAlpha << 24);            
        drawLine(image, 0, i, tileWidth-1, i, color);
        currentAlpha -= decayRate;
        if (currentAlpha < 0) {
            break;
        }
    }
}
 
Example #26
Source File: TImage.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
public static TImage makeAlphaImage(float w, float h) {
    Pixmap pixmap = new Pixmap((int) w, (int) h, Pixmap.Format.RGBA8888);
    pixmap.setColor(Color.BLACK);
    pixmap.fill();
    Texture texture = new Texture(pixmap);
    TImage image = new TImage(texture);
    image.addAction(Actions.alpha(0.5f));
    return image;
}
 
Example #27
Source File: AOTextureGenerator.java    From Cubes with MIT License 5 votes vote down vote up
private static void doubleToPixmap(double[][] in, Pixmap out) {
  Color c = new Color(0, 0, 0, 1);
  for (int x = 0; x < out.getWidth(); x++) {
    for (int y = 0; y < out.getHeight(); y++) {
      float d = (float) in[x][y];
      c.r = d;
      c.g = d;
      c.b = d;
      c.clamp();
      out.drawPixel(x, y, Color.rgba8888(c));
    }
  }
}
 
Example #28
Source File: PngFileTypeModel.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
public void setEncoding(Pixmap.Format encoding) {
    this.encoding = encoding;

    if (eventDispatcher != null) {
        eventDispatcher.postEvent(new FileTypePropertyChangedEvent(this, Property.PNG_ENCODING));
    }
}
 
Example #29
Source File: CCPanel.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
@Override
public Actor parse(CocoStudioUIEditor editor, ObjectData widget) {
    Table table = new Table();

    Size size = widget.getSize();
    if (widget.getComboBoxIndex() == 0) { // 无颜色

    } else if (widget.getComboBoxIndex() == 1 && widget.getBackColorAlpha() != 0) {// 单色
        Pixmap pixmap = new Pixmap((int) size.getX(), (int) size.getY(),
            Format.RGBA8888);

        pixmap.setColor(editor.getColor(widget.getSingleColor(),
            widget.getBackColorAlpha()));

        pixmap.fill();

        Drawable d = new TextureRegionDrawable(new TextureRegion(
            new Texture(pixmap)));
        table.setBackground(d);
        pixmap.dispose();
    }

    if (widget.getFileData() != null) {// Panel的图片并不是拉伸平铺的!!.但是这里修改为填充
        Drawable tr = editor.findDrawable(widget, widget.getFileData());
        if (tr != null) {
            Image bg = new Image(tr);
            bg.setPosition((size.getX() - bg.getWidth()) / 2,
                (size.getY() - bg.getHeight()) / 2);
            // bg.setFillParent(true);
            bg.setTouchable(Touchable.disabled);

            table.addActor(bg);
        }
    }

    table.setClip(widget.isClipAble());

    return table;
}
 
Example #30
Source File: MainMenuInterface.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
private void setUpSkin() {
	Pixmap pixmap = new Pixmap(1, 1, Format.RGBA8888);
	pixmap.setColor(Color.LIGHT_GRAY);
	pixmap.fill();
	skin.add("grey", new Texture(pixmap));
	titleSprite.setX(TITLE_SPRITE_POS_X);
	titleSprite.setY(TITLE_SPRITE_POS_Y);

	LabelStyle labelStyle = new LabelStyle();
	skin.add("default", finePrint);
	labelStyle.font = skin.getFont("default");
	skin.add("default", labelStyle);

	CheckBoxStyle checkBoxStyle = new CheckBoxStyle();
	checkBoxStyle.checkboxOff = skin.newDrawable("grey", Color.LIGHT_GRAY);
	checkBoxStyle.checkboxOn = skin.newDrawable("grey", Color.LIGHT_GRAY);
	checkBoxStyle.font = skin.getFont("default");
	checkBoxStyle.checkboxOff = new TextureRegionDrawable(unchecked);
	checkBoxStyle.checkboxOn = new TextureRegionDrawable(checked);
	skin.add("default", checkBoxStyle);

	SliderStyle sliderStyle = new SliderStyle();
	sliderStyle.background = new TextureRegionDrawable(background);
	sliderStyle.knob = new TextureRegionDrawable(knob);
	skin.add("default-horizontal", sliderStyle);

	ButtonStyle buttonStyle = new ButtonStyle();
	skin.add("default", buttonStyle);

	TextButtonStyle textButtonStyle = new TextButtonStyle();
	textButtonStyle.font = skin.getFont("default");
	textButtonStyle.up = new NinePatchDrawable(patchBox);
	skin.add("default", textButtonStyle);
}