diff options
author | Yuli Huang <yuli@google.com> | 2011-09-12 22:25:30 +0800 |
---|---|---|
committer | Yuli Huang <yuli@google.com> | 2011-09-13 00:36:00 +0800 |
commit | ab5055ac921f194f4d43f173881d17cf76719efd (patch) | |
tree | 7b1c64bd30c8185b6363069c006b701a9878cc34 /src/com/android/gallery3d/photoeditor/filters | |
parent | 6a5a246ca7973054364f5ee8ca2df3164bf38458 (diff) | |
download | android_packages_apps_Snap-ab5055ac921f194f4d43f173881d17cf76719efd.tar.gz android_packages_apps_Snap-ab5055ac921f194f4d43f173881d17cf76719efd.tar.bz2 android_packages_apps_Snap-ab5055ac921f194f4d43f173881d17cf76719efd.zip |
Fix b/4643148: Make PhotoEditor integrated into Gallery.
1. Move PhotoEditor code/resources into Gallery for single apk.
2. Change PhotoEditor package to com.android.gallery3d.photoeditor.
3. Rename PhotoEditor resources to avoid mess up Gallery resources.
4. Move Doodle effect from fix-effects to color-effects.
5. Update PhotoEditor bottom action-bar background.
Change-Id: I1a2f7d27d89a14fe6a0435575b993ed8b75e6bf4
Diffstat (limited to 'src/com/android/gallery3d/photoeditor/filters')
26 files changed, 1246 insertions, 0 deletions
diff --git a/src/com/android/gallery3d/photoeditor/filters/AutoFixFilter.java b/src/com/android/gallery3d/photoeditor/filters/AutoFixFilter.java new file mode 100644 index 000000000..a219abe8d --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/AutoFixFilter.java @@ -0,0 +1,48 @@ +/* + * 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.media.effect.Effect; +import android.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Auto-fix filter applied to the image. + */ +public class AutoFixFilter extends Filter { + + private float scale; + + /** + * Sets the auto-fix level. + * + * @param scale ranges from 0 to 1. + */ + public void setScale(float scale) { + this.scale = scale; + validate(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + Effect effect = getEffect(context, EffectFactory.EFFECT_AUTOFIX); + effect.setParameter("scale", scale); + effect.apply(src.texture(), src.width(), src.height(), dst.texture()); + } +} diff --git a/src/com/android/gallery3d/photoeditor/filters/ColorTemperatureFilter.java b/src/com/android/gallery3d/photoeditor/filters/ColorTemperatureFilter.java new file mode 100644 index 000000000..dc6f1a7b6 --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/ColorTemperatureFilter.java @@ -0,0 +1,48 @@ +/* + * 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.media.effect.Effect; +import android.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Color temperature filter applied to the image. + */ +public class ColorTemperatureFilter extends Filter { + + private float scale; + + /** + * Sets the color temperature level. + * + * @param scale ranges from 0 to 1. + */ + public void setColorTemperature(float scale) { + this.scale = scale; + validate(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + Effect effect = getEffect(context, EffectFactory.EFFECT_TEMPERATURE); + effect.setParameter("scale", scale); + effect.apply(src.texture(), src.width(), src.height(), dst.texture()); + } +} diff --git a/src/com/android/gallery3d/photoeditor/filters/CropFilter.java b/src/com/android/gallery3d/photoeditor/filters/CropFilter.java new file mode 100644 index 000000000..372279ee2 --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/CropFilter.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.graphics.RectF; +import android.media.effect.Effect; +import android.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Crop filter applied to the image. + */ +public class CropFilter extends Filter { + + private RectF bounds; + + /** + * The rect coordinates used here should range from 0 to 1. + */ + public void setCropBounds(RectF bounds) { + this.bounds = bounds; + validate(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + dst.changeDimension(Math.round(bounds.width() * src.width()), + Math.round(bounds.height() * src.height())); + + Effect effect = getEffect(context, EffectFactory.EFFECT_CROP); + effect.setParameter("xorigin", Math.round(bounds.left * src.width())); + effect.setParameter("yorigin", Math.round(bounds.top * src.height())); + effect.setParameter("width", dst.width()); + effect.setParameter("height", dst.height()); + effect.apply(src.texture(), src.width(), src.height(), dst.texture()); + } +} diff --git a/src/com/android/gallery3d/photoeditor/filters/CrossProcessFilter.java b/src/com/android/gallery3d/photoeditor/filters/CrossProcessFilter.java new file mode 100644 index 000000000..f03bf5fe9 --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/CrossProcessFilter.java @@ -0,0 +1,38 @@ +/* + * 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.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Cross-process filter applied to the image. + */ +public class CrossProcessFilter extends Filter { + + public CrossProcessFilter() { + validate(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + getEffect(context, EffectFactory.EFFECT_CROSSPROCESS).apply( + src.texture(), src.width(), src.height(), dst.texture()); + } +} diff --git a/src/com/android/gallery3d/photoeditor/filters/DocumentaryFilter.java b/src/com/android/gallery3d/photoeditor/filters/DocumentaryFilter.java new file mode 100644 index 000000000..800d59a05 --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/DocumentaryFilter.java @@ -0,0 +1,38 @@ +/* + * 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.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Documentary filter applied to the image. + */ +public class DocumentaryFilter extends Filter { + + public DocumentaryFilter() { + validate(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + getEffect(context, EffectFactory.EFFECT_DOCUMENTARY).apply( + src.texture(), src.width(), src.height(), dst.texture()); + } +} diff --git a/src/com/android/gallery3d/photoeditor/filters/DoodleFilter.java b/src/com/android/gallery3d/photoeditor/filters/DoodleFilter.java new file mode 100644 index 000000000..3c4bbf76e --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/DoodleFilter.java @@ -0,0 +1,88 @@ +/* + * 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.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Matrix; +import android.graphics.Paint; +import android.graphics.Path; +import android.graphics.RectF; +import android.media.effect.Effect; +import android.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; +import com.android.gallery3d.photoeditor.actions.DoodlePaint; + +import java.util.Vector; + +/** + * Doodle filter applied to the image. + */ +public class DoodleFilter extends Filter { + + private static class ColorPath { + private final int color; + private final Path path; + + ColorPath(int color, Path path) { + this.color = color; + this.path = path; + } + } + + private final Vector<ColorPath> doodles = new Vector<ColorPath>(); + + /** + * Signals once at least a doodle drawn within photo bounds; this filter is regarded as invalid + * (no-op on the photo) until not all its doodling is out of bounds. + */ + public void setDoodledInPhotoBounds() { + 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)); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + Bitmap bitmap = Bitmap.createBitmap(src.width(), src.height(), Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(bitmap); + + Matrix matrix = new Matrix(); + matrix.setRectToRect(new RectF(0, 0, 1, 1), + 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); + canvas.drawPath(drawingPath, paint); + } + + Effect effect = getEffect(context, EffectFactory.EFFECT_DOODLE); + effect.setParameter("doodle", bitmap); + effect.apply(src.texture(), src.width(), src.height(), dst.texture()); + } +} diff --git a/src/com/android/gallery3d/photoeditor/filters/DuotoneFilter.java b/src/com/android/gallery3d/photoeditor/filters/DuotoneFilter.java new file mode 100644 index 000000000..68db831ac --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/DuotoneFilter.java @@ -0,0 +1,46 @@ +/* + * 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.media.effect.Effect; +import android.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Duotone filter applied to the image. + */ +public class DuotoneFilter extends Filter { + + private int firstColor; + private int secondColor; + + public void setDuotone(int firstColor, int secondColor) { + this.firstColor = firstColor; + this.secondColor = secondColor; + validate(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + Effect effect = getEffect(context, EffectFactory.EFFECT_DUOTONE); + effect.setParameter("first_color", firstColor); + effect.setParameter("second_color", secondColor); + effect.apply(src.texture(), src.width(), src.height(), dst.texture()); + } +} diff --git a/src/com/android/gallery3d/photoeditor/filters/FillLightFilter.java b/src/com/android/gallery3d/photoeditor/filters/FillLightFilter.java new file mode 100644 index 000000000..a799e6f2a --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/FillLightFilter.java @@ -0,0 +1,48 @@ +/* + * 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.media.effect.Effect; +import android.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Fill-light filter applied to the image. + */ +public class FillLightFilter extends Filter { + + private float backlight; + + /** + * Sets the backlight level. + * + * @param backlight ranges from 0 to 1. + */ + public void setBacklight(float backlight) { + this.backlight = backlight; + validate(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + Effect effect = getEffect(context, EffectFactory.EFFECT_FILLLIGHT); + effect.setParameter("backlight", backlight); + 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 new file mode 100644 index 000000000..c2d3fe5af --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/Filter.java @@ -0,0 +1,72 @@ +/* + * 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.media.effect.Effect; +import android.media.effect.EffectContext; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Image filter for photo editing. + */ +public abstract class Filter { + + // TODO: This should be set in MFF instead. + private static final int DEFAULT_TILE_SIZE = 640; + + private boolean isValid; + private EffectContext context; + private Effect effect; + + protected void validate() { + isValid = true; + } + + protected Effect getEffect(EffectContext context, String name) { + if (this.context != context) { + effect = context.getFactory().createEffect(name); + effect.setParameter("tile_size", DEFAULT_TILE_SIZE); + this.context = context; + } + return effect; + } + + /** + * Some filters, e.g. lighting filters, are initially invalid until set up with parameters while + * others, e.g. Sepia or Posterize filters, are initially valid without parameters. + */ + public boolean isValid() { + return isValid; + } + + public void release() { + if (effect != null) { + effect.release(); + effect = null; + } + } + + /** + * Processes the source bitmap and matrix and output the destination bitmap and matrix. + * + * @param context effect context bound to a GL context to create GL effect. + * @param src source photo as the input. + * @param dst destination photo having the same dimension as source photo as the output. + */ + public abstract void process(EffectContext context, Photo src, Photo dst); +} diff --git a/src/com/android/gallery3d/photoeditor/filters/FisheyeFilter.java b/src/com/android/gallery3d/photoeditor/filters/FisheyeFilter.java new file mode 100644 index 000000000..b1eb2d131 --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/FisheyeFilter.java @@ -0,0 +1,48 @@ +/* + * 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.media.effect.Effect; +import android.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Fisheye filter applied to the image. + */ +public class FisheyeFilter extends Filter { + + private float scale; + + /** + * Sets the fisheye distortion level. + * + * @param scale ranges from 0 to 1. + */ + public void setScale(float scale) { + this.scale = scale; + validate(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + Effect effect = getEffect(context, EffectFactory.EFFECT_FISHEYE); + effect.setParameter("scale", scale); + effect.apply(src.texture(), src.width(), src.height(), dst.texture()); + } +} diff --git a/src/com/android/gallery3d/photoeditor/filters/FlipFilter.java b/src/com/android/gallery3d/photoeditor/filters/FlipFilter.java new file mode 100644 index 000000000..184f590a3 --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/FlipFilter.java @@ -0,0 +1,46 @@ +/* + * 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.media.effect.Effect; +import android.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Flip filter applied to the image. + */ +public class FlipFilter extends Filter { + + private boolean flipHorizontal; + private boolean flipVertical; + + public void setFlip(boolean flipHorizontal, boolean flipVertical) { + this.flipHorizontal = flipHorizontal; + this.flipVertical = flipVertical; + validate(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + Effect effect = getEffect(context, EffectFactory.EFFECT_FLIP); + effect.setParameter("horizontal", flipHorizontal); + effect.setParameter("vertical", flipVertical); + effect.apply(src.texture(), src.width(), src.height(), dst.texture()); + } +} diff --git a/src/com/android/gallery3d/photoeditor/filters/GrainFilter.java b/src/com/android/gallery3d/photoeditor/filters/GrainFilter.java new file mode 100644 index 000000000..1ee8a9c3f --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/GrainFilter.java @@ -0,0 +1,48 @@ +/* + * 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.media.effect.Effect; +import android.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Film grain filter applied to the image. + */ +public class GrainFilter extends Filter { + + private float scale; + + /** + * Set the grain noise level. + * + * @param scale ranges from 0 to 1. + */ + public void setScale(float scale) { + this.scale = scale; + validate(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + Effect effect = getEffect(context, EffectFactory.EFFECT_GRAIN); + effect.setParameter("scale", scale); + effect.apply(src.texture(), src.width(), src.height(), dst.texture()); + } +} diff --git a/src/com/android/gallery3d/photoeditor/filters/GrayscaleFilter.java b/src/com/android/gallery3d/photoeditor/filters/GrayscaleFilter.java new file mode 100644 index 000000000..ce6cdef9c --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/GrayscaleFilter.java @@ -0,0 +1,38 @@ +/* + * 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.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Grayscale filter applied to the image. + */ +public class GrayscaleFilter extends Filter { + + public GrayscaleFilter() { + validate(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + getEffect(context, EffectFactory.EFFECT_GRAYSCALE).apply( + src.texture(), src.width(), src.height(), dst.texture()); + } +} diff --git a/src/com/android/gallery3d/photoeditor/filters/HighlightFilter.java b/src/com/android/gallery3d/photoeditor/filters/HighlightFilter.java new file mode 100644 index 000000000..3169d043f --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/HighlightFilter.java @@ -0,0 +1,49 @@ +/* + * 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.media.effect.Effect; +import android.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Highlight filter applied to the image. + */ +public class HighlightFilter extends Filter { + + 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(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + Effect effect = getEffect(context, EffectFactory.EFFECT_BLACKWHITE); + effect.setParameter("black", 0f); + effect.setParameter("white", white); + 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 new file mode 100644 index 000000000..95ff62740 --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/LomoishFilter.java @@ -0,0 +1,38 @@ +/* + * 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.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Lomo-ish filter applied to the image. + */ +public class LomoishFilter extends Filter { + + public LomoishFilter() { + validate(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + getEffect(context, EffectFactory.EFFECT_LOMOISH).apply( + src.texture(), src.width(), src.height(), dst.texture()); + } +} diff --git a/src/com/android/gallery3d/photoeditor/filters/NegativeFilter.java b/src/com/android/gallery3d/photoeditor/filters/NegativeFilter.java new file mode 100644 index 000000000..0b3837f34 --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/NegativeFilter.java @@ -0,0 +1,38 @@ +/* + * 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.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Negative filter applied to the image. + */ +public class NegativeFilter extends Filter { + + public NegativeFilter() { + validate(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + getEffect(context, EffectFactory.EFFECT_NEGATIVE).apply( + src.texture(), src.width(), src.height(), dst.texture()); + } +} diff --git a/src/com/android/gallery3d/photoeditor/filters/PosterizeFilter.java b/src/com/android/gallery3d/photoeditor/filters/PosterizeFilter.java new file mode 100644 index 000000000..51202dcc1 --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/PosterizeFilter.java @@ -0,0 +1,38 @@ +/* + * 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.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Posterize filter applied to the image. + */ +public class PosterizeFilter extends Filter { + + public PosterizeFilter() { + validate(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + getEffect(context, EffectFactory.EFFECT_POSTERIZE).apply( + src.texture(), src.width(), src.height(), dst.texture()); + } +} diff --git a/src/com/android/gallery3d/photoeditor/filters/RedEyeFilter.java b/src/com/android/gallery3d/photoeditor/filters/RedEyeFilter.java new file mode 100644 index 000000000..559819d9c --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/RedEyeFilter.java @@ -0,0 +1,55 @@ +/* + * 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.graphics.PointF; +import android.media.effect.Effect; +import android.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +import java.util.Vector; + +/** + * Red-eye removal filter applied to the image. + */ +public class RedEyeFilter extends Filter { + + private final Vector<PointF> redeyes = new Vector<PointF>(); + + /** + * The point coordinates used here should range from 0 to 1. + */ + public void addRedEyePosition(PointF point) { + redeyes.add(point); + validate(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + Effect effect = getEffect(context, EffectFactory.EFFECT_REDEYE); + float[] centers = new float[redeyes.size() * 2]; + int i = 0; + for (PointF eye : redeyes) { + centers[i++] = eye.x; + centers[i++] = eye.y; + } + effect.setParameter("centers", centers); + effect.apply(src.texture(), src.width(), src.height(), dst.texture()); + } +} diff --git a/src/com/android/gallery3d/photoeditor/filters/RotateFilter.java b/src/com/android/gallery3d/photoeditor/filters/RotateFilter.java new file mode 100644 index 000000000..2823466d1 --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/RotateFilter.java @@ -0,0 +1,46 @@ +/* + * 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.media.effect.Effect; +import android.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Rotate filter applied to the image. + */ +public class RotateFilter extends Filter { + + private float degrees; + + public void setAngle(float degrees) { + this.degrees = degrees; + validate(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + if (degrees % 180 != 0) { + dst.changeDimension(src.height(), src.width()); + } + Effect effect = getEffect(context, EffectFactory.EFFECT_ROTATE); + effect.setParameter("degree", degrees); + effect.apply(src.texture(), src.width(), src.height(), dst.texture()); + } +} diff --git a/src/com/android/gallery3d/photoeditor/filters/SaturationFilter.java b/src/com/android/gallery3d/photoeditor/filters/SaturationFilter.java new file mode 100644 index 000000000..d3b5f704f --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/SaturationFilter.java @@ -0,0 +1,48 @@ +/* + * 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.media.effect.Effect; +import android.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Saturation filter applied to the image. + */ +public class SaturationFilter extends Filter { + + 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(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + Effect effect = getEffect(context, EffectFactory.EFFECT_SATURATE); + effect.setParameter("scale", scale); + 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 new file mode 100644 index 000000000..3fdda15f8 --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/SepiaFilter.java @@ -0,0 +1,38 @@ +/* + * 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.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Sepia filter applied to the image. + */ +public class SepiaFilter extends Filter { + + public SepiaFilter() { + validate(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + getEffect(context, EffectFactory.EFFECT_SEPIA).apply( + src.texture(), src.width(), src.height(), dst.texture()); + } +} diff --git a/src/com/android/gallery3d/photoeditor/filters/ShadowFilter.java b/src/com/android/gallery3d/photoeditor/filters/ShadowFilter.java new file mode 100644 index 000000000..b23ef1c67 --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/ShadowFilter.java @@ -0,0 +1,49 @@ +/* + * 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.media.effect.Effect; +import android.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Shadow filter applied to the image. + */ +public class ShadowFilter extends Filter { + + 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(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + Effect effect = getEffect(context, EffectFactory.EFFECT_BLACKWHITE); + effect.setParameter("black", black); + 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 new file mode 100644 index 000000000..a8097126f --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/SharpenFilter.java @@ -0,0 +1,48 @@ +/* + * 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.media.effect.Effect; +import android.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Sharpen filter applied to the image. + */ +public class SharpenFilter extends Filter { + + private float scale; + + /** + * Sets the sharpen level. + * + * @param scale ranges from 0 to 1. + */ + public void setSharpen(float scale) { + this.scale = scale; + validate(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + Effect effect = getEffect(context, EffectFactory.EFFECT_SHARPEN); + effect.setParameter("scale", scale); + effect.apply(src.texture(), src.width(), src.height(), dst.texture()); + } +} diff --git a/src/com/android/gallery3d/photoeditor/filters/StraightenFilter.java b/src/com/android/gallery3d/photoeditor/filters/StraightenFilter.java new file mode 100644 index 000000000..ffeb445a9 --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/StraightenFilter.java @@ -0,0 +1,46 @@ +/* + * 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.media.effect.Effect; +import android.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Straighten filter applied to the image. + */ +public class StraightenFilter extends Filter { + + public static final float MAX_DEGREES = 30.0f; + + private float angle; + + public void setAngle(float degrees) { + angle = -degrees; + validate(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + Effect effect = getEffect(context, EffectFactory.EFFECT_STRAIGHTEN); + effect.setParameter("maxAngle", MAX_DEGREES); + effect.setParameter("angle", angle); + effect.apply(src.texture(), src.width(), src.height(), dst.texture()); + } +} diff --git a/src/com/android/gallery3d/photoeditor/filters/TintFilter.java b/src/com/android/gallery3d/photoeditor/filters/TintFilter.java new file mode 100644 index 000000000..bbaf9c787 --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/TintFilter.java @@ -0,0 +1,43 @@ +/* + * 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.media.effect.Effect; +import android.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Tint filter applied to the image. + */ +public class TintFilter extends Filter { + + private int tint; + + public void setTint(int color) { + tint = color; + validate(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + Effect effect = getEffect(context, EffectFactory.EFFECT_TINT); + effect.setParameter("tint", tint); + effect.apply(src.texture(), src.width(), src.height(), dst.texture()); + } +} diff --git a/src/com/android/gallery3d/photoeditor/filters/VignetteFilter.java b/src/com/android/gallery3d/photoeditor/filters/VignetteFilter.java new file mode 100644 index 000000000..d066c8b7b --- /dev/null +++ b/src/com/android/gallery3d/photoeditor/filters/VignetteFilter.java @@ -0,0 +1,51 @@ +/* + * 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.media.effect.Effect; +import android.media.effect.EffectContext; +import android.media.effect.EffectFactory; + +import com.android.gallery3d.photoeditor.Photo; + +/** + * Vignette filter applied to the image. + */ +public class VignetteFilter extends Filter { + + private float range; + + /** + * Sets the vignette range scale. + * + * @param scale ranges from 0 to 1. + */ + public void setScale(float scale) { + // The 'range' is between 1.3 to 0.6. When scale is zero then range is 1.3 + // which means no vignette at all because the luminousity difference is + // less than 1/256 and will cause nothing. + range = 1.30f - (float) Math.sqrt(scale) * 0.7f; + validate(); + } + + @Override + public void process(EffectContext context, Photo src, Photo dst) { + Effect effect = getEffect(context, EffectFactory.EFFECT_VIGNETTE); + effect.setParameter("range", range); + effect.apply(src.texture(), src.width(), src.height(), dst.texture()); + } +} |