From b168a960831b44fcdc3a60c987fc205ec55a8f2f Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 29 Sep 2025 16:02:57 +0200 Subject: [PATCH] Refactor: Use enum class instead of bool video Pull Request: https://projects.blender.org/blender/blender/pulls/146888 --- source/blender/imbuf/IMB_colormanagement.hh | 7 +++++-- .../imbuf/intern/IMB_colormanagement_intern.hh | 9 ++++----- source/blender/imbuf/intern/colormanagement.cc | 15 +++++++++------ .../imbuf/intern/oiio/openimageio_support.cc | 9 +++++---- source/blender/imbuf/intern/readimage.cc | 2 +- source/blender/imbuf/movie/intern/movie_read.cc | 7 ++++--- source/blender/imbuf/movie/intern/movie_write.cc | 5 +++-- 7 files changed, 31 insertions(+), 23 deletions(-) diff --git a/source/blender/imbuf/IMB_colormanagement.hh b/source/blender/imbuf/IMB_colormanagement.hh index 4ab91cb01c1..c95e632d1c4 100644 --- a/source/blender/imbuf/IMB_colormanagement.hh +++ b/source/blender/imbuf/IMB_colormanagement.hh @@ -45,6 +45,8 @@ enum ColorManagedDisplaySpace { DISPLAY_SPACE_COLOR_INSPECTION, }; +enum class ColorManagedFileOutput { Image, Video }; + /* -------------------------------------------------------------------- */ /** \name Generic Functions * \{ */ @@ -79,10 +81,11 @@ blender::Vector IMB_colormanagement_space_to_icc_profile(const ColorSpace /* Get CICP code for colorspace. * For describing the colorspace of videos and high dynamic range image files. */ bool IMB_colormanagement_space_to_cicp(const ColorSpace *colorspace, - const bool video, + const ColorManagedFileOutput output, const bool rgb_matrix, int cicp[4]); -const ColorSpace *IMB_colormanagement_space_from_cicp(const int cicp[4], const bool video); +const ColorSpace *IMB_colormanagement_space_from_cicp(const int cicp[4], + const ColorManagedFileOutput output); /* Get identifier for colorspaces that works with multiple OpenColorIO configurations, * as defined by the ASWF Color Interop Forum. */ diff --git a/source/blender/imbuf/intern/IMB_colormanagement_intern.hh b/source/blender/imbuf/intern/IMB_colormanagement_intern.hh index dbd215edc3e..dad69c30a3f 100644 --- a/source/blender/imbuf/intern/IMB_colormanagement_intern.hh +++ b/source/blender/imbuf/intern/IMB_colormanagement_intern.hh @@ -8,10 +8,6 @@ #pragma once -#include "BLI_math_matrix_types.hh" -#include "BLI_math_vector_types.hh" -#include "DNA_listBase.h" - namespace blender::ocio { class ColorSpace; class CPUProcessor; @@ -20,6 +16,7 @@ class CPUProcessor; using ColorSpace = blender::ocio::ColorSpace; struct ImBuf; +enum class ColorManagedFileOutput; #define MAX_COLORSPACE_NAME 64 @@ -34,4 +31,6 @@ const ColorSpace *colormanage_colorspace_get_named(const char *name); const ColorSpace *colormanage_colorspace_get_roled(int role); void colormanage_imbuf_set_default_spaces(ImBuf *ibuf); -void colormanage_imbuf_make_linear(ImBuf *ibuf, const char *from_colorspace, bool video); +void colormanage_imbuf_make_linear(ImBuf *ibuf, + const char *from_colorspace, + ColorManagedFileOutput output); diff --git a/source/blender/imbuf/intern/colormanagement.cc b/source/blender/imbuf/intern/colormanagement.cc index af0269deeff..84ac8b2fc9a 100644 --- a/source/blender/imbuf/intern/colormanagement.cc +++ b/source/blender/imbuf/intern/colormanagement.cc @@ -871,7 +871,9 @@ void colormanage_imbuf_set_default_spaces(ImBuf *ibuf) ibuf->byte_buffer.colorspace = g_config->get_color_space(global_role_default_byte); } -void colormanage_imbuf_make_linear(ImBuf *ibuf, const char *from_colorspace, bool video) +void colormanage_imbuf_make_linear(ImBuf *ibuf, + const char *from_colorspace, + const ColorManagedFileOutput output) { const ColorSpace *colorspace = g_config->get_color_space(from_colorspace); @@ -888,7 +890,7 @@ void colormanage_imbuf_make_linear(ImBuf *ibuf, const char *from_colorspace, boo IMB_free_byte_pixels(ibuf); } - if (!video) { + if (output != ColorManagedFileOutput::Video) { const ColorSpace *image_colorspace = g_config->get_color_space_for_hdr_image( from_colorspace); if (image_colorspace) { @@ -1434,7 +1436,7 @@ static const int CICP_MATRIX_REC2020_NCL = 9; static const int CICP_RANGE_FULL = 1; bool IMB_colormanagement_space_to_cicp(const ColorSpace *colorspace, - const bool video, + const ColorManagedFileOutput output, const bool rgb_matrix, int cicp[4]) { @@ -1506,7 +1508,7 @@ bool IMB_colormanagement_space_to_cicp(const ColorSpace *colorspace, * But we have been writing sRGB like this forever, and there is the so called * "Quicktime gamma shift bug" that complicates things. */ cicp[0] = CICP_PRI_P3D65; - cicp[1] = (video) ? CICP_TRC_BT709 : CICP_TRC_SRGB; + cicp[1] = (output == ColorManagedFileOutput::Video) ? CICP_TRC_BT709 : CICP_TRC_SRGB; cicp[2] = (rgb_matrix) ? CICP_MATRIX_RGB : CICP_MATRIX_BT709; cicp[3] = CICP_RANGE_FULL; return true; @@ -1520,7 +1522,8 @@ bool IMB_colormanagement_space_to_cicp(const ColorSpace *colorspace, return false; } -const ColorSpace *IMB_colormanagement_space_from_cicp(const int cicp[4], const bool video) +const ColorSpace *IMB_colormanagement_space_from_cicp(const int cicp[4], + const ColorManagedFileOutput output) { StringRefNull interop_id; @@ -1545,7 +1548,7 @@ const ColorSpace *IMB_colormanagement_space_from_cicp(const int cicp[4], const b interop_id = "g24_rec2020_display"; } else if (cicp[0] == CICP_PRI_REC709 && cicp[1] == CICP_TRC_BT709) { - if (video) { + if (output == ColorManagedFileOutput::Video) { /* Arguably this should be g24_rec709_display, but we write sRGB like this. * So there is an exception for now. */ interop_id = "srgb_rec709_display"; diff --git a/source/blender/imbuf/intern/oiio/openimageio_support.cc b/source/blender/imbuf/intern/oiio/openimageio_support.cc index 14c7200a684..b2f534056ce 100644 --- a/source/blender/imbuf/intern/oiio/openimageio_support.cc +++ b/source/blender/imbuf/intern/oiio/openimageio_support.cc @@ -163,8 +163,8 @@ static void set_file_colorspace(ImFileColorSpace &r_colorspace, /* Get colorspace from CICP. */ int cicp[4] = {}; if (spec.getattribute("CICP", TypeDesc(TypeDesc::INT, 4), cicp, true)) { - const bool for_video = false; - const ColorSpace *colorspace = IMB_colormanagement_space_from_cicp(cicp, for_video); + const ColorSpace *colorspace = IMB_colormanagement_space_from_cicp( + cicp, ColorManagedFileOutput::Image); if (colorspace) { STRNCPY_UTF8(r_colorspace.metadata_colorspace, IMB_colormanagement_colorspace_get_name(colorspace)); @@ -484,10 +484,11 @@ ImageSpec imb_create_write_spec(const WriteContext &ctx, int file_channels, Type /* PNG only supports RGB matrix. For AVIF and HEIF we want to use a YUV matrix * as these are based on video codecs designed to use them. */ - const bool for_video = false; const bool rgb_matrix = STREQ(ctx.file_format, "png"); int cicp[4]; - if (IMB_colormanagement_space_to_cicp(colorspace, for_video, rgb_matrix, cicp)) { + if (IMB_colormanagement_space_to_cicp( + colorspace, ColorManagedFileOutput::Image, rgb_matrix, cicp)) + { file_spec.attribute("CICP", TypeDesc(TypeDesc::INT, 4), cicp); } } diff --git a/source/blender/imbuf/intern/readimage.cc b/source/blender/imbuf/intern/readimage.cc index 387a8ce2617..bf93dc6d5be 100644 --- a/source/blender/imbuf/intern/readimage.cc +++ b/source/blender/imbuf/intern/readimage.cc @@ -117,7 +117,7 @@ static void imb_handle_colorspace_and_alpha(ImBuf *ibuf, } } - colormanage_imbuf_make_linear(ibuf, new_colorspace, false); + colormanage_imbuf_make_linear(ibuf, new_colorspace, ColorManagedFileOutput::Image); } ImBuf *IMB_load_image_from_memory(const uchar *mem, diff --git a/source/blender/imbuf/movie/intern/movie_read.cc b/source/blender/imbuf/movie/intern/movie_read.cc index e10238f0d60..5e2e6afc91f 100644 --- a/source/blender/imbuf/movie/intern/movie_read.cc +++ b/source/blender/imbuf/movie/intern/movie_read.cc @@ -126,8 +126,8 @@ static void probe_video_colorspace(MovieReader *anim, char r_colorspace_name[IM_ anim->pCodecCtx->color_trc, anim->pCodecCtx->colorspace, anim->pCodecCtx->color_range}; - const bool for_video = true; - const ColorSpace *colorspace = IMB_colormanagement_space_from_cicp(cicp, for_video); + const ColorSpace *colorspace = IMB_colormanagement_space_from_cicp( + cicp, ColorManagedFileOutput::Video); if (colorspace == nullptr) { return; @@ -1329,7 +1329,8 @@ static ImBuf *ffmpeg_fetchibuf(MovieReader *anim, int position, IMB_Timecode_Typ * It might not be the most optimal thing to do from the playback performance in the * sequencer perspective, but it ensures that other areas in Blender do not run into obscure * color space mismatches. */ - colormanage_imbuf_make_linear(cur_frame_final, anim->colorspace, true); + colormanage_imbuf_make_linear( + cur_frame_final, anim->colorspace, ColorManagedFileOutput::Video); } } else { diff --git a/source/blender/imbuf/movie/intern/movie_write.cc b/source/blender/imbuf/movie/intern/movie_write.cc index 5ba54e8a0b4..8caea347419 100644 --- a/source/blender/imbuf/movie/intern/movie_write.cc +++ b/source/blender/imbuf/movie/intern/movie_write.cc @@ -794,11 +794,12 @@ static void set_colorspace_options(AVCodecContext *c, const ColorSpace *colorspa { const AVPixFmtDescriptor *pix_fmt_desc = av_pix_fmt_desc_get(c->pix_fmt); const bool is_rgb_format = (pix_fmt_desc->flags & AV_PIX_FMT_FLAG_RGB); - const bool for_video = true; const bool rgb_matrix = false; int cicp[4]; - if (colorspace && IMB_colormanagement_space_to_cicp(colorspace, for_video, rgb_matrix, cicp)) { + if (colorspace && IMB_colormanagement_space_to_cicp( + colorspace, ColorManagedFileOutput::Video, rgb_matrix, cicp)) + { /* Note ffmpeg enums are documented to match CICP. */ c->color_primaries = AVColorPrimaries(cicp[0]); c->color_trc = AVColorTransferCharacteristic(cicp[1]);