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 24 public class Convolve3x3 extends TestBase { 25 private ScriptC_ip2_convolve3x3 mScript; 26 private ScriptIntrinsicConvolve3x3 mIntrinsic; 27 28 private int mWidth; 29 private int mHeight; 30 private boolean mUseIntrinsic; 31 32 public Convolve3x3(boolean useIntrinsic) { 33 mUseIntrinsic = useIntrinsic; 34 } 35 36 public void createTest(android.content.res.Resources res) { 37 mWidth = mInPixelsAllocation.getType().getX(); 38 mHeight = mInPixelsAllocation.getType().getY(); 39 40 float f[] = new float[9]; 41 f[0] = 0.f; f[1] = -1.f; f[2] = 0.f; 42 f[3] = -1.f; f[4] = 5.f; f[5] = -1.f; 43 f[6] = 0.f; f[7] = -1.f; f[8] = 0.f; 44 45 if (mUseIntrinsic) { 46 mIntrinsic = ScriptIntrinsicConvolve3x3.create(mRS, Element.U8_4(mRS)); 47 mIntrinsic.setCoefficients(f); 48 mIntrinsic.setInput(mInPixelsAllocation); 49 } else { 50 mScript = new ScriptC_ip2_convolve3x3(mRS, res, R.raw.ip2_convolve3x3); 51 mScript.set_gCoeffs(f); 52 mScript.set_gIn(mInPixelsAllocation); 53 mScript.set_gWidth(mWidth); 54 mScript.set_gHeight(mHeight); 55 } 56 } 57 58 public void runTest() { 59 if (mUseIntrinsic) { 60 mIntrinsic.forEach(mOutPixelsAllocation); 61 } else { 62 mScript.forEach_root(mOutPixelsAllocation); 63 } 64 } 65 66 } 67