Home | History | Annotate | Download | only in rscpp
      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.cts.rscpp;
     18 
     19 import android.content.Context;
     20 import android.content.res.Resources;
     21 import android.test.AndroidTestCase;
     22 import android.renderscript.*;
     23 import android.util.Log;
     24 import java.lang.Integer;
     25 
     26 public class RSBlurTest extends RSCppTest {
     27     static {
     28         System.loadLibrary("rscpptest_jni");
     29     }
     30 
     31     private final int X = 1024;
     32     private final int Y = 1024;
     33 
     34     native boolean blurTest(String path, int X, int Y, byte[] input, byte[] output, boolean singleChannel);
     35     public void testRSBlurOneChannel() {
     36         int[] baseAlloc = new int[X * Y];
     37         RSUtils.genRandom(0x1DEFF, 255, 1, -128, baseAlloc);
     38         byte[] byteAlloc = new byte[X * Y];
     39         for (int i = 0; i < X * Y; i++) {
     40             byteAlloc[i] = (byte)baseAlloc[i];
     41         }
     42 
     43         Type.Builder build = new Type.Builder(mRS, Element.A_8(mRS));
     44         build.setX(X);
     45         build.setY(Y);
     46         Allocation rsInput = Allocation.createTyped(mRS, build.create());
     47         Allocation rsOutput = Allocation.createTyped(mRS, build.create());
     48         rsInput.copyFromUnchecked(byteAlloc);
     49         ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(mRS, Element.A_8(mRS));
     50         blur.setInput(rsInput);
     51         blur.setRadius(15);
     52         blur.forEach(rsOutput);
     53 
     54         byte[] nativeByteAlloc = new byte[X * Y];
     55         blurTest(this.getContext().getCacheDir().toString(), X, Y, byteAlloc, nativeByteAlloc, true);
     56 
     57         Allocation rsCppOutput = Allocation.createTyped(mRS, build.create());
     58         rsCppOutput.copyFromUnchecked(nativeByteAlloc);
     59         mVerify.invoke_verify(rsOutput, rsCppOutput, rsInput);
     60         checkForErrors();
     61     }
     62 
     63 
     64     public void testRSBlurFourChannels() {
     65         int[] baseAlloc = new int[X * Y * 4];
     66         RSUtils.genRandom(0xFAFADE10, 255, 1, -128, baseAlloc);
     67         byte[] byteAlloc = new byte[X * Y * 4];
     68         for (int i = 0; i < X * Y * 4; i++) {
     69             byteAlloc[i] = (byte)baseAlloc[i];
     70         }
     71 
     72         Type.Builder build = new Type.Builder(mRS, Element.RGBA_8888(mRS));
     73         build.setX(X);
     74         build.setY(Y);
     75         Allocation rsInput = Allocation.createTyped(mRS, build.create());
     76         Allocation rsOutput = Allocation.createTyped(mRS, build.create());
     77         rsInput.copyFromUnchecked(byteAlloc);
     78         ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(mRS, Element.RGBA_8888(mRS));
     79         blur.setInput(rsInput);
     80         blur.setRadius(15);
     81         blur.forEach(rsOutput);
     82 
     83         byte[] nativeByteAlloc = new byte[X * Y * 4];
     84         blurTest(this.getContext().getCacheDir().toString(), X, Y, byteAlloc, nativeByteAlloc, false);
     85 
     86         Allocation rsCppOutput = Allocation.createTyped(mRS, build.create());
     87         rsCppOutput.copyFromUnchecked(nativeByteAlloc);
     88         mVerify.invoke_verify(rsOutput, rsCppOutput, rsInput);
     89         checkForErrors();
     90     }
     91 
     92 
     93 }
     94