ImageFilter.java revision 71f04cbaedbb89e313e0b86b531640db2d3f6016
1/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
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
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17package com.android.gallery3d.filtershow.filters;
18
19import android.graphics.Bitmap;
20
21import com.android.gallery3d.R;
22import com.android.gallery3d.filtershow.editors.BasicEditor;
23import com.android.gallery3d.filtershow.presets.ImagePreset;
24
25public class ImageFilter implements Cloneable {
26
27    private ImagePreset mImagePreset;
28
29    protected String mName = "Original";
30    private final String LOGTAG = "ImageFilter";
31    public static final byte TYPE_BORDER = 1;
32    public static final byte TYPE_FX = 2;
33    public static final byte TYPE_WBALANCE = 3;
34    public static final byte TYPE_VIGNETTE = 4;
35    public static final byte TYPE_NORMAL = 5;
36    public static final byte TYPE_TINYPLANET = 6;
37    private byte filterType = TYPE_NORMAL;
38
39    public byte getFilterType() {
40        return filterType;
41    }
42
43    protected void setFilterType(byte type) {
44        filterType = type;
45    }
46
47    public int getButtonId() {
48        return 0;
49    }
50
51    public int getTextId() {
52        return 0;
53    }
54
55    public int getOverlayBitmaps() {
56        return 0;
57    }
58
59    public int getEditingViewId() {
60        return BasicEditor.ID;
61    }
62
63    public boolean showEditingControls() {
64        return true;
65    }
66
67    public boolean showParameterValue() {
68        return true;
69    }
70
71    public boolean showUtilityPanel() {
72        return true;
73    }
74
75    public void setName(String name) {
76        mName = name;
77    }
78
79    public String getName() {
80        return mName;
81    }
82
83    public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
84        // do nothing here, subclasses will implement filtering here
85        return bitmap;
86    }
87
88    /**
89     * Called on small bitmaps to create button icons for each filter.
90     * Override this to provide filter-specific button icons.
91     */
92    public Bitmap iconApply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
93        return apply(bitmap, scaleFactor, highQuality);
94    }
95
96    public ImagePreset getImagePreset() {
97        return mImagePreset;
98    }
99
100    public boolean equals(ImageFilter filter) {
101        if (!same(filter)) {
102            return false;
103        }
104        return true;
105    }
106
107    public boolean same(ImageFilter filter) {
108        if (filter == null) {
109            return false;
110        }
111        if (!filter.getName().equalsIgnoreCase(getName())) {
112            return false;
113        }
114        return true;
115    }
116
117    public void useRepresentation(FilterRepresentation representation) {
118    }
119
120    native protected void nativeApplyGradientFilter(Bitmap bitmap, int w, int h,
121            int[] redGradient, int[] greenGradient, int[] blueGradient);
122
123    public FilterRepresentation getDefaultRepresentation() {
124        return null;
125    }
126
127    public boolean hasDefaultRepresentation() {
128        return false;
129    }
130}
131