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 RS3DLUTTest 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     private final int lutSize = 64;
     35 
     36     native boolean lutTest(String path, int X, int Y, int lutSize, byte[] input, byte[] input2, byte[] output);
     37     public void testRSLUT() {
     38         int[] baseAlloc = new int[X * Y * 4];
     39         RSUtils.genRandom(0x419144, 255, 1, -128, baseAlloc);
     40         int[] colorCube = new int[lutSize * lutSize * lutSize * 4];
     41         RSUtils.genRandom(0x555007, 255, 1, -128, colorCube);
     42         byte[] byteAlloc = new byte[X * Y * 4];
     43         byte[] byteColorCube = new byte[lutSize * lutSize * lutSize * 4];
     44         for (int i = 0; i < X * Y * 4; i++) {
     45             byteAlloc[i] = (byte)baseAlloc[i];
     46         }
     47         for (int i = 0; i < lutSize * lutSize * lutSize * 4; i++) {
     48             byteColorCube[i] = (byte)colorCube[i];
     49         }
     50 
     51         Type.Builder build = new Type.Builder(mRS, Element.RGBA_8888(mRS));
     52         build.setX(X);
     53         build.setY(Y);
     54         Allocation rsInput = Allocation.createTyped(mRS, build.create());
     55         Allocation rsOutput = Allocation.createTyped(mRS, build.create());
     56         rsInput.copyFromUnchecked(byteAlloc);
     57 
     58         Type.Builder buildCube = new Type.Builder(mRS, Element.RGBA_8888(mRS));
     59         buildCube.setX(lutSize);
     60         buildCube.setY(lutSize);
     61         buildCube.setZ(lutSize);
     62         Allocation cube = Allocation.createTyped(mRS, buildCube.create());
     63         cube.copyFromUnchecked(byteColorCube);
     64         ScriptIntrinsic3DLUT lut = ScriptIntrinsic3DLUT.create(mRS, Element.RGBA_8888(mRS));
     65 
     66         lut.setLUT(cube);
     67         lut.forEach(rsInput, rsOutput);
     68 
     69         byte[] nativeByteAlloc = new byte[X * Y * 4];
     70         lutTest(this.getContext().getCacheDir().toString(), X, Y, lutSize, byteAlloc, byteColorCube, nativeByteAlloc);
     71 
     72         Allocation rsCppOutput = Allocation.createTyped(mRS, build.create());
     73         rsCppOutput.copyFromUnchecked(nativeByteAlloc);
     74         mVerify.invoke_verify(rsOutput, rsCppOutput, rsInput);
     75         checkForErrors();
     76 
     77     }
     78 
     79 }
     80