summaryrefslogtreecommitdiff
path: root/core/io
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2022-09-29 09:18:07 +0300
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2022-09-29 10:38:21 +0300
commitea1848ce0a5f03c3a9f7e0a221350f4f4044bb08 (patch)
treefdbb5979dfe5f81a4d3e53ea71f625d84848e730 /core/io
parentf8745f2f71c79972df66f17a3da75f6e328bc55d (diff)
Use `constexpr` in the conditions with template parameters and `sizeof`s to suppress C4127 warnings.
Diffstat (limited to 'core/io')
-rw-r--r--core/io/file_access.cpp2
-rw-r--r--core/io/image.cpp32
-rw-r--r--core/io/resource_format_binary.cpp8
3 files changed, 21 insertions, 21 deletions
diff --git a/core/io/file_access.cpp b/core/io/file_access.cpp
index 499f083f51..cb25564342 100644
--- a/core/io/file_access.cpp
+++ b/core/io/file_access.cpp
@@ -548,7 +548,7 @@ void FileAccess::store_64(uint64_t p_dest) {
}
void FileAccess::store_real(real_t p_real) {
- if (sizeof(real_t) == 4) {
+ if constexpr (sizeof(real_t) == 4) {
store_float(p_real);
} else {
store_double(p_real);
diff --git a/core/io/image.cpp b/core/io/image.cpp
index 812bfa8263..56c05bf042 100644
--- a/core/io/image.cpp
+++ b/core/io/image.cpp
@@ -444,7 +444,7 @@ static void _convert(int p_width, int p_height, const uint8_t *p_src, uint8_t *p
uint8_t rgba[4] = { 0, 0, 0, 255 };
- if (read_gray) {
+ if constexpr (read_gray) {
rgba[0] = rofs[0];
rgba[1] = rofs[0];
rgba[2] = rofs[0];
@@ -454,11 +454,11 @@ static void _convert(int p_width, int p_height, const uint8_t *p_src, uint8_t *p
}
}
- if (read_alpha || write_alpha) {
+ if constexpr (read_alpha || write_alpha) {
rgba[3] = read_alpha ? rofs[read_bytes] : 255;
}
- if (write_gray) {
+ if constexpr (write_gray) {
//TODO: not correct grayscale, should use fixed point version of actual weights
wofs[0] = uint8_t((uint16_t(rgba[0]) + uint16_t(rgba[1]) + uint16_t(rgba[2])) / 3);
} else {
@@ -467,7 +467,7 @@ static void _convert(int p_width, int p_height, const uint8_t *p_src, uint8_t *p
}
}
- if (write_alpha) {
+ if constexpr (write_alpha) {
wofs[write_bytes] = rgba[3];
}
}
@@ -640,7 +640,7 @@ static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_
double xfac = (double)width / p_dst_width;
double yfac = (double)height / p_dst_height;
// coordinates of source points and coefficients
- double ox, oy, dx, dy, k1, k2;
+ double ox, oy, dx, dy;
int ox1, oy1, ox2, oy2;
// destination pixel values
// width and height decreased by 1
@@ -671,7 +671,7 @@ static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_
for (int n = -1; n < 3; n++) {
// get Y coefficient
- k1 = _bicubic_interp_kernel(dy - (double)n);
+ [[maybe_unused]] double k1 = _bicubic_interp_kernel(dy - (double)n);
oy2 = oy1 + n;
if (oy2 < 0) {
@@ -683,7 +683,7 @@ static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_
for (int m = -1; m < 3; m++) {
// get X coefficient
- k2 = k1 * _bicubic_interp_kernel((double)m - dx);
+ [[maybe_unused]] double k2 = k1 * _bicubic_interp_kernel((double)m - dx);
ox2 = ox1 + m;
if (ox2 < 0) {
@@ -697,7 +697,7 @@ static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_
const T *__restrict p = ((T *)p_src) + (oy2 * p_src_width + ox2) * CC;
for (int i = 0; i < CC; i++) {
- if (sizeof(T) == 2) { //half float
+ if constexpr (sizeof(T) == 2) { //half float
color[i] = Math::half_to_float(p[i]);
} else {
color[i] += p[i] * k2;
@@ -707,9 +707,9 @@ static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_
}
for (int i = 0; i < CC; i++) {
- if (sizeof(T) == 1) { //byte
+ if constexpr (sizeof(T) == 1) { //byte
dst[i] = CLAMP(Math::fast_ftoi(color[i]), 0, 255);
- } else if (sizeof(T) == 2) { //half float
+ } else if constexpr (sizeof(T) == 2) { //half float
dst[i] = Math::make_half_float(color[i]);
} else {
dst[i] = color[i];
@@ -758,7 +758,7 @@ static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict
src_xofs_right *= CC;
for (uint32_t l = 0; l < CC; l++) {
- if (sizeof(T) == 1) { //uint8
+ if constexpr (sizeof(T) == 1) { //uint8
uint32_t p00 = p_src[y_ofs_up + src_xofs_left + l] << FRAC_BITS;
uint32_t p10 = p_src[y_ofs_up + src_xofs_right + l] << FRAC_BITS;
uint32_t p01 = p_src[y_ofs_down + src_xofs_left + l] << FRAC_BITS;
@@ -769,7 +769,7 @@ static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict
uint32_t interp = interp_up + (((interp_down - interp_up) * src_yofs_frac) >> FRAC_BITS);
interp >>= FRAC_BITS;
p_dst[i * p_dst_width * CC + j * CC + l] = uint8_t(interp);
- } else if (sizeof(T) == 2) { //half float
+ } else if constexpr (sizeof(T) == 2) { //half float
float xofs_frac = float(src_xofs_frac) / (1 << FRAC_BITS);
float yofs_frac = float(src_yofs_frac) / (1 << FRAC_BITS);
@@ -786,7 +786,7 @@ static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict
float interp = interp_up + ((interp_down - interp_up) * yofs_frac);
dst[i * p_dst_width * CC + j * CC + l] = Math::make_half_float(interp);
- } else if (sizeof(T) == 4) { //float
+ } else if constexpr (sizeof(T) == 4) { //float
float xofs_frac = float(src_xofs_frac) / (1 << FRAC_BITS);
float yofs_frac = float(src_yofs_frac) / (1 << FRAC_BITS);
@@ -877,7 +877,7 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict
const T *__restrict src_data = ((const T *)p_src) + (buffer_y * src_width + target_x) * CC;
for (uint32_t i = 0; i < CC; i++) {
- if (sizeof(T) == 2) { //half float
+ if constexpr (sizeof(T) == 2) { //half float
pixel[i] += Math::half_to_float(src_data[i]) * lanczos_val;
} else {
pixel[i] += src_data[i] * lanczos_val;
@@ -934,9 +934,9 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict
for (uint32_t i = 0; i < CC; i++) {
pixel[i] /= weight;
- if (sizeof(T) == 1) { //byte
+ if constexpr (sizeof(T) == 1) { //byte
dst_data[i] = CLAMP(Math::fast_ftoi(pixel[i]), 0, 255);
- } else if (sizeof(T) == 2) { //half float
+ } else if constexpr (sizeof(T) == 2) { //half float
dst_data[i] = Math::make_half_float(pixel[i]);
} else { // float
dst_data[i] = pixel[i];
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 06649aba5b..36fa77626e 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -107,7 +107,7 @@ void ResourceLoaderBinary::_advance_padding(uint32_t p_len) {
static Error read_reals(real_t *dst, Ref<FileAccess> &f, size_t count) {
if (f->real_is_double) {
- if (sizeof(real_t) == 8) {
+ if constexpr (sizeof(real_t) == 8) {
// Ideal case with double-precision
f->get_buffer((uint8_t *)dst, count * sizeof(double));
#ifdef BIG_ENDIAN_ENABLED
@@ -118,7 +118,7 @@ static Error read_reals(real_t *dst, Ref<FileAccess> &f, size_t count) {
}
}
#endif
- } else if (sizeof(real_t) == 4) {
+ } else if constexpr (sizeof(real_t) == 4) {
// May be slower, but this is for compatibility. Eventually the data should be converted.
for (size_t i = 0; i < count; ++i) {
dst[i] = f->get_double();
@@ -127,7 +127,7 @@ static Error read_reals(real_t *dst, Ref<FileAccess> &f, size_t count) {
ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "real_t size is neither 4 nor 8!");
}
} else {
- if (sizeof(real_t) == 4) {
+ if constexpr (sizeof(real_t) == 4) {
// Ideal case with float-precision
f->get_buffer((uint8_t *)dst, count * sizeof(float));
#ifdef BIG_ENDIAN_ENABLED
@@ -138,7 +138,7 @@ static Error read_reals(real_t *dst, Ref<FileAccess> &f, size_t count) {
}
}
#endif
- } else if (sizeof(real_t) == 8) {
+ } else if constexpr (sizeof(real_t) == 8) {
for (size_t i = 0; i < count; ++i) {
dst[i] = f->get_float();
}