Skip to content

Commit 669c18b

Browse files
jenshannoschwalmTurboGit
authored andcommitted
Some remaining demosaicer maintenance
- FCxtrans to FCNxtrans if possible - Pass width & height as parameters instead of roi in preparation for internal tiling - get some const early and make use of them as being used at several places
1 parent 92303ee commit 669c18b

File tree

10 files changed

+87
-105
lines changed

10 files changed

+87
-105
lines changed

src/iop/demosaic.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,12 @@ static gboolean _demosaic_full(const dt_dev_pixelpipe_iop_t *const piece,
252252
}
253253

254254
// Implemented in demosaicing/amaze.cc
255-
void amaze_demosaic(dt_dev_pixelpipe_iop_t *piece,
256-
const float *const in,
255+
void amaze_demosaic(const float *const in,
257256
float *out,
258-
const dt_iop_roi_t *const roi_in,
259-
const uint32_t filters);
257+
const int width,
258+
const int height,
259+
const uint32_t filters,
260+
const float procmin);
260261

261262
#include "iop/demosaicing/basics.c"
262263
#include "iop/demosaicing/vng.c"
@@ -592,8 +593,7 @@ void process(dt_iop_module_t *self,
592593
}
593594
}
594595

595-
const uint8_t(*const xtrans)[6] = xtrans_new; // (const uint8_t(*const)[6])pipe->dsc.xtrans;
596-
596+
const uint8_t(*const xtrans)[6] = xtrans_new;
597597
const dt_iop_demosaic_data_t *d = piece->data;
598598
const dt_iop_demosaic_gui_data_t *g = self->gui_data;
599599
const uint32_t filters = dt_rawspeed_crop_dcraw_filters(pipe->dsc.filters, roi_in->x, roi_in->y);
@@ -659,13 +659,17 @@ void process(dt_iop_module_t *self,
659659
|| demosaicing_method == DT_IOP_DEMOSAIC_PASSTHROUGH_COLOR;
660660
const gboolean do_capture = !passthru && !is_4bayer && !show_dual && !run_fast && d->cs_iter;
661661

662+
const float procmax = dt_iop_get_processed_maximum(piece);
663+
const float procmin = dt_iop_get_processed_minimum(piece);
664+
const int exif_iso = img->exif_iso;
665+
662666
if(!direct)
663-
out = dt_alloc_align_float((size_t)4 * width * height);
667+
out = dt_iop_image_alloc(width, height, 4);
664668

665669
if(is_bayer && d->green_eq != DT_IOP_GREEN_EQ_NO && no_masking)
666670
{
667-
const float threshold = 0.0001f * img->exif_iso;
668-
in = dt_alloc_align_float((size_t)height * width);
671+
const float threshold = 0.0001f * exif_iso;
672+
in = dt_iop_image_alloc(width, height, 1);
669673
float *aux = NULL;
670674

671675
switch(d->green_eq)
@@ -677,7 +681,7 @@ void process(dt_iop_module_t *self,
677681
green_equilibration_lavg(in, (float *)i, width, height, filters, threshold);
678682
break;
679683
case DT_IOP_GREEN_EQ_BOTH:
680-
aux = dt_alloc_align_float((size_t)height * width);
684+
aux = dt_iop_image_alloc(width, height, 1);
681685
green_equilibration_favg(aux, (float *)i, width, height, filters);
682686
green_equilibration_lavg(in, aux, width, height, filters, threshold);
683687
dt_free_align(aux);
@@ -688,18 +692,18 @@ void process(dt_iop_module_t *self,
688692
}
689693

690694
if(demosaic_mask)
691-
demosaic_box3(piece, out, in, roi_in, filters, xtrans);
695+
demosaic_box3(out, in, width, height, filters, xtrans);
692696
else if(demosaicing_method == DT_IOP_DEMOSAIC_PASSTHROUGH_MONOCHROME)
693-
passthrough_monochrome(out, in, roi_in);
697+
passthrough_monochrome(out, in, width, height);
694698
else if(demosaicing_method == DT_IOP_DEMOSAIC_PASSTHROUGH_COLOR)
695-
passthrough_color(out, in, roi_in, filters, xtrans);
699+
passthrough_color(out, in, width, height, filters, xtrans);
696700
else if(is_xtrans)
697701
{
698702
const int passes = base_demosaicing_method == DT_IOP_DEMOSAIC_MARKESTEIJN_3 ? 3 : 1;
699703
if(demosaicing_method == DT_IOP_DEMOSAIC_FDC)
700-
xtrans_fdc_interpolate(self, out, in, roi_in, xtrans);
704+
xtrans_fdc_interpolate(out, in, width, height, xtrans, exif_iso);
701705
else if(base_demosaicing_method == DT_IOP_DEMOSAIC_MARKESTEIJN || base_demosaicing_method == DT_IOP_DEMOSAIC_MARKESTEIJN_3)
702-
xtrans_markesteijn_interpolate(out, in, roi_in, xtrans, passes);
706+
xtrans_markesteijn_interpolate(out, in, width, height, xtrans, passes);
703707
else
704708
vng_interpolate(out, in, roi_in, filters, xtrans, FALSE);
705709
}
@@ -715,13 +719,13 @@ void process(dt_iop_module_t *self,
715719
}
716720
}
717721
else if(base_demosaicing_method == DT_IOP_DEMOSAIC_RCD)
718-
rcd_demosaic(piece, out, in, roi_in, filters);
722+
rcd_demosaic(out, in, width, height, filters, procmax);
719723
else if(demosaicing_method == DT_IOP_DEMOSAIC_LMMSE)
720-
lmmse_demosaic(piece, out, in, roi_in, filters, d->lmmse_refine);
724+
lmmse_demosaic(out, in, width, height, filters, d->lmmse_refine, procmax);
721725
else if(base_demosaicing_method != DT_IOP_DEMOSAIC_AMAZE)
722-
demosaic_ppg(out, in, roi_in, filters, d->median_thrs);
726+
demosaic_ppg(out, in, width, height, filters, d->median_thrs);
723727
else
724-
amaze_demosaic(piece, in, out, roi_in, filters);
728+
amaze_demosaic(in, out, width, height, filters, procmin);
725729
}
726730

727731
if(pipe->want_detail_mask)

src/iop/demosaicing/amaze.cc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,13 @@ static inline float _xdivf(float d, int n)
126126
////////////////////////////////////////////////////////////////
127127

128128

129-
void amaze_demosaic(dt_dev_pixelpipe_iop_t *piece,
130-
const float *const in,
129+
void amaze_demosaic(const float *const in,
131130
float *out,
132-
const dt_iop_roi_t *const roi_in,
133-
const uint32_t filters)
131+
const int width,
132+
const int height,
133+
const uint32_t filters,
134+
const float clip_pt)
134135
{
135-
const int width = roi_in->width;
136-
const int height = roi_in->height;
137-
138-
const float clip_pt = dt_iop_get_processed_minimum(piece);
139136
const float clip_pt8 = 0.8f * clip_pt;
140137

141138
// this allows to pass AMAZETS to the code. On some machines larger AMAZETS is faster

src/iop/demosaicing/basics.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,40 @@
2626
DT_OMP_DECLARE_SIMD(aligned(in, out))
2727
static void pre_median_b(float *out,
2828
const float *const in,
29-
const dt_iop_roi_t *const roi,
29+
const int width,
30+
const int height,
3031
const uint32_t filters,
3132
const int num_passes,
3233
const float threshold)
3334
{
34-
dt_iop_image_copy_by_size(out, in, roi->width, roi->height, 1);
35+
dt_iop_image_copy_by_size(out, in, width, height, 1);
3536

3637
// now green:
3738
const int lim[5] = { 0, 1, 2, 1, 0 };
3839
for(int pass = 0; pass < num_passes; pass++)
3940
{
4041
DT_OMP_FOR()
41-
for(int row = 3; row < roi->height - 3; row++)
42+
for(int row = 3; row < height - 3; row++)
4243
{
4344
float med[9];
4445
int col = 3;
4546
if(FC(row, col, filters) != 1 && FC(row, col, filters) != 3) col++;
46-
float *pixo = out + (size_t)roi->width * row + col;
47-
const float *pixi = in + (size_t)roi->width * row + col;
48-
for(; col < roi->width - 3; col += 2)
47+
float *pixo = out + (size_t)width * row + col;
48+
const float *pixi = in + (size_t)width * row + col;
49+
for(; col < width - 3; col += 2)
4950
{
5051
int cnt = 0;
5152
for(int k = 0, i = 0; i < 5; i++)
5253
{
5354
for(int j = -lim[i]; j <= lim[i]; j += 2)
5455
{
55-
if(fabsf(pixi[roi->width * (i - 2) + j] - pixi[0]) < threshold)
56+
if(fabsf(pixi[width * (i - 2) + j] - pixi[0]) < threshold)
5657
{
57-
med[k++] = pixi[roi->width * (i - 2) + j];
58+
med[k++] = pixi[width * (i - 2) + j];
5859
cnt++;
5960
}
6061
else
61-
med[k++] = 64.0f + pixi[roi->width * (i - 2) + j];
62+
med[k++] = 64.0f + pixi[width * (i - 2) + j];
6263
}
6364
}
6465
for(int i = 0; i < 8; i++)
@@ -75,12 +76,13 @@ static void pre_median_b(float *out,
7576

7677
static void pre_median(float *out,
7778
const float *const in,
78-
const dt_iop_roi_t *const roi,
79+
const int width,
80+
const int height,
7981
const uint32_t filters,
8082
const int num_passes,
8183
const float threshold)
8284
{
83-
pre_median_b(out, in, roi, filters, num_passes, threshold);
85+
pre_median_b(out, in, width, height, filters, num_passes, threshold);
8486
}
8587

8688
#define SWAPmed(I, J) \

src/iop/demosaicing/dual.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static void dual_demosaic(dt_dev_pixelpipe_iop_t *piece,
5454
}
5555
else
5656
{
57-
float *vng_image = dt_alloc_align_float(msize * 4);
57+
float *vng_image = dt_iop_image_alloc(roi->width, roi->height, 4);
5858
if(vng_image)
5959
{
6060
vng_interpolate(vng_image, raw_data, roi, filters, xtrans, TRUE);

src/iop/demosaicing/lmmse.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,14 @@ static inline float _calc_gamma(float val, float *table)
117117
}
118118

119119
DT_OMP_DECLARE_SIMD(aligned(in, out : 64))
120-
static void lmmse_demosaic(dt_dev_pixelpipe_iop_t *piece,
121-
float *const restrict out,
120+
static void lmmse_demosaic(float *const restrict out,
122121
const float *const restrict in,
123-
const dt_iop_roi_t *const roi_in,
122+
const int width,
123+
const int height,
124124
const uint32_t filters,
125-
const dt_iop_demosaic_lmmse_t mode)
125+
const dt_iop_demosaic_lmmse_t mode,
126+
const float scaler)
126127
{
127-
const int width = roi_in->width;
128-
const int height = roi_in->height;
129-
130128
rcd_ppg_border(out, in, width, height, filters, BORDER_AROUND);
131129
if(width < 2 * BORDER_AROUND || height < 2 * BORDER_AROUND)
132130
return;
@@ -149,8 +147,6 @@ static void lmmse_demosaic(dt_dev_pixelpipe_iop_t *piece,
149147
const int medians = (mode < DT_LMMSE_REFINE_2) ? mode : 3;
150148
// refinement steps
151149
const int refine = (mode > DT_LMMSE_REFINE_2) ? mode - 2 : 0;
152-
153-
const float scaler = dt_iop_get_processed_maximum(piece);
154150
const float revscaler = 1.0f / scaler;
155151

156152
const int num_vertical = 1 + (height - 2 * LMMSE_OVERLAP -1) / LMMSE_TILEVALID;

src/iop/demosaicing/passthrough.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@
1919

2020
static void passthrough_monochrome(float *out,
2121
const float *const in,
22-
const dt_iop_roi_t *const roi_in)
22+
const int width,
23+
const int height)
2324
{
24-
const int width = roi_in->width;
25-
const int height = roi_in->height;
26-
2725
DT_OMP_FOR(collapse(2))
2826
for(int j = 0; j < height; j++)
2927
{
@@ -39,13 +37,11 @@ static void passthrough_monochrome(float *out,
3937

4038
static void passthrough_color(float *out,
4139
const float *const in,
42-
const dt_iop_roi_t *const roi_in,
40+
const int width,
41+
const int height,
4342
const uint32_t filters,
4443
const uint8_t (*const xtrans)[6])
4544
{
46-
const int width = roi_in->width;
47-
const int height = roi_in->height;
48-
4945
if(filters != 9u)
5046
{
5147
DT_OMP_FOR(collapse(2))

src/iop/demosaicing/ppg.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,11 @@
1919
DT_OMP_DECLARE_SIMD(aligned(in, out:64))
2020
static void demosaic_ppg(float *const out,
2121
const float *const in,
22-
const dt_iop_roi_t *const roi_in,
22+
const int width,
23+
const int height,
2324
const uint32_t filters,
2425
const float thrs)
2526
{
26-
// these may differ a little, if you're unlucky enough to split a bayer block with cropping or similar.
27-
// we never want to access the input out of bounds though:
28-
const int width = roi_in->width;
29-
const int height = roi_in->height;
30-
3127
// border interpolate
3228
float sum[8];
3329
for(int j = 0; j < height; j++)
@@ -61,7 +57,7 @@ static void demosaic_ppg(float *const out,
6157
if(median)
6258
{
6359
float *med_in = dt_alloc_align_float((size_t)height * width);
64-
pre_median(med_in, in, roi_in, filters, 1, thrs);
60+
pre_median(med_in, in, width, height, filters, 1, thrs);
6561
input = med_in;
6662
}
6763
// for all pixels except those in the 3 pixel border:

src/iop/demosaicing/rcd.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,13 @@ static void rcd_ppg_border(float *const out,
268268
}
269269

270270
DT_OMP_DECLARE_SIMD(aligned(in, out : 64))
271-
static void demosaic_box3(dt_dev_pixelpipe_iop_t *piece,
272-
float *const restrict out,
273-
const float *const restrict in,
274-
const dt_iop_roi_t *const roi,
275-
const uint32_t filters,
276-
const uint8_t(*const xtrans)[6])
271+
static void demosaic_box3(float *const restrict out,
272+
const float *const restrict in,
273+
const int width,
274+
const int height,
275+
const uint32_t filters,
276+
const uint8_t(*const xtrans)[6])
277277
{
278-
const int width = roi->width;
279-
const int height = roi->height;
280278
DT_OMP_FOR()
281279
for(int row = 0; row < height; row++)
282280
{
@@ -303,15 +301,13 @@ static void demosaic_box3(dt_dev_pixelpipe_iop_t *piece,
303301
}
304302

305303
DT_OMP_DECLARE_SIMD(aligned(in, out : 64))
306-
static void rcd_demosaic(dt_dev_pixelpipe_iop_t *piece,
307-
float *const restrict out,
304+
static void rcd_demosaic(float *const restrict out,
308305
const float *const restrict in,
309-
const dt_iop_roi_t *const roi_in,
310-
const uint32_t filters)
306+
const int width,
307+
const int height,
308+
const uint32_t filters,
309+
const float scaler)
311310
{
312-
const int width = roi_in->width;
313-
const int height = roi_in->height;
314-
315311
if(width < 2*RCD_BORDER || height < 2*RCD_BORDER)
316312
{
317313
rcd_ppg_border(out, in, width, height, filters, RCD_BORDER);
@@ -320,7 +316,6 @@ static void rcd_demosaic(dt_dev_pixelpipe_iop_t *piece,
320316

321317
rcd_ppg_border(out, in, width, height, filters, RCD_MARGIN);
322318

323-
const float scaler = dt_iop_get_processed_maximum(piece);
324319
const float revscaler = 1.0f / scaler;
325320

326321
const int num_vertical = 1 + (height - 2 * RCD_BORDER -1) / RCD_TILEVALID;

0 commit comments

Comments
 (0)