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 Fisheye extends TestBase {
24    private ScriptC_fisheye_full mScript_full = null;
25    private ScriptC_fisheye_relaxed mScript_relaxed = null;
26    private ScriptC_fisheye_approx_full mScript_approx_full = null;
27    private ScriptC_fisheye_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
34    public Fisheye(boolean approx, boolean relaxed) {
35        this.approx = approx;
36        this.relaxed = relaxed;
37    }
38
39    public boolean onBar1Setup(SeekBar b, TextView t) {
40        t.setText("Scale");
41        b.setMax(100);
42        b.setProgress(25);
43        return true;
44    }
45    public boolean onBar2Setup(SeekBar b, TextView t) {
46        t.setText("Shift center X");
47        b.setMax(100);
48        b.setProgress(50);
49        return true;
50    }
51    public boolean onBar3Setup(SeekBar b, TextView t) {
52        t.setText("Shift center Y");
53        b.setMax(100);
54        b.setProgress(50);
55        return true;
56    }
57
58    public void onBar1Changed(int progress) {
59        scale = progress / 50.0f;
60        do_init();
61    }
62    public void onBar2Changed(int progress) {
63        center_x = progress / 100.0f;
64        do_init();
65    }
66    public void onBar3Changed(int progress) {
67        center_y = progress / 100.0f;
68        do_init();
69    }
70
71    private void do_init() {
72        if (approx) {
73            if (relaxed)
74                mScript_approx_relaxed.invoke_init_filter(
75                        mInPixelsAllocation.getType().getX(),
76                        mInPixelsAllocation.getType().getY(), center_x,
77                        center_y, scale);
78            else
79                mScript_approx_full.invoke_init_filter(
80                        mInPixelsAllocation.getType().getX(),
81                        mInPixelsAllocation.getType().getY(), center_x,
82                        center_y, scale);
83        } else if (relaxed)
84            mScript_relaxed.invoke_init_filter(
85                    mInPixelsAllocation.getType().getX(),
86                    mInPixelsAllocation.getType().getY(), center_x, center_y,
87                    scale);
88        else
89            mScript_full.invoke_init_filter(
90                    mInPixelsAllocation.getType().getX(),
91                    mInPixelsAllocation.getType().getY(), center_x, center_y,
92                    scale);
93    }
94
95    public void createTest(android.content.res.Resources res) {
96        if (approx) {
97            if (relaxed) {
98                mScript_approx_relaxed = new ScriptC_fisheye_approx_relaxed(mRS,
99                        res, R.raw.fisheye_approx_relaxed);
100                mScript_approx_relaxed.set_in_alloc(mInPixelsAllocation);
101                mScript_approx_relaxed.set_sampler(Sampler.CLAMP_LINEAR(mRS));
102            } else {
103                mScript_approx_full = new ScriptC_fisheye_approx_full(mRS, res,
104                        R.raw.fisheye_approx_full);
105                mScript_approx_full.set_in_alloc(mInPixelsAllocation);
106                mScript_approx_full.set_sampler(Sampler.CLAMP_LINEAR(mRS));
107            }
108        } else if (relaxed) {
109            mScript_relaxed = new ScriptC_fisheye_relaxed(mRS, res,
110                    R.raw.fisheye_relaxed);
111            mScript_relaxed.set_in_alloc(mInPixelsAllocation);
112            mScript_relaxed.set_sampler(Sampler.CLAMP_LINEAR(mRS));
113        } else {
114            mScript_full = new ScriptC_fisheye_full(mRS, res,
115                    R.raw.fisheye_full);
116            mScript_full.set_in_alloc(mInPixelsAllocation);
117            mScript_full.set_sampler(Sampler.CLAMP_LINEAR(mRS));
118        }
119        do_init();
120    }
121
122    public void runTest() {
123        if (approx) {
124            if (relaxed)
125                mScript_approx_relaxed.forEach_root(mOutPixelsAllocation);
126            else
127                mScript_approx_full.forEach_root(mOutPixelsAllocation);
128        } else if (relaxed)
129            mScript_relaxed.forEach_root(mOutPixelsAllocation);
130        else
131            mScript_full.forEach_root(mOutPixelsAllocation);
132    }
133
134}
135
136