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
17 #include "filters.h"
18
JNIFUNCF(ImageFilter,nativeApplyGradientFilter,jobject bitmap,jint width,jint height,jintArray redGradient,jintArray greenGradient,jintArray blueGradient)19 void JNIFUNCF(ImageFilter, nativeApplyGradientFilter, jobject bitmap, jint width, jint height,
20 jintArray redGradient, jintArray greenGradient, jintArray blueGradient)
21 {
22 char* destination = 0;
23 jint* redGradientArray = 0;
24 jint* greenGradientArray = 0;
25 jint* blueGradientArray = 0;
26 if (redGradient)
27 redGradientArray = (*env)->GetIntArrayElements(env, redGradient, NULL);
28 if (greenGradient)
29 greenGradientArray = (*env)->GetIntArrayElements(env, greenGradient, NULL);
30 if (blueGradient)
31 blueGradientArray = (*env)->GetIntArrayElements(env, blueGradient, NULL);
32
33 AndroidBitmap_lockPixels(env, bitmap, (void**) &destination);
34 int i;
35 int len = width * height * 4;
36 for (i = 0; i < len; i+=4)
37 {
38 if (redGradient)
39 {
40 int r = destination[RED];
41 r = redGradientArray[r];
42 destination[RED] = r;
43 }
44 if (greenGradient)
45 {
46 int g = destination[GREEN];
47 g = greenGradientArray[g];
48 destination[GREEN] = g;
49 }
50 if (blueGradient)
51 {
52 int b = destination[BLUE];
53 b = blueGradientArray[b];
54 destination[BLUE] = b;
55 }
56 }
57 if (redGradient)
58 (*env)->ReleaseIntArrayElements(env, redGradient, redGradientArray, 0);
59 if (greenGradient)
60 (*env)->ReleaseIntArrayElements(env, greenGradient, greenGradientArray, 0);
61 if (blueGradient)
62 (*env)->ReleaseIntArrayElements(env, blueGradient, blueGradientArray, 0);
63 AndroidBitmap_unlockPixels(env, bitmap);
64 }
65
66