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 ScriptIntrinsicHistogram mHist;
27    private Allocation mSum;
28    private Allocation mSums;
29
30    public void createTest(android.content.res.Resources res) {
31        mScript = new ScriptC_histogram(mRS);
32        mHist = ScriptIntrinsicHistogram.create(mRS, Element.U8_4(mRS));
33
34        int w = mInPixelsAllocation.getType().getX();
35        int h = mInPixelsAllocation.getType().getY();
36        int step = 8;
37        int steps = (h + step - 1) / step;
38
39        mScript.set_gWidth(w);
40        mScript.set_gHeight(h);
41        mScript.set_gStep(step);
42        mScript.set_gSteps(steps);
43
44        Type.Builder tb = new Type.Builder(mRS, Element.I32(mRS));
45        tb.setX(256).setY(steps);
46        Type t = tb.create();
47        mSums = Allocation.createTyped(mRS, t);
48        mSum = Allocation.createSized(mRS, Element.I32(mRS), 256);
49
50        mScript.set_gSums(mSums);
51        mScript.set_gSum(mSum);
52        mScript.set_gSrc(mInPixelsAllocation);
53        mScript.set_gDest(mOutPixelsAllocation);
54
55        mScript.forEach_clear(mOutPixelsAllocation);
56    }
57
58
59
60    public void runTest() {
61        Script.LaunchOptions lo = new Script.LaunchOptions();
62        lo.setX(0, 1);
63        //mScript.forEach_pass1(mSums, lo);
64        //mScript.forEach_pass2(mSum);
65
66        mHist.setOutput(mSum);
67        mHist.forEach_Dot(mInPixelsAllocation);
68
69        mScript.invoke_rescale();
70
71        lo.setX(0, 1024);
72        mScript.forEach_draw(mOutPixelsAllocation, lo);
73    }
74
75}
76