summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/filtershow/filters
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/gallery3d/filtershow/filters')
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterBasicRepresentation.java124
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterDirectRepresentation.java29
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java110
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilter.java98
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterBorder.java1
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterBwFilter.java18
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterContrast.java15
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java4
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterDownsample.java29
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterDraw.java1
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterEdge.java20
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterExposure.java15
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java1
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterHue.java19
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterKMeans.java34
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterNegative.java15
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterParametricBorder.java1
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterRedEye.java3
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterSaturated.java14
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterShadows.java14
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java23
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java10
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterVibrance.java15
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterVignette.java19
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterWBalance.java14
-rw-r--r--src/com/android/gallery3d/filtershow/filters/SimpleImageFilter.java50
26 files changed, 523 insertions, 173 deletions
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterBasicRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterBasicRepresentation.java
new file mode 100644
index 000000000..9e9c57ac5
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/filters/FilterBasicRepresentation.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2013 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.filtershow.filters;
+
+import com.android.gallery3d.app.Log;
+
+public class FilterBasicRepresentation extends FilterRepresentation {
+ private static final String LOGTAG = "FilterBasicRepresentation";
+ private int mMinimum;
+ private int mValue;
+ private int mMaximum;
+ private int mDefaultValue;
+ private int mPreviewValue;
+
+ public FilterBasicRepresentation(String name, int minimum, int value, int maximum) {
+ super(name);
+ mMinimum = minimum;
+ mMaximum = maximum;
+ setValue(value);
+ }
+
+ public String toString() {
+ return getName() + " : " + mMinimum + " < " + mValue + " < " + mMaximum;
+ }
+
+ @Override
+ public FilterRepresentation clone() throws CloneNotSupportedException {
+ FilterBasicRepresentation representation = (FilterBasicRepresentation) super.clone();
+ representation.setMinimum(getMinimum());
+ representation.setMaximum(getMaximum());
+ representation.setValue(getValue());
+ Log.v(LOGTAG, "cloning from <" + this + "> to <" + representation + ">");
+ return representation;
+ }
+
+ public void useParametersFrom(FilterRepresentation a) {
+ if (a instanceof FilterBasicRepresentation) {
+ FilterBasicRepresentation representation = (FilterBasicRepresentation) a;
+ setMinimum(representation.getMinimum());
+ setMaximum(representation.getMaximum());
+ setValue(representation.getValue());
+ setDefaultValue(representation.getDefaultValue());
+ setPreviewValue(representation.getPreviewValue());
+ }
+ }
+
+ @Override
+ public boolean equals(FilterRepresentation representation) {
+ if (super.equals(representation)) {
+ return false;
+ }
+ if (representation instanceof FilterBasicRepresentation) {
+ FilterBasicRepresentation basic = (FilterBasicRepresentation) representation;
+ if (basic.mMinimum == mMinimum
+ && basic.mMaximum == mMaximum
+ && basic.mValue == mValue
+ && basic.mDefaultValue == mDefaultValue
+ && basic.mPreviewValue == mPreviewValue) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public int getMinimum() {
+ return mMinimum;
+ }
+
+ public void setMinimum(int minimum) {
+ mMinimum = minimum;
+ }
+
+ public int getValue() {
+ return mValue;
+ }
+
+ public void setValue(int value) {
+ mValue = value;
+ if (mValue < mMinimum) {
+ mValue = mMinimum;
+ }
+ if (mValue > mMaximum) {
+ mValue = mMaximum;
+ }
+ }
+
+ public int getMaximum() {
+ return mMaximum;
+ }
+
+ public void setMaximum(int maximum) {
+ mMaximum = maximum;
+ }
+
+ public void setDefaultValue(int defaultValue) {
+ mDefaultValue = defaultValue;
+ }
+
+ public int getDefaultValue() {
+ return mDefaultValue;
+ }
+
+ public int getPreviewValue() {
+ return mPreviewValue;
+ }
+
+ public void setPreviewValue(int previewValue) {
+ mPreviewValue = previewValue;
+ }
+}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterDirectRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterDirectRepresentation.java
new file mode 100644
index 000000000..3807ee1f5
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/filters/FilterDirectRepresentation.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2013 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.filtershow.filters;
+
+public class FilterDirectRepresentation extends FilterRepresentation {
+
+ public FilterDirectRepresentation(String name) {
+ super(name);
+ }
+
+ public boolean isNil() {
+ return true;
+ }
+
+}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java
new file mode 100644
index 000000000..afa6ad18d
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2013 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.filtershow.filters;
+
+import com.android.gallery3d.app.Log;
+import com.android.gallery3d.filtershow.presets.ImagePreset;
+
+import java.util.HashMap;
+
+public class FilterRepresentation implements Cloneable {
+ private static final String LOGTAG = "FilterRepresentation";
+ private String mName;
+ private int mPriority;
+ private ImagePreset mPreset;
+ private boolean mShowParameterValue;
+ private Class mFilterClass;
+
+ public static String DEFAULT = "Default";
+
+ public FilterRepresentation(String name) {
+ mName = name;
+ }
+
+ @Override
+ public FilterRepresentation clone() throws CloneNotSupportedException {
+ FilterRepresentation representation = (FilterRepresentation) super.clone();
+ representation.setName(getName());
+ representation.setPriority(getPriority());
+ Log.v(LOGTAG, "cloning from <" + this + "> to <" + representation + ">");
+ return representation;
+ }
+
+ public boolean equals(FilterRepresentation representation) {
+ if (representation.mFilterClass == representation.mFilterClass
+ && representation.mName.equalsIgnoreCase(mName)
+ && representation.mPriority == mPriority
+ && representation.mShowParameterValue == mShowParameterValue) {
+ return true;
+ }
+ return false;
+ }
+
+ public String toString() {
+ return mName;
+ }
+
+ public void setName(String name) {
+ mName = name;
+ }
+
+ public String getName() {
+ return mName;
+ }
+
+ public void setPriority(int priority) {
+ mPriority = priority;
+ }
+
+ public int getPriority() {
+ return mPriority;
+ }
+
+ public void setImagePreset(ImagePreset preset) {
+ mPreset = preset;
+ }
+
+ public boolean isNil() {
+ return false;
+ }
+
+ public void useParametersFrom(FilterRepresentation a) {
+ }
+
+ public void setShowParameterValue(boolean showParameterValue) {
+ mShowParameterValue = showParameterValue;
+ }
+
+ public boolean showParameterValue() {
+ return mShowParameterValue;
+ }
+
+ public Class getFilterClass() {
+ return mFilterClass;
+ }
+
+ public void setFilterClass(Class filterClass) {
+ mFilterClass = filterClass;
+ }
+
+ public boolean same(FilterRepresentation b) {
+ if (b == null) {
+ return false;
+ }
+ return getFilterClass() == b.getFilterClass();
+ }
+}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilter.java b/src/com/android/gallery3d/filtershow/filters/ImageFilter.java
index a261031c3..abf65c4b0 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilter.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilter.java
@@ -24,15 +24,6 @@ import com.android.gallery3d.filtershow.presets.ImagePreset;
public class ImageFilter implements Cloneable {
- public static int DEFAULT_MAX_PARAMETER = 100;
- public static int DEFAULT_MIN_PARAMETER = -100;
- public static int DEFAULT_INITIAL_PARAMETER = 0;
-
- protected int mMaxParameter = DEFAULT_MAX_PARAMETER;
- protected int mMinParameter = DEFAULT_MIN_PARAMETER;
- protected int mPreviewParameter = mMaxParameter;
- protected int mDefaultParameter = DEFAULT_INITIAL_PARAMETER;
- protected int mParameter = DEFAULT_INITIAL_PARAMETER;
private ImagePreset mImagePreset;
protected String mName = "Original";
@@ -81,31 +72,6 @@ public class ImageFilter implements Cloneable {
return true;
}
- @Override
- public ImageFilter clone() throws CloneNotSupportedException {
- ImageFilter filter = (ImageFilter) super.clone();
- filter.setName(getName());
- filter.setParameter(getParameter());
- filter.setFilterType(filterType);
- filter.mMaxParameter = mMaxParameter;
- filter.mMinParameter = mMinParameter;
- filter.mImagePreset = mImagePreset;
- filter.mDefaultParameter = mDefaultParameter;
- filter.mPreviewParameter = mPreviewParameter;
- return filter;
- }
-
- public void reset() {
- setParameter(mDefaultParameter);
- }
-
- public boolean isNil() {
- if (mParameter == mDefaultParameter) {
- return true;
- }
- return false;
- }
-
public void setName(String name) {
mName = name;
}
@@ -124,68 +90,17 @@ public class ImageFilter implements Cloneable {
* Override this to provide filter-specific button icons.
*/
public Bitmap iconApply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
- int param = getParameter();
- setParameter(getPreviewParameter());
- bitmap = apply(bitmap, scaleFactor, highQuality);
- setParameter(param);
- return bitmap;
- }
-
- public int getParameter() {
- return mParameter;
- }
-
- public void setParameter(int value) {
- mParameter = value;
- }
-
- /**
- * The maximum allowed value (inclusive)
- * @return maximum value allowed as input to this filter
- */
- public int getMaxParameter() {
- return mMaxParameter;
- }
-
- /**
- * The parameter value to be used in previews.
- * @return parameter value to be used to preview the filter
- */
- public int getPreviewParameter() {
- return mPreviewParameter;
- }
-
- /**
- * The minimum allowed value (inclusive)
- * @return minimum value allowed as input to this filter
- */
- public int getMinParameter() {
- return mMinParameter;
- }
-
- /**
- * Returns the default value returned by this filter.
- * @return default value
- */
- public int getDefaultParameter() {
- return mDefaultParameter;
+ return apply(bitmap, scaleFactor, highQuality);
}
public ImagePreset getImagePreset() {
return mImagePreset;
}
- public void setImagePreset(ImagePreset mPreset) {
- this.mImagePreset = mPreset;
- }
-
public boolean equals(ImageFilter filter) {
if (!same(filter)) {
return false;
}
- if (mParameter != filter.mParameter) {
- return false;
- }
return true;
}
@@ -199,10 +114,17 @@ public class ImageFilter implements Cloneable {
return true;
}
+ public void useRepresentation(FilterRepresentation representation) {
+ }
+
native protected void nativeApplyGradientFilter(Bitmap bitmap, int w, int h,
int[] redGradient, int[] greenGradient, int[] blueGradient);
- public void useFilter(ImageFilter a) {
- setParameter(a.getParameter());
+ public FilterRepresentation getDefaultRepresentation() {
+ return null;
+ }
+
+ public boolean hasDefaultRepresentation() {
+ return false;
}
}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterBorder.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterBorder.java
index 4fe308294..7d8152b6f 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterBorder.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterBorder.java
@@ -41,7 +41,6 @@ public class ImageFilterBorder extends ImageFilter {
mNinePatch = ninePatch;
}
- @Override
public boolean isNil() {
if (mNinePatch == null) {
return true;
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterBwFilter.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterBwFilter.java
index 1bb5c76ac..1c0632395 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterBwFilter.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterBwFilter.java
@@ -22,12 +22,19 @@ import android.graphics.Bitmap;
import android.graphics.Color;
-public class ImageFilterBwFilter extends ImageFilter {
+public class ImageFilterBwFilter extends SimpleImageFilter {
public ImageFilterBwFilter() {
mName = "BW Filter";
- mMaxParameter = 180;
- mMinParameter = -180;
+ }
+
+ public FilterRepresentation getDefaultRepresentation() {
+ FilterBasicRepresentation representation = (FilterBasicRepresentation) super.getDefaultRepresentation();
+ representation.setName("BW Filter");
+ representation.setFilterClass(ImageFilterBwFilter.class);
+ representation.setMaximum(180);
+ representation.setMinimum(-180);
+ return representation;
}
@Override
@@ -50,10 +57,13 @@ public class ImageFilterBwFilter extends ImageFilter {
@Override
public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
+ if (getParameters() == null) {
+ return bitmap;
+ }
int w = bitmap.getWidth();
int h = bitmap.getHeight();
float[] hsv = new float[] {
- 180 + mParameter, 1, 1
+ 180 + getParameters().getValue(), 1, 1
};
int rgb = Color.HSVToColor(hsv);
int r = 0xFF & (rgb >> 16);
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterContrast.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterContrast.java
index 70e3d8589..7e785890d 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterContrast.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterContrast.java
@@ -20,12 +20,19 @@ import com.android.gallery3d.R;
import android.graphics.Bitmap;
-public class ImageFilterContrast extends ImageFilter {
+public class ImageFilterContrast extends SimpleImageFilter {
public ImageFilterContrast() {
mName = "Contrast";
}
+ public FilterRepresentation getDefaultRepresentation() {
+ FilterRepresentation representation = super.getDefaultRepresentation();
+ representation.setName("Contrast");
+ representation.setFilterClass(ImageFilterContrast.class);
+ return representation;
+ }
+
@Override
public int getButtonId() {
return R.id.contrastButton;
@@ -40,10 +47,12 @@ public class ImageFilterContrast extends ImageFilter {
@Override
public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
+ if (getParameters() == null) {
+ return bitmap;
+ }
int w = bitmap.getWidth();
int h = bitmap.getHeight();
- float p = mParameter;
- float value = p;
+ float value = getParameters().getValue();
nativeApplyFilter(bitmap, w, h, value);
return bitmap;
}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java
index b7e5c2ae6..15cf046c0 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java
@@ -74,7 +74,6 @@ public class ImageFilterCurves extends ImageFilter {
return filter;
}
- @Override
public boolean isNil() {
for (int i = 0; i < 4; i++) {
if (mSplines[i] != null && !mSplines[i].isOriginal()) {
@@ -148,7 +147,6 @@ public class ImageFilterCurves extends ImageFilter {
return mSplines[splineIndex];
}
- @Override
public void reset() {
Spline spline = new Spline();
@@ -160,7 +158,7 @@ public class ImageFilterCurves extends ImageFilter {
}
}
- @Override
+ // TODO: fix useFilter
public void useFilter(ImageFilter a) {
ImageFilterCurves c = (ImageFilterCurves) a;
for (int i = 0; i < 4; i++) {
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterDownsample.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterDownsample.java
index 784028a8d..c2b648110 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterDownsample.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterDownsample.java
@@ -23,20 +23,27 @@ import android.graphics.Rect;
import com.android.gallery3d.R;
import com.android.gallery3d.filtershow.cache.ImageLoader;
-public class ImageFilterDownsample extends ImageFilter {
+public class ImageFilterDownsample extends SimpleImageFilter {
private static final int ICON_DOWNSAMPLE_FRACTION = 8;
private ImageLoader mImageLoader;
public ImageFilterDownsample(ImageLoader loader) {
mName = "Downsample";
- mMaxParameter = 100;
- mMinParameter = 1;
- mPreviewParameter = 3;
- mDefaultParameter = 50;
- mParameter = 50;
mImageLoader = loader;
}
+ public FilterRepresentation getDefaultRepresentation() {
+ FilterBasicRepresentation representation = (FilterBasicRepresentation) super.getDefaultRepresentation();
+ representation.setName("Downsample");
+ representation.setFilterClass(ImageFilterDownsample.class);
+ representation.setMaximum(100);
+ representation.setMinimum(1);
+ representation.setValue(50);
+ representation.setDefaultValue(50);
+ representation.setPreviewValue(3);
+ return representation;
+ }
+
@Override
public int getButtonId() {
return R.id.downsampleButton;
@@ -48,15 +55,13 @@ public class ImageFilterDownsample extends ImageFilter {
}
@Override
- public boolean isNil() {
- return false;
- }
-
- @Override
public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
+ if (getParameters() == null) {
+ return bitmap;
+ }
int w = bitmap.getWidth();
int h = bitmap.getHeight();
- int p = mParameter;
+ int p = getParameters().getValue();
// size of original precached image
Rect size = mImageLoader.getOriginalBounds();
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterDraw.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterDraw.java
index 3177d2473..d83a521bd 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterDraw.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterDraw.java
@@ -435,7 +435,6 @@ public class ImageFilterDraw extends ImageFilter {
return filter;
}
- @Override
public boolean isNil() {
for (int i = 0; i < mDrawings.length; i++) {
if (mDrawings[i].getNumberOfStrokes() != 0) {
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterEdge.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterEdge.java
index 9eda64874..f5a0a69c1 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterEdge.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterEdge.java
@@ -20,11 +20,17 @@ import android.graphics.Bitmap;
import com.android.gallery3d.R;
-public class ImageFilterEdge extends ImageFilter {
+public class ImageFilterEdge extends SimpleImageFilter {
public ImageFilterEdge() {
mName = "Edge";
- mPreviewParameter = 0;
+ }
+
+ public FilterRepresentation getDefaultRepresentation() {
+ FilterRepresentation representation = super.getDefaultRepresentation();
+ representation.setName("Edge");
+ representation.setFilterClass(ImageFilterEdge.class);
+ return representation;
}
native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float p);
@@ -40,15 +46,13 @@ public class ImageFilterEdge extends ImageFilter {
}
@Override
- public boolean isNil() {
- return false;
- }
-
- @Override
public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
+ if (getParameters() == null) {
+ return bitmap;
+ }
int w = bitmap.getWidth();
int h = bitmap.getHeight();
- float p = mParameter + 101;
+ float p = getParameters().getValue() + 101;
p = (float) p / 100;
nativeApplyFilter(bitmap, w, h, p);
return bitmap;
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterExposure.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterExposure.java
index 63f860171..569a6f276 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterExposure.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterExposure.java
@@ -20,12 +20,19 @@ import com.android.gallery3d.R;
import android.graphics.Bitmap;
-public class ImageFilterExposure extends ImageFilter {
+public class ImageFilterExposure extends SimpleImageFilter {
public ImageFilterExposure() {
mName = "Exposure";
}
+ public FilterRepresentation getDefaultRepresentation() {
+ FilterRepresentation representation = super.getDefaultRepresentation();
+ representation.setName("Exposure");
+ representation.setFilterClass(ImageFilterExposure.class);
+ return representation;
+ }
+
@Override
public int getButtonId() {
return R.id.exposureButton;
@@ -40,10 +47,12 @@ public class ImageFilterExposure extends ImageFilter {
@Override
public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
+ if (getParameters() == null) {
+ return bitmap;
+ }
int w = bitmap.getWidth();
int h = bitmap.getHeight();
- int p = mParameter;
- float value = p;
+ float value = getParameters().getValue();
nativeApplyFilter(bitmap, w, h, value);
return bitmap;
}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java
index 345202fe6..f5dff5ed6 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java
@@ -42,7 +42,6 @@ public class ImageFilterFx extends ImageFilter {
return filter;
}
- @Override
public boolean isNil() {
if (fxBitmap != null) {
return false;
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterHue.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterHue.java
index 6b9869be3..51c476d6d 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterHue.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterHue.java
@@ -21,14 +21,21 @@ import com.android.gallery3d.filtershow.editors.BasicEditor;
import android.graphics.Bitmap;
-public class ImageFilterHue extends ImageFilter {
+public class ImageFilterHue extends SimpleImageFilter {
private ColorSpaceMatrix cmatrix = null;
public ImageFilterHue() {
mName = "Hue";
cmatrix = new ColorSpaceMatrix();
- mMaxParameter = 180;
- mMinParameter = -180;
+ }
+
+ public FilterRepresentation getDefaultRepresentation() {
+ FilterBasicRepresentation representation = (FilterBasicRepresentation) super.getDefaultRepresentation();
+ representation.setName("Hue");
+ representation.setFilterClass(ImageFilterHue.class);
+ representation.setMinimum(-180);
+ representation.setMaximum(180);
+ return representation;
}
@Override
@@ -57,10 +64,12 @@ public class ImageFilterHue extends ImageFilter {
@Override
public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
+ if (getParameters() == null) {
+ return bitmap;
+ }
int w = bitmap.getWidth();
int h = bitmap.getHeight();
- float p = mParameter;
- float value = p;
+ float value = getParameters().getValue();
cmatrix.identity();
cmatrix.setHue(value);
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterKMeans.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterKMeans.java
index f03baca39..fd098e699 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterKMeans.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterKMeans.java
@@ -20,17 +20,13 @@ import android.graphics.Bitmap;
import android.text.format.Time;
import com.android.gallery3d.R;
+import com.android.gallery3d.ingest.ui.MtpThumbnailTileView;
-public class ImageFilterKMeans extends ImageFilter {
+public class ImageFilterKMeans extends SimpleImageFilter {
private int mSeed = 0;
public ImageFilterKMeans() {
mName = "KMeans";
- mMaxParameter = 20;
- mMinParameter = 2;
- mPreviewParameter = 4;
- mDefaultParameter = 4;
- mParameter = 4;
// set random seed for session
Time t = new Time();
@@ -38,6 +34,18 @@ public class ImageFilterKMeans extends ImageFilter {
mSeed = (int) t.toMillis(false);
}
+ public FilterRepresentation getDefaultRepresentation() {
+ FilterBasicRepresentation representation = (FilterBasicRepresentation) super.getDefaultRepresentation();
+ representation.setName("KMeans");
+ representation.setFilterClass(ImageFilterKMeans.class);
+ representation.setMaximum(20);
+ representation.setMinimum(2);
+ representation.setValue(4);
+ representation.setDefaultValue(4);
+ representation.setPreviewValue(4);
+ return representation;
+ }
+
native protected void nativeApplyFilter(Bitmap bitmap, int width, int height,
Bitmap large_ds_bm, int lwidth, int lheight, Bitmap small_ds_bm,
int swidth, int sheight, int p, int seed);
@@ -53,12 +61,10 @@ public class ImageFilterKMeans extends ImageFilter {
}
@Override
- public boolean isNil() {
- return false;
- }
-
- @Override
public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
+ if (getParameters() == null) {
+ return bitmap;
+ }
int w = bitmap.getWidth();
int h = bitmap.getHeight();
@@ -87,8 +93,10 @@ public class ImageFilterKMeans extends ImageFilter {
small_bm_ds = Bitmap.createScaledBitmap(large_bm_ds, sw, sh, true);
}
- int p = Math.max(mParameter, mMinParameter) % (mMaxParameter + 1);
- nativeApplyFilter(bitmap, w, h, large_bm_ds, lw, lh, small_bm_ds, sw, sh, p, mSeed);
+ if (getParameters() != null) {
+ int p = Math.max(getParameters().getValue(), getParameters().getMinimum()) % (getParameters().getMaximum() + 1);
+ nativeApplyFilter(bitmap, w, h, large_bm_ds, lw, lh, small_bm_ds, sw, sh, p, mSeed);
+ }
return bitmap;
}
}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterNegative.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterNegative.java
index 04fd1e42e..e69fe3542 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterNegative.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterNegative.java
@@ -10,6 +10,16 @@ public class ImageFilterNegative extends ImageFilter {
mName = "Negative";
}
+ public FilterRepresentation getDefaultRepresentation() {
+ FilterRepresentation representation = new FilterDirectRepresentation("Negative");
+ representation.setFilterClass(ImageFilterNegative.class);
+ return representation;
+ }
+
+ public boolean hasDefaultRepresentation() {
+ return true;
+ }
+
@Override
public int getButtonId() {
return R.id.negativeButton;
@@ -21,11 +31,6 @@ public class ImageFilterNegative extends ImageFilter {
}
@Override
- public boolean isNil() {
- return false;
- }
-
- @Override
public boolean showEditingControls() {
return false;
}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterParametricBorder.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterParametricBorder.java
index 681eb1221..1e75eb2ae 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterParametricBorder.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterParametricBorder.java
@@ -67,7 +67,6 @@ public class ImageFilterParametricBorder extends ImageFilter {
return filter;
}
- @Override
public boolean isNil() {
return false;
}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterRedEye.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterRedEye.java
index 9ae6f511e..03780908c 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterRedEye.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterRedEye.java
@@ -45,7 +45,7 @@ public class ImageFilterRedEye extends ImageFilter {
@Override
public int getEditingViewId() {
- return R.id.imageRedEyes;
+ return R.id.imageRedEyes;
}
@Override
@@ -61,7 +61,6 @@ public class ImageFilterRedEye extends ImageFilter {
return filter;
}
- @Override
public boolean isNil() {
if (mCandidates != null && mCandidates.size() > 0) {
return false;
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterSaturated.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterSaturated.java
index 129165b3e..7d848f5fa 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterSaturated.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterSaturated.java
@@ -20,12 +20,19 @@ import com.android.gallery3d.R;
import android.graphics.Bitmap;
-public class ImageFilterSaturated extends ImageFilter {
+public class ImageFilterSaturated extends SimpleImageFilter {
public ImageFilterSaturated() {
mName = "Saturated";
}
+ public FilterRepresentation getDefaultRepresentation() {
+ FilterRepresentation representation = super.getDefaultRepresentation();
+ representation.setName("Saturated");
+ representation.setFilterClass(ImageFilterSaturated.class);
+ return representation;
+ }
+
@Override
public int getButtonId() {
return R.id.saturationButton;
@@ -40,9 +47,12 @@ public class ImageFilterSaturated extends ImageFilter {
@Override
public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
+ if (getParameters() == null) {
+ return bitmap;
+ }
int w = bitmap.getWidth();
int h = bitmap.getHeight();
- int p = mParameter;
+ int p = getParameters().getValue();
float value = 1 + p / 100.0f;
nativeApplyFilter(bitmap, w, h, value);
return bitmap;
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterShadows.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterShadows.java
index de8fcd5ea..27e5342c9 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterShadows.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterShadows.java
@@ -20,13 +20,20 @@ import com.android.gallery3d.R;
import android.graphics.Bitmap;
-public class ImageFilterShadows extends ImageFilter {
+public class ImageFilterShadows extends SimpleImageFilter {
public ImageFilterShadows() {
mName = "Shadows";
}
+ public FilterRepresentation getDefaultRepresentation() {
+ FilterRepresentation representation = super.getDefaultRepresentation();
+ representation.setName("Shadows");
+ representation.setFilterClass(ImageFilterShadows.class);
+ return representation;
+ }
+
@Override
public int getButtonId() {
return R.id.shadowRecoveryButton;
@@ -47,9 +54,12 @@ public class ImageFilterShadows extends ImageFilter {
@Override
public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
+ if (getParameters() == null) {
+ return bitmap;
+ }
int w = bitmap.getWidth();
int h = bitmap.getHeight();
- float p = mParameter;
+ float p = getParameters().getValue();
nativeApplyFilter(bitmap, w, h, p);
return bitmap;
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java
index 1f9bf22c0..58c2ac668 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java
@@ -24,10 +24,28 @@ public class ImageFilterSharpen extends ImageFilterRS {
private ScriptC_convolve3x3 mScript;
float mScaleFactor;
+ private FilterBasicRepresentation mParameters;
+
public ImageFilterSharpen() {
mName = "Sharpen";
}
+ public FilterRepresentation getDefaultRepresentation() {
+ FilterRepresentation representation = new FilterBasicRepresentation("Sharpen", 0, 0, 100);
+ representation.setShowParameterValue(true);
+ representation.setFilterClass(ImageFilterSharpen.class);
+ return representation;
+ }
+
+ public void useRepresentation(FilterRepresentation representation) {
+ FilterBasicRepresentation parameters = (FilterBasicRepresentation) representation;
+ mParameters = parameters;
+ }
+
+ public boolean hasDefaultRepresentation() {
+ return true;
+ }
+
@Override
public int getButtonId() {
return R.id.sharpenButton;
@@ -63,7 +81,7 @@ public class ImageFilterSharpen extends ImageFilterRS {
}
private void computeKernel(){
- float p1 = mParameter * mScaleFactor;
+ float p1 = mParameters.getValue() * mScaleFactor;
float value = p1 / 100.0f;
float f[] = new float[9];
float p = value;
@@ -81,6 +99,9 @@ public class ImageFilterSharpen extends ImageFilterRS {
@Override
public void runFilter() {
+ if (mParameters == null) {
+ return;
+ }
computeKernel();
mScript.set_gIn(mInPixelsAllocation);
mScript.bind_gPixels(mInPixelsAllocation);
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java
index 36bd62630..a6075daa1 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java
@@ -29,7 +29,7 @@ import com.android.gallery3d.filtershow.presets.ImagePreset;
/**
* An image filter which creates a tiny planet projection.
*/
-public class ImageFilterTinyPlanet extends ImageFilter {
+public class ImageFilterTinyPlanet extends SimpleImageFilter {
private float mAngle = 0;
private static final String TAG = ImageFilterTinyPlanet.class.getSimpleName();
@@ -51,12 +51,6 @@ public class ImageFilterTinyPlanet extends ImageFilter {
public ImageFilterTinyPlanet() {
setFilterType(TYPE_TINYPLANET);
mName = "TinyPlanet";
-
- mMinParameter = 10;
- mMaxParameter = 60;
- mDefaultParameter = 20;
- mPreviewParameter = 20;
- mParameter = 20;
mAngle = 0;
}
@@ -114,7 +108,7 @@ public class ImageFilterTinyPlanet extends ImageFilter {
}
}
nativeApplyFilter(bitmapIn, bitmapIn.getWidth(), bitmapIn.getHeight(), mBitmapOut,
- outputSize, mParameter / 100f, mAngle);
+ outputSize, getParameters().getValue() / 100f, mAngle);
return mBitmapOut;
}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterVibrance.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterVibrance.java
index 7720d0490..905850a5c 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterVibrance.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterVibrance.java
@@ -20,12 +20,19 @@ import com.android.gallery3d.R;
import android.graphics.Bitmap;
-public class ImageFilterVibrance extends ImageFilter {
+public class ImageFilterVibrance extends SimpleImageFilter {
public ImageFilterVibrance() {
mName = "Vibrance";
}
+ public FilterRepresentation getDefaultRepresentation() {
+ FilterRepresentation representation = super.getDefaultRepresentation();
+ representation.setName("Vibrance");
+ representation.setFilterClass(ImageFilterVibrance.class);
+ return representation;
+ }
+
@Override
public int getButtonId() {
return R.id.vibranceButton;
@@ -40,10 +47,12 @@ public class ImageFilterVibrance extends ImageFilter {
@Override
public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
+ if (getParameters() == null) {
+ return bitmap;
+ }
int w = bitmap.getWidth();
int h = bitmap.getHeight();
- int p = mParameter;
- float value = p;
+ float value = getParameters().getValue();
nativeApplyFilter(bitmap, w, h, value);
return bitmap;
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterVignette.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterVignette.java
index 3c904fa6c..1cc93596f 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterVignette.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterVignette.java
@@ -19,14 +19,25 @@ package com.android.gallery3d.filtershow.filters;
import com.android.gallery3d.R;
import android.graphics.Bitmap;
+import com.android.gallery3d.app.Log;
-public class ImageFilterVignette extends ImageFilter {
+public class ImageFilterVignette extends SimpleImageFilter {
+
+ private static final String LOGTAG = "ImageFilterVignette";
public ImageFilterVignette() {
setFilterType(TYPE_VIGNETTE);
mName = "Vignette";
}
+ public FilterRepresentation getDefaultRepresentation() {
+ FilterBasicRepresentation representation = (FilterBasicRepresentation) super.getDefaultRepresentation();
+ representation.setName("Vignette");
+ representation.setFilterClass(ImageFilterVignette.class);
+ representation.setPriority(TYPE_VIGNETTE);
+ return representation;
+ }
+
@Override
public int getButtonId() {
return R.id.vignetteButton;
@@ -41,10 +52,12 @@ public class ImageFilterVignette extends ImageFilter {
@Override
public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
+ if (getParameters() == null) {
+ return bitmap;
+ }
int w = bitmap.getWidth();
int h = bitmap.getHeight();
- float p = mParameter;
- float value = p / 100.0f;
+ float value = getParameters().getValue() / 100.0f;
nativeApplyFilter(bitmap, w, h, value);
return bitmap;
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterWBalance.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterWBalance.java
index 8665dc54c..05f5124ae 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterWBalance.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterWBalance.java
@@ -28,6 +28,16 @@ public class ImageFilterWBalance extends ImageFilter {
mName = "WBalance";
}
+ public FilterRepresentation getDefaultRepresentation() {
+ FilterRepresentation representation = new FilterDirectRepresentation("WBalance");
+ representation.setFilterClass(ImageFilterWBalance.class);
+ return representation;
+ }
+
+ public boolean hasDefaultRepresentation() {
+ return true;
+ }
+
@Override
public int getButtonId() {
return R.id.wbalanceButton;
@@ -52,8 +62,4 @@ public class ImageFilterWBalance extends ImageFilter {
return bitmap;
}
- @Override
- public boolean isNil() {
- return false;
- }
}
diff --git a/src/com/android/gallery3d/filtershow/filters/SimpleImageFilter.java b/src/com/android/gallery3d/filtershow/filters/SimpleImageFilter.java
new file mode 100644
index 000000000..8b6f3da5e
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/filters/SimpleImageFilter.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2013 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.filtershow.filters;
+
+import android.graphics.Bitmap;
+
+public class SimpleImageFilter extends ImageFilter {
+
+ private FilterBasicRepresentation mParameters;
+
+ public FilterRepresentation getDefaultRepresentation() {
+ FilterRepresentation representation = new FilterBasicRepresentation("Default", 0, 50, 100);
+ representation.setShowParameterValue(true);
+ return representation;
+ }
+
+ public void useRepresentation(FilterRepresentation representation) {
+ FilterBasicRepresentation parameters = (FilterBasicRepresentation) representation;
+ mParameters = parameters;
+ }
+
+ public boolean hasDefaultRepresentation() {
+ return true;
+ }
+
+ public FilterBasicRepresentation getParameters() {
+ return mParameters;
+ }
+
+ @Override
+ public Bitmap iconApply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
+ FilterRepresentation representation = getDefaultRepresentation();
+ this.useRepresentation(representation);
+ return apply(bitmap, scaleFactor, highQuality);
+ }
+}