ImageFilterFx.java revision 8029c8567a162eb66fe54255bdeae264d594278d
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.filtershow.editors.BasicEditor; 22import com.android.gallery3d.filtershow.editors.ImageOnlyEditor; 23 24public class ImageFilterFx extends ImageFilter { 25 private static final String TAG = "ImageFilterFx"; 26 Bitmap fxBitmap; 27 int mNameResource = 0; 28 private FilterFxRepresentation mParameters = null; 29 30 public ImageFilterFx() { 31 32 } 33 34 public ImageFilterFx(Bitmap fxBitmap, String name, int nameResource) { 35 setFilterType(TYPE_FX); 36 mName = name; 37 this.fxBitmap = fxBitmap; 38 mNameResource = nameResource; 39 } 40 41 public void useRepresentation(FilterRepresentation representation) { 42 FilterFxRepresentation parameters = (FilterFxRepresentation) representation; 43 mParameters = parameters; 44 } 45 46 public FilterFxRepresentation getParameters() { 47 return mParameters; 48 } 49 50 @Override 51 public int getTextId() { 52 return mNameResource; 53 } 54 55 public boolean isNil() { 56 if (fxBitmap != null) { 57 return false; 58 } 59 return true; 60 } 61 62 @Override 63 public int getEditingViewId() { 64 return ImageOnlyEditor.ID; 65 } 66 67 @Override 68 public boolean showParameterValue() { 69 return false; 70 } 71 72 @Override 73 public boolean showEditingControls() { 74 return false; 75 } 76 77 @Override 78 public boolean showUtilityPanel() { 79 return false; 80 } 81 82 native protected void nativeApplyFilter(Bitmap bitmap, int w, int h,Bitmap fxBitmap, int fxw, int fxh); 83 84 @Override 85 public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) { 86 if (getParameters() == null || getParameters().getFxBitmap() ==null) { 87 return bitmap; 88 } 89 90 int w = bitmap.getWidth(); 91 int h = bitmap.getHeight(); 92 93 int fxw = getParameters().getFxBitmap().getWidth(); 94 int fxh = getParameters().getFxBitmap().getHeight(); 95 96 nativeApplyFilter(bitmap, w, h, getParameters().getFxBitmap(), fxw, fxh); 97 return bitmap; 98 } 99} 100