1/* 2 * Copyright (C) 2012 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 17package com.android.rs.image2; 18 19import java.lang.Math; 20 21import android.support.v8.renderscript.*; 22import android.util.Log; 23 24public class CrossProcess extends TestBase { 25 private ScriptIntrinsicLUT mIntrinsic; 26 27 public void createTest(android.content.res.Resources res) { 28 mIntrinsic = ScriptIntrinsicLUT.create(mRS, Element.U8_4(mRS)); 29 for (int ct=0; ct < 256; ct++) { 30 float f = ((float)ct) / 255.f; 31 32 float r = f; 33 if (r < 0.5f) { 34 r = 4.0f * r * r * r; 35 } else { 36 r = 1.0f - r; 37 r = 1.0f - (4.0f * r * r * r); 38 } 39 mIntrinsic.setRed(ct, (int)(r * 255.f + 0.5f)); 40 41 float g = f; 42 if (g < 0.5f) { 43 g = 2.0f * g * g; 44 } else { 45 g = 1.0f - g; 46 g = 1.0f - (2.0f * g * g); 47 } 48 mIntrinsic.setGreen(ct, (int)(g * 255.f + 0.5f)); 49 50 float b = f * 0.5f + 0.25f; 51 mIntrinsic.setBlue(ct, (int)(b * 255.f + 0.5f)); 52 } 53 54 } 55 56 public void runTest() { 57 mIntrinsic.forEach(mInPixelsAllocation, mOutPixelsAllocation); 58 } 59 60} 61