@@ -52,6 +52,8 @@ DT_MODULE_INTROSPECTION(6, dt_iop_demosaic_params_t)
5252#define DT_DEMOSAIC_XTRANS 1024 // masks for non-Bayer demosaic ops
5353#define DT_DEMOSAIC_DUAL 2048 // masks for dual demosaicing methods
5454
55+ #define DT_DEMOSAIC_POSITIVE
56+
5557typedef enum dt_iop_demosaic_method_t
5658{
5759 // methods for Bayer images
@@ -240,6 +242,7 @@ typedef struct dt_iop_demosaic_global_data_t
240242 int show_blend_mask ;
241243 int capture_result ;
242244 int final_blend ;
245+ int image_positive ;
243246 float * gauss_coeffs ;
244247} dt_iop_demosaic_global_data_t ;
245248
@@ -899,6 +902,12 @@ void process(dt_iop_module_t *self,
899902 if (d -> color_smoothing != DT_DEMOSAIC_SMOOTH_OFF && no_masking && !run_fast )
900903 color_smoothing (out , width , height , d -> color_smoothing );
901904
905+ #ifdef DT_DEMOSAIC_POSITIVE
906+ DT_OMP_FOR_SIMD (aligned (out : 64 ))
907+ for (size_t k = 0 ; k < (size_t )width * height * 4 ; k ++ )
908+ out [k ] = fmaxf (0.0f , out [k ]);
909+ #endif
910+
902911 if (!direct )
903912 {
904913 dt_iop_clip_and_zoom_roi ((float * )o , out , roi_out , roi_in );
@@ -1200,8 +1209,13 @@ int process_cl(dt_iop_module_t *self,
12001209 if (err != CL_SUCCESS ) goto finish ;
12011210 }
12021211
1203- if (!direct )
1204- err = dt_iop_clip_and_zoom_roi_cl (devid , dev_out , out_image , roi_out , roi_in );
1212+ #ifdef DT_DEMOSAIC_POSITIVE
1213+ err = dt_opencl_enqueue_kernel_2d_args (devid , gd -> image_positive , iwidth , iheight ,
1214+ CLARG (out_image ), CLARG (out_image ), CLARG (iwidth ), CLARG (iheight ));
1215+ #endif
1216+
1217+ if (!direct && err == CL_SUCCESS )
1218+ err = dt_iop_clip_and_zoom_roi_cl (devid , dev_out , out_image , roi_out , roi_in );
12051219
12061220finish :
12071221 dt_opencl_release_mem_object (dev_xtrans );
@@ -1284,6 +1298,7 @@ void init_global(dt_iop_module_so_t *self)
12841298 gd -> kernel_rcd_step_5_2 = dt_opencl_create_kernel (rcd , "rcd_step_5_2" );
12851299 gd -> kernel_demosaic_box3 = dt_opencl_create_kernel (rcd , "demosaic_box3" );
12861300 gd -> kernel_write_blended_dual = dt_opencl_create_kernel (rcd , "write_blended_dual" );
1301+ gd -> image_positive = dt_opencl_create_kernel (rcd , "image_positive" );
12871302
12881303 const int capt = 38 ; // capture.cl, from programs.conf
12891304 gd -> gaussian_9x9_mul = dt_opencl_create_kernel (capt , "kernel_9x9_mul" );
@@ -1357,6 +1372,7 @@ void cleanup_global(dt_iop_module_so_t *self)
13571372 dt_opencl_free_kernel (gd -> show_blend_mask );
13581373 dt_opencl_free_kernel (gd -> capture_result );
13591374 dt_opencl_free_kernel (gd -> final_blend );
1375+ dt_opencl_free_kernel (gd -> image_positive );
13601376 dt_free_align (gd -> gauss_coeffs );
13611377 free (self -> data );
13621378 self -> data = NULL ;
0 commit comments