Skip to content

Commit f137dd0

Browse files
Calc capture radius early in OpenCL code
- required for internal tiling
1 parent 64c4df0 commit f137dd0

File tree

2 files changed

+53
-38
lines changed

2 files changed

+53
-38
lines changed

src/iop/demosaic.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,8 @@ void tiling_callback(dt_iop_module_t *self,
517517
else
518518
tiling->factor += smooth;
519519

520+
tiling->factor_cl = 3.0f;
521+
520522
tiling->overlap = overlap;
521523
}
522524
else if(demosaicing_method == DT_IOP_DEMOSAIC_RCD)
@@ -531,7 +533,7 @@ void tiling_callback(dt_iop_module_t *self,
531533

532534
tiling->overhead = is_opencl ? 0 : sizeof(float) * DT_RCD_TILESIZE * DT_RCD_TILESIZE * 8 * dt_get_num_threads();
533535
tiling->overlap = 10;
534-
tiling->factor_cl = tiling->factor + 3.0f;
536+
tiling->factor_cl = 3.0f;
535537
}
536538
else if(demosaicing_method == DT_IOP_DEMOSAIC_LMMSE)
537539
{
@@ -557,6 +559,7 @@ void tiling_callback(dt_iop_module_t *self,
557559
else
558560
tiling->factor += smooth;
559561

562+
tiling->factor_cl = 3.0f;
560563
tiling->overlap = 6;
561564
}
562565

@@ -919,6 +922,9 @@ int process_cl(dt_iop_module_t *self,
919922
|| demosaicing_method == DT_IOP_DEMOSAIC_PASSTHROUGH_COLOR;
920923
const gboolean do_capture = !passthru && !run_fast && !show_dual && d->cs_iter;
921924

925+
if(do_capture && fullpipe)
926+
_capture_radius_cl(self, piece, dev_in, iwidth, iheight, xtrans, filters);
927+
922928
cl_mem in_image = dev_in;
923929
if(is_bayer && d->green_eq != DT_IOP_GREEN_EQ_NO && no_masking)
924930
{

src/iop/demosaicing/capture.c

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,51 @@ void _capture_sharpen(dt_iop_module_t *self,
691691

692692
#if HAVE_OPENCL
693693

694+
int _capture_radius_cl(dt_iop_module_t *self,
695+
dt_dev_pixelpipe_iop_t *const piece,
696+
const cl_mem dev_in,
697+
const int width,
698+
const int height,
699+
const uint8_t (*const xtrans)[6],
700+
const uint32_t filters)
701+
{
702+
dt_dev_pixelpipe_t *pipe = piece->pipe;
703+
dt_iop_demosaic_data_t *d = piece->data;
704+
dt_iop_demosaic_gui_data_t *g = self->gui_data;
705+
706+
if(!((g && g->autoradius) || d->cs_radius < 0.01f))
707+
return CL_SUCCESS;
708+
709+
const int devid = piece->pipe->devid;
710+
float *in = dt_iop_image_alloc(width, height, 1);
711+
if(!in) return CL_MEM_OBJECT_ALLOCATION_FAILURE;
712+
713+
cl_int err = dt_opencl_copy_device_to_host(devid, in, dev_in, width, height, sizeof(float));
714+
if(err == CL_SUCCESS)
715+
{
716+
const float radius = filters != 9u
717+
? _calcRadiusBayer(in, width, height, 0.01f, 1.0f, filters)
718+
: _calcRadiusXtrans(in, width, height, 0.01f, 1.0f, xtrans);
719+
const gboolean valid = radius > 0.1f && radius < 1.0f;
720+
dt_print_pipe(DT_DEBUG_PIPE, filters != 9u ? "bayer autoradius" : "xtrans autoradius",
721+
pipe, self, devid, NULL, NULL, "autoradius=%.2f", radius);
722+
723+
if(!feqf(radius, d->cs_radius, 0.005f) && valid)
724+
{
725+
if(g)
726+
{
727+
dt_control_log(_("calculated radius"));
728+
g->autoradius = TRUE;
729+
}
730+
dt_iop_demosaic_params_t *p = self->params;
731+
p->cs_radius = d->cs_radius = radius;
732+
}
733+
else if(g) g->autoradius = FALSE;
734+
}
735+
dt_free_align(in);
736+
return err;
737+
}
738+
694739
int _capture_sharpen_cl(dt_iop_module_t *self,
695740
dt_dev_pixelpipe_iop_t *const piece,
696741
const cl_mem dev_in,
@@ -713,7 +758,6 @@ int _capture_sharpen_cl(dt_iop_module_t *self,
713758

714759
const dt_iop_demosaic_data_t *const d = piece->data;
715760
dt_iop_demosaic_global_data_t *const gd = self->global_data;
716-
dt_iop_demosaic_gui_data_t *g = self->gui_data;
717761

718762
if(pipe->type & DT_DEV_PIXELPIPE_THUMBNAIL)
719763
{
@@ -730,42 +774,7 @@ int _capture_sharpen_cl(dt_iop_module_t *self,
730774
wbon ? CAPTURE_CFACLIP * dsc->temperature.coeffs[2] : CAPTURE_CFACLIP,
731775
0.0f };
732776

733-
const gboolean fullpipe = pipe->type & DT_DEV_PIXELPIPE_FULL;
734-
const gboolean autoradius = fullpipe && g && g->autoradius;
735-
const float old_radius = d->cs_radius;
736-
float radius = old_radius;
737-
if(autoradius || radius < 0.01f)
738-
{
739-
float *in = dt_alloc_align_float(pixels);
740-
if(in)
741-
{
742-
if(dt_opencl_copy_device_to_host(devid, in, dev_in, width, height, sizeof(float)) == CL_SUCCESS)
743-
{
744-
radius = filters != 9u
745-
? _calcRadiusBayer(in, width, height, 0.01f, 1.0f, filters)
746-
: _calcRadiusXtrans(in, width, height, 0.01f, 1.0f, xtrans);
747-
const gboolean valid = radius > 0.1f && radius < 1.0f;
748-
dt_print_pipe(DT_DEBUG_PIPE, filters != 9u ? "bayer autoradius" : "xtrans autoradius",
749-
pipe, self, devid, NULL, NULL, "autoradius=%.2f", radius);
750-
751-
if(!feqf(radius, old_radius, 0.005f) && valid)
752-
{
753-
if(fullpipe)
754-
{
755-
if(g)
756-
{
757-
dt_control_log(_("calculated radius"));
758-
g->autoradius = TRUE;
759-
}
760-
dt_iop_demosaic_params_t *p = self->params;
761-
p->cs_radius = radius;
762-
}
763-
}
764-
else if(g) g->autoradius = FALSE;
765-
}
766-
dt_free_align(in);
767-
}
768-
}
777+
const float radius = d->cs_radius;
769778

770779
cl_mem gcoeffs = NULL;
771780
cl_mem gauss_idx = NULL;

0 commit comments

Comments
 (0)