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.image2; 18 19import java.lang.Math; 20 21import android.support.v8.renderscript.*; 22import android.util.Log; 23 24public class ColorMatrix extends TestBase { 25 private ScriptC_colormatrix mScript; 26 private ScriptIntrinsicColorMatrix mIntrinsic; 27 private boolean mUseIntrinsic; 28 private boolean mUseGrey; 29 30 public ColorMatrix(boolean useIntrinsic, boolean useGrey) { 31 mUseIntrinsic = useIntrinsic; 32 mUseGrey = useGrey; 33 } 34 35 public void createTest(android.content.res.Resources res) { 36 Matrix4f m = new Matrix4f(); 37 m.set(1, 0, 0.2f); 38 m.set(1, 1, 0.9f); 39 m.set(1, 2, 0.2f); 40 41 if (mUseIntrinsic) { 42 mIntrinsic = ScriptIntrinsicColorMatrix.create(mRS, Element.U8_4(mRS)); 43 if (mUseGrey) { 44 mIntrinsic.setGreyscale(); 45 } else { 46 mIntrinsic.setColorMatrix(m); 47 } 48 } else { 49 mScript = new ScriptC_colormatrix(mRS, res, R.raw.colormatrix); 50 mScript.invoke_setMatrix(m); 51 } 52 } 53 54 public void runTest() { 55 if (mUseIntrinsic) { 56 mIntrinsic.forEach(mInPixelsAllocation, mOutPixelsAllocation); 57 } else { 58 mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation); 59 } 60 } 61 62} 63