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.ScriptIntrinsicColorMatrix;
29import android.renderscript.Type;
30import android.util.Log;
31
32public class ColorMatrix extends TestBase {
33    private ScriptC_colormatrix mScript;
34    private ScriptIntrinsicColorMatrix mIntrinsic;
35    private boolean mUseIntrinsic;
36    private boolean mUseGrey;
37
38    public ColorMatrix(boolean useIntrinsic, boolean useGrey) {
39        mUseIntrinsic = useIntrinsic;
40        mUseGrey = useGrey;
41    }
42
43    public void createTest(android.content.res.Resources res) {
44        Matrix4f m = new Matrix4f();
45        m.set(1, 0, 0.2f);
46        m.set(1, 1, 0.9f);
47        m.set(1, 2, 0.2f);
48
49        if (mUseIntrinsic) {
50            mIntrinsic = ScriptIntrinsicColorMatrix.create(mRS, Element.U8_4(mRS));
51            if (mUseGrey) {
52                mIntrinsic.setGreyscale();
53            } else {
54                mIntrinsic.setColorMatrix(m);
55            }
56        } else {
57            mScript = new ScriptC_colormatrix(mRS, res, R.raw.colormatrix);
58            mScript.invoke_setMatrix(m);
59        }
60    }
61
62    public void runTest() {
63        if (mUseIntrinsic) {
64            mIntrinsic.forEach(mInPixelsAllocation, mOutPixelsAllocation);
65        } else {
66            mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
67        }
68    }
69
70}
71