1b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams/*
2b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams * Copyright (C) 2012 The Android Open Source Project
3b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams *
4b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams * Licensed under the Apache License, Version 2.0 (the "License");
5b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams * you may not use this file except in compliance with the License.
6b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams * You may obtain a copy of the License at
7b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams *
8b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams *      http://www.apache.org/licenses/LICENSE-2.0
9b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams *
10b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams * Unless required by applicable law or agreed to in writing, software
11b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams * distributed under the License is distributed on an "AS IS" BASIS,
12b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams * See the License for the specific language governing permissions and
14b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams * limitations under the License.
15b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams */
16b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams
17b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Samspackage com.android.rs.image2;
18b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams
19b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Samsimport java.lang.Math;
20b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams
21b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Samsimport android.support.v8.renderscript.*;
22b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Samsimport android.util.Log;
23b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams
24b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Samspublic class ColorMatrix extends TestBase {
25b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams    private ScriptC_colormatrix mScript;
26b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams    private ScriptIntrinsicColorMatrix mIntrinsic;
27b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams    private boolean mUseIntrinsic;
28b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams    private boolean mUseGrey;
29b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams
30b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams    public ColorMatrix(boolean useIntrinsic, boolean useGrey) {
31b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams        mUseIntrinsic = useIntrinsic;
32b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams        mUseGrey = useGrey;
33b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams    }
34b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams
35b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams    public void createTest(android.content.res.Resources res) {
36b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams        Matrix4f m = new Matrix4f();
37b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams        m.set(1, 0, 0.2f);
38b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams        m.set(1, 1, 0.9f);
39b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams        m.set(1, 2, 0.2f);
40b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams
41b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams        if (mUseIntrinsic) {
42b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams            mIntrinsic = ScriptIntrinsicColorMatrix.create(mRS, Element.U8_4(mRS));
43b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams            if (mUseGrey) {
44b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams                mIntrinsic.setGreyscale();
45b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams            } else {
46b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams                mIntrinsic.setColorMatrix(m);
47b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams            }
48b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams        } else {
49b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams            mScript = new ScriptC_colormatrix(mRS, res, R.raw.colormatrix);
50b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams            mScript.invoke_setMatrix(m);
51b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams        }
52b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams    }
53b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams
54b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams    public void runTest() {
55b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams        if (mUseIntrinsic) {
56b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams            mIntrinsic.forEach(mInPixelsAllocation, mOutPixelsAllocation);
57b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams        } else {
58b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams            mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
59b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams        }
60b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams    }
61b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams
62b2ae7a1a18ab278f6aed8d2b16576aa8361b358eJason Sams}
63