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