Skip to content

clang-tidy: avoid narrowing conversions #4415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libvips/colour/HSV2sRGB.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ vips_HSV2sRGB_line(VipsColour *colour, VipsPel *out, VipsPel **in, int width)
float c, x, m;

c = p[2] * p[1] / 255.0;
x = c * (1 - fabs(fmod(p[0] / SIXTH_OF_CHAR, 2) - 1));
x = c * (1 - fabsf(fmodf(p[0] / SIXTH_OF_CHAR, 2) - 1));
m = p[2] - c;

if (p[0] < (int) SIXTH_OF_CHAR) {
Expand Down
4 changes: 2 additions & 2 deletions libvips/colour/LCh2Lab.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ G_DEFINE_TYPE(VipsLCh2Lab, vips_LCh2Lab, VIPS_TYPE_COLOUR_TRANSFORM);
void
vips_col_Ch2ab(float C, float h, float *a, float *b)
{
*a = C * cos(VIPS_RAD(h));
*b = C * sin(VIPS_RAD(h));
*a = C * cosf(VIPS_RAD(h));
*b = C * sinf(VIPS_RAD(h));
}

/* Process a buffer of data.
Expand Down
48 changes: 24 additions & 24 deletions libvips/colour/LCh2UCS.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ vips_col_L2Lcmc(float L)
float Lcmc;

if (L < 16.0)
Lcmc = 1.744 * L;
Lcmc = 1.744F * L;
else
Lcmc = 21.75 * log(L) + 0.3838 * L - 38.54;
Lcmc = 21.75F * logf(L) + 0.3838F * L - 38.54F;

return Lcmc;
}
Expand All @@ -112,7 +112,7 @@ vips_col_C2Ccmc(float C)
{
float Ccmc;

Ccmc = 0.162 * C + 10.92 * log(0.638 + 0.07216 * C) + 4.907;
Ccmc = 0.162F * C + 10.92F * logf(0.638F + 0.07216F * C) + 4.907F;
if (Ccmc < 0)
Ccmc = 0;

Expand All @@ -136,35 +136,35 @@ vips_col_Ch2hcmc(float C, float h)
float hcmc;

if (h < 49.1) {
k4 = 133.87;
k5 = -134.5;
k6 = -.924;
k7 = 1.727;
k8 = 340.0;
k4 = 133.87F;
k5 = -134.5F;
k6 = -.924F;
k7 = 1.727F;
k8 = 340.0F;
}
else if (h < 110.1) {
k4 = 11.78;
k5 = -12.7;
k6 = -.218;
k7 = 2.12;
k8 = 333.0;
k4 = 11.78F;
k5 = -12.7F;
k6 = -.218F;
k7 = 2.12F;
k8 = 333.0F;
}
else if (h < 269.6) {
k4 = 13.87;
k5 = 10.93;
k6 = 0.14;
k7 = 1.0;
k8 = -83.0;
k4 = 13.87F;
k5 = 10.93F;
k6 = 0.14F;
k7 = 1.0F;
k8 = -83.0F;
}
else {
k4 = .14;
k5 = 5.23;
k6 = .17;
k7 = 1.61;
k8 = 233.0;
k4 = .14F;
k5 = 5.23F;
k6 = .17F;
k7 = 1.61F;
k8 = 233.0F;
}

P = cos(VIPS_RAD(k7 * h + k8));
P = cosf(VIPS_RAD(k7 * h + k8));
D = k4 + k5 * P * powf(fabsf(P), k6);
g = C * C * C * C;
f = sqrtf(g / (g + 1900.0F));
Expand Down
4 changes: 2 additions & 2 deletions libvips/colour/Lab2LCh.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void
vips_col_ab2Ch(float a, float b, float *C, float *h)
{
*h = vips_col_ab2h(a, b);
*C = hypot(a, b);
*C = hypotf(a, b);
}

static void
Expand All @@ -111,7 +111,7 @@ vips_Lab2LCh_line(VipsColour *colour, VipsPel *out, VipsPel **in, int width)

p += 3;

C = sqrt(a * a + b * b);
C = sqrtf(a * a + b * b);
h = vips_col_ab2h(a, b);

q[0] = L;
Expand Down
8 changes: 4 additions & 4 deletions libvips/colour/Lab2LabQ.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ vips_Lab2LabQ_line(VipsColour *colour, VipsPel *out, VipsPel **in, int width)
lsbs = (intv & 0x3) << 6; /* 00000011 -> 11000000 */
q[0] = intv >> 2; /* drop bot 2 bits and store */

fval = 8.0 * p[1]; /* do a */
intv = rint(fval);
fval = 8.0F * p[1]; /* do a */
intv = rintf(fval);
intv = VIPS_CLIP(-1024, intv, 1023);
lsbs |= (intv & 0x7) << 3; /* 00000111 -> 00111000 */
q[1] = intv >> 3; /* drop bot 3 bits & store */

fval = 8.0 * p[2]; /* do b */
intv = rint(fval);
fval = 8.0F * p[2]; /* do b */
intv = rintf(fval);
intv = VIPS_CLIP(-1024, intv, 1023);
lsbs |= (intv & 0x7);
q[2] = intv >> 3;
Expand Down
6 changes: 3 additions & 3 deletions libvips/colour/LabQ2Lab.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ vips_LabQ2Lab_line(VipsColour *colour, VipsPel *out, VipsPel **in, int width)
*/
l = ((unsigned char *) p)[0];
l = (l << 2) | (lsbs >> 6);
q[0] = (float) l * (100.0 / 1023.0);
q[0] = (float) l * (100.0F / 1023.0F);

/* Build a.
*/
l = VIPS_LSHIFT_INT(p[1], 3) | ((lsbs >> 3) & 0x7);
q[1] = (float) l * 0.125;
q[1] = (float) l * 0.125F;

/* And b.
*/
l = VIPS_LSHIFT_INT(p[2], 3) | (lsbs & 0x7);
q[2] = (float) l * 0.125;
q[2] = (float) l * 0.125F;

p += 4;
q += 3;
Expand Down
58 changes: 29 additions & 29 deletions libvips/colour/LabQ2sRGB.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ calcul_tables(int range, int *Y2v, float *v2Y)
float v;

if (f <= 0.0031308)
v = 12.92 * f;
v = 12.92F * f;
else
v = (1.0 + 0.055) * pow(f, 1.0 / 2.4) - 0.055;
v = (1.0F + 0.055F) * powf(f, 1.0F / 2.4F) - 0.055F;

Y2v[i] = rint((range - 1) * v);
Y2v[i] = rintf((range - 1) * v);
}

/* Copy the final element. This is used in the piecewise linear
Expand All @@ -152,9 +152,9 @@ calcul_tables(int range, int *Y2v, float *v2Y)
float f = (float) i / (range - 1);

if (f <= 0.04045)
v2Y[i] = f / 12.92;
v2Y[i] = f / 12.92F;
else
v2Y[i] = pow((f + 0.055) / (1 + 0.055), 2.4);
v2Y[i] = powf((f + 0.055F) / (1 + 0.055F), 2.4F);
}
}

Expand Down Expand Up @@ -231,15 +231,15 @@ vips_col_scRGB2XYZ(float R, float G, float B, float *X, float *Y, float *Z)
G *= SCALE;
B *= SCALE;

*X = 0.4124 * R +
0.3576 * G +
0.1805 * B;
*Y = 0.2126 * R +
0.7152 * G +
0.0722 * B;
*Z = 0.0193 * R +
0.1192 * G +
0.9505 * B;
*X = 0.4124F * R +
0.3576F * G +
0.1805F * B;
*Y = 0.2126F * R +
0.7152F * G +
0.0722F * B;
*Z = 0.0193F * R +
0.1192F * G +
0.9505F * B;

return 0;
}
Expand All @@ -266,15 +266,15 @@ vips_col_XYZ2scRGB(float X, float Y, float Z, float *R, float *G, float *B)

/* Use 6 decimal places of precision for the inverse matrix.
*/
*R = 3.240625 * X +
-1.537208 * Y +
-0.498629 * Z;
*G = -0.968931 * X +
1.875756 * Y +
0.041518 * Z;
*B = 0.055710 * X +
-0.204021 * Y +
1.056996 * Z;
*R = 3.240625F * X +
-1.537208F * Y +
-0.498629F * Z;
*G = -0.968931F * X +
1.875756F * Y +
0.041518F * Z;
*B = 0.055710F * X +
-0.204021F * Y +
1.056996F * Z;

return 0;
}
Expand Down Expand Up @@ -337,19 +337,19 @@ vips_col_scRGB2sRGB(int range, int *lut,
CLIP(0, Yf, maxval);
Yi = (int) Yf;
v = lut[Yi] + (lut[Yi + 1] - lut[Yi]) * (Yf - Yi);
*r = rint(v);
*r = rintf(v);

Yf = G * maxval;
CLIP(0, Yf, maxval);
Yi = (int) Yf;
v = lut[Yi] + (lut[Yi + 1] - lut[Yi]) * (Yf - Yi);
*g = rint(v);
*g = rintf(v);

Yf = B * maxval;
CLIP(0, Yf, maxval);
Yi = (int) Yf;
v = lut[Yi] + (lut[Yi + 1] - lut[Yi]) * (Yf - Yi);
*b = rint(v);
*b = rintf(v);

if (og_ret)
*og_ret = og;
Expand Down Expand Up @@ -394,7 +394,7 @@ vips_col_scRGB2BW(int range, int *lut, float R, float G, float B,

/* CIE linear luminance function, see https://en.wikipedia.org/wiki/Grayscale#Colorimetric_(perceptual_luminance-preserving)_conversion_to_grayscale
*/
Y = 0.2126 * R + 0.7152 * G + 0.0722 * B;
Y = 0.2126F * R + 0.7152F * G + 0.0722F * B;

/* Y can be Nan. Throw those values out, they will break
* our clipping.
Expand All @@ -417,7 +417,7 @@ vips_col_scRGB2BW(int range, int *lut, float R, float G, float B,
CLIP(0, Yf, maxval);
Yi = (int) Yf;
v = lut[Yi] + (lut[Yi + 1] - lut[Yi]) * (Yf - Yi);
*g = rint(v);
*g = rintf(v);

if (og_ret)
*og_ret = og;
Expand Down Expand Up @@ -454,7 +454,7 @@ build_tables(void *client)
for (b = 0; b < 64; b++) {
/* Scale to lab space.
*/
float L = (l << 2) * (100.0 / 256.0);
float L = (l << 2) * (100.0F / 256.0F);
float A = (signed char) (a << 2);
float B = (signed char) (b << 2);
float X, Y, Z;
Expand Down
4 changes: 2 additions & 2 deletions libvips/colour/UCS2LCh.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ vips_col_Lcmc2L(float Lcmc)
known = VIPS_CLIP(0, known, 999);

return LI[known] +
(LI[known + 1] - LI[known]) * (Lcmc * 10.0 - known);
(LI[known + 1] - LI[known]) * (Lcmc * 10.0F - known);
}

/**
Expand All @@ -177,7 +177,7 @@ vips_col_Ccmc2C(float Ccmc)
known = VIPS_CLIP(0, known, 2999);

return CI[known] +
(CI[known + 1] - CI[known]) * (Ccmc * 10.0 - known);
(CI[known + 1] - CI[known]) * (Ccmc * 10.0F - known);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions libvips/colour/XYZ2Lab.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ table_init(void *client)
float Y = (double) i / QUANT_ELEMENTS;

if (Y < 0.008856)
cbrt_table[i] = 7.787 * Y + (16.0 / 116.0);
cbrt_table[i] = 7.787F * Y + (16.0F / 116.0F);
else
cbrt_table[i] = cbrt(Y);
cbrt_table[i] = cbrtf(Y);
}

return NULL;
Expand Down Expand Up @@ -132,9 +132,9 @@ vips_col_XYZ2Lab_helper(VipsXYZ2Lab *XYZ2Lab,
f = nZ - i;
cbz = cbrt_table[i] + f * (cbrt_table[i + 1] - cbrt_table[i]);

*L = 116.0 * cby - 16.0;
*a = 500.0 * (cbx - cby);
*b = 200.0 * (cby - cbz);
*L = 116.0F * cby - 16.0F;
*a = 500.0F * (cbx - cby);
*b = 200.0F * (cby - cbz);
}

/* Process a buffer of data.
Expand Down
6 changes: 3 additions & 3 deletions libvips/colour/Yxy2XYZ.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ vips_Yxy2XYZ_line(VipsColour *colour, VipsPel *out, VipsPel **in, int width)

if (x == 0.0 ||
y == 0.0) {
X = 0.0;
Z = 0.0;
X = 0.0F;
Z = 0.0F;
}
else {
double total;
float total;

total = Y / y;
X = x * total;
Expand Down
4 changes: 2 additions & 2 deletions libvips/colour/dE76.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ vips_pythagoras(float L1, float a1, float b1, float L2, float a2, float b2)
float da = a1 - a2;
float db = b1 - b2;

return sqrt(dL * dL + da * da + db * db);
return sqrtf(dL * dL + da * da + db * db);
}

/* Find the difference between two buffers of LAB data.
Expand All @@ -96,7 +96,7 @@ vips__pythagoras_line(VipsColour *colour,
float da = p1[1] - p2[1];
float db = p1[2] - p2[2];

q[x] = sqrt(dL * dL + da * da + db * db);
q[x] = sqrtf(dL * dL + da * da + db * db);

p1 += 3;
p2 += 3;
Expand Down
Loading
Loading