diff options
author | nicolasroard <nicolasroard@google.com> | 2012-09-25 14:27:56 -0700 |
---|---|---|
committer | nicolasroard <nicolasroard@google.com> | 2012-09-26 16:13:45 -0700 |
commit | 5728a84cf5fa2733b09af06b9016957a9a566624 (patch) | |
tree | d6d95a724fa12a61dc03460865758c9392e59217 /src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java | |
parent | 4994b8649de154c59de47cb1a2e14acca1a17096 (diff) | |
download | android_packages_apps_Snap-5728a84cf5fa2733b09af06b9016957a9a566624.tar.gz android_packages_apps_Snap-5728a84cf5fa2733b09af06b9016957a9a566624.tar.bz2 android_packages_apps_Snap-5728a84cf5fa2733b09af06b9016957a9a566624.zip |
Initial import of the new image editor
bug:7165910
Change-Id: I756d6594f5bddd233772c979410362ca22e232a3
Diffstat (limited to 'src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java')
-rw-r--r-- | src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java new file mode 100644 index 000000000..c21ae1f9f --- /dev/null +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java @@ -0,0 +1,106 @@ + +package com.android.gallery3d.filtershow.filters; + +import com.android.gallery3d.filtershow.ui.Spline; + +import android.graphics.Bitmap; +import android.util.Log; + +public class ImageFilterCurves extends ImageFilter { + + private static final String LOGTAG = "ImageFilterCurves"; + + private float[] mCurve = new float[256]; + + private boolean mUseRed = true; + private boolean mUseGreen = true; + private boolean mUseBlue = true; + private String mName = "Curves"; + private Spline mSpline = null; + + public String name() { + return mName; + } + + public void setName(String name) { + mName = name; + } + + public void setUseRed(boolean value) { + mUseRed = value; + } + + public void setUseGreen(boolean value) { + mUseGreen = value; + } + + public void setUseBlue(boolean value) { + mUseBlue = value; + } + + public void setCurve(float[] curve) { + for (int i = 0; i < curve.length; i++) { + if (i < 256) { + mCurve[i] = curve[i]; + } + } + } + + public boolean same(ImageFilter filter) { + boolean isCurveFilter = super.same(filter); + if (!isCurveFilter) { + return false; + } + ImageFilterCurves curve = (ImageFilterCurves) filter; + for (int i = 0; i < 256; i++) { + if (curve.mCurve[i] != mCurve[i]) { + return false; + } + } + return true; + } + + public ImageFilter copy() { + ImageFilterCurves curves = new ImageFilterCurves(); + curves.setCurve(mCurve); + curves.setName(mName); + curves.setSpline(new Spline(mSpline)); + return curves; + } + + public void populateArray(int[] array) { + for (int i = 0; i < 256; i++) { + array[i] = (int) (mCurve[i]); + } + } + + public void apply(Bitmap bitmap) { + + int[] redGradient = null; + if (mUseRed) { + redGradient = new int[256]; + populateArray(redGradient); + } + int[] greenGradient = null; + if (mUseGreen) { + greenGradient = new int[256]; + populateArray(greenGradient); + } + int[] blueGradient = null; + if (mUseBlue) { + blueGradient = new int[256]; + populateArray(blueGradient); + } + + nativeApplyGradientFilter(bitmap, bitmap.getWidth(), bitmap.getHeight(), + redGradient, greenGradient, blueGradient); + } + + public void setSpline(Spline spline) { + mSpline = spline; + } + + public Spline getSpline() { + return mSpline; + } +} |