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;
20 import android.graphics.Matrix;
21 import android.widget.Toast;
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;
28 public abstract class ImageFilter implements Cloneable {
29 private FilterEnvironment mEnvironment = null;
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
37 private static FilterShowActivity sActivity = null;
39 public static void setActivityForMemoryToasts(FilterShowActivity activity) {
43 public static void resetStatics() {
47 public void freeResources() {}
49 public void displayLowMemoryToast() {
50 if (sActivity != null) {
51 sActivity.runOnUiThread(new Runnable() {
53 Toast.makeText(sActivity, "Memory too low for filter " + getName() +
54 ", please file a bug report", Toast.LENGTH_SHORT).show();
60 public void setName(String name) {
64 public String getName() {
68 public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
69 // do nothing here, subclasses will implement filtering here
73 public ImagePreset getImagePreset() {
74 return getEnvironment().getImagePreset();
77 public abstract void useRepresentation(FilterRepresentation representation);
79 native protected void nativeApplyGradientFilter(Bitmap bitmap, int w, int h,
80 int[] redGradient, int[] greenGradient, int[] blueGradient);
82 public FilterRepresentation getDefaultRepresentation() {
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(),
92 return originalToScreen;
95 public void setEnvironment(FilterEnvironment environment) {
96 mEnvironment = environment;
99 public FilterEnvironment getEnvironment() {