Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2013 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 android.renderscript.cts;
     18 
     19 import android.renderscript.*;
     20 import android.util.Log;
     21 
     22 public class IntrinsicResize extends IntrinsicBase {
     23 
     24     static final int inX = 307;
     25     static final int inY = 157;
     26 
     27     private void testReszie(int w, int h, Element.DataType dt, int vecSize, float scaleX, float scaleY) {
     28 
     29         Element e = makeElement(dt, vecSize);
     30 
     31         System.gc();
     32         makeSource(w, h, e);
     33 
     34         int outW = (int) (w*scaleX);
     35         int outH = (int) (h*scaleY);
     36         if (mAllocRef != null) {
     37             mAllocRef.destroy();
     38         }
     39         if (mAllocDst != null) {
     40             mAllocDst.destroy();
     41         }
     42         mAllocRef = makeAllocation(outW, outH, e);
     43         mAllocDst = makeAllocation(outW, outH, e);
     44 
     45         ScriptIntrinsicResize si = ScriptIntrinsicResize.create(mRS);
     46         si.setInput(mAllocSrc);
     47         si.forEach_bicubic(mAllocRef);
     48 
     49         ScriptC_intrinsic_resize sr = new ScriptC_intrinsic_resize(mRS);
     50         sr.set_scaleX((float)w/outW);
     51         sr.set_scaleY((float)h/outH);
     52         sr.set_gIn(mAllocSrc);
     53         sr.set_gWidthIn(w);
     54         sr.set_gHeightIn(h);
     55         if (dt == Element.DataType.UNSIGNED_8) {
     56             switch(vecSize) {
     57             case 4:
     58                 sr.forEach_bicubic_U4(mAllocDst);
     59                 break;
     60             case 3:
     61                 sr.forEach_bicubic_U3(mAllocDst);
     62                 break;
     63             case 2:
     64                 sr.forEach_bicubic_U2(mAllocDst);
     65                 break;
     66             case 1:
     67                 sr.forEach_bicubic_U1(mAllocDst);
     68                 break;
     69             }
     70         }
     71 
     72         mVerify.invoke_verify(mAllocRef, mAllocDst, mAllocSrc);
     73         if (outW == w && outH == h) {
     74             //when scale = 1, check with the original.
     75             mVerify.invoke_verify(mAllocRef, mAllocSrc, mAllocSrc);
     76             mVerify.invoke_verify(mAllocDst, mAllocSrc, mAllocSrc);
     77         }
     78         mRS.finish();
     79     }
     80 
     81 
     82     public void test_U8_4_SCALE10_10_inSqure() {
     83         testReszie(inX, inX, Element.DataType.UNSIGNED_8, 4, 1.f, 1.f);
     84         checkError();
     85     }
     86     public void test_U8_3_SCALE10_10_inSqure() {
     87         testReszie(inX, inX, Element.DataType.UNSIGNED_8, 3, 1.f, 1.f);
     88         checkError();
     89     }
     90     public void test_U8_2_SCALE10_10_inSqure() {
     91         testReszie(inX, inX, Element.DataType.UNSIGNED_8, 2, 1.f, 1.f);
     92         checkError();
     93     }
     94     public void test_U8_1_SCALE10_10_inSqure() {
     95         testReszie(inX, inX, Element.DataType.UNSIGNED_8, 1, 1.f, 1.f);
     96         checkError();
     97     }
     98 
     99     public void test_U8_4_SCALE20_20_inSqure() {
    100         testReszie(inX, inX, Element.DataType.UNSIGNED_8, 4, 2.f, 2.f);
    101         checkError();
    102     }
    103     public void test_U8_3_SCALE20_20_inSqure() {
    104         testReszie(inX, inX, Element.DataType.UNSIGNED_8, 3, 2.f, 2.f);
    105         checkError();
    106     }
    107     public void test_U8_2_SCALE20_20_inSqure() {
    108         testReszie(inX, inX, Element.DataType.UNSIGNED_8, 2, 2.f, 2.f);
    109         checkError();
    110     }
    111     public void test_U8_1_SCALE20_20_inSqure() {
    112         testReszie(inX, inX, Element.DataType.UNSIGNED_8, 1, 2.f, 2.f);
    113         checkError();
    114     }
    115 
    116     public void test_U8_4_SCALE05_20_inSqure() {
    117         testReszie(inX, inX, Element.DataType.UNSIGNED_8, 4, 0.5f, 2.f);
    118         checkError();
    119     }
    120     public void test_U8_3_SCALE05_20_inSqure() {
    121         testReszie(inX, inX, Element.DataType.UNSIGNED_8, 3, 0.5f, 2.f);
    122         checkError();
    123     }
    124     public void test_U8_2_SCALE05_20_inSqure() {
    125         testReszie(inX, inX, Element.DataType.UNSIGNED_8, 2, 0.5f, 2.f);
    126         checkError();
    127     }
    128     public void test_U8_1_SCALE05_20_inSqure() {
    129         testReszie(inX, inX, Element.DataType.UNSIGNED_8, 1, 0.5f, 2.f);
    130         checkError();
    131     }
    132 
    133     public void test_U8_4_SCALE20_05_inSqure() {
    134         testReszie(inX, inX, Element.DataType.UNSIGNED_8, 4, 2.f, 0.5f);
    135         checkError();
    136     }
    137     public void test_U8_3_SCALE20_05_inSqure() {
    138         testReszie(inX, inX, Element.DataType.UNSIGNED_8, 3, 2.f, 0.5f);
    139         checkError();
    140     }
    141     public void test_U8_2_SCALE20_05_inSqure() {
    142         testReszie(inX, inX, Element.DataType.UNSIGNED_8, 2, 2.f, 0.5f);
    143         checkError();
    144     }
    145     public void test_U8_1_SCALE20_05_inSqure() {
    146         testReszie(inX, inX, Element.DataType.UNSIGNED_8, 1, 2.f, 0.5f);
    147         checkError();
    148     }
    149 
    150     public void test_U8_4_SCALE05_05_inSqure() {
    151         testReszie(inX, inX, Element.DataType.UNSIGNED_8, 4, 0.5f, 0.5f);
    152         checkError();
    153     }
    154     public void test_U8_3_SCALE05_05_inSqure() {
    155         testReszie(inX, inX, Element.DataType.UNSIGNED_8, 3, 0.5f, 0.5f);
    156         checkError();
    157     }
    158     public void test_U8_2_SCALE05_05_inSqure() {
    159         testReszie(inX, inX, Element.DataType.UNSIGNED_8, 2, 0.5f, 0.5f);
    160         checkError();
    161     }
    162     public void test_U8_1_SCALE05_05_inSqure() {
    163         testReszie(inX, inX, Element.DataType.UNSIGNED_8, 1, 0.5f, 0.5f);
    164         checkError();
    165     }
    166 
    167     public void test_U8_4_SCALE10_10_inRectangle() {
    168         testReszie(inX, inY, Element.DataType.UNSIGNED_8, 4, 1.f, 1.f);
    169         checkError();
    170     }
    171     public void test_U8_3_SCALE10_10_inRectangle() {
    172         testReszie(inX, inY, Element.DataType.UNSIGNED_8, 3, 1.f, 1.f);
    173         checkError();
    174     }
    175     public void test_U8_2_SCALE10_10_inRectangle() {
    176         testReszie(inX, inY, Element.DataType.UNSIGNED_8, 2, 1.f, 1.f);
    177         checkError();
    178     }
    179     public void test_U8_1_SCALE10_10_inRectangle() {
    180         testReszie(inX, inY, Element.DataType.UNSIGNED_8, 1, 1.f, 1.f);
    181         checkError();
    182     }
    183 
    184     public void test_U8_4_SCALE20_20_inRectangle() {
    185         testReszie(inX, inY, Element.DataType.UNSIGNED_8, 4, 2.f, 2.f);
    186         checkError();
    187     }
    188     public void test_U8_3_SCALE20_20_inRectangle() {
    189         testReszie(inX, inY, Element.DataType.UNSIGNED_8, 3, 2.f, 2.f);
    190         checkError();
    191     }
    192     public void test_U8_2_SCALE20_20_inRectangle() {
    193         testReszie(inX, inY, Element.DataType.UNSIGNED_8, 2, 2.f, 2.f);
    194         checkError();
    195     }
    196     public void test_U8_1_SCALE20_20_inRectangle() {
    197         testReszie(inX, inY, Element.DataType.UNSIGNED_8, 1, 2.f, 2.f);
    198         checkError();
    199     }
    200 
    201     public void test_U8_4_SCALE05_20_inRectangle() {
    202         testReszie(inX, inY, Element.DataType.UNSIGNED_8, 4, 0.5f, 2.f);
    203         checkError();
    204     }
    205     public void test_U8_3_SCALE05_20_inRectangle() {
    206         testReszie(inX, inY, Element.DataType.UNSIGNED_8, 3, 0.5f, 2.f);
    207         checkError();
    208     }
    209     public void test_U8_2_SCALE05_20_inRectangle() {
    210         testReszie(inX, inY, Element.DataType.UNSIGNED_8, 2, 0.5f, 2.f);
    211         checkError();
    212     }
    213     public void test_U8_1_SCALE05_20_inRectangle() {
    214         testReszie(inX, inY, Element.DataType.UNSIGNED_8, 1, 0.5f, 2.f);
    215         checkError();
    216     }
    217 
    218     public void test_U8_4_SCALE20_05_inRectangle() {
    219         testReszie(inX, inY, Element.DataType.UNSIGNED_8, 4, 2.f, 0.5f);
    220         checkError();
    221     }
    222     public void test_U8_3_SCALE20_05_inRectangle() {
    223         testReszie(inX, inY, Element.DataType.UNSIGNED_8, 3, 2.f, 0.5f);
    224         checkError();
    225     }
    226     public void test_U8_2_SCALE20_05_inRectangle() {
    227         testReszie(inX, inY, Element.DataType.UNSIGNED_8, 2, 2.f, 0.5f);
    228         checkError();
    229     }
    230     public void test_U8_1_SCALE20_05_inRectangle() {
    231         testReszie(inX, inY, Element.DataType.UNSIGNED_8, 1, 2.f, 0.5f);
    232         checkError();
    233     }
    234 
    235     public void test_U8_4_SCALE05_05_inRectangle() {
    236         testReszie(inX, inY, Element.DataType.UNSIGNED_8, 4, 0.5f, 0.5f);
    237         checkError();
    238     }
    239     public void test_U8_3_SCALE05_05_inRectangle() {
    240         testReszie(inX, inY, Element.DataType.UNSIGNED_8, 3, 0.5f, 0.5f);
    241         checkError();
    242     }
    243     public void test_U8_2_SCALE05_05_inRectangle() {
    244         testReszie(inX, inY, Element.DataType.UNSIGNED_8, 2, 0.5f, 0.5f);
    245         checkError();
    246     }
    247     public void test_U8_1_SCALE05_05_inRectangle() {
    248         testReszie(inX, inY, Element.DataType.UNSIGNED_8, 1, 0.5f, 0.5f);
    249         checkError();
    250     }
    251 }
    252