1 /* 2 * Copyright (C) 2013 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 21 import com.android.gallery3d.R; 22 23 public class ImageFilterHighlights extends SimpleImageFilter { 24 private static final String LOGTAG = "ImageFilterVignette"; 25 26 public ImageFilterHighlights() { 27 mName = "Highlights"; 28 } 29 30 SplineMath mSpline = new SplineMath(5); 31 double[] mHighlightCurve = { 0.0, 0.32, 0.418, 0.476, 0.642 }; 32 33 public FilterRepresentation getDefaultRepresentation() { 34 FilterBasicRepresentation representation = 35 (FilterBasicRepresentation) super.getDefaultRepresentation(); 36 representation.setName("Shadows"); 37 representation.setFilterClass(ImageFilterHighlights.class); 38 representation.setTextId(R.string.highlight_recovery); 39 representation.setButtonId(R.id.highlightRecoveryButton); 40 representation.setMinimum(-100); 41 representation.setMaximum(100); 42 representation.setDefaultValue(0); 43 representation.setSupportsPartialRendering(true); 44 return representation; 45 } 46 47 native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float[] luminanceMap); 48 49 @Override 50 public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) { 51 if (getParameters() == null) { 52 return bitmap; 53 } 54 float p = getParameters().getValue(); 55 double t = p/100.; 56 for (int i = 0; i < 5; i++) { 57 double x = i / 4.; 58 double y = mHighlightCurve[i] *t+x*(1-t); 59 mSpline.setPoint(i, x, y); 60 } 61 62 float[][] curve = mSpline.calculatetCurve(256); 63 float[] luminanceMap = new float[curve.length]; 64 for (int i = 0; i < luminanceMap.length; i++) { 65 luminanceMap[i] = curve[i][1]; 66 } 67 int w = bitmap.getWidth(); 68 int h = bitmap.getHeight(); 69 70 nativeApplyFilter(bitmap, w, h, luminanceMap); 71 return bitmap; 72 } 73 } 74