Skip to content

Commit 5ff4cdc

Browse files
Interpolator maintenance
const added where possible
1 parent 0a8bb33 commit 5ff4cdc

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/common/interpolation.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ static float _maketaps_lanczos(float *taps,
340340
dt_aligned_pixel_t sign;
341341
for_four_channels(c)
342342
{
343-
int a = (int)vt[c];
343+
const int a = (int)vt[c];
344344
r[c] = vt[c] - (float)a;
345345
sign[c] = (a & 1) ? -1.0f : 1.0f;
346346
}
@@ -429,7 +429,7 @@ static inline float _compute_upsampling_kernel(const dt_interpolation_t *itor,
429429
// yielding an incorrect result for the slightly-negative positions
430430
// that can occur at the top and left edges when doing perspective
431431
// correction
432-
int f = (int)floorf(t) - itor->width + 1;
432+
const int f = (int)floorf(t) - itor->width + 1;
433433
if(first)
434434
{
435435
*first = f;
@@ -474,10 +474,10 @@ static inline void _compute_downsampling_kernel(const dt_interpolation_t *itor,
474474
}
475475

476476
// Compute first interpolator parameter
477-
float t = xin * outoinratio - (float)xout;
477+
const float t = xin * outoinratio - (float)xout;
478478

479479
// Compute all filter taps
480-
int num_taps = *taps = (int)((w - t) / outoinratio);
480+
const int num_taps = *taps = (int)((w - t) / outoinratio);
481481
itor->maketaps(kernel, num_taps, itor->width, t, outoinratio);
482482
// compute the kernel norm if requested
483483
if(norm)
@@ -510,8 +510,8 @@ float dt_interpolation_compute_sample(const dt_interpolation_t *itor,
510510
float DT_ALIGNED_ARRAY kernelv[MAX_KERNEL_REQ];
511511

512512
// Compute both horizontal and vertical kernels
513-
float normh = _compute_upsampling_kernel(itor, kernelh, NULL, x);
514-
float normv = _compute_upsampling_kernel(itor, kernelv, NULL, y);
513+
const float normh = _compute_upsampling_kernel(itor, kernelh, NULL, x);
514+
const float normv = _compute_upsampling_kernel(itor, kernelv, NULL, y);
515515

516516
int ix = (int)x;
517517
int iy = (int)y;
@@ -544,7 +544,7 @@ float dt_interpolation_compute_sample(const dt_interpolation_t *itor,
544544
s += kernelv[i] * h;
545545
in += linestride;
546546
}
547-
r = fmaxf(0.0f, s / (normh * normv));
547+
r = s / (normh * normv);
548548
}
549549
else if(ix >= 0 && iy >= 0 && ix < width && iy < height)
550550
{
@@ -582,14 +582,14 @@ float dt_interpolation_compute_sample(const dt_interpolation_t *itor,
582582
s += kernelv[i] * h;
583583
}
584584

585-
r = fmaxf(0.0f, s / (normh * normv));
585+
r = s / (normh * normv);
586586
}
587587
else
588588
{
589589
// invalid coordinate
590590
r = 0.0f;
591591
}
592-
return r;
592+
return fmaxf(0.0f, r); // make sure we don't push NaNs
593593
}
594594

595595
/* --------------------------------------------------------------------------
@@ -612,8 +612,8 @@ void dt_interpolation_compute_pixel4c(const dt_interpolation_t *itor,
612612
float DT_ALIGNED_ARRAY kernelv[MAX_KERNEL_REQ];
613613

614614
// Compute both horizontal and vertical kernels
615-
float normh = _compute_upsampling_kernel(itor, kernelh, NULL, x);
616-
float normv = _compute_upsampling_kernel(itor, kernelv, NULL, y);
615+
const float normh = _compute_upsampling_kernel(itor, kernelh, NULL, x);
616+
const float normv = _compute_upsampling_kernel(itor, kernelv, NULL, y);
617617

618618
// Precompute the inverse of the filter norm for later use
619619
const float oonorm = (1.f / (normh * normv));
@@ -1102,7 +1102,7 @@ void dt_interpolation_resample(const dt_interpolation_t *itor,
11021102
int hkidx = 0; // H(orizontal) K(ernel) I(n)d(e)x
11031103

11041104
// Number of lines contributing to the output line
1105-
int vl = vlength[vlidx++]; // V(ertical) L(ength)
1105+
const int vl = vlength[vlidx++]; // V(ertical) L(ength)
11061106

11071107
// Process each output column
11081108
for(size_t ox = 0; ox < (size_t)roi_out->width; ox++)
@@ -1111,12 +1111,12 @@ void dt_interpolation_resample(const dt_interpolation_t *itor,
11111111
dt_aligned_pixel_t vs = { 0.0f, 0.0f, 0.0f, 0.0f };
11121112

11131113
// Number of horizontal samples contributing to the output
1114-
int hl = hlength[hlidx++]; // H(orizontal) L(ength)
1114+
const int hl = hlength[hlidx++]; // H(orizontal) L(ength)
11151115

11161116
for(size_t iy = 0; iy < vl; iy++)
11171117
{
11181118
// This is our input line
1119-
size_t baseidx_vindex = (size_t)vindex[viidx++] * in_stride_floats;
1119+
const size_t baseidx_vindex = (size_t)vindex[viidx++] * in_stride_floats;
11201120

11211121
dt_aligned_pixel_t vhs = { 0.0f, 0.0f, 0.0f, 0.0f };
11221122

@@ -1146,7 +1146,7 @@ void dt_interpolation_resample(const dt_interpolation_t *itor,
11461146
// Negative RGB are invalid values no matter the RGB space (light is positive)
11471147
dt_aligned_pixel_t pixel;
11481148
for_each_channel(c, aligned(vs:16))
1149-
pixel[c] = MAX(vs[c], 0.f);
1149+
pixel[c] = fmaxf(0.0f, vs[c]);
11501150
copy_pixel_nontemporal(out + baseidx, pixel);
11511151

11521152
// Reset vertical resampling context
@@ -1565,7 +1565,7 @@ void dt_interpolation_resample_1c(const dt_interpolation_t *itor,
15651565
// Output pixel is ready
15661566
float *o = (float *)((char *)out + (size_t)oy * out_stride
15671567
+ (size_t)ox * sizeof(float));
1568-
*o = vs;
1568+
*o = fmaxf(0.0f, vs);
15691569

15701570
// Reset vertical resampling context
15711571
viidx -= vl;

0 commit comments

Comments
 (0)