diff options
Diffstat (limited to 'src/com/android/gallery3d')
41 files changed, 484 insertions, 248 deletions
diff --git a/src/com/android/gallery3d/photoeditor/FilterStack.java b/src/com/android/gallery3d/photoeditor/FilterStack.java index 7a155096a..7194575a3 100644 --- a/src/com/android/gallery3d/photoeditor/FilterStack.java +++ b/src/com/android/gallery3d/photoeditor/FilterStack.java @@ -17,9 +17,11 @@ package com.android.gallery3d.photoeditor; import android.graphics.Bitmap; +import android.os.Bundle; import com.android.gallery3d.photoeditor.filters.Filter; +import java.util.ArrayList; import java.util.Stack; /** @@ -35,6 +37,9 @@ public class FilterStack { void onStackChanged(boolean canUndo, boolean canRedo); } + private static final String APPLIED_STACK_KEY = "applied_stack"; + private static final String REDO_STACK_KEY = "redo_stack"; + private final Stack<Filter> appliedStack = new Stack<Filter>(); private final Stack<Filter> redoStack = new Stack<Filter>(); @@ -45,12 +50,28 @@ public class FilterStack { private Photo source; private Runnable queuedTopFilterChange; - private boolean topFilterOutputted; + private boolean outputTopFilter; private volatile boolean paused; - public FilterStack(PhotoView photoView, StackListener stackListener) { + public FilterStack(PhotoView photoView, StackListener stackListener, Bundle savedState) { this.photoView = photoView; this.stackListener = stackListener; + if (savedState != null) { + appliedStack.addAll(getFilters(savedState, APPLIED_STACK_KEY)); + redoStack.addAll(getFilters(savedState, REDO_STACK_KEY)); + outputTopFilter = true; + stackChanged(); + } + } + + private ArrayList<Filter> getFilters(Bundle savedState, String key) { + // Infer Filter array-list from the Parcelable array-list by the specified returned type. + return savedState.getParcelableArrayList(key); + } + + public void saveStacks(Bundle outState) { + outState.putParcelableArrayList(APPLIED_STACK_KEY, new ArrayList<Filter>(appliedStack)); + outState.putParcelableArrayList(REDO_STACK_KEY, new ArrayList<Filter>(redoStack)); } private void reallocateBuffer(int target) { @@ -72,18 +93,19 @@ public class FilterStack { // Source photo will be displayed if there is no filter stacked. Photo photo = source; - int size = topFilterOutputted ? appliedStack.size() : appliedStack.size() - 1; + int size = outputTopFilter ? appliedStack.size() : appliedStack.size() - 1; for (int i = 0; i < size && !paused; i++) { photo = runFilter(i); } - photoView.setPhoto(photo, topFilterOutputted); + // Clear photo-view transformation when the top filter will be outputted. + photoView.setPhoto(photo, outputTopFilter); } } private void invalidateTopFilter() { if (!appliedStack.empty()) { + outputTopFilter = true; photoView.setPhoto(runFilter(appliedStack.size() - 1), true); - topFilterOutputted = true; } } @@ -133,12 +155,12 @@ public class FilterStack { }); } - public void saveBitmap(final OnDoneBitmapCallback callback) { + public void getOutputBitmap(final OnDoneBitmapCallback callback) { photoView.queue(new Runnable() { @Override public void run() { - int filterIndex = appliedStack.size() - (topFilterOutputted ? 1 : 2); + int filterIndex = appliedStack.size() - (outputTopFilter ? 1 : 2); Photo photo = (filterIndex < 0) ? source : buffers[getOutBufferIndex(filterIndex)]; final Bitmap bitmap = (photo != null) ? photo.save() : null; photoView.post(new Runnable() { @@ -166,7 +188,7 @@ public class FilterStack { private void pushFilterInternal(Filter filter) { appliedStack.push(filter); - topFilterOutputted = false; + outputTopFilter = false; stackChanged(); } diff --git a/src/com/android/gallery3d/photoeditor/PhotoEditor.java b/src/com/android/gallery3d/photoeditor/PhotoEditor.java index 2294d0316..78d414d9f 100644 --- a/src/com/android/gallery3d/photoeditor/PhotoEditor.java +++ b/src/com/android/gallery3d/photoeditor/PhotoEditor.java @@ -53,7 +53,7 @@ public class PhotoEditor extends Activity { public void onStackChanged(boolean canUndo, boolean canRedo) { actionBar.updateButtons(canUndo, canRedo); } - }); + }, savedInstanceState); EffectsBar effectsBar = (EffectsBar) findViewById(R.id.effects_bar); effectsBar.initialize(filterStack); @@ -125,7 +125,7 @@ public class PhotoEditor extends Activity { @Override public void run() { final SpinnerProgressDialog progressDialog = createProgressDialog(); - filterStack.saveBitmap(new OnDoneBitmapCallback() { + filterStack.getOutputBitmap(new OnDoneBitmapCallback() { @Override public void onDone(Bitmap bitmap) { @@ -200,6 +200,12 @@ public class PhotoEditor extends Activity { } @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + filterStack.saveStacks(outState); + } + + @Override public void onBackPressed() { actionBar.clickBack(); } diff --git a/src/com/android/gallery3d/photoeditor/actions/ColorTemperatureAction.java b/src/com/android/gallery3d/photoeditor/actions/ColorTemperatureAction.java index 41a89dbbe..24978faf0 100644 --- a/src/com/android/gallery3d/photoeditor/actions/ColorTemperatureAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/ColorTemperatureAction.java @@ -44,7 +44,7 @@ public class ColorTemperatureAction extends EffectAction { @Override public void onProgressChanged(float progress, boolean fromUser) { if (fromUser) { - filter.setColorTemperature(progress); + filter.setScale(progress); notifyFilterChanged(filter, true); } } diff --git a/src/com/android/gallery3d/photoeditor/actions/Doodle.java b/src/com/android/gallery3d/photoeditor/actions/Doodle.java new file mode 100644 index 000000000..ea23e2380 --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/actions/Doodle.java @@ -0,0 +1,122 @@ +/* + * 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.actions; + +import android.graphics.Color; +import android.graphics.Matrix; +import android.graphics.Paint; +import android.graphics.Path; +import android.graphics.PointF; +import android.graphics.RectF; +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.Vector; + +/** + * Doodle that consists of a color and doodling path for drawing. + */ +public class Doodle implements Parcelable { + + private final int color; + private final Path normalizedPath = new Path(); + private final Vector<PointF> points = new Vector<PointF>(); + + /** + * Creates paint for doodles. + */ + public static Paint createPaint() { + Paint paint = new Paint(Paint.DITHER_FLAG | Paint.ANTI_ALIAS_FLAG); + paint.setStyle(Paint.Style.STROKE); + paint.setStrokeJoin(Paint.Join.ROUND); + paint.setStrokeCap(Paint.Cap.ROUND); + paint.setStrokeWidth(15); + return paint; + } + + public Doodle(int color, PointF startPoint) { + this.color = Color.argb(192, Color.red(color), Color.green(color), Color.blue(color)); + normalizedPath.moveTo(startPoint.x, startPoint.y); + points.add(startPoint); + } + + /** + * Adds control points whose coordinates range from 0 to 1 to construct the doodle path. + * + * @return true if the constructed path is in (0, 0, 1, 1) bounds; otherwise, false. + */ + public boolean addControlPoint(PointF point) { + PointF last = points.lastElement(); + normalizedPath.quadTo(last.x, last.y, (last.x + point.x) / 2, (last.y + point.y) / 2); + points.add(point); + + RectF r = new RectF(); + normalizedPath.computeBounds(r, false); + return r.intersects(0, 0, 1, 1); + } + + public int getColor() { + return color; + } + + public boolean isEmpty() { + return normalizedPath.isEmpty(); + } + + /** + * Gets the drawing path from the normalized doodle path. + */ + public void getDrawingPath(Matrix matrix, Path path) { + path.set(normalizedPath); + path.transform(matrix); + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(color); + dest.writeInt(points.size()); + for (PointF point : points) { + dest.writeParcelable(point, 0); + } + } + + public static final Parcelable.Creator<Doodle> CREATOR = new Parcelable.Creator<Doodle>() { + + @Override + public Doodle createFromParcel(Parcel source) { + int color = source.readInt(); + int size = source.readInt(); + if (size > 0) { + Doodle doodle = new Doodle(color, (PointF) source.readParcelable(null)); + for (int i = 1; i < size; i++) { + doodle.addControlPoint((PointF) source.readParcelable(null)); + } + return doodle; + } + return new Doodle(color, new PointF(0, 0)); + } + + @Override + public Doodle[] newArray(int size) { + return new Doodle[size]; + }}; +} diff --git a/src/com/android/gallery3d/photoeditor/actions/DoodleAction.java b/src/com/android/gallery3d/photoeditor/actions/DoodleAction.java index b82414dc8..4ad2cfb11 100644 --- a/src/com/android/gallery3d/photoeditor/actions/DoodleAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/DoodleAction.java @@ -17,7 +17,6 @@ package com.android.gallery3d.photoeditor.actions; import android.content.Context; -import android.graphics.Path; import android.util.AttributeSet; import com.android.gallery3d.photoeditor.filters.DoodleFilter; @@ -64,8 +63,8 @@ public class DoodleAction extends EffectAction { } @Override - public void onDoodleFinished(Path path, int color) { - filter.addPath(path, color); + public void onDoodleFinished(Doodle doodle) { + filter.addDoodle(doodle); notifyFilterChanged(filter, false); } }); diff --git a/src/com/android/gallery3d/photoeditor/actions/DoodleView.java b/src/com/android/gallery3d/photoeditor/actions/DoodleView.java index cc5af84be..b59686151 100644 --- a/src/com/android/gallery3d/photoeditor/actions/DoodleView.java +++ b/src/com/android/gallery3d/photoeditor/actions/DoodleView.java @@ -19,7 +19,6 @@ package com.android.gallery3d.photoeditor.actions; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; -import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Path; @@ -40,19 +39,20 @@ class DoodleView extends FullscreenToolView { void onDoodleInPhotoBounds(); - void onDoodleFinished(Path path, int color); + void onDoodleFinished(Doodle doodle); } - private final Path normalizedPath = new Path(); - private final Path drawingPath = new Path(); - private final Paint doodlePaint = new DoodlePaint(); private final Paint bitmapPaint = new Paint(Paint.DITHER_FLAG); + private final Paint doodlePaint = Doodle.createPaint(); private final PointF lastPoint = new PointF(); - private final Matrix pathMatrix = new Matrix(); + private final Path drawingPath = new Path(); + private final Matrix drawingMatrix = new Matrix(); private final Matrix displayMatrix = new Matrix(); private Bitmap bitmap; private Canvas bitmapCanvas; + private Doodle doodle; + private int color; private OnDoodleChangeListener listener; public DoodleView(Context context, AttributeSet attrs) { @@ -71,50 +71,51 @@ class DoodleView extends FullscreenToolView { if ((bitmap == null) && !r.isEmpty()) { bitmap = Bitmap.createBitmap((int) r.width(), (int) r.height(), Bitmap.Config.ARGB_8888); - bitmap.eraseColor(0x00000000); bitmapCanvas = new Canvas(bitmap); // Set up a matrix that maps back normalized paths to be drawn on the bitmap or canvas. - pathMatrix.setRectToRect(new RectF(0, 0, 1, 1), r, Matrix.ScaleToFit.FILL); + drawingMatrix.setRectToRect(new RectF(0, 0, 1, 1), r, Matrix.ScaleToFit.FILL); } displayMatrix.setRectToRect(r, displayBounds, Matrix.ScaleToFit.FILL); } private void drawDoodle(Canvas canvas) { - if ((canvas != null) && !normalizedPath.isEmpty()) { - drawingPath.set(normalizedPath); - drawingPath.transform(pathMatrix); + if ((canvas != null) && (doodle != null)) { + doodlePaint.setColor(doodle.getColor()); + doodle.getDrawingPath(drawingMatrix, drawingPath); canvas.drawPath(drawingPath, doodlePaint); } } public void setColor(int color) { - // Reset path to draw in a new color. - finishCurrentPath(); - normalizedPath.moveTo(lastPoint.x, lastPoint.y); - doodlePaint.setColor(Color.argb(192, Color.red(color), Color.green(color), - Color.blue(color))); + // Restart doodle to draw in a new color. + this.color = color; + finishDoodle(); + startDoodle(); + } + + private void startDoodle() { + doodle = new Doodle(color, new PointF(lastPoint.x, lastPoint.y)); } - private void finishCurrentPath() { - if (!normalizedPath.isEmpty()) { - // Update the finished path to the bitmap. + private void finishDoodle() { + if ((doodle != null) && !doodle.isEmpty()) { + // Update the finished non-empty doodle to the bitmap. drawDoodle(bitmapCanvas); if (listener != null) { - listener.onDoodleFinished(new Path(normalizedPath), doodlePaint.getColor()); + listener.onDoodleFinished(doodle); } - normalizedPath.rewind(); invalidate(); } + doodle = null; } - private void checkCurrentPathInBounds() { - if ((listener != null) && !normalizedPath.isEmpty()) { - RectF r = new RectF(); - normalizedPath.computeBounds(r, false); - if (r.intersects(0, 0, 1, 1)) { + private void addLastPointIntoDoodle() { + if ((doodle != null) && doodle.addControlPoint(new PointF(lastPoint.x, lastPoint.y))) { + if (listener != null) { listener.onDoodleInPhotoBounds(); } + invalidate(); } } @@ -129,26 +130,20 @@ class DoodleView extends FullscreenToolView { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mapPhotoPoint(x, y, lastPoint); - normalizedPath.moveTo(lastPoint.x, lastPoint.y); + startDoodle(); break; case MotionEvent.ACTION_MOVE: - float lastX = lastPoint.x; - float lastY = lastPoint.y; mapPhotoPoint(x, y, lastPoint); - normalizedPath.quadTo(lastX, lastY, (lastX + lastPoint.x) / 2, - (lastY + lastPoint.y) / 2); - checkCurrentPathInBounds(); - invalidate(); + addLastPointIntoDoodle(); break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: // Line to last position with offset to draw at least dots for single clicks. mapPhotoPoint(x + 1, y + 1, lastPoint); - normalizedPath.lineTo(lastPoint.x, lastPoint.y); - checkCurrentPathInBounds(); - finishCurrentPath(); + addLastPointIntoDoodle(); + finishDoodle(); break; } } diff --git a/src/com/android/gallery3d/photoeditor/actions/FillLightAction.java b/src/com/android/gallery3d/photoeditor/actions/FillLightAction.java index 962486bbf..73cf3d85d 100644 --- a/src/com/android/gallery3d/photoeditor/actions/FillLightAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/FillLightAction.java @@ -44,7 +44,7 @@ public class FillLightAction extends EffectAction { @Override public void onProgressChanged(float progress, boolean fromUser) { if (fromUser) { - filter.setBacklight(progress); + filter.setScale(progress); notifyFilterChanged(filter, true); } } diff --git a/src/com/android/gallery3d/photoeditor/actions/HighlightAction.java b/src/com/android/gallery3d/photoeditor/actions/HighlightAction.java index cd8f4b278..a3d62d286 100644 --- a/src/com/android/gallery3d/photoeditor/actions/HighlightAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/HighlightAction.java @@ -44,7 +44,7 @@ public class HighlightAction extends EffectAction { @Override public void onProgressChanged(float progress, boolean fromUser) { if (fromUser) { - filter.setHighlight(progress); + filter.setScale(progress); notifyFilterChanged(filter, true); } } diff --git a/src/com/android/gallery3d/photoeditor/actions/SaturationAction.java b/src/com/android/gallery3d/photoeditor/actions/SaturationAction.java index 31bcfd664..2f67e0a01 100644 --- a/src/com/android/gallery3d/photoeditor/actions/SaturationAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/SaturationAction.java @@ -44,7 +44,7 @@ public class SaturationAction extends EffectAction { @Override public void onProgressChanged(float progress, boolean fromUser) { if (fromUser) { - filter.setSaturation(progress); + filter.setScale(progress); notifyFilterChanged(filter, true); } } diff --git a/src/com/android/gallery3d/photoeditor/actions/ShadowAction.java b/src/com/android/gallery3d/photoeditor/actions/ShadowAction.java index 185febc7c..15ba8508f 100644 --- a/src/com/android/gallery3d/photoeditor/actions/ShadowAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/ShadowAction.java @@ -44,7 +44,7 @@ public class ShadowAction extends EffectAction { @Override public void onProgressChanged(float progress, boolean fromUser) { if (fromUser) { - filter.setShadow(progress); + filter.setScale(progress); notifyFilterChanged(filter, true); } } diff --git a/src/com/android/gallery3d/photoeditor/actions/SharpenAction.java b/src/com/android/gallery3d/photoeditor/actions/SharpenAction.java index 7524c76ec..c6b240b40 100644 --- a/src/com/android/gallery3d/photoeditor/actions/SharpenAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/SharpenAction.java @@ -44,14 +44,14 @@ public class SharpenAction extends EffectAction { @Override public void onProgressChanged(float progress, boolean fromUser) { if (fromUser) { - filter.setSharpen(progress); + filter.setScale(progress); notifyFilterChanged(filter, true); } } }); scalePicker.setProgress(DEFAULT_SCALE); - filter.setSharpen(DEFAULT_SCALE); + filter.setScale(DEFAULT_SCALE); notifyFilterChanged(filter, true); } diff --git a/src/com/android/gallery3d/photoeditor/actions/DoodlePaint.java b/src/com/android/gallery3d/photoeditor/filters/AbstractScaleFilter.java index bcde9f1b0..727a98cab 100644 --- a/src/com/android/gallery3d/photoeditor/actions/DoodlePaint.java +++ b/src/com/android/gallery3d/photoeditor/filters/AbstractScaleFilter.java @@ -14,21 +14,32 @@ * limitations under the License. */ -package com.android.gallery3d.photoeditor.actions; +package com.android.gallery3d.photoeditor.filters; -import android.graphics.Paint; +import android.os.Parcel; /** - * A paint class for doodle effect. + * Filter base that has a scale value ranging from 0 to 1 for adjustments and can persist states. */ -public class DoodlePaint extends Paint { +public abstract class AbstractScaleFilter extends Filter { - public DoodlePaint() { - super(Paint.DITHER_FLAG | Paint.ANTI_ALIAS_FLAG); + protected float scale; - setStyle(Paint.Style.STROKE); - setStrokeJoin(Paint.Join.ROUND); - setStrokeCap(Paint.Cap.ROUND); - setStrokeWidth(15); + /** + * 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) { |