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