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