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
21
22public class Resize extends TestBase {
23    private ScriptC_resize mScript;
24
25    private Allocation mScratchAllocation;
26    private int mWidth;
27    private int mHeight;
28
29    public Resize(boolean useIntrinsic) {
30    }
31
32    public void createTest(android.content.res.Resources res) {
33        mWidth = mInPixelsAllocation.getType().getX();
34        mHeight = mInPixelsAllocation.getType().getY();
35        float scale = 1.f / 32.f;
36
37        Type.Builder tb = new Type.Builder(mRS, mInPixelsAllocation.getElement());
38        tb.setX((int)(mWidth * scale));
39        tb.setY((int)(mHeight * scale));
40        Type t = tb.create();
41        mScratchAllocation = Allocation.createTyped(mRS, t);
42
43        // make small buffer
44        mScript = new ScriptC_resize(mRS);
45        mScript.set_gIn(mInPixelsAllocation);
46        mScript.set_gWidthIn(mWidth);
47        mScript.set_gHeightIn(mHeight);
48        mScript.set_scale(1.f / scale);
49        mScript.forEach_nearest(mScratchAllocation);
50
51        // setup normal ops
52        mScript.set_gIn(mScratchAllocation);
53        mScript.set_gWidthIn(t.getX());
54        mScript.set_gHeightIn(t.getY());
55        mScript.set_scale(scale);
56    }
57
58    public void runTest() {
59        mScript.forEach_bicubic(mOutPixelsAllocation);
60    }
61
62}
63