blend_linear.cl 4.55 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*M///////////////////////////////////////////////////////////////////////////////////////
//
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
//  By downloading, copying, installing or using the software you agree to this license.
//  If you do not agree to this license, do not download, install,
//  copy or use the software.
//
//
//                           License Agreement
//                For Open Source Computer Vision Library
//
// Copyright (C) 2010-2012, MulticoreWare Inc., all rights reserved.
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// @Authors
18
//    Liu Liujun, liujun@multicorewareinc.com
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
//   * Redistribution's of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//
//   * Redistribution's in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other GpuMaterials provided with the distribution.
//
//   * The name of the copyright holders may not be used to endorse or promote products
//     derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors as is and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
__kernel void BlendLinear_C1_D0(
yao's avatar
yao committed
46 47 48 49 50
    __global uchar4 *dst,
    __global uchar4 *img1,
    __global uchar4 *img2,
    __global float4 *weight1,
    __global float4 *weight2,
51 52 53 54 55
    int rows,
    int cols,
    int istep,
    int wstep
    )
56
{
57 58
    int idx = get_global_id(0);
    int idy = get_global_id(1);
yao's avatar
yao committed
59
    if (idx << 2 < cols && idy < rows)
60
    {
yao's avatar
yao committed
61 62 63
        int pos = mad24(idy,istep >> 2,idx);
        int wpos = mad24(idy,wstep >> 2,idx);
        float4 w1 = weight1[wpos], w2 = weight2[wpos];
64
        dst[pos] = convert_uchar4((convert_float4(img1[pos]) * w1 +
yao's avatar
yao committed
65
            convert_float4(img2[pos]) * w2) / (w1 + w2 + 1e-5f));
66
    }
67 68 69
}

__kernel void BlendLinear_C4_D0(
yao's avatar
yao committed
70 71 72
    __global uchar4 *dst,
    __global uchar4 *img1,
    __global uchar4 *img2,
73 74 75 76 77 78 79
    __global float *weight1,
    __global float *weight2,
    int rows,
    int cols,
    int istep,
    int wstep
    )
80
{
81 82
    int idx = get_global_id(0);
    int idy = get_global_id(1);
yao's avatar
yao committed
83
    if (idx < cols && idy < rows)
84
    {
yao's avatar
yao committed
85 86
        int pos = mad24(idy,istep >> 2,idx);
        int wpos = mad24(idy,wstep, idx);
87 88
        float w1 = weight1[wpos];
        float w2 = weight2[wpos];
89
        dst[pos] = convert_uchar4((convert_float4(img1[pos]) * w1 +
yao's avatar
yao committed
90
            convert_float4(img2[pos]) * w2) / (w1 + w2 + 1e-5f));
91
    }
92 93
}

yao's avatar
yao committed
94

95
__kernel void BlendLinear_C1_D5(
yao's avatar
yao committed
96 97 98 99 100
    __global float4 *dst,
    __global float4 *img1,
    __global float4 *img2,
    __global float4 *weight1,
    __global float4 *weight2,
101 102 103 104 105
    int rows,
    int cols,
    int istep,
    int wstep
    )
106
{
107 108
    int idx = get_global_id(0);
    int idy = get_global_id(1);
yao's avatar
yao committed
109
    if (idx << 2 < cols && idy < rows)
110
    {
yao's avatar
yao committed
111 112 113
        int pos = mad24(idy,istep >> 2,idx);
        int wpos = mad24(idy,wstep >> 2,idx);
        float4 w1 = weight1[wpos], w2 = weight2[wpos];
114 115
        dst[pos] = (img1[pos] * w1 + img2[pos] * w2) / (w1 + w2 + 1e-5f);
    }
116 117 118
}

__kernel void BlendLinear_C4_D5(
yao's avatar
yao committed
119 120 121
    __global float4 *dst,
    __global float4 *img1,
    __global float4 *img2,
122 123 124 125 126 127 128
    __global float *weight1,
    __global float *weight2,
    int rows,
    int cols,
    int istep,
    int wstep
    )
129
{
130 131
    int idx = get_global_id(0);
    int idy = get_global_id(1);
yao's avatar
yao committed
132
    if (idx < cols && idy < rows)
133
    {
yao's avatar
yao committed
134 135
        int pos = mad24(idy,istep >> 2,idx);
        int wpos = mad24(idy,wstep, idx);
136 137 138 139
        float w1 = weight1[wpos];
        float w2 = weight2[wpos];
        dst[pos] = (img1[pos] * w1 + img2[pos] * w2) / (w1 + w2 + 1e-5f);
    }
140
}