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