fix AwtBitmap
- set dimension for bitmaps read from InputStream - convert to premultiplied alpha
This commit is contained in:
parent
a2c30e5321
commit
75ef8f83e1
@ -24,15 +24,18 @@ public class AwtBitmap implements Bitmap {
|
|||||||
bitmap = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
bitmap = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
if (!this.bitmap.isAlphaPremultiplied())
|
||||||
|
this.bitmap.coerceData(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
AwtBitmap(InputStream inputStream) throws IOException {
|
AwtBitmap(InputStream inputStream) throws IOException {
|
||||||
this.bitmap = ImageIO.read(inputStream);
|
this.bitmap = ImageIO.read(inputStream);
|
||||||
this.width = this.bitmap.getWidth();
|
this.width = this.bitmap.getWidth();
|
||||||
this.height = this.bitmap.getHeight();
|
this.height = this.bitmap.getHeight();
|
||||||
if(!this.bitmap.isAlphaPremultiplied())
|
if (!this.bitmap.isAlphaPremultiplied())
|
||||||
this.bitmap.coerceData(true);
|
this.bitmap.coerceData(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
return width;
|
return width;
|
||||||
@ -45,13 +48,11 @@ public class AwtBitmap implements Bitmap {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] getPixels() {
|
public int[] getPixels() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void eraseColor(int transparent) {
|
public void eraseColor(int transparent) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IntBuffer tmpBuffer = BufferUtils.newIntBuffer(512 * 256);
|
private static IntBuffer tmpBuffer = BufferUtils.newIntBuffer(512 * 256);
|
||||||
@ -62,32 +63,30 @@ public class AwtBitmap implements Bitmap {
|
|||||||
int[] pixels;
|
int[] pixels;
|
||||||
IntBuffer buffer;
|
IntBuffer buffer;
|
||||||
|
|
||||||
if (width == 512 && height == 256){
|
if (width == 512 && height == 256) {
|
||||||
pixels = tmpPixel;
|
pixels = tmpPixel;
|
||||||
buffer = tmpBuffer;
|
buffer = tmpBuffer;
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
Log.d("AwtBitmap", "default texture");
|
//Log.d("AwtBitmap", "default texture");
|
||||||
}else{
|
} else {
|
||||||
pixels = new int[width * height];
|
pixels = new int[width * height];
|
||||||
buffer = BufferUtils.newIntBuffer(width * height);
|
buffer = BufferUtils.newIntBuffer(width * height);
|
||||||
Log.d("AwtBitmap", "create texture buffer " + width + "x" + height);
|
//Log.d("AwtBitmap", "create texture buffer " + width + "x" + height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bitmap.getRGB(0, 0, width, height, pixels, 0, width);
|
bitmap.getRGB(0, 0, width, height, pixels, 0, width);
|
||||||
|
|
||||||
buffer.put(pixels);
|
buffer.put(pixels);
|
||||||
buffer.flip();
|
buffer.flip();
|
||||||
|
|
||||||
Gdx.gl20.glTexImage2D(GL20.GL_TEXTURE_2D, 0, GL20.GL_RGBA, width,
|
Gdx.gl20.glTexImage2D(GL20.GL_TEXTURE_2D, 0, GL20.GL_RGBA, width,
|
||||||
height, 0, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, buffer);
|
height, 0, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, buffer);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void recycle() {
|
public void recycle() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user