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.app.Activity;
20 import android.graphics.Bitmap;
21 import android.graphics.Matrix;
22 import android.renderscript.Allocation;
23 import android.widget.Toast;
25 import com.android.gallery3d.filtershow.imageshow.GeometryMathUtils;
26 import com.android.gallery3d.filtershow.imageshow.MasterImage;
27 import com.android.gallery3d.filtershow.pipeline.FilterEnvironment;
29 public abstract class ImageFilter implements Cloneable {
30 private FilterEnvironment mEnvironment = null;
32 protected String mName = "Original";
33 private final String LOGTAG = "ImageFilter";
34 protected static final boolean SIMPLE_ICONS = true;
35 // TODO: Temporary, for dogfood note memory issues with toasts for better
36 // feedback. Remove this when filters actually work in low memory
38 private static Activity sActivity = null;
40 public static void setActivityForMemoryToasts(Activity activity) {
44 public static void resetStatics() {
48 public void freeResources() {}
50 public void displayLowMemoryToast() {
51 if (sActivity != null) {
52 sActivity.runOnUiThread(new Runnable() {
54 Toast.makeText(sActivity, "Memory too low for filter " + getName() +
55 ", please file a bug report", Toast.LENGTH_SHORT).show();
61 public void setName(String name) {
65 public String getName() {
69 public boolean supportsAllocationInput() { return false; }
71 public void apply(Allocation in, Allocation out) {
72 setGeneralParameters();
75 public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
76 // do nothing here, subclasses will implement filtering here
77 setGeneralParameters();
81 public abstract void useRepresentation(FilterRepresentation representation);
83 native protected void nativeApplyGradientFilter(Bitmap bitmap, int w, int h,
84 int[] redGradient, int[] greenGradient, int[] blueGradient);
86 public FilterRepresentation getDefaultRepresentation() {
90 protected Matrix getOriginalToScreenMatrix(int w, int h) {
91 return GeometryMathUtils.getImageToScreenMatrix(getEnvironment().getImagePreset()
92 .getGeometryFilters(), true, MasterImage.getImage().getOriginalBounds(), w, h);
95 public void setEnvironment(FilterEnvironment environment) {
96 mEnvironment = environment;
99 public FilterEnvironment getEnvironment() {
103 public void setGeneralParameters() {
104 // should implement in subclass which like to transport
105 // some information to other filters. (like the style setting from RetroLux
106 // and Film to FixedFrame)
107 mEnvironment.clearGeneralParameters();