From 5a0e8317f4e31c2e642c9ac8493a6571e158672c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 21 Aug 2024 19:18:55 +1000 Subject: [PATCH] Cleanup: use const vars/args --- intern/ghost/intern/GHOST_WindowWayland.cc | 4 +- intern/ghost/intern/GHOST_WindowWayland.hh | 2 +- .../blender/imbuf/intern/cineon/cineon_dpx.cc | 2 +- .../blender/imbuf/intern/cineon/cineonlib.cc | 2 +- source/blender/imbuf/intern/cineon/dpxlib.cc | 2 +- .../imbuf/intern/cineon/logImageCore.cc | 68 ++++++++++--------- .../imbuf/intern/cineon/logImageCore.h | 2 +- .../imbuf/intern/openexr/openexr_api.cpp | 2 +- 8 files changed, 44 insertions(+), 40 deletions(-) diff --git a/intern/ghost/intern/GHOST_WindowWayland.cc b/intern/ghost/intern/GHOST_WindowWayland.cc index fd0a8ab3424..bd2976f4686 100644 --- a/intern/ghost/intern/GHOST_WindowWayland.cc +++ b/intern/ghost/intern/GHOST_WindowWayland.cc @@ -316,7 +316,7 @@ static void gwl_window_cursor_custom_store(GWL_WindowCursorCustomShape &ccs, ccs.can_invert_color = can_invert_color; } -static GHOST_TSuccess gwl_window_cursor_custom_load(GWL_WindowCursorCustomShape &ccs, +static GHOST_TSuccess gwl_window_cursor_custom_load(const GWL_WindowCursorCustomShape &ccs, GHOST_SystemWayland *system) { return system->cursor_shape_custom_set(ccs.bitmap, @@ -2892,7 +2892,7 @@ bool GHOST_WindowWayland::outputs_leave(GWL_Output *output) #ifdef USE_EVENT_BACKGROUND_THREAD -void GHOST_WindowWayland::pending_actions_handle() +const void GHOST_WindowWayland::pending_actions_handle() { /* Caller must lock `server_mutex`, while individual actions could lock, * it's simpler to lock once when handling all window actions. */ diff --git a/intern/ghost/intern/GHOST_WindowWayland.hh b/intern/ghost/intern/GHOST_WindowWayland.hh index 1567cb68b86..0526d87e7c5 100644 --- a/intern/ghost/intern/GHOST_WindowWayland.hh +++ b/intern/ghost/intern/GHOST_WindowWayland.hh @@ -199,7 +199,7 @@ class GHOST_WindowWayland : public GHOST_Window { void outputs_changed_update_scale_tag(); #ifdef USE_EVENT_BACKGROUND_THREAD - void pending_actions_handle(); + const void pending_actions_handle(); #endif private: diff --git a/source/blender/imbuf/intern/cineon/cineon_dpx.cc b/source/blender/imbuf/intern/cineon/cineon_dpx.cc index fdd9d4f3790..392ef2d2f44 100644 --- a/source/blender/imbuf/intern/cineon/cineon_dpx.cc +++ b/source/blender/imbuf/intern/cineon/cineon_dpx.cc @@ -125,7 +125,7 @@ static int imb_save_dpx_cineon(ImBuf *ibuf, const char *filepath, int use_cineon for (y = 0; y < ibuf->y; y++) { float *dst_ptr = fbuf + 4 * ((ibuf->y - y - 1) * ibuf->x); - float *src_ptr = ibuf->float_buffer.data + 4 * (y * ibuf->x); + const float *src_ptr = ibuf->float_buffer.data + 4 * (y * ibuf->x); memcpy(dst_ptr, src_ptr, 4 * ibuf->x * sizeof(float)); } diff --git a/source/blender/imbuf/intern/cineon/cineonlib.cc b/source/blender/imbuf/intern/cineon/cineonlib.cc index ca223563523..4200b46ad85 100644 --- a/source/blender/imbuf/intern/cineon/cineonlib.cc +++ b/source/blender/imbuf/intern/cineon/cineonlib.cc @@ -41,7 +41,7 @@ static void fillCineonMainHeader(LogImageFile *cineon, const char *creator) { time_t fileClock; - tm *fileTime; + const tm *fileTime; int i; memset(header, 0, sizeof(CineonMainHeader)); diff --git a/source/blender/imbuf/intern/cineon/dpxlib.cc b/source/blender/imbuf/intern/cineon/dpxlib.cc index e4c9dd9e2e8..4441a1c63b7 100644 --- a/source/blender/imbuf/intern/cineon/dpxlib.cc +++ b/source/blender/imbuf/intern/cineon/dpxlib.cc @@ -45,7 +45,7 @@ static void fillDpxMainHeader(LogImageFile *dpx, const char *creator) { time_t fileClock; - tm *fileTime; + const tm *fileTime; memset(header, 0, sizeof(DpxMainHeader)); diff --git a/source/blender/imbuf/intern/cineon/logImageCore.cc b/source/blender/imbuf/intern/cineon/logImageCore.cc index 41588dc4d1c..e1f54f3bf3b 100644 --- a/source/blender/imbuf/intern/cineon/logImageCore.cc +++ b/source/blender/imbuf/intern/cineon/logImageCore.cc @@ -64,12 +64,12 @@ static int logImageElementGetData12Packed(LogImageFile *logImage, static int logImageElementGetData16(LogImageFile *logImage, const LogImageElement &logElement, float *data); -static int convertLogElementToRGBA(float *src, +static int convertLogElementToRGBA(const float *src, float *dst, LogImageFile *logImage, const LogImageElement &logElement, int dstIsLinearRGB); -static int convertRGBAToLogElement(float *src, +static int convertRGBAToLogElement(const float *src, float *dst, LogImageFile *logImage, const LogImageElement &logElement, @@ -245,7 +245,7 @@ size_t getRowLength(size_t width, const LogImageElement *logElement) * Data writing */ -int logImageSetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB) +int logImageSetDataRGBA(LogImageFile *logImage, const float *data, int dataIsLinearRGB) { float *elementData; int returnValue; @@ -1222,14 +1222,14 @@ static float *getSrgbToLinLut(const LogImageElement &logElement) return lut; } -static int convertRGBA_RGB(float *src, +static int convertRGBA_RGB(const float *src, float *dst, LogImageFile *logImage, const LogImageElement &logElement, int elementIsSource) { uint i; - float *src_ptr = src; + const float *src_ptr = src; float *dst_ptr = dst; switch (logElement.transfer) { @@ -1277,14 +1277,14 @@ static int convertRGBA_RGB(float *src, } } -static int convertRGB_RGBA(float *src, +static int convertRGB_RGBA(const float *src, float *dst, LogImageFile *logImage, const LogImageElement &logElement, int elementIsSource) { uint i; - float *src_ptr = src; + const float *src_ptr = src; float *dst_ptr = dst; switch (logElement.transfer) { @@ -1332,14 +1332,14 @@ static int convertRGB_RGBA(float *src, } } -static int convertRGBA_RGBA(float *src, +static int convertRGBA_RGBA(const float *src, float *dst, LogImageFile *logImage, const LogImageElement &logElement, int elementIsSource) { uint i; - float *src_ptr = src; + const float *src_ptr = src; float *dst_ptr = dst; switch (logElement.transfer) { @@ -1377,14 +1377,14 @@ static int convertRGBA_RGBA(float *src, } } -static int convertABGR_RGBA(float *src, +static int convertABGR_RGBA(const float *src, float *dst, LogImageFile *logImage, const LogImageElement &logElement, int elementIsSource) { uint i; - float *src_ptr = src; + const float *src_ptr = src; float *dst_ptr = dst; switch (logElement.transfer) { @@ -1431,14 +1431,14 @@ static int convertABGR_RGBA(float *src, } } -static int convertCbYCr_RGBA(float *src, +static int convertCbYCr_RGBA(const float *src, float *dst, LogImageFile *logImage, const LogImageElement &logElement) { uint i; float conversionMatrix[9], refLowData, y, cb, cr; - float *src_ptr = src; + const float *src_ptr = src; float *dst_ptr = dst; if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) { @@ -1463,14 +1463,14 @@ static int convertCbYCr_RGBA(float *src, return 0; } -static int convertCbYCrA_RGBA(float *src, +static int convertCbYCrA_RGBA(const float *src, float *dst, LogImageFile *logImage, const LogImageElement &logElement) { uint i; float conversionMatrix[9], refLowData, y, cb, cr, a; - float *src_ptr = src; + const float *src_ptr = src; float *dst_ptr = dst; if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) { @@ -1496,14 +1496,14 @@ static int convertCbYCrA_RGBA(float *src, return 0; } -static int convertCbYCrY_RGBA(float *src, +static int convertCbYCrY_RGBA(const float *src, float *dst, LogImageFile *logImage, const LogImageElement &logElement) { uint i; float conversionMatrix[9], refLowData, y1, y2, cb, cr; - float *src_ptr = src; + const float *src_ptr = src; float *dst_ptr = dst; if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) { @@ -1548,14 +1548,14 @@ static int convertCbYCrY_RGBA(float *src, return 0; } -static int convertCbYACrYA_RGBA(float *src, +static int convertCbYACrYA_RGBA(const float *src, float *dst, LogImageFile *logImage, const LogImageElement &logElement) { uint i; float conversionMatrix[9], refLowData, y1, y2, cb, cr, a1, a2; - float *src_ptr = src; + const float *src_ptr = src; float *dst_ptr = dst; if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) { @@ -1602,14 +1602,14 @@ static int convertCbYACrYA_RGBA(float *src, return 0; } -static int convertLuminance_RGBA(float *src, +static int convertLuminance_RGBA(const float *src, float *dst, LogImageFile *logImage, const LogImageElement &logElement) { uint i; float conversionMatrix[9], value, refLowData; - float *src_ptr = src; + const float *src_ptr = src; float *dst_ptr = dst; if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) { @@ -1628,14 +1628,14 @@ static int convertLuminance_RGBA(float *src, return 0; } -static int convertYA_RGBA(float *src, +static int convertYA_RGBA(const float *src, float *dst, LogImageFile *logImage, const LogImageElement &logElement) { uint i; float conversionMatrix[9], value, refLowData; - float *src_ptr = src; + const float *src_ptr = src; float *dst_ptr = dst; if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) { @@ -1654,7 +1654,7 @@ static int convertYA_RGBA(float *src, return 0; } -static int convertLogElementToRGBA(float *src, +static int convertLogElementToRGBA(const float *src, float *dst, LogImageFile *logImage, const LogImageElement &logElement, @@ -1727,7 +1727,7 @@ static int convertLogElementToRGBA(float *src, return 0; } -static int convertRGBAToLogElement(float *src, +static int convertRGBAToLogElement(const float *src, float *dst, LogImageFile *logImage, const LogImageElement &logElement, @@ -1735,21 +1735,24 @@ static int convertRGBAToLogElement(float *src, { uint i; int rvalue; - float *srgbSrc; + const float *srgbSrc; + float *srgbSrc_alloc; float *srgbSrc_ptr; - float *src_ptr = src; + const float *src_ptr = src; float *lut; if (srcIsLinearRGB != 0) { /* we need to convert src to sRGB */ - srgbSrc = (float *)imb_alloc_pixels( + srgbSrc_alloc = (float *)imb_alloc_pixels( logImage->width, logImage->height, 4, sizeof(float), false, __func__); - if (srgbSrc == nullptr) { + if (srgbSrc_alloc == nullptr) { return 1; } - memcpy(srgbSrc, src, 4 * size_t(logImage->width) * size_t(logImage->height) * sizeof(float)); - srgbSrc_ptr = srgbSrc; + memcpy(srgbSrc_alloc, + src, + 4 * size_t(logImage->width) * size_t(logImage->height) * sizeof(float)); + srgbSrc_ptr = srgbSrc_alloc; /* convert data from Linear RGB to sRGB via lut */ lut = getLinToSrgbLut(logElement); @@ -1761,6 +1764,7 @@ static int convertRGBAToLogElement(float *src, src_ptr++; } MEM_freeN(lut); + srgbSrc = srgbSrc_alloc; } else { srgbSrc = src; @@ -1790,7 +1794,7 @@ static int convertRGBAToLogElement(float *src, } if (srcIsLinearRGB != 0) { - MEM_freeN(srgbSrc); + MEM_freeN(srgbSrc_alloc); } return rvalue; diff --git a/source/blender/imbuf/intern/cineon/logImageCore.h b/source/blender/imbuf/intern/cineon/logImageCore.h index 0a62b9f2963..21713c2c34c 100644 --- a/source/blender/imbuf/intern/cineon/logImageCore.h +++ b/source/blender/imbuf/intern/cineon/logImageCore.h @@ -193,7 +193,7 @@ void logImageClose(LogImageFile *logImage); /* Data handling */ size_t getRowLength(size_t width, const LogImageElement *logElement); -int logImageSetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB); +int logImageSetDataRGBA(LogImageFile *logImage, const float *data, int dataIsLinearRGB); int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB); /* diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp index 7631a1d862c..fa5c7dc35b8 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.cpp +++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp @@ -1158,7 +1158,7 @@ void IMB_exr_write_channels(void *handle) LISTBASE_FOREACH (ExrChannel *, echan, &data->channels) { /* Writing starts from last scan-line, stride negative. */ if (echan->use_half_float) { - float *rect = echan->rect; + const float *rect = echan->rect; half *cur = current_rect_half; for (size_t i = 0; i < num_pixels; i++, cur++) { *cur = float_to_half_safe(rect[i * echan->xstride]);