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
17#pragma version(1)
18#pragma rs java_package_name(com.android.rs.sample)
19#include "rs_graphics.rsh"
20
21static rs_allocation sourceAlloc;
22static rs_allocation destAlloc;
23static rs_sampler allocSampler;
24
25void setSampleData(rs_allocation dest, rs_allocation source, rs_sampler sampler) {
26    destAlloc = dest;
27    sourceAlloc = source;
28    allocSampler = sampler;
29}
30
31void root(uchar4 *out, uint32_t x, uint32_t y) {
32
33    float destX = (float)rsAllocationGetDimX(destAlloc) - 1.0f;
34    float destY = (float)rsAllocationGetDimY(destAlloc) - 1.0f;
35
36    float2 uv;
37    uv.x = (float)x / destX;
38    uv.y = (float)y / destY;
39
40    out->xyz = convert_uchar3(rsSample(sourceAlloc, allocSampler, uv * 2.0f).xyz * 255.0f);
41    out->w = 0xff;
42}
43
44