2 * Copyright (C) 2012 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.gallery3d.filtershow.filters;
19 import android.graphics.Bitmap;
21 import com.android.gallery3d.R;
22 import com.android.gallery3d.filtershow.presets.ImagePreset;
24 public class ImageFilter implements Cloneable {
26 public static int DEFAULT_MAX_PARAMETER = 100;
27 public static int DEFAULT_MIN_PARAMETER = -100;
28 public static int DEFAULT_INITIAL_PARAMETER = 0;
30 protected int mMaxParameter = DEFAULT_MAX_PARAMETER;
31 protected int mMinParameter = DEFAULT_MIN_PARAMETER;
32 protected int mPreviewParameter = mMaxParameter;
33 protected int mDefaultParameter = DEFAULT_INITIAL_PARAMETER;
34 protected int mParameter = DEFAULT_INITIAL_PARAMETER;
35 private ImagePreset mImagePreset;
37 protected String mName = "Original";
38 private final String LOGTAG = "ImageFilter";
39 public static final byte TYPE_BORDER = 1;
40 public static final byte TYPE_FX = 2;
41 public static final byte TYPE_WBALANCE = 3;
42 public static final byte TYPE_VIGNETTE = 4;
43 public static final byte TYPE_NORMAL = 5;
44 public static final byte TYPE_TINYPLANET = 6;
45 private byte filterType = TYPE_NORMAL;
47 public byte getFilterType() {
51 protected void setFilterType(byte type) {
55 public int getButtonId() {
59 public int getTextId() {
63 public int getOverlayBitmaps() {
67 public int getEditingViewId() {
68 return R.id.imageShow;
71 public boolean showEditingControls() {
75 public boolean showParameterValue() {
80 public ImageFilter clone() throws CloneNotSupportedException {
81 ImageFilter filter = (ImageFilter) super.clone();
82 filter.setName(getName());
83 filter.setParameter(getParameter());
84 filter.setFilterType(filterType);
85 filter.mMaxParameter = mMaxParameter;
86 filter.mMinParameter = mMinParameter;
87 filter.mImagePreset = mImagePreset;
88 filter.mDefaultParameter = mDefaultParameter;
89 filter.mPreviewParameter = mPreviewParameter;
94 setParameter(mDefaultParameter);
97 public boolean isNil() {
98 if (mParameter == mDefaultParameter) {
104 public void setName(String name) {
108 public String getName() {
112 public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
113 // do nothing here, subclasses will implement filtering here
117 public int getParameter() {
121 public void setParameter(int value) {
126 * The maximum allowed value (inclusive)
127 * @return maximum value allowed as input to this filter
129 public int getMaxParameter() {
130 return mMaxParameter;
134 * The parameter value to be used in previews.
135 * @return parameter value to be used to preview the filter
137 public int getPreviewParameter() {
138 return mPreviewParameter;
142 * The minimum allowed value (inclusive)
143 * @return minimum value allowed as input to this filter
145 public int getMinParameter() {
146 return mMinParameter;
150 * Returns the default value returned by this filter.
151 * @return default value
153 public int getDefaultParameter() {
154 return mDefaultParameter;
157 public ImagePreset getImagePreset() {
161 public void setImagePreset(ImagePreset mPreset) {
162 this.mImagePreset = mPreset;
165 public boolean same(ImageFilter filter) {
166 if (filter == null) {
169 if (!filter.getName().equalsIgnoreCase(getName())) {
175 native protected void nativeApplyGradientFilter(Bitmap bitmap, int w, int h,
176 int[] redGradient, int[] greenGradient, int[] blueGradient);