11/*
22 This file is part of darktable,
3- copyright (c ) 2017 edgardo hoszowski .
3+ Copyright (C ) 2017-2026 darktable developers .
44
55 darktable is free software: you can redistribute it and/or modify
66 it under the terms of the GNU General Public License as published by
@@ -38,22 +38,28 @@ retouch_clear_alpha(global float4 *in, int width, int height)
3838}
3939
4040kernel void
41- retouch_copy_alpha (__read_only image2d_t in , global float4 * out , int width , int height )
41+ retouch_copy_alpha (__read_only image2d_t in ,
42+ global float4 * out ,
43+ int width ,
44+ int height )
4245{
4346 const int x = get_global_id (0 );
4447 const int y = get_global_id (1 );
4548
4649 if (x >= width || y >= height ) return ;
4750
48- float4 pixel = read_imagef (in , sampleri , ( int2 )( x , y ) );
51+ float alpha = readalpha (in , x , y );
4952 const int idx = mad24 (y , width , x );
50- out [idx ].w = pixel . w ;
53+ out [idx ].w = alpha ;
5154}
5255
5356kernel void
54- retouch_copy_buffer_to_image (global float4 * in , global dt_iop_roi_t * roi_in ,
55- __write_only image2d_t out , global dt_iop_roi_t * roi_out , const int xoffs ,
56- const int yoffs )
57+ retouch_copy_buffer_to_image (global float4 * in ,
58+ global dt_iop_roi_t * roi_in ,
59+ __write_only image2d_t out ,
60+ global dt_iop_roi_t * roi_out ,
61+ const int xoffs ,
62+ const int yoffs )
5763{
5864 const int x = get_global_id (0 );
5965 const int y = get_global_id (1 );
@@ -66,8 +72,12 @@ retouch_copy_buffer_to_image(global float4 *in, global dt_iop_roi_t *roi_in,
6672}
6773
6874kernel void
69- retouch_copy_buffer_to_buffer (global float4 * in , global dt_iop_roi_t * roi_in , global float4 * out ,
70- global dt_iop_roi_t * roi_out , const int xoffs , const int yoffs )
75+ retouch_copy_buffer_to_buffer (global float4 * in ,
76+ global dt_iop_roi_t * roi_in ,
77+ global float4 * out ,
78+ global dt_iop_roi_t * roi_out ,
79+ const int xoffs ,
80+ const int yoffs )
7181{
7282 const int x = get_global_id (0 );
7383 const int y = get_global_id (1 );
@@ -79,39 +89,45 @@ retouch_copy_buffer_to_buffer(global float4 *in, global dt_iop_roi_t *roi_in, gl
7989}
8090
8191kernel void
82- retouch_copy_mask_to_alpha (global float4 * in , global dt_iop_roi_t * roi_in , global float * mask_scaled ,
83- global dt_iop_roi_t * roi_mask_scaled , const float opacity )
92+ retouch_copy_mask_to_alpha (global float4 * in ,
93+ global dt_iop_roi_t * roi_in ,
94+ global float * mask_scaled ,
95+ global dt_iop_roi_t * roi_mask_scaled ,
96+ const float opacity )
8497{
8598 const int x = get_global_id (0 );
8699 const int y = get_global_id (1 );
87100
88101 if (x >= roi_mask_scaled -> width || y >= roi_mask_scaled -> height ) return ;
89102
90103 const int mask_index = mad24 (y , roi_mask_scaled -> width , x );
91- const int dest_index
92- = mad24 (y + roi_mask_scaled -> y - roi_in -> y , roi_in -> width , x + roi_mask_scaled -> x - roi_in -> x );
104+ const int dest_index = mad24 (y + roi_mask_scaled -> y - roi_in -> y , roi_in -> width , x + roi_mask_scaled -> x - roi_in -> x );
93105
94- const float f = mask_scaled [mask_index ] * opacity ;
106+ const float f = clipf ( mask_scaled [mask_index ] * opacity ) ;
95107
96108 if (f > in [dest_index ].w ) in [dest_index ].w = f ;
97109}
98110
99111kernel void
100- retouch_fill (global float4 * in , global dt_iop_roi_t * roi_in , global float * mask_scaled ,
101- global dt_iop_roi_t * roi_mask_scaled , const float opacity , const float color_x ,
102- const float color_y , const float color_z )
112+ retouch_fill (global float4 * in ,
113+ global dt_iop_roi_t * roi_in ,
114+ global float * mask_scaled ,
115+ global dt_iop_roi_t * roi_mask_scaled ,
116+ const float opacity ,
117+ const float color_x ,
118+ const float color_y ,
119+ const float color_z )
103120{
104121 const int x = get_global_id (0 );
105122 const int y = get_global_id (1 );
106123
107124 if (x >= roi_mask_scaled -> width || y >= roi_mask_scaled -> height ) return ;
108125
109126 const int mask_index = mad24 (y , roi_mask_scaled -> width , x );
110- const int dest_index
111- = mad24 (y + roi_mask_scaled -> y - roi_in -> y , roi_in -> width , x + roi_mask_scaled -> x - roi_in -> x );
127+ const int dest_index = mad24 (y + roi_mask_scaled -> y - roi_in -> y , roi_in -> width , x + roi_mask_scaled -> x - roi_in -> x );
112128
113129 float4 fill_color = { color_x , color_y , color_z , 0.f };
114- const float f = mask_scaled [mask_index ] * opacity ;
130+ const float f = clipf ( mask_scaled [mask_index ] * opacity ) ;
115131 const float w = in [dest_index ].w ;
116132
117133 in [dest_index ] = in [dest_index ] * (1.0f - f ) + fill_color * f ;
@@ -120,9 +136,12 @@ retouch_fill(global float4 *in, global dt_iop_roi_t *roi_in, global float *mask_
120136}
121137
122138kernel void
123- retouch_copy_buffer_to_buffer_masked (global float4 * buffer_src , global float4 * buffer_dest ,
124- global dt_iop_roi_t * roi_buffer_dest , global float * mask_scaled ,
125- global dt_iop_roi_t * roi_mask_scaled , const float opacity )
139+ retouch_copy_buffer_to_buffer_masked (global float4 * buffer_src ,
140+ global float4 * buffer_dest ,
141+ global dt_iop_roi_t * roi_buffer_dest ,
142+ global float * mask_scaled ,
143+ global dt_iop_roi_t * roi_mask_scaled ,
144+ const float opacity )
126145{
127146 const int x = get_global_id (0 );
128147 const int y = get_global_id (1 );
@@ -134,7 +153,7 @@ retouch_copy_buffer_to_buffer_masked(global float4 *buffer_src, global float4 *b
134153 const int idx_src = mad24 (y , roi_mask_scaled -> width , x );
135154 const int idx_mask = mad24 (y , roi_mask_scaled -> width , x );
136155
137- const float f = mask_scaled [idx_mask ] * opacity ;
156+ const float f = clipf ( mask_scaled [idx_mask ] * opacity ) ;
138157 const float w = buffer_dest [idx_dest ].w ;
139158
140159 buffer_dest [idx_dest ] = buffer_dest [idx_dest ] * (1.0f - f ) + buffer_src [idx_src ] * f ;
@@ -143,9 +162,12 @@ retouch_copy_buffer_to_buffer_masked(global float4 *buffer_src, global float4 *b
143162}
144163
145164kernel void
146- retouch_copy_image_to_buffer_masked (__read_only image2d_t buffer_src , global float4 * buffer_dest ,
147- global dt_iop_roi_t * roi_buffer_dest , global float * mask_scaled ,
148- global dt_iop_roi_t * roi_mask_scaled , const float opacity )
165+ retouch_copy_image_to_buffer_masked (__read_only image2d_t buffer_src ,
166+ global float4 * buffer_dest ,
167+ global dt_iop_roi_t * roi_buffer_dest ,
168+ global float * mask_scaled ,
169+ global dt_iop_roi_t * roi_mask_scaled ,
170+ const float opacity )
149171{
150172 const int x = get_global_id (0 );
151173 const int y = get_global_id (1 );
@@ -156,17 +178,19 @@ retouch_copy_image_to_buffer_masked(__read_only image2d_t buffer_src, global flo
156178 x + roi_mask_scaled -> x - roi_buffer_dest -> x );
157179 const int idx_mask = mad24 (y , roi_mask_scaled -> width , x );
158180
159- const float f = mask_scaled [idx_mask ] * opacity ;
181+ const float f = clipf ( mask_scaled [idx_mask ] * opacity ) ;
160182 const float w = buffer_dest [idx_dest ].w ;
161183
162- float4 pix = read_imagef (buffer_src , sampleri , ( int2 )( x , y ) );
184+ float4 pix = readpixel (buffer_src , x , y );
163185 buffer_dest [idx_dest ] = buffer_dest [idx_dest ] * (1.0f - f ) + pix * f ;
164186
165187 buffer_dest [idx_dest ].w = w ;
166188}
167189
168190kernel void
169- retouch_image_rgb2lab (global float4 * in , int width , int height )
191+ retouch_image_rgb2lab (global float4 * in ,
192+ int width ,
193+ int height )
170194{
171195 const int x = get_global_id (0 );
172196 const int y = get_global_id (1 );
@@ -179,7 +203,9 @@ retouch_image_rgb2lab(global float4 *in, int width, int height)
179203}
180204
181205kernel void
182- retouch_image_lab2rgb (global float4 * in , int width , int height )
206+ retouch_image_lab2rgb (global float4 * in ,
207+ int width ,
208+ int height )
183209{
184210 const int x = get_global_id (0 );
185211 const int y = get_global_id (1 );
0 commit comments