OSDN Git Service

Added photonegative filter.
authorRuben Brunk <rubenbrunk@google.com>
Tue, 11 Dec 2012 03:40:27 +0000 (19:40 -0800)
committerRuben Brunk <rubenbrunk@google.com>
Thu, 13 Dec 2012 00:03:45 +0000 (16:03 -0800)
Change-Id: I73594573b26873cb3fda49aca6d40761dec3707f

jni/Android.mk
jni/filters/negative.c [new file with mode: 0644]
res/values/filtershow_ids.xml
res/values/filtershow_strings.xml
src/com/android/gallery3d/filtershow/FilterShowActivity.java
src/com/android/gallery3d/filtershow/PanelController.java
src/com/android/gallery3d/filtershow/filters/ImageFilter.java
src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java
src/com/android/gallery3d/filtershow/filters/ImageFilterNegative.java [new file with mode: 0644]

index db31bfd..8a2fc9e 100644 (file)
@@ -35,6 +35,7 @@ LOCAL_SRC_FILES := filters/bw.c \
                    filters/hsv.c \
                    filters/vibrance.c \
                    filters/geometry.c \
+                   filters/negative.c \
                    filters/vignette.c \
                    filters/redEyeMath.c \
                    filters/fx.c \
diff --git a/jni/filters/negative.c b/jni/filters/negative.c
new file mode 100644 (file)
index 0000000..735e583
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "filters.h"
+
+void JNIFUNCF(ImageFilterNegative, nativeApplyFilter, jobject bitmap, jint width, jint height)
+{
+    char* destination = 0;
+    AndroidBitmap_lockPixels(env, bitmap, (void**) &destination);
+
+    int tot_len = height * width * 4;
+    int i;
+    char * dst = destination;
+    for (i = 0; i < tot_len; i+=4) {
+        dst[RED] = 255 - dst[RED];
+        dst[GREEN] = 255 - dst[GREEN];
+        dst[BLUE] = 255 - dst[BLUE];
+    }
+    AndroidBitmap_unlockPixels(env, bitmap);
+}
index 502d2f8..7f7c98b 100644 (file)
@@ -30,4 +30,5 @@
     <item type="id" name="shadowRecoveryButton" />
     <item type="id" name="sharpenButton" />
     <item type="id" name="curvesButtonRGB" />
+    <item type="id" name="negativeButton" />
 </resources>
index 7cfcfa0..e011396 100644 (file)
     <string name="rotate" msgid="460017689320955494">Rotate</string>
     <!--  Label for the image flip effect [CHAR LIMIT=15] -->
     <string name="mirror">Mirror</string>
+    <!-- Name for the photo effect that inverts photo to negative images. [CHAR LIMIT=10] -->
+    <string name="negative">Negative</string>
     <!--  Label for having no filters applied to the image [CHAR LIMIT=10] -->
     <string name="none" msgid="3601545724573307541">None</string>
 
index c7de018..6275ae6 100644 (file)
@@ -64,6 +64,7 @@ import com.android.gallery3d.filtershow.filters.ImageFilterCurves;
 import com.android.gallery3d.filtershow.filters.ImageFilterExposure;
 import com.android.gallery3d.filtershow.filters.ImageFilterFx;
 import com.android.gallery3d.filtershow.filters.ImageFilterHue;
+import com.android.gallery3d.filtershow.filters.ImageFilterNegative;
 import com.android.gallery3d.filtershow.filters.ImageFilterParametricBorder;
 import com.android.gallery3d.filtershow.filters.ImageFilterRS;
 import com.android.gallery3d.filtershow.filters.ImageFilterSaturated;
@@ -307,7 +308,8 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
                 new ImageFilterCurves(),
                 new ImageFilterHue(),
                 new ImageFilterSaturated(),
-                new ImageFilterBwFilter()
+                new ImageFilterBwFilter(),
+                new ImageFilterNegative()
         };
 
         for (int i = 0; i < filters.length; i++) {
index 4f59258..41833a6 100644 (file)
@@ -32,6 +32,7 @@ import com.android.gallery3d.filtershow.filters.ImageFilterContrast;
 import com.android.gallery3d.filtershow.filters.ImageFilterCurves;
 import com.android.gallery3d.filtershow.filters.ImageFilterExposure;
 import com.android.gallery3d.filtershow.filters.ImageFilterHue;
+import com.android.gallery3d.filtershow.filters.ImageFilterNegative;
 import com.android.gallery3d.filtershow.filters.ImageFilterRedEye;
 import com.android.gallery3d.filtershow.filters.ImageFilterSaturated;
 import com.android.gallery3d.filtershow.filters.ImageFilterShadows;
@@ -571,9 +572,9 @@ public class PanelController implements OnClickListener {
                 if (view.getId() == R.id.curvesButtonRGB) {
                     // TODO: delegate to the filter / editing view the management of the
                     // panel accessory view
-                    mUtilityPanel.setShowParameter(false);
                     mUtilityPanel.showCurvesButtons();
                 }
+                mUtilityPanel.setShowParameter(filter.showParameterValue());
                 ensureFilter(ename);
                 mCurrentImage.select();
             }
index 8bd8556..2319fcc 100644 (file)
@@ -68,6 +68,10 @@ public class ImageFilter implements Cloneable {
         return true;
     }
 
+    public boolean showParameterValue() {
+        return true;
+    }
+
     @Override
     public ImageFilter clone() throws CloneNotSupportedException {
         ImageFilter filter = (ImageFilter) super.clone();
index 46a00f4..ba49a8f 100644 (file)
@@ -52,6 +52,11 @@ public class ImageFilterCurves extends ImageFilter {
     }
 
     @Override
+    public boolean showParameterValue() {
+        return false;
+    }
+
+    @Override
     public ImageFilter clone() throws CloneNotSupportedException {
         ImageFilterCurves filter = (ImageFilterCurves) super.clone();
         for (int i = 0; i < 4; i++) {
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterNegative.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterNegative.java
new file mode 100644 (file)
index 0000000..04fd1e4
--- /dev/null
@@ -0,0 +1,47 @@
+package com.android.gallery3d.filtershow.filters;
+
+import android.graphics.Bitmap;
+
+import com.android.gallery3d.R;
+
+public class ImageFilterNegative extends ImageFilter {
+
+    public ImageFilterNegative() {
+        mName = "Negative";
+    }
+
+    @Override
+    public int getButtonId() {
+        return R.id.negativeButton;
+    }
+
+    @Override
+    public int getTextId() {
+        return R.string.negative;
+    }
+
+    @Override
+    public boolean isNil() {
+        return false;
+    }
+
+    @Override
+    public boolean showEditingControls() {
+        return false;
+    }
+
+    @Override
+    public boolean showParameterValue() {
+        return false;
+    }
+
+    native protected void nativeApplyFilter(Bitmap bitmap, int w, int h);
+
+    @Override
+    public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
+        int w = bitmap.getWidth();
+        int h = bitmap.getHeight();
+        nativeApplyFilter(bitmap, w, h);
+        return bitmap;
+    }
+}