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.image2;
     18 
     19 import java.lang.Math;
     20 
     21 import android.graphics.Bitmap;
     22 import android.support.v8.renderscript.*;
     23 import android.util.Log;
     24 import android.widget.SeekBar;
     25 import android.widget.TextView;
     26 
     27 public class Blur25G extends TestBase {
     28     private final int MAX_RADIUS = 25;
     29     private float mRadius = MAX_RADIUS;
     30 
     31     private ScriptIntrinsicBlur mIntrinsic;
     32 
     33     private ScriptC_greyscale mScript;
     34     private Allocation mScratchPixelsAllocation1;
     35     private Allocation mScratchPixelsAllocation2;
     36 
     37 
     38     public Blur25G() {
     39     }
     40 
     41     public boolean onBar1Setup(SeekBar b, TextView t) {
     42         t.setText("Radius");
     43         b.setProgress(100);
     44         return true;
     45     }
     46 
     47 
     48     public void onBar1Changed(int progress) {
     49         mRadius = ((float)progress) / 100.0f * MAX_RADIUS;
     50         if (mRadius <= 0.10f) {
     51             mRadius = 0.10f;
     52         }
     53         mIntrinsic.setRadius(mRadius);
     54     }
     55 
     56 
     57     public void createTest(android.content.res.Resources res) {
     58         int width = mInPixelsAllocation.getType().getX();
     59         int height = mInPixelsAllocation.getType().getY();
     60 
     61         Type.Builder tb = new Type.Builder(mRS, Element.U8(mRS));
     62         tb.setX(width);
     63         tb.setY(height);
     64         mScratchPixelsAllocation1 = Allocation.createTyped(mRS, tb.create());
     65         mScratchPixelsAllocation2 = Allocation.createTyped(mRS, tb.create());
     66 
     67         mScript = new ScriptC_greyscale(mRS);
     68         mScript.forEach_toU8(mInPixelsAllocation, mScratchPixelsAllocation1);
     69 
     70         mIntrinsic = ScriptIntrinsicBlur.create(mRS, Element.U8(mRS));
     71         mIntrinsic.setRadius(MAX_RADIUS);
     72         mIntrinsic.setInput(mScratchPixelsAllocation1);
     73     }
     74 
     75     public void runTest() {
     76         mIntrinsic.forEach(mScratchPixelsAllocation2);
     77     }
     78 
     79     public void setupBenchmark() {
     80         mIntrinsic.setRadius(MAX_RADIUS);
     81     }
     82 
     83     public void exitBenchmark() {
     84         mIntrinsic.setRadius(mRadius);
     85     }
     86 
     87     public void updateBitmap(Bitmap b) {
     88         mScript.forEach_toU8_4(mScratchPixelsAllocation2, mOutPixelsAllocation);
     89         mOutPixelsAllocation.copyTo(b);
     90     }
     91 
     92 }
     93 
     94