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