Home | History | Annotate | Download | only in image
      1 /*
      2  * Copyright (C) 2013 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.*;
     22 import android.util.Log;
     23 
     24 public class Histogram extends TestBase {
     25     private ScriptC_histogram mScript;
     26     private ScriptIntrinsicHistogram mHist;
     27     private Allocation mSum;
     28     private Allocation mSums;
     29     private boolean mUseIntrinsic;
     30 
     31     public Histogram(boolean useIntrisic) {
     32         mUseIntrinsic = useIntrisic;
     33     }
     34 
     35 
     36     public void createTest(android.content.res.Resources res) {
     37         mScript = new ScriptC_histogram(mRS);
     38         mHist = ScriptIntrinsicHistogram.create(mRS, Element.U8_4(mRS));
     39 
     40         int w = mInPixelsAllocation.getType().getX();
     41         int h = mInPixelsAllocation.getType().getY();
     42         int step = 8;
     43         int steps = (h + step - 1) / step;
     44 
     45         mScript.set_gWidth(w);
     46         mScript.set_gHeight(h);
     47         mScript.set_gStep(step);
     48         mScript.set_gSteps(steps);
     49 
     50         Type.Builder tb = new Type.Builder(mRS, Element.I32(mRS));
     51         tb.setX(256).setY(steps);
     52         Type t = tb.create();
     53         mSums = Allocation.createTyped(mRS, t);
     54         mSum = Allocation.createSized(mRS, Element.I32(mRS), 256);
     55 
     56         mScript.set_gSums(mSums);
     57         mScript.set_gSum(mSum);
     58         mScript.set_gSrc(mInPixelsAllocation);
     59         mScript.set_gDest(mOutPixelsAllocation);
     60 
     61         mScript.forEach_clear(mOutPixelsAllocation);
     62     }
     63 
     64 
     65 
     66     public void runTest() {
     67         Script.LaunchOptions lo = new Script.LaunchOptions();
     68 
     69         if (mUseIntrinsic) {
     70             mHist.setOutput(mSum);
     71             mHist.forEach_Dot(mInPixelsAllocation);
     72         } else {
     73             lo.setX(0, mSums.getType().getY());
     74             mScript.forEach_pass1(lo);
     75             mScript.forEach_pass2(mSum);
     76         }
     77 
     78         mScript.invoke_rescale();
     79         lo.setX(0, 1024);
     80         mScript.forEach_draw(mOutPixelsAllocation, lo);
     81     }
     82 
     83 }
     84