fix AwtBitmap

- set dimension for bitmaps read from InputStream
- convert to premultiplied alpha
This commit is contained in:
Hannes Janetzek 2013-06-24 15:44:15 +02:00
parent a2c30e5321
commit 75ef8f83e1

View File

@ -24,15 +24,18 @@ public class AwtBitmap implements Bitmap {
bitmap = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
this.width = width;
this.height = height;
if (!this.bitmap.isAlphaPremultiplied())
this.bitmap.coerceData(true);
}
AwtBitmap(InputStream inputStream) throws IOException {
this.bitmap = ImageIO.read(inputStream);
this.width = this.bitmap.getWidth();
this.height = this.bitmap.getHeight();
if(!this.bitmap.isAlphaPremultiplied())
if (!this.bitmap.isAlphaPremultiplied())
this.bitmap.coerceData(true);
}
}
@Override
public int getWidth() {
return width;
@ -45,13 +48,11 @@ public class AwtBitmap implements Bitmap {
@Override
public int[] getPixels() {
// TODO Auto-generated method stub
return null;
}
@Override
public void eraseColor(int transparent) {
// TODO Auto-generated method stub
}
private static IntBuffer tmpBuffer = BufferUtils.newIntBuffer(512 * 256);
@ -62,18 +63,17 @@ public class AwtBitmap implements Bitmap {
int[] pixels;
IntBuffer buffer;
if (width == 512 && height == 256){
if (width == 512 && height == 256) {
pixels = tmpPixel;
buffer = tmpBuffer;
buffer.clear();
Log.d("AwtBitmap", "default texture");
}else{
//Log.d("AwtBitmap", "default texture");
} else {
pixels = new int[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);
buffer.put(pixels);
@ -88,6 +88,5 @@ public class AwtBitmap implements Bitmap {
@Override
public void recycle() {
// TODO Auto-generated method stub
}
}