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