OSDN Git Service

support for simplified computed icons
[android-x86/packages-apps-Gallery2.git] / src / com / android / gallery3d / filtershow / filters / ImageFilter.java
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
17 package com.android.gallery3d.filtershow.filters;
18
19 import android.graphics.Bitmap;
20 import android.graphics.Matrix;
21 import android.widget.Toast;
22
23 import com.android.gallery3d.filtershow.FilterShowActivity;
24 import com.android.gallery3d.filtershow.imageshow.GeometryMetadata;
25 import com.android.gallery3d.filtershow.presets.FilterEnvironment;
26 import com.android.gallery3d.filtershow.presets.ImagePreset;
27
28 public abstract class ImageFilter implements Cloneable {
29     private FilterEnvironment mEnvironment = null;
30
31     protected String mName = "Original";
32     private final String LOGTAG = "ImageFilter";
33     protected static final boolean SIMPLE_ICONS = true;
34     // TODO: Temporary, for dogfood note memory issues with toasts for better
35     // feedback. Remove this when filters actually work in low memory
36     // situations.
37     private static FilterShowActivity sActivity = null;
38
39     public static void setActivityForMemoryToasts(FilterShowActivity activity) {
40         sActivity = activity;
41     }
42
43     public static void resetStatics() {
44         sActivity = null;
45     }
46
47     public void freeResources() {}
48
49     public void displayLowMemoryToast() {
50         if (sActivity != null) {
51             sActivity.runOnUiThread(new Runnable() {
52                 public void run() {
53                     Toast.makeText(sActivity, "Memory too low for filter " + getName() +
54                             ", please file a bug report", Toast.LENGTH_SHORT).show();
55                 }
56             });
57         }
58     }
59
60     public void setName(String name) {
61         mName = name;
62     }
63
64     public String getName() {
65         return mName;
66     }
67
68     public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
69         // do nothing here, subclasses will implement filtering here
70         return bitmap;
71     }
72
73     public ImagePreset getImagePreset() {
74         return getEnvironment().getImagePreset();
75     }
76
77     public abstract void useRepresentation(FilterRepresentation representation);
78
79     native protected void nativeApplyGradientFilter(Bitmap bitmap, int w, int h,
80             int[] redGradient, int[] greenGradient, int[] blueGradient);
81
82     public FilterRepresentation getDefaultRepresentation() {
83         return null;
84     }
85
86     protected Matrix getOriginalToScreenMatrix(int w, int h) {
87         GeometryMetadata geo = getImagePreset().mGeoData;
88         Matrix originalToScreen = geo.getOriginalToScreen(true,
89                 getImagePreset().getImageLoader().getOriginalBounds().width(),
90                 getImagePreset().getImageLoader().getOriginalBounds().height(),
91                 w, h);
92         return originalToScreen;
93     }
94
95     public void setEnvironment(FilterEnvironment environment) {
96         mEnvironment = environment;
97     }
98
99     public FilterEnvironment getEnvironment() {
100         return mEnvironment;
101     }
102 }