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.imagejb;
     18 
     19 import java.lang.Math;
     20 
     21 import android.renderscript.Allocation;
     22 import android.renderscript.Element;
     23 import android.renderscript.Matrix4f;
     24 import android.renderscript.RenderScript;
     25 import android.renderscript.Script;
     26 import android.renderscript.ScriptC;
     27 import android.renderscript.ScriptIntrinsicColorMatrix;
     28 import android.renderscript.Type;
     29 import android.util.Log;
     30 
     31 public class ColorMatrix extends TestBase {
     32     private ScriptC_colormatrix mScript;
     33     private ScriptIntrinsicColorMatrix mIntrinsic;
     34     private boolean mUseIntrinsic;
     35     private boolean mUseGrey;
     36 
     37     public ColorMatrix(boolean useIntrinsic, boolean useGrey) {
     38         mUseIntrinsic = useIntrinsic;
     39         mUseGrey = useGrey;
     40     }
     41 
     42     public void createTest(android.content.res.Resources res) {
     43         Matrix4f m = new Matrix4f();
     44         m.set(1, 0, 0.2f);
     45         m.set(1, 1, 0.9f);
     46         m.set(1, 2, 0.2f);
     47 
     48         if (mUseIntrinsic) {
     49             mIntrinsic = ScriptIntrinsicColorMatrix.create(mRS, Element.U8_4(mRS));
     50             if (mUseGrey) {
     51                 mIntrinsic.setGreyscale();
     52             } else {
     53                 mIntrinsic.setColorMatrix(m);
     54             }
     55         } else {
     56             mScript = new ScriptC_colormatrix(mRS);
     57             mScript.invoke_setMatrix(m);
     58         }
     59     }
     60 
     61     public void animateBars(float time) {
     62         Matrix4f m = new Matrix4f();
     63         m.set(1, 0, (time + 0.2f) % 1.0f);
     64         m.set(1, 1, (time + 0.9f) % 1.0f);
     65         m.set(1, 2, (time + 0.4f) % 1.0f);
     66         if (mUseIntrinsic) {
     67             if (mUseGrey) {
     68                 return;
     69             } else {
     70                 mIntrinsic.setColorMatrix(m);
     71             }
     72         } else {
     73             mScript.invoke_setMatrix(m);
     74         }
     75     }
     76 
     77     public void runTest() {
     78         if (mUseIntrinsic) {
     79             mIntrinsic.forEach(mInPixelsAllocation, mOutPixelsAllocation);
     80         } else {
     81             mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
     82         }
     83     }
     84 
     85 }
     86