Convolve5x5.java revision 572a5031a5d8602db0bec0b253428a034bd4dd59
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.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.ScriptIntrinsicConvolve5x5; 29import android.renderscript.Type; 30import android.util.Log; 31 32public class Convolve5x5 extends TestBase { 33 private ScriptC_convolve5x5 mScript; 34 private ScriptIntrinsicConvolve5x5 mIntrinsic; 35 36 private int mWidth; 37 private int mHeight; 38 private boolean mUseIntrinsic; 39 40 public Convolve5x5(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[25]; 49 //f[0] = 0.012f; f[1] = 0.025f; f[2] = 0.031f; f[3] = 0.025f; f[4] = 0.012f; 50 //f[5] = 0.025f; f[6] = 0.057f; f[7] = 0.075f; f[8] = 0.057f; f[9] = 0.025f; 51 //f[10]= 0.031f; f[11]= 0.075f; f[12]= 0.095f; f[13]= 0.075f; f[14]= 0.031f; 52 //f[15]= 0.025f; f[16]= 0.057f; f[17]= 0.075f; f[18]= 0.057f; f[19]= 0.025f; 53 //f[20]= 0.012f; f[21]= 0.025f; f[22]= 0.031f; f[23]= 0.025f; f[24]= 0.012f; 54 55 //f[0] = 1.f; f[1] = 2.f; f[2] = 0.f; f[3] = -2.f; f[4] = -1.f; 56 //f[5] = 4.f; f[6] = 8.f; f[7] = 0.f; f[8] = -8.f; f[9] = -4.f; 57 //f[10]= 6.f; f[11]=12.f; f[12]= 0.f; f[13]=-12.f; f[14]= -6.f; 58 //f[15]= 4.f; f[16]= 8.f; f[17]= 0.f; f[18]= -8.f; f[19]= -4.f; 59 //f[20]= 1.f; f[21]= 2.f; f[22]= 0.f; f[23]= -2.f; f[24]= -1.f; 60 61 f[0] = -1.f; f[1] = -3.f; f[2] = -4.f; f[3] = -3.f; f[4] = -1.f; 62 f[5] = -3.f; f[6] = 0.f; f[7] = 6.f; f[8] = 0.f; f[9] = -3.f; 63 f[10]= -4.f; f[11]= 6.f; f[12]= 20.f; f[13]= 6.f; f[14]= -4.f; 64 f[15]= -3.f; f[16]= 0.f; f[17]= 6.f; f[18]= 0.f; f[19]= -3.f; 65 f[20]= -1.f; f[21]= -3.f; f[22]= -4.f; f[23]= -3.f; f[24]= -1.f; 66 67 if (mUseIntrinsic) { 68 mIntrinsic = ScriptIntrinsicConvolve5x5.create(mRS, Element.U8_4(mRS)); 69 mIntrinsic.setCoefficients(f); 70 mIntrinsic.setInput(mInPixelsAllocation); 71 } else { 72 mScript = new ScriptC_convolve5x5(mRS, res, R.raw.convolve5x5); 73 mScript.set_gCoeffs(f); 74 mScript.set_gIn(mInPixelsAllocation); 75 mScript.set_gWidth(mWidth); 76 mScript.set_gHeight(mHeight); 77 } 78 } 79 80 public void runTest() { 81 if (mUseIntrinsic) { 82 mIntrinsic.forEach(mOutPixelsAllocation); 83 } else { 84 mScript.forEach_root(mOutPixelsAllocation); 85 } 86 } 87 88} 89