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 RSBlendTest extends RSCppTest { 27 static { 28 System.loadLibrary("rscpptest_jni"); 29 } 30 31 private static final int X = 256; 32 private static final int Y = 256; 33 blendTest(String path, int X, int Y, byte[] input, byte[] output, int optionFlag)34 native boolean blendTest(String path, int X, int Y, byte[] input, byte[] output, int optionFlag); testRSBlend()35 public void testRSBlend() { 36 for (int iter = 0; iter < 15; iter++) { 37 int[] baseAlloc = new int[X * Y * 4]; 38 RSUtils.genRandom(0x789321, 255, 1, -128, baseAlloc); 39 byte[] byteAlloc = new byte[X * Y * 4]; 40 for (int i = 0; i < X * Y * 4; i++) { 41 byteAlloc[i] = (byte)baseAlloc[i]; 42 } 43 44 int[] baseAlloc2 = new int[X * Y * 4]; 45 RSUtils.genRandom(0x359201, 255, 1, -128, baseAlloc2); 46 byte[] byteAlloc2 = new byte[X * Y * 4]; 47 for (int i = 0; i < X * Y * 4; i++) { 48 byteAlloc2[i] = (byte)baseAlloc2[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 rsOutput.copyFromUnchecked(byteAlloc2); 58 59 ScriptIntrinsicBlend blend = ScriptIntrinsicBlend.create(mRS, Element.RGBA_8888(mRS)); 60 61 switch(iter) { 62 case 0: 63 blend.forEachAdd(rsInput, rsOutput); 64 break; 65 case 1: 66 blend.forEachClear(rsInput, rsOutput); 67 break; 68 case 2: 69 blend.forEachDst(rsInput, rsOutput); 70 break; 71 case 3: 72 blend.forEachDstAtop(rsInput, rsOutput); 73 break; 74 case 4: 75 blend.forEachDstIn(rsInput, rsOutput); 76 break; 77 case 5: 78 blend.forEachDstOut(rsInput, rsOutput); 79 break; 80 case 6: 81 blend.forEachDstOver(rsInput, rsOutput); 82 break; 83 case 7: 84 blend.forEachMultiply(rsInput, rsOutput); 85 break; 86 case 8: 87 blend.forEachSrc(rsInput, rsOutput); 88 break; 89 case 9: 90 blend.forEachSrcAtop(rsInput, rsOutput); 91 break; 92 case 10: 93 blend.forEachSrcIn(rsInput, rsOutput); 94 break; 95 case 11: 96 blend.forEachSrcOut(rsInput, rsOutput); 97 break; 98 case 12: 99 blend.forEachSrcOver(rsInput, rsOutput); 100 break; 101 case 13: 102 blend.forEachSubtract(rsInput, rsOutput); 103 break; 104 case 14: 105 blend.forEachXor(rsInput, rsOutput); 106 break; 107 default: 108 break; 109 } 110 111 blendTest(this.getContext().getCacheDir().toString(), X, Y, byteAlloc, byteAlloc2, iter); 112 113 Allocation rsCppOutput = Allocation.createTyped(mRS, build.create()); 114 rsCppOutput.copyFromUnchecked(byteAlloc2); 115 mVerify.invoke_verify(rsOutput, rsCppOutput, rsInput); 116 checkForErrors(); 117 } 118 119 } 120 } 121