diff options
author | Campbell Barton <campbell@blender.org> | 2022-09-25 11:33:28 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-09-25 13:17:08 +0300 |
commit | f68cfd6bb078482c4a779a6e26a56e2734edb5b8 (patch) | |
tree | 2878e5b80dba5bdeba186d99661d604eb38879cd /source/blender/imbuf | |
parent | c7b247a118e302a3afc6473797e53b6af28b69e2 (diff) |
Cleanup: replace C-style casts with functional casts for numeric types
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r-- | source/blender/imbuf/intern/oiio/openimageio_api.cpp | 2 | ||||
-rw-r--r-- | source/blender/imbuf/intern/openexr/openexr_api.cpp | 62 | ||||
-rw-r--r-- | source/blender/imbuf/intern/transform.cc | 12 |
3 files changed, 38 insertions, 38 deletions
diff --git a/source/blender/imbuf/intern/oiio/openimageio_api.cpp b/source/blender/imbuf/intern/oiio/openimageio_api.cpp index 5c7b7d9fae4..f8d00b5222f 100644 --- a/source/blender/imbuf/intern/oiio/openimageio_api.cpp +++ b/source/blender/imbuf/intern/oiio/openimageio_api.cpp @@ -193,7 +193,7 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac } ImageSpec spec, config; - config.attribute("oiio:UnassociatedAlpha", (int)1); + config.attribute("oiio:UnassociatedAlpha", int(1)); if (!in->open(filename, spec, config)) { std::cerr << __func__ << ": ImageInput::open() failed:" << std::endl diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp index e8818a8b55e..7a94a938861 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.cpp +++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp @@ -552,10 +552,10 @@ static bool imb_save_openexr_half(ImBuf *ibuf, const char *name, const int flags from = (uchar *)ibuf->rect + 4 * i * width; for (int j = ibuf->x; j > 0; j--) { - to->r = srgb_to_linearrgb((float)from[0] / 255.0f); - to->g = srgb_to_linearrgb((float)from[1] / 255.0f); - to->b = srgb_to_linearrgb((float)from[2] / 255.0f); - to->a = channels >= 4 ? (float)from[3] / 255.0f : 1.0f; + to->r = srgb_to_linearrgb(float(from[0]) / 255.0f); + to->g = srgb_to_linearrgb(float(from[1]) / 255.0f); + to->b = srgb_to_linearrgb(float(from[2]) / 255.0f); + to->a = channels >= 4 ? float(from[3]) / 255.0f : 1.0f; to++; from += 4; } @@ -838,7 +838,7 @@ static void imb_exr_insert_view_name(char *name_full, const char *passname, cons len = BLI_str_rpartition(passname, delims, &sep, &token); if (sep) { - BLI_snprintf(name_full, EXR_PASS_MAXNAME, "%.*s.%s.%s", (int)len, passname, viewname, token); + BLI_snprintf(name_full, EXR_PASS_MAXNAME, "%.*s.%s.%s", int(len), passname, viewname, token); } else { BLI_snprintf(name_full, EXR_PASS_MAXNAME, "%s.%s", passname, viewname); @@ -1171,7 +1171,7 @@ void IMB_exr_write_channels(void *handle) ExrChannel *echan; if (data->channels.first) { - const size_t num_pixels = ((size_t)data->width) * data->height; + const size_t num_pixels = size_t(data->width) * data->height; half *rect_half = nullptr, *current_rect_half = nullptr; /* We allocate temporary storage for half pixels for all the channels at once. */ @@ -1454,7 +1454,7 @@ static int imb_exr_split_token(const char *str, const char *end, const char **to *token = str; } - return (int)(end - *token); + return int(end - *token); } static int imb_exr_split_channel_name(ExrChannel *echan, char *layname, char *passname) @@ -1551,7 +1551,7 @@ static int imb_exr_split_channel_name(ExrChannel *echan, char *layname, char *pa /* all preceding tokens combined as layer name */ if (end > name) { - BLI_strncpy(layname, name, (int)(end - name) + 1); + BLI_strncpy(layname, name, int(end - name) + 1); } else { layname[0] = '\0'; @@ -1670,29 +1670,29 @@ static bool imb_exr_multilayer_parse_channels_from_file(ExrHandle *data) if (ELEM(pass->totchan, 3, 4)) { if (pass->chan[0]->chan_id == 'B' || pass->chan[1]->chan_id == 'B' || pass->chan[2]->chan_id == 'B') { - lookup[(uint)'R'] = 0; - lookup[(uint)'G'] = 1; - lookup[(uint)'B'] = 2; - lookup[(uint)'A'] = 3; + lookup[uint('R')] = 0; + lookup[uint('G')] = 1; + lookup[uint('B')] = 2; + lookup[uint('A')] = 3; } else if (pass->chan[0]->chan_id == 'Y' || pass->chan[1]->chan_id == 'Y' || pass->chan[2]->chan_id == 'Y') { - lookup[(uint)'X'] = 0; - lookup[(uint)'Y'] = 1; - lookup[(uint)'Z'] = 2; - lookup[(uint)'W'] = 3; + lookup[uint('X')] = 0; + lookup[uint('Y')] = 1; + lookup[uint('Z')] = 2; + lookup[uint('W')] = 3; } else { - lookup[(uint)'U'] = 0; - lookup[(uint)'V'] = 1; - lookup[(uint)'A'] = 2; + lookup[uint('U')] = 0; + lookup[uint('V')] = 1; + lookup[uint('A')] = 2; } for (int a = 0; a < pass->totchan; a++) { echan = pass->chan[a]; - echan->rect = pass->rect + lookup[(uint)echan->chan_id]; + echan->rect = pass->rect + lookup[uint(echan->chan_id)]; echan->xstride = pass->totchan; echan->ystride = data->width * pass->totchan; - pass->chan_id[(uint)lookup[(uint)echan->chan_id]] = echan->chan_id; + pass->chan_id[uint(lookup[uint(echan->chan_id)])] = echan->chan_id; } } else { /* unknown */ @@ -2015,8 +2015,8 @@ struct ImBuf *imb_load_openexr(const uchar *mem, if (hasXDensity(file->header(0))) { /* Convert inches to meters. */ - ibuf->ppm[0] = (double)xDensity(file->header(0)) / 0.0254; - ibuf->ppm[1] = ibuf->ppm[0] * (double)file->header(0).pixelAspectRatio(); + ibuf->ppm[0] = double(xDensity(file->header(0))) / 0.0254; + ibuf->ppm[1] = ibuf->ppm[0] * double(file->header(0).pixelAspectRatio()); } ibuf->ftype = IMB_FTYPE_OPENEXR; @@ -2115,7 +2115,7 @@ struct ImBuf *imb_load_openexr(const uchar *mem, #endif if (num_rgb_channels == 0 && has_luma && exr_has_chroma(*file)) { - for (size_t a = 0; a < (size_t)ibuf->x * ibuf->y; a++) { + for (size_t a = 0; a < size_t(ibuf->x) * ibuf->y; a++) { float *color = ibuf->rect_float + a * 4; ycc_to_rgb(color[0] * 255.0f, color[1] * 255.0f, @@ -2128,7 +2128,7 @@ struct ImBuf *imb_load_openexr(const uchar *mem, } else if (num_rgb_channels <= 1) { /* Convert 1 to 3 channels. */ - for (size_t a = 0; a < (size_t)ibuf->x * ibuf->y; a++) { + for (size_t a = 0; a < size_t(ibuf->x) * ibuf->y; a++) { float *color = ibuf->rect_float + a * 4; if (num_rgb_channels <= 1) { color[1] = color[0]; @@ -2222,10 +2222,10 @@ struct ImBuf *imb_load_filepath_thumbnail_openexr(const char *filepath, colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_FLOAT); } - float scale_factor = MIN2((float)max_thumb_size / (float)source_w, - (float)max_thumb_size / (float)source_h); - int dest_w = (int)(source_w * scale_factor); - int dest_h = (int)(source_h * scale_factor); + float scale_factor = MIN2(float(max_thumb_size) / float(source_w), + float(max_thumb_size) / float(source_h)); + int dest_w = int(source_w * scale_factor); + int dest_h = int(source_h * scale_factor); struct ImBuf *ibuf = IMB_allocImBuf(dest_w, dest_h, 32, IB_rectfloat); @@ -2236,13 +2236,13 @@ struct ImBuf *imb_load_filepath_thumbnail_openexr(const char *filepath, for (int h = 0; h < dest_h; h++) { /* Load the single source row that corresponds with destination row. */ - int source_y = (int)((float)h / scale_factor) + dw.min.y; + int source_y = int(float(h) / scale_factor) + dw.min.y; file->setFrameBuffer(&pixels[0] - dw.min.x - source_y * source_w, 1, source_w); file->readPixels(source_y); for (int w = 0; w < dest_w; w++) { /* For each destination pixel find single corresponding source pixel. */ - int source_x = (int)(MIN2((w / scale_factor), dw.max.x - 1)); + int source_x = int(MIN2((w / scale_factor), dw.max.x - 1)); float *dest_px = &ibuf->rect_float[(h * dest_w + w) * 4]; dest_px[0] = pixels[source_x].r; dest_px[1] = pixels[source_x].g; diff --git a/source/blender/imbuf/intern/transform.cc b/source/blender/imbuf/intern/transform.cc index 276d31c0557..532652df189 100644 --- a/source/blender/imbuf/intern/transform.cc +++ b/source/blender/imbuf/intern/transform.cc @@ -165,7 +165,7 @@ class PixelPointer { public: void init_pixel_pointer(const ImBuf *image_buffer, int x, int y) { - const size_t offset = (y * (size_t)image_buffer->x + x) * NumChannels; + const size_t offset = (y * size_t(image_buffer->x) + x) * NumChannels; if constexpr (std::is_same_v<StorageType, float>) { pointer = image_buffer->rect_float + offset; @@ -235,7 +235,7 @@ class WrapRepeatUV : public BaseUVWrapping { float modify_u(const ImBuf *source_buffer, float u) override { - int x = (int)floor(u); + int x = int(floor(u)); x = x % source_buffer->x; if (x < 0) { x += source_buffer->x; @@ -245,7 +245,7 @@ class WrapRepeatUV : public BaseUVWrapping { float modify_v(const ImBuf *source_buffer, float v) override { - int y = (int)floor(v); + int y = int(floor(v)); y = y % source_buffer->y; if (y < 0) { y += source_buffer->y; @@ -349,8 +349,8 @@ class Sampler { BLI_STATIC_ASSERT(std::is_same_v<StorageType, float>); /* ImBuf in must have a valid rect or rect_float, assume this is already checked */ - int x1 = (int)(u); - int y1 = (int)(v); + int x1 = int(u); + int y1 = int(v); /* Break when sample outside image is requested. */ if (x1 < 0 || x1 >= source->x || y1 < 0 || y1 >= source->y) { @@ -360,7 +360,7 @@ class Sampler { return; } - const size_t offset = ((size_t)source->x * y1 + x1) * NumChannels; + const size_t offset = (size_t(source->x) * y1 + x1) * NumChannels; const float *dataF = source->rect_float + offset; for (int i = 0; i < NumChannels; i++) { r_sample[i] = dataF[i]; |