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