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 #pragma version(1)
     18 #pragma rs java_package_name(com.android.gallery3d.filtershow.filters)
     19 #pragma rs_fp_relaxed
     20 
     21 int32_t gWidth;
     22 int32_t gHeight;
     23 const uchar4 *gPixels;
     24 rs_allocation gIn;
     25 
     26 float gCoeffs[9];
     27 
     28 void root(const uchar4 *in, uchar4 *out, const void *usrData, uint32_t x, uint32_t y) {
     29     uint32_t x1 = min((int32_t)x+1, gWidth-1);
     30     uint32_t x2 = max((int32_t)x-1, 0);
     31     uint32_t y1 = min((int32_t)y+1, gHeight-1);
     32     uint32_t y2 = max((int32_t)y-1, 0);
     33 
     34     float4 p00 = rsUnpackColor8888(gPixels[x1 + gWidth * y1]);
     35     float4 p01 = rsUnpackColor8888(gPixels[x + gWidth * y1]);
     36     float4 p02 = rsUnpackColor8888(gPixels[x2 + gWidth * y1]);
     37     float4 p10 = rsUnpackColor8888(gPixels[x1 + gWidth * y]);
     38     float4 p11 = rsUnpackColor8888(gPixels[x + gWidth * y]);
     39     float4 p12 = rsUnpackColor8888(gPixels[x2 + gWidth * y]);
     40     float4 p20 = rsUnpackColor8888(gPixels[x1 + gWidth * y2]);
     41     float4 p21 = rsUnpackColor8888(gPixels[x + gWidth * y2]);
     42     float4 p22 = rsUnpackColor8888(gPixels[x2 + gWidth * y2]);
     43 
     44     p00 *= gCoeffs[0];
     45     p01 *= gCoeffs[1];
     46     p02 *= gCoeffs[2];
     47     p10 *= gCoeffs[3];
     48     p11 *= gCoeffs[4];
     49     p12 *= gCoeffs[5];
     50     p20 *= gCoeffs[6];
     51     p21 *= gCoeffs[7];
     52     p22 *= gCoeffs[8];
     53 
     54     p00 += p01;
     55     p02 += p10;
     56     p11 += p12;
     57     p20 += p21;
     58 
     59     p22 += p00;
     60     p02 += p11;
     61 
     62     p20 += p22;
     63     p20 += p02;
     64 
     65     p20 = clamp(p20, 0.f, 1.f);
     66     *out = rsPackColorTo8888(p20.r, p20.g, p20.b);
     67 }
     68