Skip to content

Commit ecbef72

Browse files
jenshannoschwalmTurboGit
authored andcommitted
Simplify and fix for detail mask distortion
1. Slightly simplified code for readability and maintenance 2. Fixed a double_free bug if a module distort produced wrong dimensions
1 parent 32067c7 commit ecbef72

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

src/develop/blend.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -271,19 +271,15 @@ static void _refine_with_detail_mask(dt_iop_module_t *self,
271271
const gboolean detail = (level > 0.0f);
272272
const float threshold = _detail_mask_threshold(level, detail);
273273

274-
float *lum = NULL;
275-
float *warp_mask = NULL;
276-
277274
dt_dev_pixelpipe_t *p = piece->pipe;
278275
if(p->scharr.data == NULL) goto error;
279276

280-
lum = dt_masks_calc_detail_mask(piece, threshold, detail);
281-
if(!lum) goto error;
277+
float *lum = dt_masks_calc_detail_mask(piece, threshold, detail);
278+
if(lum == NULL) goto error;
282279

283280
// here we have the slightly blurred full detail mask available
284-
warp_mask = dt_dev_distort_detail_mask(piece, lum, self);
281+
float *warp_mask = dt_dev_distort_detail_mask(piece, lum, self);
285282
dt_free_align(lum);
286-
lum = NULL;
287283

288284
if(warp_mask == NULL) goto error;
289285

@@ -304,8 +300,6 @@ static void _refine_with_detail_mask(dt_iop_module_t *self,
304300
"refine with detail mask",
305301
piece->pipe, self, DT_DEVICE_CPU, roi_in, roi_out, "no mask data available");
306302
dt_control_log(_("detail mask blending error"));
307-
dt_free_align(warp_mask);
308-
dt_free_align(lum);
309303
}
310304

311305
static size_t
@@ -884,13 +878,12 @@ static void _refine_with_detail_mask_cl(dt_iop_module_t *self,
884878

885879
// here we have the slightly blurred full detail mask available
886880
float *warp_mask = dt_dev_distort_detail_mask(piece, lum, self);
881+
dt_free_align(lum);
887882
if(warp_mask == NULL)
888883
{
889884
err = DT_OPENCL_PROCESS_CL;
890885
goto error;
891886
}
892-
dt_free_align(lum);
893-
894887
dt_print_pipe(DT_DEBUG_PIPE,
895888
"refine with detail mask",
896889
piece->pipe, self, piece->pipe->devid, roi_in, roi_out);
@@ -909,7 +902,6 @@ static void _refine_with_detail_mask_cl(dt_iop_module_t *self,
909902
"refine with detail_mask",
910903
piece->pipe, self, piece->pipe->devid, roi_in, roi_out, "OpenCL error: %s", cl_errstr(err));
911904

912-
dt_free_align(lum);
913905
dt_opencl_release_mem_object(tmp);
914906
dt_opencl_release_mem_object(blur);
915907
dt_opencl_release_mem_object(out);

src/develop/pixelpipe_hb.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3393,6 +3393,8 @@ float *dt_dev_distort_detail_mask(dt_dev_pixelpipe_iop_t *piece,
33933393
float *src,
33943394
const dt_iop_module_t *target_module)
33953395
{
3396+
if(!src) return NULL;
3397+
33963398
dt_dev_pixelpipe_t *pipe = piece->pipe;
33973399
gboolean valid = FALSE;
33983400
const gboolean raw_img = dt_image_is_raw(&pipe->image);
@@ -3475,7 +3477,7 @@ float *dt_dev_distort_detail_mask(dt_dev_pixelpipe_iop_t *piece,
34753477

34763478
if(!correct)
34773479
{
3478-
dt_free_align(resmask);
3480+
if(resmask != src) dt_free_align(resmask);
34793481
resmask = NULL;
34803482
}
34813483

0 commit comments

Comments
 (0)