1 /*
2  * Copyright (C) 2014 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 IntrinsicLut extends IntrinsicBase {
23     private ScriptIntrinsicLUT mIntrinsic;
24     private ScriptC_intrinsic_lut mScript;
25 
26     short mRed[] = new short[256];
27     short mGreen[] = new short[256];
28     short mBlue[] = new short[256];
29     short mAlpha[] = new short[256];
30 
31     @Override
tearDown()32     protected void tearDown() throws Exception {
33         if (mIntrinsic != null) {
34             mIntrinsic.destroy();
35         }
36         if (mScript != null) {
37             mScript.destroy();
38         }
39         super.tearDown();
40     }
41 
createTest()42     public void createTest() {
43         java.util.Random r = new java.util.Random(100);
44 
45         mIntrinsic = ScriptIntrinsicLUT.create(mRS, Element.U8_4(mRS));
46         mScript = new ScriptC_intrinsic_lut(mRS);
47 
48         for (int ct=0; ct < 256; ct++) {
49             mRed[ct] = (short)r.nextInt(256);
50             mGreen[ct] = (short)r.nextInt(256);
51             mBlue[ct] = (short)r.nextInt(256);
52             mAlpha[ct] = (short)r.nextInt(256);
53             mIntrinsic.setRed(ct, mRed[ct]);
54             mIntrinsic.setGreen(ct, mGreen[ct]);
55             mIntrinsic.setBlue(ct, mBlue[ct]);
56             mIntrinsic.setAlpha(ct, mAlpha[ct]);
57         }
58         mScript.set_red(mRed);
59         mScript.set_green(mGreen);
60         mScript.set_blue(mBlue);
61         mScript.set_alpha(mAlpha);
62     }
63 
64 
65 
test()66     public void test() {
67         createTest();
68         makeBuffers(97, 97, Element.U8_4(mRS));
69 
70         mIntrinsic.forEach(mAllocSrc, mAllocDst);
71         mScript.forEach_root(mAllocSrc, mAllocRef);
72 
73         mVerify.set_gAllowedIntError(0);
74         mVerify.invoke_verify(mAllocRef, mAllocDst, mAllocSrc);
75         mRS.finish();
76         checkError();
77     }
78 
test1C()79     public void test1C() {
80         createTest();
81         makeBuffers(97, 97, Element.U8_4(mRS));
82 
83         Script.LaunchOptions lo = makeClipper(11, 11, 87, 87);
84 
85         mIntrinsic.forEach(mAllocSrc, mAllocDst, lo);
86         mScript.forEach_root(mAllocSrc, mAllocRef, lo);
87 
88         mVerify.set_gAllowedIntError(0);
89         mVerify.invoke_verify(mAllocRef, mAllocDst, mAllocSrc);
90         mRS.finish();
91         checkError();
92     }
93 
94 
test_ID()95     public void test_ID() {
96         ScriptIntrinsicLUT s = ScriptIntrinsicLUT.create(mRS, Element.U8_4(mRS));
97         Script.KernelID kid = s.getKernelID();
98         if (kid == null) {
99             throw new IllegalStateException("kid must be valid");
100         }
101         s.destroy();
102     }
103 
104 }
105