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.imagejb;
     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 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     public void animateBars(float time) {
     75         scale = time % 2.f;
     76         do_init();
     77     }
     78 
     79     private void do_init() {
     80         if (approx) {
     81             if (relaxed)
     82                 mScript_approx_relaxed.invoke_init_filter(
     83                         mInPixelsAllocation.getType().getX(),
     84                         mInPixelsAllocation.getType().getY(), center_x,
     85                         center_y, scale);
     86             else
     87                 mScript_approx_full.invoke_init_filter(
     88                         mInPixelsAllocation.getType().getX(),
     89                         mInPixelsAllocation.getType().getY(), center_x,
     90                         center_y, scale);
     91         } else if (relaxed)
     92             mScript_relaxed.invoke_init_filter(
     93                     mInPixelsAllocation.getType().getX(),
     94                     mInPixelsAllocation.getType().getY(), center_x, center_y,
     95                     scale);
     96         else
     97             mScript_full.invoke_init_filter(
     98                     mInPixelsAllocation.getType().getX(),
     99                     mInPixelsAllocation.getType().getY(), center_x, center_y,
    100                     scale);
    101     }
    102 
    103     public void createTest(android.content.res.Resources res) {
    104         if (approx) {
    105             if (relaxed) {
    106                 mScript_approx_relaxed = new ScriptC_fisheye_approx_relaxed(mRS);
    107                 mScript_approx_relaxed.set_in_alloc(mInPixelsAllocation);
    108                 mScript_approx_relaxed.set_sampler(Sampler.CLAMP_LINEAR(mRS));
    109             } else {
    110                 mScript_approx_full = new ScriptC_fisheye_approx_full(mRS);
    111                 mScript_approx_full.set_in_alloc(mInPixelsAllocation);
    112                 mScript_approx_full.set_sampler(Sampler.CLAMP_LINEAR(mRS));
    113             }
    114         } else if (relaxed) {
    115             mScript_relaxed = new ScriptC_fisheye_relaxed(mRS);
    116             mScript_relaxed.set_in_alloc(mInPixelsAllocation);
    117             mScript_relaxed.set_sampler(Sampler.CLAMP_LINEAR(mRS));
    118         } else {
    119             mScript_full = new ScriptC_fisheye_full(mRS);
    120             mScript_full.set_in_alloc(mInPixelsAllocation);
    121             mScript_full.set_sampler(Sampler.CLAMP_LINEAR(mRS));
    122         }
    123         do_init();
    124     }
    125 
    126     public void runTest() {
    127         if (approx) {
    128             if (relaxed)
    129                 mScript_approx_relaxed.forEach_root(mOutPixelsAllocation);
    130             else
    131                 mScript_approx_full.forEach_root(mOutPixelsAllocation);
    132         } else if (relaxed)
    133             mScript_relaxed.forEach_root(mOutPixelsAllocation);
    134         else
    135             mScript_full.forEach_root(mOutPixelsAllocation);
    136     }
    137 
    138 }
    139 
    140