Home | History | Annotate | Download | only in image
      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 
     17 package com.android.rs.image2;
     18 
     19 import android.widget.SeekBar;
     20 import android.widget.TextView;
     21 
     22 public 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 
     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     public void animateBars(float time) {
     94         scale = time % 2.f;
     95         do_init();
     96     }
     97 
     98     private void do_init() {
     99         if (approx) {
    100             if (relaxed)
    101                 mScript_approx_relaxed.invoke_init_vignette(
    102                         mInPixelsAllocation.getType().getX(),
    103                         mInPixelsAllocation.getType().getY(), center_x,
    104                         center_y, scale, shade, slope);
    105             else
    106                 mScript_approx_full.invoke_init_vignette(
    107                         mInPixelsAllocation.getType().getX(),
    108                         mInPixelsAllocation.getType().getY(), center_x,
    109                         center_y, scale, shade, slope);
    110         } else if (relaxed)
    111             mScript_relaxed.invoke_init_vignette(
    112                     mInPixelsAllocation.getType().getX(),
    113                     mInPixelsAllocation.getType().getY(), center_x, center_y,
    114                     scale, shade, slope);
    115         else
    116             mScript_full.invoke_init_vignette(
    117                     mInPixelsAllocation.getType().getX(),
    118                     mInPixelsAllocation.getType().getY(), center_x, center_y,
    119                     scale, shade, slope);
    120     }
    121 
    122     public void createTest(android.content.res.Resources res) {
    123         if (approx) {
    124             if (relaxed)
    125                 mScript_approx_relaxed = new ScriptC_vignette_approx_relaxed(mRS);
    126             else
    127                 mScript_approx_full = new ScriptC_vignette_approx_full(mRS);
    128         } else if (relaxed)
    129             mScript_relaxed = new ScriptC_vignette_relaxed(mRS);
    130         else
    131             mScript_full = new ScriptC_vignette_full(mRS);
    132         do_init();
    133     }
    134 
    135     public void runTest() {
    136         if (approx) {
    137             if (relaxed)
    138                 mScript_approx_relaxed.forEach_root(mInPixelsAllocation,
    139                         mOutPixelsAllocation);
    140             else
    141                 mScript_approx_full.forEach_root(mInPixelsAllocation,
    142                         mOutPixelsAllocation);
    143         } else if (relaxed)
    144             mScript_relaxed.forEach_root(mInPixelsAllocation,
    145                     mOutPixelsAllocation);
    146         else
    147             mScript_full.forEach_root(mInPixelsAllocation,
    148                     mOutPixelsAllocation);
    149     }
    150 
    151 }
    152 
    153