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.support.v8.renderscript.*;
     22 import android.util.Log;
     23 import android.widget.SeekBar;
     24 import android.widget.TextView;
     25 
     26 public class Blur25 extends TestBase {
     27     private boolean mUseIntrinsic = false;
     28     private ScriptIntrinsicBlur mIntrinsic;
     29 
     30     private int MAX_RADIUS = 25;
     31     private ScriptC_threshold mScript;
     32     private float mRadius = MAX_RADIUS;
     33     private float mSaturation = 1.0f;
     34     private Allocation mScratchPixelsAllocation1;
     35     private Allocation mScratchPixelsAllocation2;
     36 
     37 
     38     public Blur25(boolean useIntrinsic) {
     39         mUseIntrinsic = useIntrinsic;
     40     }
     41 
     42     public boolean onBar1Setup(SeekBar b, TextView t) {
     43         t.setText("Radius");
     44         b.setProgress(100);
     45         return true;
     46     }
     47 
     48 
     49     public void onBar1Changed(int progress) {
     50         mRadius = ((float)progress) / 100.0f * MAX_RADIUS;
     51         if (mRadius <= 0.10f) {
     52             mRadius = 0.10f;
     53         }
     54         if (mUseIntrinsic) {
     55             mIntrinsic.setRadius(mRadius);
     56         } else {
     57             mScript.invoke_setRadius((int)mRadius);
     58         }
     59     }
     60 
     61 
     62     public void createTest(android.content.res.Resources res) {
     63         int width = mInPixelsAllocation.getType().getX();
     64         int height = mInPixelsAllocation.getType().getY();
     65 
     66         if (mUseIntrinsic) {
     67             mIntrinsic = ScriptIntrinsicBlur.create(mRS, Element.U8_4(mRS));
     68             mIntrinsic.setRadius(MAX_RADIUS);
     69             mIntrinsic.setInput(mInPixelsAllocation);
     70         } else {
     71 
     72             Type.Builder tb = new Type.Builder(mRS, Element.F32_4(mRS));
     73             tb.setX(width);
     74             tb.setY(height);
     75             mScratchPixelsAllocation1 = Allocation.createTyped(mRS, tb.create());
     76             mScratchPixelsAllocation2 = Allocation.createTyped(mRS, tb.create());
     77 
     78             mScript = new ScriptC_threshold(mRS);
     79             mScript.set_width(width);
     80             mScript.set_height(height);
     81             mScript.invoke_setRadius(MAX_RADIUS);
     82 
     83             mScript.set_InPixel(mInPixelsAllocation);
     84             mScript.set_ScratchPixel1(mScratchPixelsAllocation1);
     85             mScript.set_ScratchPixel2(mScratchPixelsAllocation2);
     86         }
     87     }
     88 
     89     public void runTest() {
     90         if (mUseIntrinsic) {
     91             mIntrinsic.forEach(mOutPixelsAllocation);
     92         } else {
     93             mScript.forEach_copyIn(mInPixelsAllocation, mScratchPixelsAllocation1);
     94             mScript.forEach_horz(mScratchPixelsAllocation2);
     95             mScript.forEach_vert(mOutPixelsAllocation);
     96         }
     97     }
     98 }
     99