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.imagejb; 18 19import java.lang.Math; 20 21import android.renderscript.Matrix3f; 22import android.util.Log; 23import android.widget.SeekBar; 24import android.widget.TextView; 25 26 27public class LevelsV4 extends TestBase { 28 private ScriptC_levels_relaxed mScriptR; 29 private ScriptC_levels_full mScriptF; 30 private float mInBlack = 0.0f; 31 private float mOutBlack = 0.0f; 32 private float mInWhite = 255.0f; 33 private float mOutWhite = 255.0f; 34 private float mSaturation = 1.0f; 35 36 Matrix3f satMatrix = new Matrix3f(); 37 float mInWMinInB; 38 float mOutWMinOutB; 39 float mOverInWMinInB; 40 41 boolean mUseFull; 42 boolean mUseV4; 43 44 LevelsV4(boolean useFull, boolean useV4) { 45 mUseFull = useFull; 46 mUseV4 = useV4; 47 } 48 49 50 private void setLevels() { 51 mInWMinInB = mInWhite - mInBlack; 52 mOutWMinOutB = mOutWhite - mOutBlack; 53 mOverInWMinInB = 1.f / mInWMinInB; 54 55 mScriptR.set_inBlack(mInBlack); 56 mScriptR.set_outBlack(mOutBlack); 57 mScriptR.set_inWMinInB(mInWMinInB); 58 mScriptR.set_outWMinOutB(mOutWMinOutB); 59 mScriptR.set_overInWMinInB(mOverInWMinInB); 60 mScriptF.set_inBlack(mInBlack); 61 mScriptF.set_outBlack(mOutBlack); 62 mScriptF.set_inWMinInB(mInWMinInB); 63 mScriptF.set_outWMinOutB(mOutWMinOutB); 64 mScriptF.set_overInWMinInB(mOverInWMinInB); 65 } 66 67 private void setSaturation() { 68 float rWeight = 0.299f; 69 float gWeight = 0.587f; 70 float bWeight = 0.114f; 71 float oneMinusS = 1.0f - mSaturation; 72 73 satMatrix.set(0, 0, oneMinusS * rWeight + mSaturation); 74 satMatrix.set(0, 1, oneMinusS * rWeight); 75 satMatrix.set(0, 2, oneMinusS * rWeight); 76 satMatrix.set(1, 0, oneMinusS * gWeight); 77 satMatrix.set(1, 1, oneMinusS * gWeight + mSaturation); 78 satMatrix.set(1, 2, oneMinusS * gWeight); 79 satMatrix.set(2, 0, oneMinusS * bWeight); 80 satMatrix.set(2, 1, oneMinusS * bWeight); 81 satMatrix.set(2, 2, oneMinusS * bWeight + mSaturation); 82 mScriptR.set_colorMat(satMatrix); 83 mScriptF.set_colorMat(satMatrix); 84 } 85 86 public boolean onBar1Setup(SeekBar b, TextView t) { 87 b.setProgress(50); 88 t.setText("Saturation"); 89 return true; 90 } 91 public boolean onBar2Setup(SeekBar b, TextView t) { 92 b.setMax(128); 93 b.setProgress(0); 94 t.setText("In Black"); 95 return true; 96 } 97 public boolean onBar3Setup(SeekBar b, TextView t) { 98 b.setMax(128); 99 b.setProgress(0); 100 t.setText("Out Black"); 101 return true; 102 } 103 public boolean onBar4Setup(SeekBar b, TextView t) { 104 b.setMax(128); 105 b.setProgress(128); 106 t.setText("In White"); 107 return true; 108 } 109 public boolean onBar5Setup(SeekBar b, TextView t) { 110 b.setMax(128); 111 b.setProgress(128); 112 t.setText("Out White"); 113 return true; 114 } 115 116 public void onBar1Changed(int progress) { 117 mSaturation = (float)progress / 50.0f; 118 setSaturation(); 119 } 120 public void onBar2Changed(int progress) { 121 mInBlack = (float)progress; 122 setLevels(); 123 } 124 public void onBar3Changed(int progress) { 125 mOutBlack = (float)progress; 126 setLevels(); 127 } 128 public void onBar4Changed(int progress) { 129 mInWhite = (float)progress + 127.0f; 130 setLevels(); 131 } 132 public void onBar5Changed(int progress) { 133 mOutWhite = (float)progress + 127.0f; 134 setLevels(); 135 } 136 137 public void animateBars(float time) { 138 mSaturation = time % 2.f; 139 setSaturation(); 140 } 141 142 143 public void createTest(android.content.res.Resources res) { 144 mScriptR = new ScriptC_levels_relaxed(mRS); 145 mScriptF = new ScriptC_levels_full(mRS); 146 setSaturation(); 147 setLevels(); 148 } 149 150 public void runTest() { 151 if (mUseFull) { 152 if (mUseV4) { 153 mScriptF.forEach_root4(mInPixelsAllocation, mOutPixelsAllocation); 154 } else { 155 mScriptF.forEach_root(mInPixelsAllocation, mOutPixelsAllocation); 156 } 157 } else { 158 if (mUseV4) { 159 mScriptR.forEach_root4(mInPixelsAllocation, mOutPixelsAllocation); 160 } else { 161 mScriptR.forEach_root(mInPixelsAllocation, mOutPixelsAllocation); 162 } 163 } 164 } 165 166} 167 168