Home | History | Annotate | Download | only in image
      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 package com.android.rs.image;
     18 
     19 import java.lang.Math;
     20 
     21 import android.renderscript.Allocation;
     22 import android.renderscript.Element;
     23 import android.renderscript.RenderScript;
     24 import android.renderscript.ScriptIntrinsicLUT;
     25 import android.util.Log;
     26 
     27 public class CrossProcess extends TestBase {
     28     private ScriptIntrinsicLUT mIntrinsic;
     29 
     30     public void createTest(android.content.res.Resources res) {
     31         mIntrinsic = ScriptIntrinsicLUT.create(mRS, Element.U8_4(mRS));
     32         for (int ct=0; ct < 256; ct++) {
     33             float f = ((float)ct) / 255.f;
     34 
     35             float r = f;
     36             if (r < 0.5f) {
     37                 r = 4.0f * r * r * r;
     38             } else {
     39                 r = 1.0f - r;
     40                 r = 1.0f - (4.0f * r * r * r);
     41             }
     42             mIntrinsic.setRed(ct, (int)(r * 255.f + 0.5f));
     43 
     44             float g = f;
     45             if (g < 0.5f) {
     46                 g = 2.0f * g * g;
     47             } else {
     48                 g = 1.0f - g;
     49                 g = 1.0f - (2.0f * g * g);
     50             }
     51             mIntrinsic.setGreen(ct, (int)(g * 255.f + 0.5f));
     52 
     53             float b = f * 0.5f + 0.25f;
     54             mIntrinsic.setBlue(ct, (int)(b * 255.f + 0.5f));
     55         }
     56 
     57     }
     58 
     59     public void runTest() {
     60         mIntrinsic.forEach(mInPixelsAllocation, mOutPixelsAllocation);
     61     }
     62 
     63 }
     64