Home | History | Annotate | Download | only in filters
      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 
     19 void JNIFUNCF(ImageFilterHue, nativeApplyFilter, jobject bitmap, jint width, jint height, jfloatArray matrix)
     20 {
     21     char* destination = 0;
     22     AndroidBitmap_lockPixels(env, bitmap, (void**) &destination);
     23     unsigned char * rgb = (unsigned char * )destination;
     24     int i;
     25     int len = width * height * 4;
     26     jfloat* mat = (*env)->GetFloatArrayElements(env, matrix,0);
     27 
     28     for (i = 0; i < len; i+=4)
     29     {
     30       int r = rgb[RED];
     31       int g = rgb[GREEN];
     32       int b = rgb[BLUE];
     33 
     34       float rf = r*mat[0] + g*mat[4] +  b*mat[8] + mat[12];
     35       float gf = r*mat[1] + g*mat[5] +  b*mat[9] + mat[13];
     36       float bf = r*mat[2] + g*mat[6] +  b*mat[10] + mat[14];
     37 
     38       rgb[RED]   = clamp((int)rf);
     39       rgb[GREEN] = clamp((int)gf);
     40       rgb[BLUE]  = clamp((int)bf);
     41     }
     42 
     43     (*env)->ReleaseFloatArrayElements(env, matrix, mat, 0);
     44     AndroidBitmap_unlockPixels(env, bitmap);
     45 }
     46 
     47