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 android.support.v8.renderscript.*;
20import android.widget.SeekBar;
21import android.widget.TextView;
22
23public class Vignette extends TestBase {
24    private ScriptC_vignette_full mScript_full = null;
25    private ScriptC_vignette_relaxed mScript_relaxed = null;
26    private ScriptC_vignette_approx_full mScript_approx_full = null;
27    private ScriptC_vignette_approx_relaxed mScript_approx_relaxed = null;
28    private final boolean approx;
29    private final boolean relaxed;
30    private float center_x = 0.5f;
31    private float center_y = 0.5f;
32    private float scale = 0.5f;
33    private float shade = 0.5f;
34    private float slope = 20.0f;
35
36    public Vignette(boolean approx, boolean relaxed) {
37        this.approx = approx;
38        this.relaxed = relaxed;
39    }
40
41    public boolean onBar1Setup(SeekBar b, TextView t) {
42        t.setText("Scale");
43        b.setMax(100);
44        b.setProgress(25);
45        return true;
46    }
47    public boolean onBar2Setup(SeekBar b, TextView t) {
48        t.setText("Shade");
49        b.setMax(100);
50        b.setProgress(50);
51        return true;
52    }
53    public boolean onBar3Setup(SeekBar b, TextView t) {
54        t.setText("Slope");
55        b.setMax(100);
56        b.setProgress(20);
57        return true;
58    }
59    public boolean onBar4Setup(SeekBar b, TextView t) {
60        t.setText("Shift center X");
61        b.setMax(100);
62        b.setProgress(50);
63        return true;
64    }
65    public boolean onBar5Setup(SeekBar b, TextView t) {
66        t.setText("Shift center Y");
67        b.setMax(100);
68        b.setProgress(50);
69        return true;
70    }
71
72    public void onBar1Changed(int progress) {
73        scale = progress / 50.0f;
74        do_init();
75    }
76    public void onBar2Changed(int progress) {
77        shade = progress / 100.0f;
78        do_init();
79    }
80    public void onBar3Changed(int progress) {
81        slope = (float)progress;
82        do_init();
83    }
84    public void onBar4Changed(int progress) {
85        center_x = progress / 100.0f;
86        do_init();
87    }
88    public void onBar5Changed(int progress) {
89        center_y = progress / 100.0f;
90        do_init();
91    }
92
93    private void do_init() {
94        if (approx) {
95            if (relaxed)
96                mScript_approx_relaxed.invoke_init_vignette(
97                        mInPixelsAllocation.getType().getX(),
98                        mInPixelsAllocation.getType().getY(), center_x,
99                        center_y, scale, shade, slope);
100            else
101                mScript_approx_full.invoke_init_vignette(
102                        mInPixelsAllocation.getType().getX(),
103                        mInPixelsAllocation.getType().getY(), center_x,
104                        center_y, scale, shade, slope);
105        } else if (relaxed)
106            mScript_relaxed.invoke_init_vignette(
107                    mInPixelsAllocation.getType().getX(),
108                    mInPixelsAllocation.getType().getY(), center_x, center_y,
109                    scale, shade, slope);
110        else
111            mScript_full.invoke_init_vignette(
112                    mInPixelsAllocation.getType().getX(),
113                    mInPixelsAllocation.getType().getY(), center_x, center_y,
114                    scale, shade, slope);
115    }
116
117    public void createTest(android.content.res.Resources res) {
118        if (approx) {
119            if (relaxed)
120                mScript_approx_relaxed = new ScriptC_vignette_approx_relaxed(
121                        mRS, res, R.raw.vignette_approx_relaxed);
122            else
123                mScript_approx_full = new ScriptC_vignette_approx_full(
124                        mRS, res, R.raw.vignette_approx_full);
125        } else if (relaxed)
126            mScript_relaxed = new ScriptC_vignette_relaxed(mRS, res,
127                    R.raw.vignette_relaxed);
128        else
129            mScript_full = new ScriptC_vignette_full(mRS, res,
130                    R.raw.vignette_full);
131        do_init();
132    }
133
134    public void runTest() {
135        if (approx) {
136            if (relaxed)
137                mScript_approx_relaxed.forEach_root(mInPixelsAllocation,
138                        mOutPixelsAllocation);
139            else
140                mScript_approx_full.forEach_root(mInPixelsAllocation,
141                        mOutPixelsAllocation);
142        } else if (relaxed)
143            mScript_relaxed.forEach_root(mInPixelsAllocation,
144                    mOutPixelsAllocation);
145        else
146            mScript_full.forEach_root(mInPixelsAllocation,
147                    mOutPixelsAllocation);
148    }
149
150}
151
152