1/*
2* Copyright (C) 2016 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.jniallocations)
19
20// Kernel performs basic vector swizzle
21uchar4 __attribute__((kernel)) swizzle_kernel(uchar4 in)
22{
23    return in.wzyx;
24}
25
26// Kernel squares every element in allocation
27uint __attribute__((kernel)) square_kernel(ushort in)
28{
29    uint result = (uint)(in) * (uint)in;
30    return result;
31}
32
33// Helper function adding 1/2 to passed in double
34static double half_helper(double in)
35{
36    return (in + 0.5);
37}
38
39// Kernel returns first 3 elements of a double4 plus 1/2
40double3 __attribute__((kernel)) add_half_kernel(double4 in)
41{
42    double3 result;
43    result.x = half_helper(in.x);
44    result.y = half_helper(in.y);
45    result.z = half_helper(in.z);
46    return result;
47}
48