Skip to content

Commit 0536572

Browse files
Fix non-raw OpenCL rastermask code path
1. Use the correct OpenCL interpolator here 2. Avoid the bilinear interpolation if the provided rastermask has the same dimension as roi_in of the rastermask module itself for performance
1 parent ab60bc5 commit 0536572

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/iop/rasterfile.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,13 @@ static inline dt_hash_t _get_cache_hash(dt_iop_module_t *self)
323323
return hash;
324324
}
325325

326-
static float *_get_rasterfile_mask(dt_dev_pixelpipe_iop_t *piece)
326+
static float *_get_rasterfile_mask(dt_dev_pixelpipe_iop_t *piece,
327+
const dt_iop_roi_t *const roi,
328+
const dt_iop_roi_t *const roo)
327329
{
328330
dt_iop_module_t *self = piece->module;
329331
dt_iop_rasterfile_data_t *d = piece->data;
330332

331-
const dt_iop_roi_t *roi = &piece->processed_roi_in;
332-
const dt_iop_roi_t *roo = &piece->processed_roi_out;
333-
334333
dt_rasterfile_cache_t *cd = self->data;
335334
float *res = NULL;
336335

@@ -346,13 +345,14 @@ static float *_get_rasterfile_mask(dt_dev_pixelpipe_iop_t *piece)
346345
}
347346
if(cd->mask)
348347
{
349-
float *tmp = dt_iop_image_alloc(roi->width, roi->height, 1);
348+
const gboolean scale = cd->width != roi->width || cd->height != roi->height;
349+
float *tmp = scale ? dt_iop_image_alloc(roi->width, roi->height, 1) : cd->mask;
350350
if(tmp)
351351
{
352-
interpolate_bilinear(cd->mask, cd->width, cd->height, tmp, roi->width, roi->height, 1);
352+
if(scale) interpolate_bilinear(cd->mask, cd->width, cd->height, tmp, roi->width, roi->height, 1);
353353
res = dt_iop_image_alloc(roo->width, roo->height, 1);
354354
if(res) self->distort_mask(self, piece, tmp, res, roi, roo);
355-
dt_free_align(tmp);
355+
if(scale) dt_free_align(tmp);
356356
}
357357
}
358358
dt_pthread_mutex_unlock(&cd->lock);
@@ -378,7 +378,7 @@ int process_cl(dt_iop_module_t *self,
378378
if(visual) return err;
379379

380380
if(roi_out->scale != roi_in->scale && ch == 4)
381-
err = dt_iop_clip_and_zoom_roi_cl(devid, dev_out, dev_in, roi_out, roi_in);
381+
err = dt_iop_clip_and_zoom_cl(devid, dev_out, dev_in, roi_out, roi_in);
382382
else
383383
{
384384
size_t iorigin[] = { roi_out->x, roi_out->y, 0 };
@@ -390,7 +390,7 @@ int process_cl(dt_iop_module_t *self,
390390
if(dt_iop_is_raster_mask_used(piece->module, BLEND_RASTER_ID)
391391
&& (err == CL_SUCCESS))
392392
{
393-
float *mask = _get_rasterfile_mask(piece);
393+
float *mask = _get_rasterfile_mask(piece, roi_in, roi_out);
394394
if(mask)
395395
dt_iop_piece_set_raster(piece, mask, roi_in, roi_out);
396396
else
@@ -427,7 +427,7 @@ void process(dt_iop_module_t *self,
427427
const gboolean fullpipe = pipe->type & DT_DEV_PIXELPIPE_FULL;
428428
const gboolean request = dt_iop_is_raster_mask_used(piece->module, BLEND_RASTER_ID);
429429
const gboolean visual = fullpipe && dt_iop_has_focus(self);
430-
float *mask = visual || request ? _get_rasterfile_mask(piece) : NULL;
430+
float *mask = visual || request ? _get_rasterfile_mask(piece, roi_in, roi_out) : NULL;
431431

432432
if(visual)
433433
{

0 commit comments

Comments
 (0)