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.image2; 18 19import java.lang.Math; 20 21import android.graphics.Bitmap; 22import android.support.v8.renderscript.*; 23import android.util.Log; 24import android.widget.SeekBar; 25import android.widget.TextView; 26 27public 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 updateBitmap(Bitmap b) { 80 mScript.forEach_toU8_4(mScratchPixelsAllocation2, mOutPixelsAllocation); 81 mOutPixelsAllocation.copyTo(b); 82 } 83 84} 85 86