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 __inline__ int interp(unsigned char *src, int p , int *off ,float dr,float dg, float db){
21 float fr00 = (src[p+off[0]])*(1-dr)+(src[p+off[1]])*dr;
22 float fr01 = (src[p+off[2]])*(1-dr)+(src[p+off[3]])*dr;
23 float fr10 = (src[p+off[4]])*(1-dr)+(src[p+off[5]])*dr;
24 float fr11 = (src[p+off[6]])*(1-dr)+(src[p+off[7]])*dr;
25 float frb0 = fr00 * (1-db)+fr01*db;
26 float frb1 = fr10 * (1-db)+fr11*db;
27 float frbg = frb0 * (1-dg)+frb1*dg;
32 void JNIFUNCF(ImageFilterFx, nativeApplyFilter, jobject bitmap, jint width __unused,
33 jint height __unused, jobject lutbitmap, jint lutwidth, jint lutheight,
36 char* destination = 0;
38 AndroidBitmap_lockPixels(env, bitmap, (void**) &destination);
39 AndroidBitmap_lockPixels(env, lutbitmap, (void**) &lut);
40 unsigned char * rgb = (unsigned char * )destination;
41 unsigned char * lutrgb = (unsigned char * )lut;
42 int lutdim_r = lutheight;
43 int lutdim_g = lutheight;;
44 int lutdim_b = lutwidth/lutheight;;
52 STEP*(lutdim_r*lutdim_b),
53 STEP*(lutdim_r*lutdim_b+1),
54 STEP*(lutdim_r*lutdim_b+lutdim_r),
55 STEP*(lutdim_r*lutdim_b+lutdim_r + 1)
58 float scale_R = (lutdim_r-1.f)/256.f;
59 float scale_G = (lutdim_g-1.f)/256.f;
60 float scale_B = (lutdim_b-1.f)/256.f;
63 for (i = start; i < end; i+= STEP)
75 int p = lut_r+lut_b*lutdim_r+lut_g*lutdim_r*lutdim_b;
80 rgb[RED] = clamp(interp(lutrgb,p ,off,dr,dg,db));
81 rgb[GREEN] = clamp(interp(lutrgb,p+1,off,dr,dg,db));
82 rgb[BLUE] = clamp(interp(lutrgb,p+2,off,dr,dg,db));
86 AndroidBitmap_unlockPixels(env, bitmap);
87 AndroidBitmap_unlockPixels(env, lutbitmap);