summaryrefslogtreecommitdiffstats
path: root/jni
diff options
context:
space:
mode:
authorJohn Hoford <hoford@google.com>2013-02-16 17:20:59 (GMT)
committerJohn Hoford <hoford@google.com>2013-02-19 23:25:43 (GMT)
commit4c54808f10fa647c4dc8f95551eb369172535d50 (patch)
tree571d3e0242ae4eb5c121a442b68592efed7511ec /jni
parentf03a91a0f1c3b20eb73de2910391ea7575e67b54 (diff)
downloadandroid_packages_apps_Snap-4c54808f10fa647c4dc8f95551eb369172535d50.zip
android_packages_apps_Snap-4c54808f10fa647c4dc8f95551eb369172535d50.tar.gz
android_packages_apps_Snap-4c54808f10fa647c4dc8f95551eb369172535d50.tar.bz2
add movable vignette
Change-Id: I54f2fccd0d748ca4c908d5b0f3c3ef7349cd686d
Diffstat (limited to 'jni')
-rw-r--r--jni/filters/vignette.c44
1 files changed, 12 insertions, 32 deletions
diff --git a/jni/filters/vignette.c b/jni/filters/vignette.c
index 2799ff0..b9ee3ff 100644
--- a/jni/filters/vignette.c
+++ b/jni/filters/vignette.c
@@ -15,52 +15,32 @@
*/
#include "filters.h"
+#include <math.h>
static int* gVignetteMap = 0;
static int gVignetteWidth = 0;
static int gVignetteHeight = 0;
-__inline__ void createVignetteMap(int w, int h)
-{
- if (gVignetteMap && (gVignetteWidth != w || gVignetteHeight != h))
- {
- free(gVignetteMap);
- gVignetteMap = 0;
- }
- if (gVignetteMap == 0)
- {
- gVignetteWidth = w;
- gVignetteHeight = h;
-
- int cx = w / 2;
- int cy = h / 2;
- int i, j;
-
- gVignetteMap = malloc(w * h * sizeof(int));
- float maxDistance = cx * cx * 2.0f;
- for (i = 0; i < w; i++)
- {
- for (j = 0; j < h; j++)
- {
- float distance = (cx - i) * (cx - i) + (cy - j) * (cy - j);
- gVignetteMap[j * w + i] = (int) (distance / maxDistance * 255);
- }
- }
- }
-}
-
-void JNIFUNCF(ImageFilterVignette, nativeApplyFilter, jobject bitmap, jint width, jint height, jfloat strength)
+void JNIFUNCF(ImageFilterVignette, nativeApplyFilter, jobject bitmap, jint width, jint height, jint centerx, jint centery, jfloat radiusx, jfloat radiusy, jfloat strength)
{
char* destination = 0;
AndroidBitmap_lockPixels(env, bitmap, (void**) &destination);
- createVignetteMap(width, height);
int i;
int len = width * height * 4;
int vignette = 0;
+ float d = centerx;
+ if (radiusx == 0) radiusx = 10;
+ if (radiusy == 0) radiusy = 10;
+ float scalex = 1/radiusx;
+ float scaley = 1/radiusy;
for (i = 0; i < len; i += 4)
{
- vignette = (int) (strength * gVignetteMap[i / 4]);
+ int p = i/4;
+ float x = ((p%width)-centerx)*scalex;
+ float y = ((p/width)-centery)*scaley;
+ float dist = sqrt(x*x+y*y)-1;
+ vignette = (int) (strength*256*MAX(dist,0));
destination[RED] = CLAMP(destination[RED] - vignette);
destination[GREEN] = CLAMP(destination[GREEN] - vignette);
destination[BLUE] = CLAMP(destination[BLUE] - vignette);