summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/camera/ui/CanvasTexture.java3
-rw-r--r--src/com/android/camera/ui/ResourceTexture.java20
-rw-r--r--src/com/android/camera/ui/Texture.java27
3 files changed, 23 insertions, 27 deletions
diff --git a/src/com/android/camera/ui/CanvasTexture.java b/src/com/android/camera/ui/CanvasTexture.java
index f1ac85a..fa0b76e 100644
--- a/src/com/android/camera/ui/CanvasTexture.java
+++ b/src/com/android/camera/ui/CanvasTexture.java
@@ -2,6 +2,7 @@ package com.android.camera.ui;
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 {
@@ -13,7 +14,7 @@ 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;
diff --git a/src/com/android/camera/ui/ResourceTexture.java b/src/com/android/camera/ui/ResourceTexture.java
index 0d19d2a..e63a2ef 100644
--- a/src/com/android/camera/ui/ResourceTexture.java
+++ b/src/com/android/camera/ui/ResourceTexture.java
@@ -1,12 +1,10 @@
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 {
@@ -22,17 +20,11 @@ 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;
}
diff --git a/src/com/android/camera/ui/Texture.java b/src/com/android/camera/ui/Texture.java
index a384d3a..0d4b6a1 100644
--- a/src/com/android/camera/ui/Texture.java
+++ b/src/com/android/camera/ui/Texture.java
@@ -1,11 +1,10 @@
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;
@@ -96,7 +95,19 @@ public abstract class Texture {
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);
}
@@ -156,12 +167,4 @@ public abstract class Texture {
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);
- }
}