import android.graphics.Bitmap;
import android.graphics.Canvas;
+import android.graphics.Bitmap.Config;
/** Using a canvas to draw the texture */
public abstract class CanvasTexture extends Texture {
@Override
protected Bitmap getBitmap() {
- Bitmap bitmap = generateGLCompatibleBitmap(mWidth, mHeight);
+ Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888);
mCanvas = new Canvas(bitmap);
onDraw(mCanvas, bitmap);
return bitmap;
package com.android.camera.ui;
+import com.android.camera.Util;
+
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Matrix;
-
-import com.android.camera.Util;
public class ResourceTexture extends Texture {
@Override
protected Bitmap getBitmap() {
if (mBitmap != null) return mBitmap;
- mBitmap = BitmapFactory.decodeResource(mContext.getResources(), mResId);
+ BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inPreferredConfig = Bitmap.Config.ARGB_8888;
+ mBitmap = BitmapFactory.decodeResource(
+ mContext.getResources(), mResId, options);
setSize(mBitmap.getWidth(), mBitmap.getHeight());
-
- if (Util.isPowerOf2(mWidth) && Util.isPowerOf2(mHeight)) return mBitmap;
-
- Bitmap oldBitmap = mBitmap;
- mBitmap = generateGLCompatibleBitmap(mWidth, mHeight);
- Canvas canvas = new Canvas(mBitmap);
- canvas.drawBitmap(oldBitmap, new Matrix(), null);
- oldBitmap.recycle();
-
return mBitmap;
}
package com.android.camera.ui;
+import com.android.camera.Util;
+
import android.graphics.Bitmap;
-import android.graphics.Bitmap.Config;
import android.opengl.GLUtils;
-import com.android.camera.Util;
-
import javax.microedition.khronos.opengles.GL11;
import javax.microedition.khronos.opengles.GL11Ext;
GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
gl.glTexParameterf(GL11.GL_TEXTURE_2D,
GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
- GLUtils.texImage2D(GL11.GL_TEXTURE_2D, 0, bitmap, 0);
+
+ int width = bitmap.getWidth();
+ int height = bitmap.getHeight();
+ int widthExt = Util.nextPowerOf2(width);
+ int heightExt = Util.nextPowerOf2(height);
+ int format = GLUtils.getInternalFormat(bitmap);
+ int type = GLUtils.getType(bitmap);
+ mTexCoordWidth = (float) width / widthExt;
+ mTexCoordHeight = (float) height / heightExt;
+ gl.glTexImage2D(GL11.GL_TEXTURE_2D, 0, format,
+ widthExt, heightExt, 0, format, type, null);
+ GLUtils.texSubImage2D(
+ GL11.GL_TEXTURE_2D, 0, 0, 0, bitmap, format, type);
} finally {
freeBitmap(bitmap);
}
coord[offset++] = w;
coord[offset] = h;
}
-
- protected Bitmap generateGLCompatibleBitmap(int width, int height) {
- int newWidth = Util.nextPowerOf2(width);
- int newHeight = Util.nextPowerOf2(height);
- mTexCoordWidth = (float) width / newWidth;
- mTexCoordHeight = (float) height / newHeight;
- return Bitmap.createBitmap(newWidth, newHeight, Config.ARGB_8888);
- }
}