Jason Sams | 5729fcd | 2012-09-04 19:57:40 -0700 | [diff] [blame] | 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.image; |
| 18 | |
| 19 | import java.lang.Math; |
| 20 | |
| 21 | import android.renderscript.Allocation; |
| 22 | import android.renderscript.Element; |
| 23 | import android.renderscript.Matrix4f; |
| 24 | import android.renderscript.RenderScript; |
| 25 | import android.renderscript.Script; |
| 26 | import android.renderscript.ScriptC; |
| 27 | import android.renderscript.ScriptGroup; |
| 28 | import android.renderscript.ScriptIntrinsicConvolve3x3; |
| 29 | import android.renderscript.Type; |
| 30 | import android.util.Log; |
| 31 | |
| 32 | public 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)); |
Jason Sams | 80d8190 | 2012-09-13 17:00:48 -0700 | [diff] [blame] | 55 | mIntrinsic.setCoefficients(f); |
Jason Sams | 5729fcd | 2012-09-04 19:57:40 -0700 | [diff] [blame] | 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 | if (mUseIntrinsic) { |
| 68 | mIntrinsic.forEach(mOutPixelsAllocation); |
| 69 | } else { |
| 70 | mScript.forEach_root(mOutPixelsAllocation); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | } |