2 * Copyright (C) 2012 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 void JNIFUNCF(ImageFilter, nativeApplyGradientFilter, jobject bitmap, jint width, jint height,
20 jintArray redGradient, jintArray greenGradient, jintArray blueGradient)
22 char* destination = 0;
23 jint* redGradientArray = 0;
24 jint* greenGradientArray = 0;
25 jint* blueGradientArray = 0;
27 redGradientArray = (*env)->GetIntArrayElements(env, redGradient, NULL);
29 greenGradientArray = (*env)->GetIntArrayElements(env, greenGradient, NULL);
31 blueGradientArray = (*env)->GetIntArrayElements(env, blueGradient, NULL);
33 AndroidBitmap_lockPixels(env, bitmap, (void**) &destination);
35 int len = width * height * 4;
36 for (i = 0; i < len; i+=4)
40 int r = destination[RED];
41 r = redGradientArray[r];
46 int g = destination[GREEN];
47 g = greenGradientArray[g];
48 destination[GREEN] = g;
52 int b = destination[BLUE];
53 b = blueGradientArray[b];
54 destination[BLUE] = b;
58 (*env)->ReleaseIntArrayElements(env, redGradient, redGradientArray, 0);
60 (*env)->ReleaseIntArrayElements(env, greenGradient, greenGradientArray, 0);
62 (*env)->ReleaseIntArrayElements(env, blueGradient, blueGradientArray, 0);
63 AndroidBitmap_unlockPixels(env, bitmap);