summaryrefslogtreecommitdiff
path: root/java/tests/ImageProcessing_jb/src/com/android/rs/image/LevelsV4.java
blob: e6963922d7ee2b3ac0f8c22f9bcb7885030e9629 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.rs.imagejb;

import java.lang.Math;

import android.renderscript.Matrix3f;
import android.util.Log;
import android.widget.SeekBar;
import android.widget.TextView;


public class LevelsV4 extends TestBase {
    private ScriptC_levels_relaxed mScriptR;
    private ScriptC_levels_full mScriptF;
    private float mInBlack = 0.0f;
    private float mOutBlack = 0.0f;
    private float mInWhite = 255.0f;
    private float mOutWhite = 255.0f;
    private float mSaturation = 1.0f;

    Matrix3f satMatrix = new Matrix3f();
    float mInWMinInB;
    float mOutWMinOutB;
    float mOverInWMinInB;

    boolean mUseFull;
    boolean mUseV4;

    LevelsV4(boolean useFull, boolean useV4) {
        mUseFull = useFull;
        mUseV4 = useV4;
    }


    private void setLevels() {
        mInWMinInB = mInWhite - mInBlack;
        mOutWMinOutB = mOutWhite - mOutBlack;
        mOverInWMinInB = 1.f / mInWMinInB;

        mScriptR.set_inBlack(mInBlack);
        mScriptR.set_outBlack(mOutBlack);
        mScriptR.set_inWMinInB(mInWMinInB);
        mScriptR.set_outWMinOutB(mOutWMinOutB);
        mScriptR.set_overInWMinInB(mOverInWMinInB);
        mScriptF.set_inBlack(mInBlack);
        mScriptF.set_outBlack(mOutBlack);
        mScriptF.set_inWMinInB(mInWMinInB);
        mScriptF.set_outWMinOutB(mOutWMinOutB);
        mScriptF.set_overInWMinInB(mOverInWMinInB);
    }

    private void setSaturation() {
        float rWeight = 0.299f;
        float gWeight = 0.587f;
        float bWeight = 0.114f;
        float oneMinusS = 1.0f - mSaturation;

        satMatrix.set(0, 0, oneMinusS * rWeight + mSaturation);
        satMatrix.set(0, 1, oneMinusS * rWeight);
        satMatrix.set(0, 2, oneMinusS * rWeight);
        satMatrix.set(1, 0, oneMinusS * gWeight);
        satMatrix.set(1, 1, oneMinusS * gWeight + mSaturation);
        satMatrix.set(1, 2, oneMinusS * gWeight);
        satMatrix.set(2, 0, oneMinusS * bWeight);
        satMatrix.set(2, 1, oneMinusS * bWeight);
        satMatrix.set(2, 2, oneMinusS * bWeight + mSaturation);
        mScriptR.set_colorMat(satMatrix);
        mScriptF.set_colorMat(satMatrix);
    }

    public boolean onBar1Setup(SeekBar b, TextView t) {
        b.setProgress(50);
        t.setText("Saturation");
        return true;
    }
    public boolean onBar2Setup(SeekBar b, TextView t) {
        b.setMax(128);
        b.setProgress(0);
        t.setText("In Black");
        return true;
    }
    public boolean onBar3Setup(SeekBar b, TextView t) {
        b.setMax(128);
        b.setProgress(0);
        t.setText("Out Black");
        return true;
    }
    public boolean onBar4Setup(SeekBar b, TextView t) {
        b.setMax(128);
        b.setProgress(128);
        t.setText("In White");
        return true;
    }
    public boolean onBar5Setup(SeekBar b, TextView t) {
        b.setMax(128);
        b.setProgress(128);
        t.setText("Out White");
        return true;
    }

    public void onBar1Changed(int progress) {
        mSaturation = (float)progress / 50.0f;
        setSaturation();
    }
    public void onBar2Changed(int progress) {
        mInBlack = (float)progress;
        setLevels();
    }
    public void onBar3Changed(int progress) {
        mOutBlack = (float)progress;
        setLevels();
    }
    public void onBar4Changed(int progress) {
        mInWhite = (float)progress + 127.0f;
        setLevels();
    }
    public void onBar5Changed(int progress) {
        mOutWhite = (float)progress + 127.0f;
        setLevels();
    }

    public void animateBars(float time) {
        mSaturation = time % 2.f;
        setSaturation();
    }


    public void createTest(android.content.res.Resources res) {
        mScriptR = new ScriptC_levels_relaxed(mRS);
        mScriptF = new ScriptC_levels_full(mRS);
        setSaturation();
        setLevels();
    }

    public void runTest() {
        if (mUseFull) {
            if (mUseV4) {
                mScriptF.forEach_root4(mInPixelsAllocation, mOutPixelsAllocation);
            } else {
                mScriptF.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
            }
        } else {
            if (mUseV4) {
                mScriptR.forEach_root4(mInPixelsAllocation, mOutPixelsAllocation);
            } else {
                mScriptR.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
            }
        }
    }

}