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 17package com.android.rs.image2; 18 19import android.support.v8.renderscript.*; 20 21public class Posterize extends TestBase { 22 private ScriptC_posterize mScript; 23 boolean mUseInvokes; 24 25 Posterize(boolean useInvoke) { 26 mUseInvokes = useInvoke; 27 } 28 29 public void createTest(android.content.res.Resources res) { 30 mScript = new ScriptC_posterize(mRS); 31 } 32 33 void setParams(float intensHigh, float intensLow, int r, int g, int b) { 34 if (mUseInvokes) { 35 mScript.invoke_setParams(intensHigh, intensLow, 36 (short)r, (short)g, (short)b); 37 } else { 38 mScript.set_intensityLow(intensLow); 39 mScript.set_intensityHigh(intensHigh); 40 mScript.set_color(new Short4((short)r, (short)g, (short)b, (short)255)); 41 } 42 } 43 44 public void runTest() { 45 mScript.set_inputImage(mInPixelsAllocation); 46 setParams(.2f, 0.f, 255, 0, 0); 47 mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation); 48 setParams(.4f, 0.2f, 0, 255, 0); 49 mScript.forEach_root(mOutPixelsAllocation, mOutPixelsAllocation); 50 setParams(.6f, 0.4f, 0, 0, 255); 51 mScript.forEach_root(mOutPixelsAllocation, mOutPixelsAllocation); 52 setParams(.8f, 0.6f, 255, 255, 0); 53 mScript.forEach_root(mOutPixelsAllocation, mOutPixelsAllocation); 54 setParams(1.0f, 0.8f, 0, 255, 255); 55 mScript.forEach_root(mOutPixelsAllocation, mOutPixelsAllocation); 56 } 57 58} 59