summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d
diff options
context:
space:
mode:
authornicolasroard <nicolasroard@google.com>2013-08-27 18:01:16 -0700
committernicolasroard <nicolasroard@google.com>2013-08-27 18:01:16 -0700
commit655afcf4a88cf9dcdbab708212df1dec0a4c05d6 (patch)
treeff493a4dee0ac9290c2f6194d407106a842f2a0d /src/com/android/gallery3d
parent8141e2414467458c6e98b40845fc22a9cdcfffb0 (diff)
downloadandroid_packages_apps_Gallery2-655afcf4a88cf9dcdbab708212df1dec0a4c05d6.tar.gz
android_packages_apps_Gallery2-655afcf4a88cf9dcdbab708212df1dec0a4c05d6.tar.bz2
android_packages_apps_Gallery2-655afcf4a88cf9dcdbab708212df1dec0a4c05d6.zip
Fix param border
needed to replace bitmap borders bug:9470514 Change-Id: I69f6324246ee8c9491ec430c5e20d87574302fcf
Diffstat (limited to 'src/com/android/gallery3d')
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterColorBorderRepresentation.java43
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterColorBorder.java42
2 files changed, 67 insertions, 18 deletions
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterColorBorderRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterColorBorderRepresentation.java
index 929d7cc58..eb9f53020 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterColorBorderRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterColorBorderRepresentation.java
@@ -17,6 +17,8 @@
package com.android.gallery3d.filtershow.filters;
import android.graphics.Color;
+import android.util.JsonReader;
+import android.util.JsonWriter;
import com.android.gallery3d.R;
import com.android.gallery3d.filtershow.controller.BasicParameterInt;
@@ -26,6 +28,9 @@ import com.android.gallery3d.filtershow.controller.ParameterColor;
import com.android.gallery3d.filtershow.editors.EditorColorBorder;
import com.android.gallery3d.filtershow.editors.ImageOnlyEditor;
+import java.io.IOException;
+import java.util.ArrayList;
+
public class FilterColorBorderRepresentation extends FilterRepresentation {
private static final String LOGTAG = "FilterColorBorderRepresentation";
private static final String SERIALIZATION_NAME = "COLORBORDER";
@@ -38,8 +43,8 @@ public class FilterColorBorderRepresentation extends FilterRepresentation {
public static int DEFAULT_MENU_COLOR3 = Color.GRAY;
public static int DEFAULT_MENU_COLOR4 = 0xFFFFCCAA;
public static int DEFAULT_MENU_COLOR5 = 0xFFAAAAAA;
- private BasicParameterInt mParamSize = new BasicParameterInt(PARAM_SIZE, 20, 2, 300);
- private BasicParameterInt mParamRadius = new BasicParameterInt(PARAM_RADIUS, 4, 2, 300);
+ private BasicParameterInt mParamSize = new BasicParameterInt(PARAM_SIZE, 4, 2, 30);
+ private BasicParameterInt mParamRadius = new BasicParameterInt(PARAM_RADIUS, 4, 2, 100);
private ParameterColor mParamColor = new ParameterColor(PARAM_COLOR, DEFAULT_MENU_COLOR1);
private Parameter[] mAllParam = {
@@ -59,7 +64,7 @@ public class FilterColorBorderRepresentation extends FilterRepresentation {
setFilterClass(ImageFilterColorBorder.class);
mParamColor.setValue(color);
mParamSize.setValue(size);
- mParamColor.setValue(radius);
+ mParamRadius.setValue(radius);
}
public String toString() {
@@ -155,4 +160,36 @@ public class FilterColorBorderRepresentation extends FilterRepresentation {
public String getValueString() {
return "";
}
+
+ // Serialization...
+
+ public void serializeRepresentation(JsonWriter writer) throws IOException {
+ writer.beginObject();
+ {
+ writer.name("size");
+ writer.value(mParamSize.getValue());
+ writer.name("radius");
+ writer.value(mParamRadius.getValue());
+ writer.name("color");
+ writer.value(mParamColor.getValue());
+ }
+ writer.endObject();
+ }
+
+ public void deSerializeRepresentation(JsonReader reader) throws IOException {
+ reader.beginObject();
+ while (reader.hasNext()) {
+ String name = reader.nextName();
+ if (name.equalsIgnoreCase("size")) {
+ mParamSize.setValue(reader.nextInt());
+ } else if (name.equalsIgnoreCase("radius")) {
+ mParamRadius.setValue(reader.nextInt());
+ } else if (name.equalsIgnoreCase("color")) {
+ mParamColor.setValue(reader.nextInt());
+ } else {
+ reader.skipValue();
+ }
+ }
+ reader.endObject();
+ }
}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterColorBorder.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterColorBorder.java
index 26f74a2a3..5cc7c3da6 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterColorBorder.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterColorBorder.java
@@ -19,26 +19,24 @@ package com.android.gallery3d.filtershow.filters;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
-import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
-import com.android.gallery3d.app.Log;
-
public class ImageFilterColorBorder extends ImageFilter {
private static final String LOGTAG = "ImageFilterColorBorder";
private FilterColorBorderRepresentation mParameters = null;
Paint mPaint = new Paint();
- RectF mRect = new RectF();
+ RectF mBounds = new RectF();
+ RectF mInsideBounds = new RectF();
+ Path mBorderPath = new Path();
public ImageFilterColorBorder() {
mName = "Border";
- mPaint.setStyle(Paint.Style.STROKE);
}
public FilterRepresentation getDefaultRepresentation() {
- return new FilterColorBorderRepresentation(Color.WHITE, 4, 4);
+ return new FilterColorBorderRepresentation(Color.WHITE, 3, 2);
}
public void useRepresentation(FilterRepresentation representation) {
@@ -55,17 +53,31 @@ public class ImageFilterColorBorder extends ImageFilter {
if (getParameters() == null) {
return;
}
- mRect.set(0, 0, w, h);
- mPaint.setColor(getParameters().getColor());
float size = getParameters().getBorderSize();
float radius = getParameters().getBorderRadius();
- Matrix m = getOriginalToScreenMatrix(w, h);
- radius = m.mapRadius(radius);
- size = m.mapRadius(size);
- mPaint.setStrokeWidth(size);
- canvas.drawRoundRect(mRect, radius, radius, mPaint);
- mRect.set(0 - radius, -radius, w + radius, h + radius);
- canvas.drawRoundRect(mRect, 0, 0, mPaint);
+
+ mPaint.reset();
+ mPaint.setColor(getParameters().getColor());
+ mPaint.setAntiAlias(true);
+ mBounds.set(0, 0, w, h);
+ mBorderPath.reset();
+ mBorderPath.moveTo(0, 0);
+
+ float bs = size / 100.f * mBounds.width();
+ float r = radius / 100.f * mBounds.width();
+
+ mInsideBounds.set(mBounds.left + bs,
+ mBounds.top + bs, mBounds.right - bs,
+ mBounds.bottom - bs);
+
+ mBorderPath.moveTo(mBounds.left, mBounds.top);
+ mBorderPath.lineTo(mBounds.right, mBounds.top);
+ mBorderPath.lineTo(mBounds.right, mBounds.bottom);
+ mBorderPath.lineTo(mBounds.left, mBounds.bottom);
+ mBorderPath.addRoundRect(mInsideBounds,
+ r, r, Path.Direction.CCW);
+
+ canvas.drawPath(mBorderPath, mPaint);
}
@Override