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 17package com.android.rs.imagejb; 18 19import java.lang.Math; 20 21import android.renderscript.Allocation; 22import android.renderscript.Element; 23import android.renderscript.RenderScript; 24import android.renderscript.ScriptIntrinsicBlur; 25import android.renderscript.Type; 26import android.util.Log; 27import android.widget.SeekBar; 28import android.widget.TextView; 29 30public class Blur25 extends TestBase { 31 private boolean mUseIntrinsic = false; 32 private boolean mUseHalfPrecision = false; 33 private ScriptIntrinsicBlur mIntrinsic; 34 35 private int MAX_RADIUS = 25; 36 private ScriptC_threshold mScript; 37 private ScriptC_threshold_half mScript_half; 38 private float mRadius = MAX_RADIUS; 39 private float mSaturation = 1.0f; 40 private Allocation mScratchPixelsAllocation1; 41 private Allocation mScratchPixelsAllocation2; 42 43 44 public Blur25(boolean useIntrinsic, boolean useHalfPrecision) { 45 mUseIntrinsic = useIntrinsic; 46 mUseHalfPrecision = useHalfPrecision; 47 } 48 49 public boolean onBar1Setup(SeekBar b, TextView t) { 50 t.setText("Radius"); 51 b.setProgress(100); 52 return true; 53 } 54 55 56 public void onBar1Changed(int progress) { 57 mRadius = ((float)progress) / 100.0f * MAX_RADIUS; 58 if (mRadius <= 0.10f) { 59 mRadius = 0.10f; 60 } 61 if (mUseIntrinsic) { 62 mIntrinsic.setRadius(mRadius); 63 } else if (mUseHalfPrecision) { 64 mScript_half.invoke_setRadius((int)mRadius); 65 } else { 66 mScript.invoke_setRadius((int)mRadius); 67 } 68 } 69 70 71 public void createTest(android.content.res.Resources res) { 72 int width = mInPixelsAllocation.getType().getX(); 73 int height = mInPixelsAllocation.getType().getY(); 74 75 if (mUseIntrinsic) { 76 mIntrinsic = ScriptIntrinsicBlur.create(mRS, Element.U8_4(mRS)); 77 mIntrinsic.setRadius(MAX_RADIUS); 78 mIntrinsic.setInput(mInPixelsAllocation); 79 } else { 80 81 Type.Builder tb; 82 if (mUseHalfPrecision) 83 tb = new Type.Builder(mRS, Element.F16_4(mRS)); 84 else 85 tb = new Type.Builder(mRS, Element.F32_4(mRS)); 86 tb.setX(width); 87 tb.setY(height); 88 mScratchPixelsAllocation1 = Allocation.createTyped(mRS, tb.create()); 89 mScratchPixelsAllocation2 = Allocation.createTyped(mRS, tb.create()); 90 91 if (mUseHalfPrecision) { 92 mScript_half = new ScriptC_threshold_half(mRS); 93 mScript_half.set_width(width); 94 mScript_half.set_height(height); 95 96 mScript_half.invoke_setRadius(MAX_RADIUS); 97 mScript_half.set_InPixel(mInPixelsAllocation); 98 mScript_half.set_ScratchPixel1(mScratchPixelsAllocation1); 99 mScript_half.set_ScratchPixel2(mScratchPixelsAllocation2); 100 } else { 101 mScript = new ScriptC_threshold(mRS); 102 mScript.set_width(width); 103 mScript.set_height(height); 104 105 mScript.invoke_setRadius(MAX_RADIUS); 106 mScript.set_InPixel(mInPixelsAllocation); 107 mScript.set_ScratchPixel1(mScratchPixelsAllocation1); 108 mScript.set_ScratchPixel2(mScratchPixelsAllocation2); 109 } 110 111 } 112 } 113 114 public void runTest() { 115 if (mUseIntrinsic) { 116 mIntrinsic.forEach(mOutPixelsAllocation); 117 } 118 else if (mUseHalfPrecision) { 119 mScript_half.forEach_copyIn(mInPixelsAllocation, mScratchPixelsAllocation1); 120 mScript_half.forEach_horz(mScratchPixelsAllocation2); 121 mScript_half.forEach_vert(mOutPixelsAllocation); 122 } 123 else { 124 mScript.forEach_copyIn(mInPixelsAllocation, mScratchPixelsAllocation1); 125 mScript.forEach_horz(mScratchPixelsAllocation2); 126 mScript.forEach_vert(mOutPixelsAllocation); 127 } 128 } 129} 130