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.image;
     18 
     19 import android.renderscript.Allocation;
     20 import android.renderscript.Element;
     21 import android.renderscript.Sampler;
     22 import android.renderscript.Type;
     23 import android.widget.SeekBar;
     24 import android.widget.TextView;
     25 
     26 public 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(mRS);
    124             else
    125                 mScript_approx_full = new ScriptC_vignette_approx_full(mRS);
    126         } else if (relaxed)
    127             mScript_relaxed = new ScriptC_vignette_relaxed(mRS);
    128         else
    129             mScript_full = new ScriptC_vignette_full(mRS);
    130         do_init();
    131     }
    132 
    133     public void runTest() {
    134         if (approx) {
    135             if (relaxed)
    136                 mScript_approx_relaxed.forEach_root(mInPixelsAllocation,
    137                         mOutPixelsAllocation);
    138             else
    139                 mScript_approx_full.forEach_root(mInPixelsAllocation,
    140                         mOutPixelsAllocation);
    141         } else if (relaxed)
    142             mScript_relaxed.forEach_root(mInPixelsAllocation,
    143                     mOutPixelsAllocation);
    144         else
    145             mScript_full.forEach_root(mInPixelsAllocation,
    146                     mOutPixelsAllocation);
    147     }
    148 
    149 }
    150 
    151