Histogram.java revision 204009b9114b33f184d7178838861d2fa9c9f88c
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 17package com.android.rs.image; 18 19import java.lang.Math; 20 21import android.renderscript.*; 22import android.util.Log; 23 24public class Histogram extends TestBase { 25 private ScriptC_histogram mScript; 26 private Allocation mSum; 27 private Allocation mSums; 28 29 public void createTest(android.content.res.Resources res) { 30 mScript = new ScriptC_histogram(mRS); 31 32 int w = mInPixelsAllocation.getType().getX(); 33 int h = mInPixelsAllocation.getType().getY(); 34 int step = 8; 35 int steps = (h + step - 1) / step; 36 37 mScript.set_gWidth(w); 38 mScript.set_gHeight(h); 39 mScript.set_gStep(step); 40 mScript.set_gSteps(steps); 41 42 Type.Builder tb = new Type.Builder(mRS, Element.I32(mRS)); 43 tb.setX(256).setY(steps); 44 Type t = tb.create(); 45 mSums = Allocation.createTyped(mRS, t); 46 mSum = Allocation.createSized(mRS, Element.I32(mRS), 256); 47 48 mScript.set_gSums(mSums); 49 mScript.set_gSum(mSum); 50 mScript.set_gSrc(mInPixelsAllocation); 51 mScript.set_gDest(mOutPixelsAllocation); 52 53 mScript.forEach_clear(mOutPixelsAllocation); 54 } 55 56 57 58 public void runTest() { 59 Script.LaunchOptions lo = new Script.LaunchOptions(); 60 lo.setX(0, 1); 61 mScript.forEach_pass1(mSums, lo); 62 mScript.forEach_pass2(mSum); 63 64 mScript.invoke_rescale(); 65 66 lo.setX(0, 1024); 67 mScript.forEach_draw(mOutPixelsAllocation, lo); 68 } 69 70} 71