summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/photoeditor/filters
diff options
context:
space:
mode:
authorYuli Huang <yuli@google.com>2011-11-04 16:39:50 +0800
committerYuli Huang <yuli@google.com>2011-11-09 01:08:44 +0800
commit16ac4446300bdc6b23a9436328a667996a70c278 (patch)
treed3984b476c56049afd695a25dae79397ad48ce00 /src/com/android/gallery3d/photoeditor/filters
parentb820346074c813500f2ea5b5ae1488fae2b29103 (diff)
downloadandroid_packages_apps_Snap-16ac4446300bdc6b23a9436328a667996a70c278.tar.gz
android_packages_apps_Snap-16ac4446300bdc6b23a9436328a667996a70c278.tar.bz2
android_packages_apps_Snap-16ac4446300bdc6b23a9436328a667996a70c278.zip
Fix b/5510870 by saving/restoring Activity states.
1. Filters implement Parcelable for saving/restoring states. 2. Extract Doodle for making doodling paths parcelable. Change-Id: Ice8e6e068891da8a8f9251e62d95ea755fa99933
Diffstat (limited to 'src/com/android/gallery3d/photoeditor/filters')
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/AbstractScaleFilter.java45
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/AutoFixFilter.java14
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/ColorTemperatureFilter.java15
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/CropFilter.java13
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/CrossProcessFilter.java2
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/DocumentaryFilter.java2
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/DoodleFilter.java47
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/DuotoneFilter.java15
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/FaceTanFilter.java14
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/FaceliftFilter.java14
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/FillLightFilter.java16
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/Filter.java33
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/FilterCreator.java53
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/FisheyeFilter.java14
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/FlipFilter.java24
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/GrainFilter.java14
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/GrayscaleFilter.java2
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/HighlightFilter.java16
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/LomoishFilter.java2
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/NegativeFilter.java2
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/PosterizeFilter.java2
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/RedEyeFilter.java19
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/RotateFilter.java13
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/SaturationFilter.java16
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/SepiaFilter.java2
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/ShadowFilter.java16
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/SharpenFilter.java14
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/StraightenFilter.java18
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/TintFilter.java19
-rw-r--r--src/com/android/gallery3d/photoeditor/filters/VignetteFilter.java14
30 files changed, 308 insertions, 182 deletions
diff --git a/src/com/android/gallery3d/photoeditor/filters/AbstractScaleFilter.java b/src/com/android/gallery3d/photoeditor/filters/AbstractScaleFilter.java
new file mode 100644
index 000000000..727a98cab
--- /dev/null
+++ b/src/com/android/gallery3d/photoeditor/filters/AbstractScaleFilter.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.gallery3d.photoeditor.filters;
+
+import android.os.Parcel;
+
+/**
+ * Filter base that has a scale value ranging from 0 to 1 for adjustments and can persist states.
+ */
+public abstract class AbstractScaleFilter extends Filter {
+
+ protected float scale;
+
+ /**
+ * Sets the scale from 0 to 1.
+ */
+ public void setScale(float scale) {
+ this.scale = scale;
+ validate();
+ }
+
+ @Override
+ protected void writeToParcel(Parcel out) {
+ out.writeFloat(scale);
+ }
+
+ @Override
+ protected void readFromParcel(Parcel in) {
+ scale = in.readFloat();
+ }
+}
diff --git a/src/com/android/gallery3d/photoeditor/filters/AutoFixFilter.java b/src/com/android/gallery3d/photoeditor/filters/AutoFixFilter.java
index 78153d0a8..d168a787f 100644
--- a/src/com/android/gallery3d/photoeditor/filters/AutoFixFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/AutoFixFilter.java
@@ -24,19 +24,9 @@ import com.android.gallery3d.photoeditor.Photo;
/**
* Auto-fix filter applied to the image.
*/
-public class AutoFixFilter extends Filter {
+public class AutoFixFilter extends AbstractScaleFilter {
- private float scale;
-
- /**
- * Sets the auto-fix level.
- *
- * @param scale ranges from 0 to 1.
- */
- public void setScale(float scale) {
- this.scale = scale;
- validate();
- }
+ public static final Creator<AutoFixFilter> CREATOR = creatorOf(AutoFixFilter.class);
@Override
public void process(Photo src, Photo dst) {
diff --git a/src/com/android/gallery3d/photoeditor/filters/ColorTemperatureFilter.java b/src/com/android/gallery3d/photoeditor/filters/ColorTemperatureFilter.java
index f9c640059..c5a6a35e4 100644
--- a/src/com/android/gallery3d/photoeditor/filters/ColorTemperatureFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/ColorTemperatureFilter.java
@@ -24,19 +24,10 @@ import com.android.gallery3d.photoeditor.Photo;
/**
* Color temperature filter applied to the image.
*/
-public class ColorTemperatureFilter extends Filter {
+public class ColorTemperatureFilter extends AbstractScaleFilter {
- private float scale;
-
- /**
- * Sets the color temperature level.
- *
- * @param scale ranges from 0 to 1.
- */
- public void setColorTemperature(float scale) {
- this.scale = scale;
- validate();
- }
+ public static final Creator<ColorTemperatureFilter> CREATOR = creatorOf(
+ ColorTemperatureFilter.class);
@Override
public void process(Photo src, Photo dst) {
diff --git a/src/com/android/gallery3d/photoeditor/filters/CropFilter.java b/src/com/android/gallery3d/photoeditor/filters/CropFilter.java
index f984f3bc2..ccca81387 100644
--- a/src/com/android/gallery3d/photoeditor/filters/CropFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/CropFilter.java
@@ -19,6 +19,7 @@ package com.android.gallery3d.photoeditor.filters;
import android.graphics.RectF;
import android.media.effect.Effect;
import android.media.effect.EffectFactory;
+import android.os.Parcel;
import com.android.gallery3d.photoeditor.Photo;
@@ -27,6 +28,8 @@ import com.android.gallery3d.photoeditor.Photo;
*/
public class CropFilter extends Filter {
+ public static final Creator<CropFilter> CREATOR = creatorOf(CropFilter.class);
+
private RectF bounds;
/**
@@ -49,4 +52,14 @@ public class CropFilter extends Filter {
effect.setParameter("height", dst.height());
effect.apply(src.texture(), src.width(), src.height(), dst.texture());
}
+
+ @Override
+ protected void writeToParcel(Parcel out) {
+ out.writeParcelable(bounds, 0);
+ }
+
+ @Override
+ protected void readFromParcel(Parcel in) {
+ bounds = in.readParcelable(null);
+ }
}
diff --git a/src/com/android/gallery3d/photoeditor/filters/CrossProcessFilter.java b/src/com/android/gallery3d/photoeditor/filters/CrossProcessFilter.java
index bea8a272c..e82a66736 100644
--- a/src/com/android/gallery3d/photoeditor/filters/CrossProcessFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/CrossProcessFilter.java
@@ -25,6 +25,8 @@ import com.android.gallery3d.photoeditor.Photo;
*/
public class CrossProcessFilter extends Filter {
+ public static final Creator<CrossProcessFilter> CREATOR = creatorOf(CrossProcessFilter.class);
+
public CrossProcessFilter() {
validate();
}
diff --git a/src/com/android/gallery3d/photoeditor/filters/DocumentaryFilter.java b/src/com/android/gallery3d/photoeditor/filters/DocumentaryFilter.java
index 4075b27cc..d6f347b1f 100644
--- a/src/com/android/gallery3d/photoeditor/filters/DocumentaryFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/DocumentaryFilter.java
@@ -25,6 +25,8 @@ import com.android.gallery3d.photoeditor.Photo;
*/
public class DocumentaryFilter extends Filter {
+ public static final Creator<DocumentaryFilter> CREATOR = creatorOf(DocumentaryFilter.class);
+
public DocumentaryFilter() {
validate();
}
diff --git a/src/com/android/gallery3d/photoeditor/filters/DoodleFilter.java b/src/com/android/gallery3d/photoeditor/filters/DoodleFilter.java
index d9e904a94..277e06df7 100644
--- a/src/com/android/gallery3d/photoeditor/filters/DoodleFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/DoodleFilter.java
@@ -24,9 +24,10 @@ import android.graphics.Path;
import android.graphics.RectF;
import android.media.effect.Effect;
import android.media.effect.EffectFactory;
+import android.os.Parcel;
import com.android.gallery3d.photoeditor.Photo;
-import com.android.gallery3d.photoeditor.actions.DoodlePaint;
+import com.android.gallery3d.photoeditor.actions.Doodle;
import java.util.Vector;
@@ -35,17 +36,9 @@ import java.util.Vector;
*/
public class DoodleFilter extends Filter {
- private static class ColorPath {
- private final int color;
- private final Path path;
+ public static final Creator<DoodleFilter> CREATOR = creatorOf(DoodleFilter.class);
- ColorPath(int color, Path path) {
- this.color = color;
- this.path = path;
- }
- }
-
- private final Vector<ColorPath> doodles = new Vector<ColorPath>();
+ private final Vector<Doodle> doodles = new Vector<Doodle>();
/**
* Signals once at least a doodle drawn within photo bounds; this filter is regarded as invalid
@@ -55,11 +48,8 @@ public class DoodleFilter extends Filter {
validate();
}
- /**
- * The path coordinates used here should range from 0 to 1.
- */
- public void addPath(Path path, int color) {
- doodles.add(new ColorPath(color, path));
+ public void addDoodle(Doodle doodle) {
+ doodles.add(doodle);
}
@Override
@@ -72,11 +62,10 @@ public class DoodleFilter extends Filter {
new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight()), Matrix.ScaleToFit.FILL);
Path drawingPath = new Path();
- Paint paint = new DoodlePaint();
- for (ColorPath doodle : doodles) {
- paint.setColor(doodle.color);
- drawingPath.set(doodle.path);
- drawingPath.transform(matrix);
+ Paint paint = Doodle.createPaint();
+ for (Doodle doodle : doodles) {
+ paint.setColor(doodle.getColor());
+ doodle.getDrawingPath(matrix, drawingPath);
canvas.drawPath(drawingPath, paint);
}
@@ -84,4 +73,20 @@ public class DoodleFilter extends Filter {
effect.setParameter("bitmap", bitmap);
effect.apply(src.texture(), src.width(), src.height(), dst.texture());
}
+
+ @Override
+ protected void writeToParcel(Parcel out) {
+ out.writeInt(doodles.size());
+ for (Doodle doodle : doodles) {
+ out.writeParcelable(doodle, 0);
+ }
+ }
+
+ @Override
+ protected void readFromParcel(Parcel in) {
+ int size = in.readInt();
+ for (int i = 0; i < size; i++) {
+ doodles.add((Doodle) in.readParcelable(Doodle.class.getClassLoader()));
+ }
+ }
}
diff --git a/src/com/android/gallery3d/photoeditor/filters/DuotoneFilter.java b/src/com/android/gallery3d/photoeditor/filters/DuotoneFilter.java
index 89e95b9c8..b94f95e5a 100644
--- a/src/com/android/gallery3d/photoeditor/filters/DuotoneFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/DuotoneFilter.java
@@ -18,6 +18,7 @@ package com.android.gallery3d.photoeditor.filters;
import android.media.effect.Effect;
import android.media.effect.EffectFactory;
+import android.os.Parcel;
import com.android.gallery3d.photoeditor.Photo;
@@ -26,6 +27,8 @@ import com.android.gallery3d.photoeditor.Photo;
*/
public class DuotoneFilter extends Filter {
+ public static final Creator<DuotoneFilter> CREATOR = creatorOf(DuotoneFilter.class);
+
private int firstColor;
private int secondColor;
@@ -42,4 +45,16 @@ public class DuotoneFilter extends Filter {
effect.setParameter("second_color", secondColor);
effect.apply(src.texture(), src.width(), src.height(), dst.texture());
}
+
+ @Override
+ protected void writeToParcel(Parcel out) {
+ out.writeInt(firstColor);
+ out.writeInt(secondColor);
+ }
+
+ @Override
+ protected void readFromParcel(Parcel in) {
+ firstColor = in.readInt();
+ secondColor = in.readInt();
+ }
}
diff --git a/src/com/android/gallery3d/photoeditor/filters/FaceTanFilter.java b/src/com/android/gallery3d/photoeditor/filters/FaceTanFilter.java
index 24b89c93f..c52bb8848 100644
--- a/src/com/android/gallery3d/photoeditor/filters/FaceTanFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/FaceTanFilter.java
@@ -23,19 +23,9 @@ import com.android.gallery3d.photoeditor.Photo;
/**
* Face tanning filter applied to the image.
*/
-public class FaceTanFilter extends Filter {
+public class FaceTanFilter extends AbstractScaleFilter {
- private float scale;
-
- /**
- * Sets the face tanning level.
- *
- * @param scale ranges from 0 to 1.
- */
- public void setScale(float scale) {
- this.scale = scale;
- validate();
- }
+ public static final Creator<FaceTanFilter> CREATOR = creatorOf(FaceTanFilter.class);
@Override
public void process(Photo src, Photo dst) {
diff --git a/src/com/android/gallery3d/photoeditor/filters/FaceliftFilter.java b/src/com/android/gallery3d/photoeditor/filters/FaceliftFilter.java
index 3c7a7315d..c6ad84b80 100644
--- a/src/com/android/gallery3d/photoeditor/filters/FaceliftFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/FaceliftFilter.java
@@ -23,19 +23,9 @@ import com.android.gallery3d.photoeditor.Photo;
/**
* Facelift filter applied to the image.
*/
-public class FaceliftFilter extends Filter {
+public class FaceliftFilter extends AbstractScaleFilter {
- private float scale;
-
- /**
- * Sets the facelift level.
- *
- * @param scale ranges from 0 to 1.
- */
- public void setScale(float scale) {
- this.scale = scale;
- validate();
- }
+ public static final Creator<FaceliftFilter> CREATOR = creatorOf(FaceliftFilter.class);
@Override
public void process(Photo src, Photo dst) {
diff --git a/src/com/android/gallery3d/photoeditor/filters/FillLightFilter.java b/src/com/android/gallery3d/photoeditor/filters/FillLightFilter.java
index 2346953d7..3aedd745e 100644
--- a/src/com/android/gallery3d/photoeditor/filters/FillLightFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/FillLightFilter.java
@@ -24,24 +24,14 @@ import com.android.gallery3d.photoeditor.Photo;
/**
* Fill-light filter applied to the image.
*/
-public class FillLightFilter extends Filter {
+public class FillLightFilter extends AbstractScaleFilter {
- private float backlight;
-
- /**
- * Sets the backlight level.
- *
- * @param backlight ranges from 0 to 1.
- */
- public void setBacklight(float backlight) {
- this.backlight = backlight;
- validate();
- }
+ public static final Creator<FillLightFilter> CREATOR = creatorOf(FillLightFilter.class);
@Override
public void process(Photo src, Photo dst) {
Effect effect = getEffect(EffectFactory.EFFECT_FILLLIGHT);
- effect.setParameter("strength", backlight);
+ effect.setParameter("strength", scale);
effect.apply(src.texture(), src.width(), src.height(), dst.texture());
}
}
diff --git a/src/com/android/gallery3d/photoeditor/filters/Filter.java b/src/com/android/gallery3d/photoeditor/filters/Filter.java
index 8c00dbb3f..baa37472c 100644
--- a/src/com/android/gallery3d/photoeditor/filters/Filter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/Filter.java
@@ -18,6 +18,8 @@ package com.android.gallery3d.photoeditor.filters;
import android.media.effect.Effect;
import android.media.effect.EffectContext;
+import android.os.Parcel;
+import android.os.Parcelable;
import com.android.gallery3d.photoeditor.Photo;
@@ -27,7 +29,7 @@ import java.util.HashMap;
* Image filter for photo editing; most of its methods must be called from a single GL thread except
* validate()/isValid() that are called from UI thread.
*/
-public abstract class Filter {
+public abstract class Filter implements Parcelable {
// TODO: This should be set in MFF instead.
private static final int DEFAULT_TILE_SIZE = 640;
@@ -91,4 +93,33 @@ public abstract class Filter {
* @param dst destination photo having the same dimension as source photo as the output.
*/
public abstract void process(Photo src, Photo dst);
+
+ /**
+ * Instantiates CREATOR of subclasses for Parcelable implementations.
+ */
+ protected static <T extends Filter> Parcelable.Creator<T> creatorOf(Class<T> filterClass) {
+ return new FilterCreator<T>(filterClass);
+ }
+
+ /**
+ * Saves states for restoring filter later; subclasses can override this to persist states.
+ */
+ protected void writeToParcel(Parcel out) {
+ }
+
+ /**
+ * Restores filter from the saved states; subclasses can override this to persist states.
+ */
+ protected void readFromParcel(Parcel in) {
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ writeToParcel(dest);
+ }
}
diff --git a/src/com/android/gallery3d/photoeditor/filters/FilterCreator.java b/src/com/android/gallery3d/photoeditor/filters/FilterCreator.java
new file mode 100644
index 000000000..9b05244a8
--- /dev/null
+++ b/src/com/android/gallery3d/photoeditor/filters/FilterCreator.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.gallery3d.photoeditor.filters;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.lang.reflect.Array;
+
+/**
+ * Creator that creates the specific parcelable filter from the parcel.
+ */
+public class FilterCreator<T extends Filter> implements Parcelable.Creator<T> {
+
+ private final Class<T> filterClass;
+
+ public FilterCreator(Class<T> filterClass) {
+ this.filterClass = filterClass;
+ }
+
+ @Override
+ public T createFromParcel(Parcel source) {
+ try {
+ T filter = filterClass.newInstance();
+ filter.readFromParcel(source);
+ return filter;
+ } catch (InstantiationException e) {
+ throw new RuntimeException(e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public T[] newArray(int size) {
+ return (T[]) Array.newInstance(filterClass, size);
+ }
+}
diff --git a/src/com/android/gallery3d/photoeditor/filters/FisheyeFilter.java b/src/com/android/gallery3d/photoeditor/filters/FisheyeFilter.java
index 6bd406c1c..7fe6108c9 100644
--- a/src/com/android/gallery3d/photoeditor/filters/FisheyeFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/FisheyeFilter.java
@@ -24,19 +24,9 @@ import com.android.gallery3d.photoeditor.Photo;
/**
* Fisheye filter applied to the image.
*/
-public class FisheyeFilter extends Filter {
+public class FisheyeFilter extends AbstractScaleFilter {
- private float scale;
-
- /**
- * Sets the fisheye distortion level.
- *
- * @param scale ranges from 0 to 1.
- */
- public void setScale(float scale) {
- this.scale = scale;
- validate();
- }
+ public static final Creator<FisheyeFilter> CREATOR = creatorOf(FisheyeFilter.class);
@Override
public void process(Photo src, Photo dst) {
diff --git a/src/com/android/gallery3d/photoeditor/filters/FlipFilter.java b/src/com/android/gallery3d/photoeditor/filters/FlipFilter.java
index 7035912a5..816aad87d 100644
--- a/src/com/android/gallery3d/photoeditor/filters/FlipFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/FlipFilter.java
@@ -18,6 +18,7 @@ package com.android.gallery3d.photoeditor.filters;
import android.media.effect.Effect;
import android.media.effect.EffectFactory;
+import android.os.Parcel;
import com.android.gallery3d.photoeditor.Photo;
@@ -26,20 +27,31 @@ import com.android.gallery3d.photoeditor.Photo;
*/
public class FlipFilter extends Filter {
- private boolean flipHorizontal;
- private boolean flipVertical;
+ public static final Creator<FlipFilter> CREATOR = creatorOf(FlipFilter.class);
+
+ private final boolean[] flips = new boolean[2];
public void setFlip(boolean flipHorizontal, boolean flipVertical) {
- this.flipHorizontal = flipHorizontal;
- this.flipVertical = flipVertical;
+ flips[0] = flipHorizontal;
+ flips[1] = flipVertical;
validate();
}
@Override
public void process(Photo src, Photo dst) {
Effect effect = getEffect(EffectFactory.EFFECT_FLIP);
- effect.setParameter("horizontal", flipHorizontal);
- effect.setParameter("vertical", flipVertical);
+ effect.setParameter("horizontal", flips[0]);
+ effect.setParameter("vertical", flips[1]);
effect.apply(src.texture(), src.width(), src.height(), dst.texture());
}
+
+ @Override
+ protected void writeToParcel(Parcel out) {
+ out.writeBooleanArray(flips);
+ }
+
+ @Override
+ protected void readFromParcel(Parcel in) {
+ in.readBooleanArray(flips);
+ }
}
diff --git a/src/com/android/gallery3d/photoeditor/filters/GrainFilter.java b/src/com/android/gallery3d/photoeditor/filters/GrainFilter.java
index ddaad7a25..04867c6ac 100644
--- a/src/com/android/gallery3d/photoeditor/filters/GrainFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/GrainFilter.java
@@ -24,19 +24,9 @@ import com.android.gallery3d.photoeditor.Photo;
/**
* Film grain filter applied to the image.
*/
-public class GrainFilter extends Filter {
+public class GrainFilter extends AbstractScaleFilter {
- private float scale;
-
- /**
- * Set the grain noise level.
- *
- * @param scale ranges from 0 to 1.
- */
- public void setScale(float scale) {
- this.scale = scale;
- validate();
- }
+ public static final Creator<GrainFilter> CREATOR = creatorOf(GrainFilter.class);
@Override
public void process(Photo src, Photo dst) {
diff --git a/src/com/android/gallery3d/photoeditor/filters/GrayscaleFilter.java b/src/com/android/gallery3d/photoeditor/filters/GrayscaleFilter.java
index d5ef8a0c0..38dfb528a 100644
--- a/src/com/android/gallery3d/photoeditor/filters/GrayscaleFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/GrayscaleFilter.java
@@ -25,6 +25,8 @@ import com.android.gallery3d.photoeditor.Photo;
*/
public class GrayscaleFilter extends Filter {
+ public static final Creator<GrayscaleFilter> CREATOR = creatorOf(GrayscaleFilter.class);
+
public GrayscaleFilter() {
validate();
}
diff --git a/src/com/android/gallery3d/photoeditor/filters/HighlightFilter.java b/src/com/android/gallery3d/photoeditor/filters/HighlightFilter.java
index dfaaa6580..e079c2e58 100644
--- a/src/com/android/gallery3d/photoeditor/filters/HighlightFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/HighlightFilter.java
@@ -24,25 +24,15 @@ import com.android.gallery3d.photoeditor.Photo;
/**
* Highlight filter applied to the image.
*/
-public class HighlightFilter extends Filter {
+public class HighlightFilter extends AbstractScaleFilter {
- private float white;
-
- /**
- * Sets the highlight level.
- *
- * @param highlight ranges from 0 to 1.
- */
- public void setHighlight(float highlight) {
- white = 1f - highlight * 0.5f;
- validate();
- }
+ public static final Creator<HighlightFilter> CREATOR = creatorOf(HighlightFilter.class);
@Override
public void process(Photo src, Photo dst) {
Effect effect = getEffect(EffectFactory.EFFECT_BLACKWHITE);
effect.setParameter("black", 0f);
- effect.setParameter("white", white);
+ effect.setParameter("white", 1f - scale * 0.5f);
effect.apply(src.texture(), src.width(), src.height(), dst.texture());
}
}
diff --git a/src/com/android/gallery3d/photoeditor/filters/LomoishFilter.java b/src/com/android/gallery3d/photoeditor/filters/LomoishFilter.java
index 140f2d6f6..f8c517314 100644
--- a/src/com/android/gallery3d/photoeditor/filters/LomoishFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/LomoishFilter.java
@@ -25,6 +25,8 @@ import com.android.gallery3d.photoeditor.Photo;
*/
public class LomoishFilter extends Filter {
+ public static final Creator<LomoishFilter> CREATOR = creatorOf(LomoishFilter.class);
+
public LomoishFilter() {
validate();
}
diff --git a/src/com/android/gallery3d/photoeditor/filters/NegativeFilter.java b/src/com/android/gallery3d/photoeditor/filters/NegativeFilter.java
index 94bf87e95..88bbd58ac 100644
--- a/src/com/android/gallery3d/photoeditor/filters/NegativeFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/NegativeFilter.java
@@ -25,6 +25,8 @@ import com.android.gallery3d.photoeditor.Photo;
*/
public class NegativeFilter extends Filter {
+ public static final Creator<NegativeFilter> CREATOR = creatorOf(NegativeFilter.class);
+
public NegativeFilter() {
validate();
}
diff --git a/src/com/android/gallery3d/photoeditor/filters/PosterizeFilter.java b/src/com/android/gallery3d/photoeditor/filters/PosterizeFilter.java
index 96f598563..186baa9cb 100644
--- a/src/com/android/gallery3d/photoeditor/filters/PosterizeFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/PosterizeFilter.java
@@ -25,6 +25,8 @@ import com.android.gallery3d.photoeditor.Photo;
*/
public class PosterizeFilter extends Filter {
+ public static final Creator<PosterizeFilter> CREATOR = creatorOf(PosterizeFilter.class);
+
public PosterizeFilter() {
validate();
}
diff --git a/src/com/android/gallery3d/photoeditor/filters/RedEyeFilter.java b/src/com/android/gallery3d/photoeditor/filters/RedEyeFilter.java
index b49915427..257d3229e 100644
--- a/src/com/android/gallery3d/photoeditor/filters/RedEyeFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/RedEyeFilter.java
@@ -19,6 +19,7 @@ package com.android.gallery3d.photoeditor.filters;
import android.graphics.PointF;
import android.media.effect.Effect;
import android.media.effect.EffectFactory;
+import android.os.Parcel;
import com.android.gallery3d.photoeditor.Photo;
@@ -29,6 +30,8 @@ import java.util.Vector;
*/
public class RedEyeFilter extends Filter {
+ public static final Creator<RedEyeFilter> CREATOR = creatorOf(RedEyeFilter.class);
+
private final Vector<PointF> redeyes = new Vector<PointF>();
/**
@@ -51,4 +54,20 @@ public class RedEyeFilter extends Filter {
effect.setParameter("centers", centers);
effect.apply(src.texture(), src.width(), src.height(), dst.texture());
}
+
+ @Override
+ protected void writeToParcel(Parcel out) {
+ out.writeInt(redeyes.size());
+ for (PointF eye : redeyes) {
+ out.writeParcelable(eye, 0);
+ }
+ }
+
+ @Override
+ protected void readFromParcel(Parcel in) {
+ int size = in.readInt();
+ for (int i = 0; i < size; i++) {
+ redeyes.add((PointF) in.readParcelable(null));
+ }
+ }
}
diff --git a/src/com/android/gallery3d/photoeditor/filters/RotateFilter.java b/src/com/android/gallery3d/photoeditor/filters/RotateFilter.java
index 548cc592b..d377f96b4 100644
--- a/src/com/android/gallery3d/photoeditor/filters/RotateFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/RotateFilter.java
@@ -18,6 +18,7 @@ package com.android.gallery3d.photoeditor.filters;
import android.media.effect.Effect;
import android.media.effect.EffectFactory;
+import android.os.Parcel;
import com.android.gallery3d.photoeditor.Photo;
@@ -26,6 +27,8 @@ import com.android.gallery3d.photoeditor.Photo;
*/
public class RotateFilter extends Filter {
+ public static final Creator<RotateFilter> CREATOR = creatorOf(RotateFilter.class);
+
private float degrees;
public void setAngle(float degrees) {
@@ -42,4 +45,14 @@ public class RotateFilter extends Filter {
effect.setParameter("angle", (int) degrees);
effect.apply(src.texture(), src.width(), src.height(), dst.texture());
}
+
+ @Override
+ protected void writeToParcel(Parcel out) {
+ out.writeFloat(degrees);
+ }
+
+ @Override
+ protected void readFromParcel(Parcel in) {
+ degrees = in.readFloat();
+ }
}
diff --git a/src/com/android/gallery3d/photoeditor/filters/SaturationFilter.java b/src/com/android/gallery3d/photoeditor/filters/SaturationFilter.java
index b2c7ccedc..af08a7b9c 100644
--- a/src/com/android/gallery3d/photoeditor/filters/SaturationFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/SaturationFilter.java
@@ -24,24 +24,14 @@ import com.android.gallery3d.photoeditor.Photo;
/**
* Saturation filter applied to the image.
*/
-public class SaturationFilter extends Filter {
+public class SaturationFilter extends AbstractScaleFilter {
- private float scale;
-
- /**
- * Sets the saturation level.
- *
- * @param scale ranges from 0 to 1.
- */
- public void setSaturation(float scale) {
- this.scale = (scale - 0.5f) * 2;
- validate();
- }
+ public static final Creator<SaturationFilter> CREATOR = creatorOf(SaturationFilter.class);
@Override
public void process(Photo src, Photo dst) {
Effect effect = getEffect(EffectFactory.EFFECT_SATURATE);
- effect.setParameter("scale", scale);
+ effect.setParameter("scale", (scale - 0.5f) * 2);
effect.apply(src.texture(), src.width(), src.height(), dst.texture());
}
}
diff --git a/src/com/android/gallery3d/photoeditor/filters/SepiaFilter.java b/src/com/android/gallery3d/photoeditor/filters/SepiaFilter.java
index 170b95d88..6c1a70ef1 100644
--- a/src/com/android/gallery3d/photoeditor/filters/SepiaFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/SepiaFilter.java
@@ -25,6 +25,8 @@ import com.android.gallery3d.photoeditor.Photo;
*/
public class SepiaFilter extends Filter {
+ public static final Creator<SepiaFilter> CREATOR = creatorOf(SepiaFilter.class);
+
public SepiaFilter() {
validate();
}
diff --git a/src/com/android/gallery3d/photoeditor/filters/ShadowFilter.java b/src/com/android/gallery3d/photoeditor/filters/ShadowFilter.java
index 793187473..03960e405 100644
--- a/src/com/android/gallery3d/photoeditor/filters/ShadowFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/ShadowFilter.java
@@ -24,24 +24,14 @@ import com.android.gallery3d.photoeditor.Photo;
/**
* Shadow filter applied to the image.
*/
-public class ShadowFilter extends Filter {
+public class ShadowFilter extends AbstractScaleFilter {
- private float black;
-
- /**
- * Sets the shadow blackness level.
- *
- * @param shadow ranges from 0 to 1.
- */
- public void setShadow(float shadow) {
- black = shadow * 0.5f;
- validate();
- }
+ public static final Creator<ShadowFilter> CREATOR = creatorOf(ShadowFilter.class);
@Override
public void process(Photo src, Photo dst) {
Effect effect = getEffect(EffectFactory.EFFECT_BLACKWHITE);
- effect.setParameter("black", black);
+ effect.setParameter("black", scale * 0.5f);
effect.setParameter("white", 1f);
effect.apply(src.texture(), src.width(), src.height(), dst.texture());
}
diff --git a/src/com/android/gallery3d/photoeditor/filters/SharpenFilter.java b/src/com/android/gallery3d/photoeditor/filters/SharpenFilter.java
index e6f7cd59a..f066dcf75 100644
--- a/src/com/android/gallery3d/photoeditor/filters/SharpenFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/SharpenFilter.java
@@ -24,19 +24,9 @@ import com.android.gallery3d.photoeditor.Photo;
/**
* Sharpen filter applied to the image.
*/
-public class SharpenFilter extends Filter {
+public class SharpenFilter extends AbstractScaleFilter {
- private float scale;
-
- /**
- * Sets the sharpen level.
- *
- * @param scale ranges from 0 to 1.
- */
- public void setSharpen(float scale) {
- this.scale = scale;
- validate();
- }
+ public static final Creator<SharpenFilter> CREATOR = creatorOf(SharpenFilter.class);
@Override
public void process(Photo src, Photo dst) {
diff --git a/src/com/android/gallery3d/photoeditor/filters/StraightenFilter.java b/src/com/android/gallery3d/photoeditor/filters/StraightenFilter.java
index 30a8ac58f..90738f0f3 100644
--- a/src/com/android/gallery3d/photoeditor/filters/StraightenFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/StraightenFilter.java
@@ -18,6 +18,7 @@ package com.android.gallery3d.photoeditor.filters;
import android.media.effect.Effect;
import android.media.effect.EffectFactory;
+import android.os.Parcel;
import com.android.gallery3d.photoeditor.Photo;
@@ -26,12 +27,13 @@ import com.android.gallery3d.photoeditor.Photo;
*/
public class StraightenFilter extends Filter {
+ public static final Creator<StraightenFilter> CREATOR = creatorOf(StraightenFilter.class);
public static final float MAX_DEGREES = 30.0f;
- private float angle;
+ private float degrees;
public void setAngle(float degrees) {
- angle = -degrees;
+ this.degrees = degrees;
validate();
}
@@ -39,7 +41,17 @@ public class StraightenFilter extends Filter {
public void process(Photo src, Photo dst) {
Effect effect = getEffect(EffectFactory.EFFECT_STRAIGHTEN);
effect.setParameter("maxAngle", MAX_DEGREES);
- effect.setParameter("angle", angle);
+ effect.setParameter("angle", -degrees);
effect.apply(src.texture(), src.width(), src.height(), dst.texture());
}
+
+ @Override
+ protected void writeToParcel(Parcel out) {
+ out.writeFloat(degrees);
+ }
+
+ @Override
+ protected void readFromParcel(Parcel in) {
+ degrees = in.readFloat();
+ }
}
diff --git a/src/com/android/gallery3d/photoeditor/filters/TintFilter.java b/src/com/android/gallery3d/photoeditor/filters/TintFilter.java
index e5e467bc0..af3d77773 100644
--- a/src/com/android/gallery3d/photoeditor/filters/TintFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/TintFilter.java
@@ -18,6 +18,7 @@ package com.android.gallery3d.photoeditor.filters;
import android.media.effect.Effect;
import android.media.effect.EffectFactory;
+import android.os.Parcel;
import com.android.gallery3d.photoeditor.Photo;
@@ -26,17 +27,29 @@ import com.android.gallery3d.photoeditor.Photo;
*/
public class TintFilter extends Filter {
- private int tint;
+ public static final Creator<TintFilter> CREATOR = creatorOf(TintFilter.class);
+
+ private int color;
public void setTint(int color) {
- tint = color;
+ this.color = color;
validate();
}
@Override
public void process(Photo src, Photo dst) {
Effect effect = getEffect(EffectFactory.EFFECT_TINT);
- effect.setParameter("tint", tint);
+ effect.setParameter("tint", color);
effect.apply(src.texture(), src.width(), src.height(), dst.texture());
}
+
+ @Override
+ protected void writeToParcel(Parcel out) {
+ out.writeInt(color);
+ }
+
+ @Override
+ protected void readFromParcel(Parcel in) {
+ color = in.readInt();
+ }
}
diff --git a/src/com/android/gallery3d/photoeditor/filters/VignetteFilter.java b/src/com/android/gallery3d/photoeditor/filters/VignetteFilter.java
index ec393938f..59034615f 100644
--- a/src/com/android/gallery3d/photoeditor/filters/VignetteFilter.java
+++ b/src/com/android/gallery3d/photoeditor/filters/VignetteFilter.java
@@ -24,19 +24,9 @@ import com.android.gallery3d.photoeditor.Photo;
/**
* Vignette filter applied to the image.
*/
-public class VignetteFilter extends Filter {
+public class VignetteFilter extends AbstractScaleFilter {
- private float scale;
-
- /**
- * Sets the vignette range scale.
- *
- * @param scale ranges from 0 to 1.
- */
- public void setScale(float scale) {
- this.scale = scale;
- validate();
- }
+ public static final Creator<VignetteFilter> CREATOR = creatorOf(VignetteFilter.class);
@Override
public void process(Photo src, Photo dst) {