1 #define ANGLE_PRIME
95273
2 #define RADIUS_PRIME
29537
4 void sample_min_max
(const __global float4
*src_buf
,
7 const __global float
*radiuses
,
8 const __global float
*lut_cos
,
9 const __global float
*lut_sin
,
21 float4 center_pix
= *(src_buf + src_width
* y
+ x
);
24 best_min
= center_pix
;
25 best_max
= center_pix
;
27 int angle_no
= (src_width * y
+ x
) * (iterations) *
28 samples
+ j
* samples
;
29 int radius_no
= angle_no
;
30 angle_no %
= ANGLE_PRIME
;
31 radius_no %
= RADIUS_PRIME
;
32 for
(i=0; i<samples; i++)
36 /* if we
've sampled outside the valid image
37 area
, we grab another sample instead
, this
38 should potentially work better than mirroring
39 or extending the image
*/
42 rmag
= radiuses
[radius_no
++] * radius
;
44 if
( angle_no
>= ANGLE_PRIME
)
46 if
( radius_no
>= RADIUS_PRIME
)
49 int u
= x
+ rmag
* lut_cos
[angle];
50 int v = y + rmag * lut_sin[angle];
52 if
(u>=src_width || u
<0 || v
>=src_height || v
<0)
57 float4 pixel
= *(src_buf + (src_width * v
+ u
));
64 best_min
= pixel
< best_min ? pixel
: best_min
;
65 best_max
= pixel
> best_max ? pixel
: best_max
;
68 (*min
).xyz
= best_min.xyz
;
69 (*max
).xyz
= best_max.xyz
;
72 void compute_envelopes
(const __global float4
*src_buf
,
75 const __global float
*radiuses
,
76 const __global float
*lut_cos
,
77 const __global float
*lut_sin
,
87 float4 relative_brightness_sum
= 0;
88 float4 pixel
= *(src_buf + src_width
* y
+ x
);
91 for
(i =0; i<iterations; i++)
94 float4 range
, relative_brightness
;
96 sample_min_max
(src_buf, src_width
, src_height
,
97 radiuses
, lut_cos
, lut_sin
, x
, y
,
98 radius
,samples
,&min
,&max
,i
,iterations
);
100 relative_brightness
= range
<= 0.0f ?
101 0.5f
: (pixel - min
) / range
;
102 relative_brightness_sum
+= relative_brightness
;
106 float4 relative_brightness
= relative_brightness_sum
/ (float4)(iterations);
107 float4 range
= range_sum
/ (float4)(iterations);
110 *max_envelope
= pixel
+ (1.0f - relative_brightness
) * range
;
113 *min_envelope
= pixel - relative_brightness
* range
;
116 __kernel void c2g
(const __global float4
*src_buf
,
119 const __global float
*radiuses
,
120 const __global float
*lut_cos
,
121 const __global float
*lut_sin
,
122 __global float2
*dst_buf
,
127 int gidx
= get_global_id
(0);
128 int gidy
= get_global_id
(1);
130 int x
= gidx
+ radius
;
131 int y
= gidy
+ radius
;
133 int src_offset
= (src_width * y
+ x
);
134 int dst_offset
= gidx
+ get_global_size
(0) * gidy
;
137 compute_envelopes
(src_buf, src_width
, src_height
,
138 radiuses
, lut_cos
, lut_sin
, x
, y
,
139 radius
, samples
, iterations
, &min
, &max
);
141 float4 pixel
= *(src_buf + src_offset
);
143 float nominator
=0, denominator
=0;
144 float4 t1
= (pixel - min
) * (pixel - min
);
145 float4 t2
= (pixel - max
) * (pixel - max
);
147 nominator
= t1.x
+ t1.y
+ t1.z
;
148 denominator
= t2.x
+ t2.y
+ t2.z
;
150 nominator
= sqrt
(nominator);
151 denominator
= sqrt
(denominator);
152 denominator
+= nominator
+ denominator
;
154 dst_buf
[dst_offset].x = (denominator > 0.000f)
155 ? (nominator / denominator) : 0.5f;
156 dst_buf[dst_offset].y
= src_buf
[src_offset].w;