summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/photoeditor/RendererUtils.java
diff options
context:
space:
mode:
authorYuli Huang <yuli@google.com>2011-10-20 18:29:05 +0800
committerYuli Huang <yuli@google.com>2011-10-20 22:13:07 +0800
commit960647247705f2c3e375061d234424b71c286e4d (patch)
tree04e72e17d3020501488249aede683aef68b6bb44 /src/com/android/gallery3d/photoeditor/RendererUtils.java
parentc1965fc2a109cf9d267b161800356c0dc4326cf0 (diff)
downloadandroid_packages_apps_Snap-960647247705f2c3e375061d234424b71c286e4d.tar.gz
android_packages_apps_Snap-960647247705f2c3e375061d234424b71c286e4d.tar.bz2
android_packages_apps_Snap-960647247705f2c3e375061d234424b71c286e4d.zip
Fix b/5401109.
1. Add FlipView similar to existing RotateView. 2. Add flipPhoto() similar to existing rotatePhoto() in PhotoView, and add setRenderToFlip() in RendererUtils. 3. Make FlipAction use FlipView/PhotoView similar to how RotateAction uses RotateView/PhotoView. Change-Id: I5642266adbc248c0b8eda48ddc29558ae9cbd21e
Diffstat (limited to 'src/com/android/gallery3d/photoeditor/RendererUtils.java')
-rw-r--r--src/com/android/gallery3d/photoeditor/RendererUtils.java79
1 files changed, 73 insertions, 6 deletions
diff --git a/src/com/android/gallery3d/photoeditor/RendererUtils.java b/src/com/android/gallery3d/photoeditor/RendererUtils.java
index ff593d4ef..b92907df0 100644
--- a/src/com/android/gallery3d/photoeditor/RendererUtils.java
+++ b/src/com/android/gallery3d/photoeditor/RendererUtils.java
@@ -121,13 +121,13 @@ public class RendererUtils {
checkGlError("glDeleteTextures");
}
- public static void setRenderToFit(RenderContext context, int srcWidth, int srcHeight,
- int dstWidth, int dstHeight) {
+ private static float[] getFitVertices(int srcWidth, int srcHeight, int dstWidth,
+ int dstHeight) {
float srcAspectRatio = ((float) srcWidth) / srcHeight;
float dstAspectRatio = ((float) dstWidth) / dstHeight;
float relativeAspectRatio = dstAspectRatio / srcAspectRatio;
- float vertices[] = new float[8];
+ float[] vertices = new float[8];
System.arraycopy(POS_VERTICES, 0, vertices, 0, vertices.length);
if (relativeAspectRatio > 1.0f) {
// Screen is wider than the camera, scale down X
@@ -141,13 +141,20 @@ public class RendererUtils {
vertices[5] *= relativeAspectRatio;
vertices[7] *= relativeAspectRatio;
}
- context.posVertices = createVerticesBuffer(vertices);
+ return vertices;
+ }
+
+ public static void setRenderToFit(RenderContext context, int srcWidth, int srcHeight,
+ int dstWidth, int dstHeight) {
+ context.posVertices = createVerticesBuffer(
+ getFitVertices(srcWidth, srcHeight, dstWidth, dstHeight));
}
public static void setRenderToRotate(RenderContext context, int srcWidth, int srcHeight,
int dstWidth, int dstHeight, float degrees) {
- float cosTheta = (float) Math.cos(-degrees * DEGREE_TO_RADIAN);
- float sinTheta = (float) Math.sin(-degrees * DEGREE_TO_RADIAN);
+ float radian = -degrees * DEGREE_TO_RADIAN;
+ float cosTheta = (float) Math.cos(radian);
+ float sinTheta = (float) Math.sin(radian);
float cosWidth = cosTheta * srcWidth;
float sinWidth = sinTheta * srcWidth;
float cosHeight = cosTheta * srcHeight;
@@ -174,6 +181,66 @@ public class RendererUtils {
context.posVertices = createVerticesBuffer(vertices);
}
+ public static void setRenderToFlip(RenderContext context, int srcWidth, int srcHeight,
+ int dstWidth, int dstHeight, float horizontalDegrees, float verticalDegrees) {
+ // Calculate the base flip coordinates.
+ float[] base = getFitVertices(srcWidth, srcHeight, dstWidth, dstHeight);
+ int horizontalRounds = (int) horizontalDegrees / 180;
+ if (horizontalRounds % 2 != 0) {
+ base[0] = -base[0];
+ base[4] = base[0];
+ base[2] = -base[2];
+ base[6] = base[2];
+ }
+ int verticalRounds = (int) verticalDegrees / 180;
+ if (verticalRounds % 2 != 0) {
+ base[1] = -base[1];
+ base[3] = base[1];
+ base[5] = -base[5];
+ base[7] = base[5];
+ }
+
+ float length = 5;
+ float[] vertices = new float[8];
+ System.arraycopy(base, 0, vertices, 0, vertices.length);
+ if (horizontalDegrees % 180f != 0) {
+ float radian = (horizontalDegrees - horizontalRounds * 180) * DEGREE_TO_RADIAN;
+ float cosTheta = (float) Math.cos(radian);
+ float sinTheta = (float) Math.sin(radian);
+
+ float scale = length / (length + sinTheta * base[0]);
+ vertices[0] = cosTheta * base[0] * scale;
+ vertices[1] = base[1] * scale;
+ vertices[4] = vertices[0];
+ vertices[5] = base[5] * scale;
+
+ scale = length / (length + sinTheta * base[2]);
+ vertices[2] = cosTheta * base[2] * scale;
+ vertices[3] = base[3] * scale;
+ vertices[6] = vertices[2];
+ vertices[7] = base[7] * scale;
+ }
+
+ if (verticalDegrees % 180f != 0) {
+ float radian = (verticalDegrees - verticalRounds * 180) * DEGREE_TO_RADIAN;
+ float cosTheta = (float) Math.cos(radian);
+ float sinTheta = (float) Math.sin(radian);
+
+ float scale = length / (length + sinTheta * base[1]);
+ vertices[0] = base[0] * scale;
+ vertices[1] = cosTheta * base[1] * scale;
+ vertices[2] = base[2] * scale;
+ vertices[3] = vertices[1];
+
+ scale = length / (length + sinTheta * base[5]);
+ vertices[4] = base[4] * scale;
+ vertices[5] = cosTheta * base[5] * scale;
+ vertices[6] = base[6] * scale;
+ vertices[7] = vertices[5];
+ }
+ context.posVertices = createVerticesBuffer(vertices);
+ }
+
public static void renderBackground() {
GLES20.glClearColor(0, 0, 0, 1);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);