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