88 ColormanageProcessor *cm_processor,
92static std::unique_ptr<ocio::Config> &
g_config()
94 static std::unique_ptr<ocio::Config> g_config_ =
nullptr;
101 return g_all_view_names_;
121 return g_config_active_;
128 return g_config_requested_;
135 std::optional<std::string>
ocio;
140 return g_startup_env_;
143#define DISPLAY_BUFFER_CHANNELS 4
211 char *colorspace_name,
213 const char *backup_role,
214 const bool optional =
false)
218 if (ociocs ==
nullptr && backup_role) {
222 if (ociocs ==
nullptr) {
227 if (ociocs ==
nullptr) {
231 colorspace_name[0] =
'\0';
309 if (video_rec709 ==
nullptr) {
376 std::optional<std::string> &r_old_ocio_env)
383 if (
const char *ocio_env =
BLI_getenv(
"OCIO")) {
384 r_old_ocio_env = ocio_env;
392 BLI_setenv(
"OCIO", old_ocio_env.has_value() ? old_ocio_env->c_str() :
nullptr);
417 else if (env.
ocio.has_value() && !env.
ocio->empty()) {
422 if (bmain !=
nullptr) {
438 if (configdir.has_value()) {
454 return "BLENDER_OCIO";
480 !candidate.unresolved_path.empty() && candidate.path.empty())
483 &
LOG,
"Invalid project config path, skipping: %s", candidate.unresolved_path.c_str());
490 std::unique_ptr<ocio::Config> config;
491 std::optional<std::string> old_ocio_env;
503 const auto validate = [&](
const ocio::Config &new_config) {
509 loaded =
g_config()->switch_to(*config, validate);
511 else if (config && validate(*config)) {
526 "Failed to load config from %s: %s",
528 candidate.path.c_str());
539 "Using config from %s: \"%s\"",
548 if (
const char *env =
BLI_getenv(
"BLENDER_OCIO")) {
562 std::optional<std::string> ocio_env)
610 std::optional<std::string> old_ocio_env;
618 if (!
g_config()->switch_to_from_environment(validate)) {
619 CLOG_ERROR(&
LOG,
"Failed to load OpenColorIO config from '%s'", filepath);
649 if (look->
view() == view_name) {
655 const int64_t separator_offset = view_name.
find(
" - ");
656 if (separator_offset == -1) {
663 if (look->
view() == view_short_name) {
664 return view_short_name;
705 if (sima && sima->
image) {
707 *r_view_settings =
nullptr;
727 const char *view_transform,
728 const float exposure,
730 const float temperature,
732 const bool use_white_balance,
733 const char *from_colorspace,
739 display_parameters.
view = view_transform;
742 display_parameters.
scale = (exposure == 0.0f) ? 1.0f :
powf(2.0f, exposure);
745 display_parameters.
tint = tint;
757 return g_config()->get_display_cpu_processor(display_parameters);
769 view_settings->
flag = {};
770 view_settings->
gamma = 1.0f;
773 view_settings->
tint = 10.0f;
784 else if (channels == 2) {
805 const char *from_colorspace,
828 if (image_colorspace) {
829 from_colorspace = image_colorspace->
name().
c_str();
836 if (from_colorspace[0] ==
'\0') {
841 from_colorspace, to_colorspace);
884 display =
g_config()->get_display_by_index(display_index);
886 new_display_name = display->
name();
892 if (
g_config()->get_num_displays() > 1) {
895 "Display \"%s\" used by %s not found, setting to \"%s\".",
898 new_display_name.
c_str());
908 if (view_name ==
"Standard" && display->
get_view_by_name(
"Un-tone-mapped")) {
909 return "Un-tone-mapped";
911 if (view_name ==
"Un-tone-mapped" && display->
get_view_by_name(
"Standard")) {
924 const int64_t separator_offset = view_name.
find(
" - ");
925 if (separator_offset != -1) {
926 const StringRef view_short_name = view_name.
substr(0, separator_offset);
972 "%s view \"%s\" not found, setting to \"%s\".",
975 new_view_name.
c_str());
983 if (view_settings->
look[0] ==
'\0') {
988 if (look ==
nullptr) {
990 if (
g_config()->get_num_looks() > 1) {
993 "%s look \"%s\" not found, setting default \"%s\".",
1003 "%s look \"%s\" is not compatible with view \"%s\", setting "
1007 view_settings->
look,
1017 if (view_settings->
exposure == 0.0f && view_settings->
gamma == 0.0f) {
1019 view_settings->
gamma = 1.0f;
1029 g_config()->get_color_space(name) :
1040 if (name[0] ==
'\0') {
1048 if (interop_id[0] !=
'\0') {
1049 if (
const ColorSpace *colorspace_by_interop_id =
g_config()->get_color_space_by_interop_id(
1058 &
LOG, log_level,
"%s colorspace \"%s\" not found, will use default instead.", what, name);
1060 interop_id[0] =
'\0';
1073 if (interop_id[0] ==
'\0') {
1095 if (!default_display) {
1101 bool is_missing_opencolorio_config =
false;
1105 const bool is_new_file = bmain->
filepath[0] ==
'\0';
1133 sequencer_colorspace_settings,
"sequencer", log_level);
1135 if (sequencer_colorspace_settings->
name[0] ==
'\0') {
1141 if (scene.
ed !=
nullptr) {
1144 ok &= colormanage_check_colorspace_settings(
1145 &strip->data->colorspace_settings,
"sequencer strip", log_level);
1151 is_missing_opencolorio_config |= (!ok && !
ID_IS_LINKED(&scene.
id));
1157 &
image.colorspace_settings,
"image", log_level);
1161 for (
MovieClip &clip : bmain->movieclips) {
1163 &clip.colorspace_settings,
"clip", log_level);
1164 is_missing_opencolorio_config |= (!ok && !
ID_IS_LINKED(&clip.id));
1168 for (
bNodeTree &ntree : bmain->nodetrees) {
1175 &nctd->display_settings,
"node", default_display, log_level);
1177 &nctd->display_settings, &nctd->view_settings,
"node", log_level);
1182 ncs->from_color_space, ncs->from_interop_id,
"node", log_level);
1184 ncs->to_color_space, ncs->to_interop_id,
"node", log_level);
1189 &nfo->format.linear_colorspace_settings,
"node", log_level);
1192 &item.format.linear_colorspace_settings,
"node", log_level);
1196 is_missing_opencolorio_config |= (!ok && !
ID_IS_LINKED(&ntree.id));
1203 if (!is_new_file && is_missing_opencolorio_config) {
1204 bmain->colorspace.is_missing_opencolorio_config =
true;
1251 CLOG_WARN(&
LOG,
"Unknown role was passed to %s", __func__);
1300 return g_config()->get_color_space_from_filepath(filepath);
1305 return g_config()->get_color_space(name);
1309 return g_config()->get_color_space(name);
1353 for (
const char *interop_id : {
"srgb_rec709_scene",
"srgb_rec709_display"}) {
1360 for (
const char *name :
1361 {
"sRGB Encoded Rec.709 (sRGB)",
"Utility - sRGB - Texture",
"sRGB - Texture",
"sRGB"})
1377 fstream f(filepath, std::ios::binary | std::ios::in | std::ios::ate);
1382 const std::streamsize size = f.tellg();
1388 f.seekg(0, std::ios::beg);
1389 if (!f.read(icc_profile.
data(), icc_profile.
size())) {
1390 icc_profile.
clear();
1411 if (!dir.has_value()) {
1420 BLI_path_join(icc_filepath,
sizeof(icc_filepath), dir->c_str(),
"icc", icc_filename);
1425 const StringRef icc_filepath_ref = icc_filepath;
1426 if (icc_filepath_ref.
endswith(
"_scene.icc")) {
1427 const std::string icc_filepath_display = icc_filepath_ref.
drop_suffix(strlen(
"_scene.icc")) +
1476 const bool rgb_matrix,
1500 if (interop_id ==
"pq_rec2020_display") {
1507 if (interop_id ==
"hlg_rec2020_display") {
1514 if (interop_id ==
"pq_p3d65_display") {
1522 if (interop_id ==
"pq_xyzd65_display") {
1529 if (interop_id ==
"g26_xyzd65_display") {
1536 if (interop_id ==
"g26_p3d65_display") {
1542 if (
ELEM(interop_id,
"g22_rec709_display",
"g22_rec709_scene")) {
1549 if (
ELEM(interop_id,
"blender:g24_rec2020_display",
"g24_rec2020_scene")) {
1557 if (
ELEM(interop_id,
"g24_rec709_display",
"g24_rec709_scene")) {
1565 if (
ELEM(interop_id,
"srgb_p3d65_display",
"srgbe_p3d65_display",
"srgb_p3d65_scene")) {
1572 if (
ELEM(interop_id,
"srgb_rec709_display",
"srgb_rec709_scene")) {
1579 if (interop_id ==
"blender:g1961_rec709_display") {
1587 if (
ELEM(interop_id,
"lin_rec709_display",
"lin_rec709_scene")) {
1594 if (
ELEM(interop_id,
"lin_p3d65_display",
"lin_p3d65_scene")) {
1601 if (
ELEM(interop_id,
"lin_rec2020_display",
"lin_rec2020_scene")) {
1608 if (interop_id ==
"lin_ciexyzd65_scene") {
1627 interop_id =
"pq_rec2020_display";
1630 interop_id =
"hlg_rec2020_display";
1633 interop_id =
"pq_p3d65_display";
1636 interop_id =
"pq_xyzd65_display";
1639 interop_id =
"g26_xyzd65_display";
1642 interop_id =
"g22_rec709_display";
1645 interop_id =
"blender:g24_rec2020_display";
1652 interop_id =
"srgb_p3d65_display";
1655 interop_id =
"srgb_rec709_display";
1658 interop_id =
"lin_rec709_display";
1661 interop_id =
"lin_p3d65_display";
1664 interop_id =
"lin_rec2020_display";
1667 interop_id =
"lin_ciexyzd65_scene";
1671 interop_id =
"srgb_rec709_display";
1684 return g_config()->get_color_space_by_interop_id(interop_id);
1693 if (interop_id[0] &&
colorspace->alternate_interop_id() == interop_id) {
1701 const int offset =
g_config()->get_num_all_color_spaces();
1702 const bool is_alternate =
index >= offset;
1733 float whitepoint[3])
1795 float dither = ibuf->
dither;
1798 size_t offset = size_t(channels) * start_line * ibuf->
x;
1837 float *linear_buffer,
1838 bool *is_straight_alpha)
1841 int width = handle->
width;
1843 size_t buffer_size = size_t(channels) * width * height;
1845 bool is_data = handle->
is_data;
1857 const size_t i_last = size_t(width) * height;
1861 for (i = 0, fp = linear_buffer, cp = byte_buffer; i != i_last;
1862 i++, fp += channels, cp += channels)
1864 if (channels == 3) {
1867 else if (channels == 4) {
1871 BLI_assert_msg(0,
"Buffers of 3 or 4 channels are only supported here");
1875 if (!is_data && !is_data_display) {
1878 linear_buffer, width, height, channels, from_colorspace, to_colorspace,
false);
1881 *is_straight_alpha =
true;
1893 memcpy(linear_buffer, handle->
buffer, buffer_size *
sizeof(
float));
1895 if (!is_data && !is_data_display) {
1897 linear_buffer, width, height, channels, from_colorspace, to_colorspace, predivide);
1900 *is_straight_alpha =
false;
1909 memcpy(linear_buffer, handle->
buffer, buffer_size *
sizeof(
float));
1911 *is_straight_alpha =
false;
1917 const int width = handle->
width;
1918 const int height = handle->
tot_line;
1923 else if (handle->
buffer) {
1951 if (cm_processor ==
nullptr) {
1959 int width = handle->
width;
1962 size_t(channels) *
size_t(width) *
size_t(height),
"color conversion linear buffer");
1964 bool is_straight_alpha;
1967 bool predivide = handle->
predivide && (is_straight_alpha ==
false);
1971 cm_processor->
apply(linear_buffer, width, height, channels, predivide);
1975 if (display_buffer_byte) {
1988 if (display_buffer) {
1989 memcpy(display_buffer, linear_buffer,
size_t(width) * height * channels *
sizeof(
float));
1991 if (is_straight_alpha && channels == 4) {
1992 const size_t i_last = size_t(width) * height;
1996 for (i = 0, fp = display_buffer; i != i_last; i++, fp += channels) {
2002 MEM_delete(linear_buffer);
2006 const float *buffer,
2008 float *display_buffer,
2009 uchar *display_buffer_byte,
2014 init_data.
ibuf = ibuf;
2016 init_data.
buffer = buffer;
2040 DisplayBufferThread handle;
2041 display_buffer_init_handle(&handle, y_range.first(), y_range.size(), &init_data);
2042 do_display_buffer_apply_thread(&handle);
2053 if (view_settings) {
2056 view_settings->
exposure != 0.0f || view_settings->
gamma != 1.0f)
2068 view_settings, display_settings);
2073 if (view_settings ==
nullptr) {
2079 return untonemapped_view && untonemapped_view->
name() == view_settings->
view_transform;
2088 switch (display_space) {
2111 float *display_buffer,
2112 uchar *display_buffer_byte,
2117 std::optional<ColormanageProcessor> cm_processor;
2119 ibuf, view_settings, display_settings, display_space))
2122 view_settings, display_settings, display_space,
false,
nullptr);
2131 display_buffer_byte,
2167 const int channels = init_data->
channels;
2168 const int width = init_data->
width;
2169 const bool predivide = init_data->
predivide;
2171 const size_t offset = size_t(channels) * start_line * width;
2185 handle->
width = width;
2198 const int channels = handle->
channels;
2199 const int width = handle->
width;
2200 const int height = handle->
tot_line;
2201 const bool predivide = handle->
predivide;
2202 if (byte_buffer !=
nullptr) {
2205 if (float_buffer !=
nullptr) {
2211 float *float_buffer,
2216 const bool predivide)
2223 init_data.
width = width;
2224 init_data.
height = height;
2244 float *float_buffer,
2248 const char *from_colorspace,
2249 const char *to_colorspace,
2252 if (from_colorspace[0] ==
'\0') {
2257 from_colorspace, to_colorspace);
2263 byte_buffer, float_buffer, width, height, channels, &cm_processor, predivide);
2270 const char *from_colorspace,
2271 const char *to_colorspace,
2275 nullptr, buffer, width, height, channels, from_colorspace, to_colorspace, predivide);
2282 const char *from_colorspace,
2283 const char *to_colorspace)
2286 buffer,
nullptr, width, height, channels, from_colorspace, to_colorspace,
false);
2290 const uchar *byte_buffer,
2294 const char *from_colorspace,
2295 const char *to_colorspace)
2297 if (from_colorspace ==
nullptr || from_colorspace[0] ==
'\0') {
2300 if (
STREQ(from_colorspace, to_colorspace) && channels == 4) {
2304 float *dst_ptr = float_buffer + pix_range.
first() * channels;
2305 const uchar *src_ptr = byte_buffer + pix_range.
first() * channels;
2306 for ([[maybe_unused]]
const int i : pix_range) {
2308 float cr =
float(src_ptr[0]) * (1.0f / 255.0f);
2309 float cg =
float(src_ptr[1]) * (1.0f / 255.0f);
2310 float cb =
float(src_ptr[2]) * (1.0f / 255.0f);
2311 float ca =
float(src_ptr[3]) * (1.0f / 255.0f);
2312 dst_ptr[0] = cr * ca;
2313 dst_ptr[1] = cg * ca;
2314 dst_ptr[2] = cb * ca;
2323 from_colorspace, to_colorspace);
2325 const size_t offset = size_t(channels) * y_range.
first() * width;
2326 const uchar *src = byte_buffer + offset;
2327 float *dst = float_buffer + offset;
2329 cm_processor.
apply(dst, width, y_range.
size(), channels,
false);
2335 const char *from_colorspace,
2336 const char *to_colorspace)
2338 if (from_colorspace[0] ==
'\0') {
2342 if (
STREQ(from_colorspace, to_colorspace)) {
2350 from_colorspace, to_colorspace);
2359 printf(
"%s: perform conversion from unknown color space\n", __func__);
2363 if (processor ==
nullptr) {
2373 printf(
"%s: perform conversion from unknown color space\n", __func__);
2377 if (processor ==
nullptr) {
2384 const bool predivide,
2388 printf(
"%s: perform conversion from unknown color space\n", __func__);
2392 if (processor ==
nullptr) {
2408 const bool predivide)
2411 printf(
"%s: perform conversion from unknown color space\n", __func__);
2415 if (processor ==
nullptr) {
2424 size_t(channels) *
sizeof(
float),
2425 size_t(channels) *
sizeof(
float) * width);
2431 processor->
apply(img);
2442 printf(
"%s: perform conversion from unknown color space\n", __func__);
2446 if (processor ==
nullptr) {
2455 size_t(channels) *
sizeof(
float),
2456 size_t(channels) *
sizeof(
float) * width);
2457 processor->
apply(img);
2466 const bool store_premultiplied)
2479 for (
int y = 0;
y < height;
y++) {
2480 const size_t in_offset = (offset_y +
y) * ibuf->
x + offset_x;
2481 const size_t out_offset =
y * width;
2482 const uchar *
in = in_buffer + in_offset * 4;
2483 uchar *
out = out_buffer + out_offset * 4;
2485 if (use_premultiply) {
2487 for (
int x = 0;
x < width;
x++,
in += 4,
out += 4) {
2488 out[0] = (
in[0] *
in[3]) >> 8;
2489 out[1] = (
in[1] *
in[3]) >> 8;
2490 out[2] = (
in[2] *
in[3]) >> 8;
2496 for (
int x = 0;
x < width;
x++,
in += 4,
out += 4) {
2512 const bool store_premultiplied)
2519 const int in_channels = ibuf->
channels;
2522 for (
int y = 0;
y < height;
y++) {
2523 const size_t in_offset = (offset_y +
y) * ibuf->
x + offset_x;
2524 const size_t out_offset =
y * width;
2525 const float *
in = in_buffer + in_offset * in_channels;
2526 float *
out = out_buffer + out_offset * 4;
2528 if (in_channels == 1) {
2530 for (
int x = 0;
x < width;
x++,
in += 1,
out += 4) {
2537 else if (in_channels == 3) {
2539 for (
int x = 0;
x < width;
x++,
in += 3,
out += 4) {
2546 else if (in_channels == 4) {
2548 if (use_unpremultiply) {
2549 for (
int x = 0;
x < width;
x++,
in += 4,
out += 4) {
2554 memcpy(
out,
in,
sizeof(
float[4]) * width);
2570 for (
const int y : y_range) {
2571 const size_t in_offset = (offset_y +
y) * ibuf->
x + offset_x;
2572 const size_t out_offset =
y * width;
2573 const uchar *
in = in_buffer + in_offset * 4;
2574 float *
out = out_buffer + out_offset * 4;
2575 for (
int x = 0;
x < width;
x++,
in += 4,
out += 4) {
2585 if (use_premultiply) {
2596 const float scene_linear[3])
2603 std::shared_ptr<const ocio::CPUProcessor> cpu_processor =
g_config()->get_cpu_processor(
2606 if (cpu_processor) {
2625 const float color_picking[3])
2632 std::shared_ptr<const ocio::CPUProcessor> cpu_processor =
g_config()->get_cpu_processor(
2635 if (cpu_processor) {
2659 if (processor !=
nullptr) {
2670 if (processor !=
nullptr) {
2677 const float pixel[4],
2683 view_settings, display_settings, display_space);
2692 if (colormanaged_ibuf != ibuf) {
2694 return colormanaged_ibuf;
2697 if (allocate_result) {
2713 bool save_as_render,
2714 bool allocate_result,
2717 ImBuf *colormanaged_ibuf = ibuf;
2745 float color[3] = {0, 0, 0};
2751 colormanaged_ibuf->
x,
2752 colormanaged_ibuf->
y,
2758 colormanaged_ibuf->
x,
2759 colormanaged_ibuf->
y,
2764 if (save_as_render && !linear_float_output) {
2768 if (!colormanaged_ibuf->
byte_data() && byte_output) {
2803 if (image_colorspace) {
2804 to_colorspace = image_colorspace->
name().
c_str();
2809 if (to_colorspace[0] ==
'\0' ||
STREQ(from_colorspace, to_colorspace)) {
2811 if (byte_output && !colormanaged_ibuf->
byte_data()) {
2828 colormanaged_ibuf->
x,
2829 colormanaged_ibuf->
y,
2852 colormanaged_ibuf->
x,
2853 colormanaged_ibuf->
y,
2866 return colormanaged_ibuf;
2871 const float *linear_buffer,
2880 "display transform temp buffer");
2881 memcpy(buffer, linear_buffer,
sizeof(
float) * 4 * width * height);
2882 processor.
apply(buffer, width, height, 4,
true);
2897 return display->
index;
2919 return g_config()->get_display_by_name(name);
2924 if (
g_config()->get_display_by_name(
"None") !=
nullptr) {
2934 if (!default_view) {
2947 const ocio::View *view = (view_settings && display) ?
2958 g_config()->get_display_view_color_space(
2960 untonemapped_view->
name()) :
2962 return (untonemapped_colorspace) ? untonemapped_colorspace :
colorspace;
2966 const char *view_name)
2969 if (display ==
nullptr) {
2973 return (view) ? view->
is_hdr() :
false;
2977 const char *view_name)
2980 if (display ==
nullptr) {
2991 if (display ==
nullptr) {
3001 if (display ==
nullptr) {
3005 return view ? view->
max_nits() : 0;
3013 if (display ==
nullptr) {
3016 const ocio::View *view = (display) ? (view_settings) ?
3020 if (view ==
nullptr) {
3097 return g_config()->get_color_space(name);
3111 return g_config()->get_num_all_color_spaces();
3176 if (type !=
nullptr) {
3177 if (type->
save !=
nullptr) {
3219 const char *look_name)
3281 if (!working_spaces.
contains(scene_linear)) {
3282 working_spaces.
prepend(scene_linear);
3313 CLOG_DEBUG(&
LOG,
"Setting blend file working color space to '%s'", name);
3316 g_config()->set_scene_linear_role(name);
3327 const float3x3 &scene_linear_to_xyz,
3328 const bool report_missing)
3347 interop_id =
"lin_ap1_scene";
3353 interop_id =
"lin_rec709_scene";
3359 interop_id =
"lin_rec2020_scene";
3377 if (report_missing) {
3379 &
LOG,
"Unknown scene linear working space '%s'. Missing OpenColorIO configuration?", name);
3393 "Blend file has unknown scene linear working color space, setting to default");
3404 const bool is_smaller_gamut,
3409 for (
int i = 0; i < 3; i++) {
3411 rgb[i] = 1e-5f *
roundf(rgb[i] * 1e5f);
3413 if (
fabsf(rgb[i]) < 5
e-5) {
3416 else if (
fabsf(1.0f - rgb[i]) < 5
e-5) {
3421 if (is_smaller_gamut) {
3430 const bool is_smaller_gamut,
3439 const float3x3 ¤t_scene_linear_to_xyz,
3440 const float3x3 &new_xyz_to_scene_linear,
3441 const bool depsgraph_tag,
3442 const bool linked_only,
3443 const bool editable_assets_only)
3448 current_scene_linear_to_xyz;
3450 float3x3 M = new_xyz_to_scene_linear * bmain_scene_linear_to_xyz;
3458 CLOG_ERROR(&
LOG,
"Working space conversion matrix is not invertible");
3464 bool is_smaller_gamut =
false;
3465 for (
int i = 0; i < 3; i++) {
3466 for (
int j = 0; j < 3; j++) {
3467 if (
M[i][j] < 0.0f) {
3468 is_smaller_gamut =
true;
3474 const auto single = [&
M, is_smaller_gamut](
float rgb[3]) {
3482 struct ColorArrayInfo {
3491 const auto implicit_sharing_array =
3494 if (!sharing_info) {
3500 [&](ColorArrayInfo *value) {
3501 new (value) ColorArrayInfo();
3502 value->data_ptrs.append(&data);
3503 value->sharing_info_ptrs.append(&sharing_info);
3504 value->max_size = size;
3506 [&](ColorArrayInfo *value) {
3507 BLI_assert(data == *value->data_ptrs.last());
3508 value->data_ptrs.append(&data);
3509 value->sharing_info_ptrs.append(&sharing_info);
3510 value->max_size = std::max(value->max_size, size);
3522 if (!id_iter->
lib) {
3526 if (editable_assets_only) {
3535 if (depsgraph_tag) {
3554 for (const int item_index : range) {
3555 const auto &item = color_array_items[item_index];
3557 if (item.value.data_ptrs.size() == item.key->strong_users()) {
3560 item.key->tag_ensured_mutable();
3561 MutableSpan<ColorGeometry4f> data(*item.value.data_ptrs.first(), item.value.max_size);
3562 threading::parallel_for(data.index_range(), 1024, [&](const IndexRange range) {
3563 for (const int64_t i : range) {
3564 data[i] = imb_working_space_convert(M, is_smaller_gamut, data[i]);
3571 const Span<ColorGeometry4f> src_data(*item.value.data_ptrs.first(), item.value.max_size);
3573 auto *dst_data = MEM_new_array_uninitialized<ColorGeometry4f>(
3574 src_data.size(),
"IMB_colormanagement_working_space_convert");
3575 const ImplicitSharingPtr<> sharing_ptr(implicit_sharing::info_for_mem_free(dst_data));
3577 threading::parallel_for(src_data.index_range(), 1024, [&](const IndexRange range) {
3578 for (const int64_t i : range) {
3579 dst_data[i] = imb_working_space_convert(M, is_smaller_gamut, src_data[i]);
3585 for (ColorGeometry4f **pointer : item.value.data_ptrs) {
3586 *pointer = dst_data;
3588 for (ImplicitSharingPtr<> *pointer : item.value.sharing_info_ptrs) {
3589 *pointer = sharing_ptr;
3638 const bool is_startup,
3639 const bool have_editable_assets)
3645 const bool report_missing = !is_startup;
3661 if (have_editable_assets) {
3691 const bool report_missing = bmain->
filepath[0] !=
'\0';
3695 previous_scene_linear_to_xyz,
3710 for (
const bool hdr : {
false,
true}) {
3716 if (display->
is_hdr() != hdr) {
3723 item.
name = (hdr) ?
"HDR" :
"SDR";
3747 const char *display_name)
3771 const char *view_name)
3798 for (
const int colorspace_index :
IndexRange(
g_config()->get_num_active_color_spaces())) {
3820 if (
colorspace->alternate_interop_id().is_empty()) {
3837 for (
const int colorspace_index :
IndexRange(
g_config()->get_num_active_color_spaces())) {
3856 item.
name =
"Working Space";
3859 item.
description =
"Working color space of the current file";
3872 cpu_processor_ = std::move(other.cpu_processor_);
3873 curve_mapping_ = other.curve_mapping_;
3874 is_data_result_ = other.is_data_result_;
3876 other.cpu_processor_ =
nullptr;
3877 other.curve_mapping_ =
nullptr;
3878 other.is_data_result_ =
false;
3882 if (
this == &other) {
3886 if (curve_mapping_) {
3890 cpu_processor_ = std::move(other.cpu_processor_);
3891 curve_mapping_ = other.curve_mapping_;
3892 is_data_result_ = other.is_data_result_;
3894 other.cpu_processor_ =
nullptr;
3895 other.curve_mapping_ =
nullptr;
3896 other.is_data_result_ =
false;
3903 if (curve_mapping_) {
3915 if (from_colorspace == to_colorspace) {
3919 processor.cpu_processor_ =
g_config()->get_cpu_processor(from_colorspace, to_colorspace);
3929 processor.is_data_result_ = to_colorspace.
is_data();
3940 processor.is_data_result_ = from_colorspace.
is_data();
3951 const char *from_colorspace)
3959 if (view_settings) {
3960 applied_view_settings = view_settings;
3965 applied_view_settings = &untonemapped_view_settings;
3970 if (display_colorspace) {
3971 cm_processor.is_data_result_ = display_colorspace->
is_data();
3975 const char *processor_from_colorspace = from_colorspace ? from_colorspace :
3978 applied_view_settings->
look,
3981 applied_view_settings->
gamma,
3983 applied_view_settings->
tint,
3985 processor_from_colorspace,
3994 return cm_processor;
4004 ibuf, view_settings, display_settings, display_space))
4006 return std::nullopt;
4010 view_settings, display_settings, display_space,
false, from_colorspace);
4015 return is_data_result_;
4020 if (curve_mapping_) {
4028 if (!cpu_processor) {
4041 return cpu_processor->
is_noop();
4046 if (curve_mapping_) {
4051 if (cpu_processor) {
4058 if (curve_mapping_) {
4063 if (cpu_processor) {
4070 if (curve_mapping_) {
4075 if (cpu_processor) {
4082 if (channels == 4) {
4085 else if (channels == 3) {
4088 else if (channels == 1) {
4089 if (curve_mapping_) {
4095 false,
"Incorrect number of channels passed to IMB_colormanagement_processor_apply_pixel");
4100 float *buffer,
int width,
int height,
int channels,
bool predivide)
const
4103 if (curve_mapping_) {
4106 for (
y = 0;
y < height;
y++) {
4107 for (
x = 0;
x < width;
x++) {
4108 float *pixel = buffer + channels * (size_t(
y) * width +
x);
4116 if (cpu_processor && channels >= 3) {
4124 size_t(channels) *
sizeof(
float),
4125 size_t(channels) *
sizeof(
float) * width);
4131 cpu_processor->
apply(img);
4143 for (
int y = 0;
y < height;
y++) {
4144 for (
int x = 0;
x < width;
x++) {
4145 size_t offset = channels * (size_t(
y) * width +
x);
4159 if (!use_curve_mapping) {
4196 bool do_overlay_merge,
4203 if (view_settings) {
4204 applied_view_settings = view_settings;
4211 applied_view_settings = &untonemapped_view_settings;
4220 const float exposure = applied_view_settings->
exposure;
4221 const float gamma = applied_view_settings->
gamma;
4229 display_parameters.
look = (use_look) ? applied_view_settings->
look :
"";
4231 display_parameters.
scale = (exposure == 0.0f) ? 1.0f :
powf(2.0f, exposure);
4233 display_parameters.
dither = dither;
4235 display_parameters.
tint = applied_view_settings->
tint;
4242 display_settings, display_parameters.
view.
c_str());
4247 display_parameters.
opacity = opacity;
4251 display_parameters);
4262 view_settings, display_settings,
nullptr, dither, predivide,
false);
4276 view_settings, display_settings, from_colorspace, dither, predivide,
false);
4285 const bool predivide)
4288 from_colorspace_name, predivide);
4295 g_config()->get_gpu_shader_binder().unbind();
4313 {2.48845471e+03f, -1.11330907e-03f, 3.22621544e+00f},
4314 {3.34143193e+03f, -4.86551192e-04f, 1.76486769e+00f},
4315 {4.09461742e+03f, -1.27446582e-04f, 7.25731635e-01f},
4316 {4.67028036e+03f, 2.91258199e-05f, 1.26703442e-01f},
4317 {4.59509185e+03f, 2.87495649e-05f, 1.50345020e-01f},
4318 {3.78717450e+03f, 9.35907826e-06f, 3.99075871e-01f}};
4321 {-4.88999748e+02f, 6.04330754e-04f, -7.55807526e-02f},
4322 {-7.55994277e+02f, 3.16730098e-04f, 4.78306139e-01f},
4323 {-1.02363977e+03f, 1.20223470e-04f, 9.36662319e-01f},
4324 {-1.26571316e+03f, 4.87340896e-06f, 1.27054498e+00f},
4325 {-1.42529332e+03f, -4.01150431e-05f, 1.43972784e+00f},
4326 {-1.17554822e+03f, -2.16378048e-05f, 1.30408023e+00f},
4327 {-5.00799571e+02f, -4.59832026e-06f, 1.09098763e+00f}};
4330 {5.96945309e-11f, -4.85742887e-08f, -9.70622247e-05f, -4.07936148e-03f},
4331 {2.40430366e-11f, 5.55021075e-08f, -1.98503712e-04f, 2.89312858e-02f},
4332 {-1.40949732e-11f, 1.89878968e-07f, -3.56632824e-04f, 9.10767778e-02f},
4333 {-3.61460868e-11f, 2.84822009e-07f, -4.93211319e-04f, 1.56723440e-01f},
4334 {-1.97075738e-11f, 1.75359352e-07f, -2.50542825e-04f, -2.22783266e-02f},
4335 {-1.61997957e-13f, -1.64216008e-08f, 3.86216271e-04f, -7.38077418e-01f},
4336 {6.72650283e-13f, -2.73078809e-08f, 4.24098264e-04f, -7.52335691e-01f}};
4340 if (t >= 12000.0f) {
4341 rec709[0] = 0.8262954810464208f;
4342 rec709[1] = 0.9945080501520986f;
4343 rec709[2] = 1.566307710274283f;
4345 else if (t < 800.0f) {
4346 rec709[0] = 5.413294490189271f;
4347 rec709[1] = -0.20319390035873933f;
4348 rec709[2] = -0.0822535242887164f;
4351 int i = (t >= 6365.0f) ? 6 :
4352 (t >= 3315.0f) ? 5 :
4353 (t >= 1902.0f) ? 4 :
4354 (t >= 1449.0f) ? 3 :
4355 (t >= 1167.0f) ? 2 :
4363 const float t_inv = 1.0f / t;
4364 rec709[0] = r[0] * t_inv + r[1] * t + r[2];
4365 rec709[1] = g[0] * t_inv + g[1] * t + g[2];
4366 rec709[2] = ((
b[0] * t +
b[1]) * t +
b[2]) * t +
b[3];
4388 for (
int i = 0; i < width; i++) {
4407 {0.0014f, 0.0000f, 0.0065f}, {0.0022f, 0.0001f, 0.0105f}, {0.0042f, 0.0001f, 0.0201f},
4408 {0.0076f, 0.0002f, 0.0362f}, {0.0143f, 0.0004f, 0.0679f}, {0.0232f, 0.0006f, 0.1102f},
4409 {0.0435f, 0.0012f, 0.2074f}, {0.0776f, 0.0022f, 0.3713f}, {0.1344f, 0.0040f, 0.6456f},
4410 {0.2148f, 0.0073f, 1.0391f}, {0.2839f, 0.0116f, 1.3856f}, {0.3285f, 0.0168f, 1.6230f},
4411 {0.3483f, 0.0230f, 1.7471f}, {0.3481f, 0.0298f, 1.7826f}, {0.3362f, 0.0380f, 1.7721f},
4412 {0.3187f, 0.0480f, 1.7441f}, {0.2908f, 0.0600f, 1.6692f}, {0.2511f, 0.0739f, 1.5281f},
4413 {0.1954f, 0.0910f, 1.2876f}, {0.1421f, 0.1126f, 1.0419f}, {0.0956f, 0.1390f, 0.8130f},
4414 {0.0580f, 0.1693f, 0.6162f}, {0.0320f, 0.2080f, 0.4652f}, {0.0147f, 0.2586f, 0.3533f},
4415 {0.0049f, 0.3230f, 0.2720f}, {0.0024f, 0.4073f, 0.2123f}, {0.0093f, 0.5030f, 0.1582f},
4416 {0.0291f, 0.6082f, 0.1117f}, {0.0633f, 0.7100f, 0.0782f}, {0.1096f, 0.7932f, 0.0573f},
4417 {0.1655f, 0.8620f, 0.0422f}, {0.2257f, 0.9149f, 0.0298f}, {0.2904f, 0.9540f, 0.0203f},
4418 {0.3597f, 0.9803f, 0.0134f}, {0.4334f, 0.9950f, 0.0087f}, {0.5121f, 1.0000f, 0.0057f},
4419 {0.5945f, 0.9950f, 0.0039f}, {0.6784f, 0.9786f, 0.0027f}, {0.7621f, 0.9520f, 0.0021f},
4420 {0.8425f, 0.9154f, 0.0018f}, {0.9163f, 0.8700f, 0.0017f}, {0.9786f, 0.8163f, 0.0014f},
4421 {1.0263f, 0.7570f, 0.0011f}, {1.0567f, 0.6949f, 0.0010f}, {1.0622f, 0.6310f, 0.0008f},
4422 {1.0456f, 0.5668f, 0.0006f}, {1.0026f, 0.5030f, 0.0003f}, {0.9384f, 0.4412f, 0.0002f},
4423 {0.8544f, 0.3810f, 0.0002f}, {0.7514f, 0.3210f, 0.0001f}, {0.6424f, 0.2650f, 0.0000f},
4424 {0.5419f, 0.2170f, 0.0000f}, {0.4479f, 0.1750f, 0.0000f}, {0.3608f, 0.1382f, 0.0000f},
4425 {0.2835f, 0.1070f, 0.0000f}, {0.2187f, 0.0816f, 0.0000f}, {0.1649f, 0.0610f, 0.0000f},
4426 {0.1212f, 0.0446f, 0.0000f}, {0.0874f, 0.0320f, 0.0000f}, {0.0636f, 0.0232f, 0.0000f},
4427 {0.0468f, 0.0170f, 0.0000f}, {0.0329f, 0.0119f, 0.0000f}, {0.0227f, 0.0082f, 0.0000f},
4428 {0.0158f, 0.0057f, 0.0000f}, {0.0114f, 0.0041f, 0.0000f}, {0.0081f, 0.0029f, 0.0000f},
4429 {0.0058f, 0.0021f, 0.0000f}, {0.0041f, 0.0015f, 0.0000f}, {0.0029f, 0.0010f, 0.0000f},
4430 {0.0020f, 0.0007f, 0.0000f}, {0.0014f, 0.0005f, 0.0000f}, {0.0010f, 0.0004f, 0.0000f},
4431 {0.0007f, 0.0002f, 0.0000f}, {0.0005f, 0.0002f, 0.0000f}, {0.0003f, 0.0001f, 0.0000f},
4432 {0.0002f, 0.0001f, 0.0000f}, {0.0002f, 0.0001f, 0.0000f}, {0.0001f, 0.0000f, 0.0000f},
4433 {0.0001f, 0.0000f, 0.0000f}, {0.0001f, 0.0000f, 0.0000f}, {0.0000f, 0.0000f, 0.0000f}};
4437 float ii = (lambda_nm - 380.0f) * (1.0f / 5.0f);
4440 if (i < 0 || i >= 80) {
4448 xyz[0] = c[0] + ii * (c[3] - c[0]);
4449 xyz[1] = c[1] + ii * (c[4] - c[1]);
4450 xyz[2] = c[2] + ii * (c[5] - c[2]);
4469 for (
int i = 0; i < width; i++) {
4470 float wavelength = 380 + 400 /
float(width) *
float(i);
#define FOREACH_MAIN_ID_END
#define FOREACH_MAIN_ID_BEGIN(_bmain, _id)
#define CMP_NODE_OUTPUT_FILE
#define CMP_NODE_CONVERT_COLOR_SPACE
#define CMP_NODE_CONVERT_TO_DISPLAY
File and directory operations.
#define BLI_path_join(...)
#define STRNCPY_UTF8(dst, src)
#define BLI_MUTEX_INITIALIZER
#define CLOG_ERROR(clg_ref,...)
#define CLOG_DEBUG(clg_ref,...)
#define CLOG_WARN(clg_ref,...)
#define CLOG_INFO_NOCHECK(clg_ref, format,...)
#define CLOG_AT_LEVEL(clg_ref, verbose_level,...)
#define CLOG_INFO(clg_ref,...)
ID and Library types, which are fundamental for SDNA.
#define ID_IS_LINKED(_id)
#define MAX_COLORSPACE_NAME
Function declarations for filter.cc.
Read Blender memory allocation and freeing.
#define OCIO_ROLE_COLOR_PICKING
#define OCIO_ROLE_VIDEO_REC709
#define OCIO_ROLE_TEXTURE_PAINT
#define OCIO_ROLE_DEFAULT_FLOAT
#define OCIO_ROLE_DEFAULT_SEQUENCER
#define OCIO_ROLE_DEFAULT_BYTE
#define OCIO_ROLE_ACES_INTERCHANGE
#define OCIO_ROLE_SCENE_LINEAR
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
static ColormanageProcessor display_processor_new(const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, ColorManagedDisplaySpace display_space=DISPLAY_SPACE_DRAW, bool inverse=false, const char *from_colorspace=nullptr)
void apply(float *buffer, int width, int height, int channels, bool predivide) const
void apply_v3(float pixel[3]) const
ColormanageProcessor & operator=(ColormanageProcessor &&other) noexcept
bool is_data_result() const
void apply_byte(unsigned char *buffer, int width, int height, int channels) const
static ColormanageProcessor colorspace_processor_from_scene_linear_new(const ColorSpace &to_colorspace)
void apply_v4_predivide(float pixel[4]) const
static ColormanageProcessor colorspace_processor_new(StringRefNull from_colorspace, StringRefNull to_colorspace)
void apply_v4(float pixel[4]) const
static ColormanageProcessor colorspace_processor_to_scene_linear_new(const ColorSpace &from_colorspace)
static std::optional< ColormanageProcessor > display_processor_for_imbuf(const ImBuf *ibuf, const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, ColorManagedDisplaySpace display_space=DISPLAY_SPACE_DRAW)
void apply_pixel(float *pixel, int channels) const
ColormanageProcessor()=default
constexpr int64_t first() const
constexpr int64_t size() const
constexpr IndexRange()=default
SubIterator begin() const
auto add_or_modify(const Key &key, const CreateValueF &create_value, const ModifyValueF &modify_value) -> decltype(create_value(nullptr))
ItemIterator items() const &
constexpr MutableSpan()=default
constexpr const char * c_str() const
constexpr StringRef drop_suffix(int64_t n) const
void prepend(const T &value)
bool contains(const T &value) const
void append(const T &value)
IndexRange index_range() const
NonCopyable(const NonCopyable &other)=delete
constexpr bool startswith(StringRef prefix) const
constexpr bool is_empty() const
constexpr int64_t find(char c, int64_t pos=0) const
constexpr StringRef substr(int64_t start, int64_t size) const
constexpr bool endswith(StringRef suffix) const
constexpr const char * c_str() const
virtual void apply_rgba_predivide(float rgba[4]) const =0
virtual void apply_predivide(const PackedImage &image) const =0
virtual bool is_noop() const =0
virtual void apply_rgb(float rgb[3]) const =0
virtual void apply(const PackedImage &image) const =0
virtual void apply_rgba(float rgba[4]) const =0
virtual StringRefNull name() const =0
virtual const CPUProcessor * get_to_scene_linear_cpu_processor() const =0
virtual const CPUProcessor * get_from_scene_linear_cpu_processor() const =0
virtual bool is_data() const =0
virtual StringRefNull interop_id() const =0
virtual float3 get_default_luma_coefs() const =0
virtual int get_num_looks() const =0
static std::unique_ptr< Config > create_fallback()
virtual const Display * get_display_by_index(int index) const =0
virtual const ColorSpace * get_color_space_by_interop_id(StringRefNull interop_id) const =0
virtual const ColorSpace * get_color_space(StringRefNull name) const =0
static std::unique_ptr< Config > create_from_environment()
virtual int get_num_displays() const =0
virtual float3x3 get_xyz_to_scene_linear_matrix() const =0
virtual StringRefNull name() const =0
virtual const View * get_view_by_name(StringRefNull name) const =0
virtual const CPUProcessor * get_to_scene_linear_cpu_processor(bool use_display_emulation) const =0
virtual const CPUProcessor * get_from_scene_linear_cpu_processor(bool use_display_emulation) const =0
virtual const View * get_default_view() const =0
virtual bool is_hdr() const =0
virtual int get_num_views() const =0
virtual StringRefNull ui_name() const =0
virtual const View * get_untonemapped_view() const =0
virtual StringRefNull description() const =0
virtual const View * get_view_by_index(int index) const =0
virtual StringRefNull view() const =0
virtual StringRefNull description() const =0
virtual StringRefNull name() const =0
virtual StringRefNull ui_name() const =0
virtual StringRefNull process_space() const =0
virtual const ColorSpace * display_colorspace() const =0
virtual StringRefNull name() const =0
virtual bool support_emulation() const =0
virtual StringRefNull description() const =0
virtual Gamut gamut() const =0
virtual bool is_hdr() const =0
virtual const ScopeInfo & scope_info() const =0
virtual int max_nits() const
#define DISPLAY_BUFFER_CHANNELS
#define image(slot, qualifiers, format)
MatBase< C, R > inverse(MatBase< C, R >) RET
bNodeTree * node_tree_from_id(ID *id)
ColorSceneLinear4f< eAlpha::Straight > unpremultiply_alpha(const ColorSceneLinear4f< Alpha > &color)
ColorSceneLinear4f< eAlpha::Premultiplied > premultiply_alpha(const ColorSceneLinear4f< Alpha > &color)
bool scene_linear_is_rec709
float3x3 rec2020_to_scene_linear
float3x3 acescg_to_scene_linear
float3x3 aces_to_scene_linear
float3x3 scene_linear_to_rec2020
float3x3 rec709_to_scene_linear
float3x3 scene_linear_to_xyz
float3x3 scene_linear_to_rec709
float3x3 scene_linear_to_acescg
float3x3 scene_linear_to_aces
float3x3 xyz_to_scene_linear
T clamp(const T &a, const T &min, const T &max)
float3 whitepoint_from_temp_tint(float temperature, float tint)
bool whitepoint_to_temp_tint(const float3 &white, float &temperature, float &tint)
CartesianBasis invert(const CartesianBasis &basis)
bool is_equal(const MatBase< T, NumCol, NumRow > &a, const MatBase< T, NumCol, NumRow > &b, const T epsilon=T(0))
T determinant(const MatBase< T, Size, Size > &mat)
StringRef interop_id_drop_namespace(const StringRef interop_id)
void foreach_strip(ListBaseT< Strip > *seqbase, ForEachFunc callback, void *user_data)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
void IMB_colormanagement_transform_byte_to_float(float *float_buffer, const unsigned char *byte_buffer, int width, int height, int channels, const char *from_colorspace, const char *to_colorspace)
void IMB_alpha_under_color_byte(unsigned char *rect, int x, int y, const float backcol[3])
blender::GlobalGPUState global_gpu_state
static bool colormanage_check_colorspace_settings(ColorManagedColorspaceSettings *settings, const char *what, const CLG_Level log_level)
static void curve_mapping_apply_pixel(const CurveMapping *curve_mapping, float *pixel, int channels)
bool BKE_image_format_is_byte(const ImageFormatData *imf)
void IMB_colormanagement_assign_float_colorspace(ImBuf *ibuf, const char *name)
const char * IMB_colormanagement_display_get_none_name()
static void do_processor_transform_thread(ProcessorTransformThread *handle)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void colormanage_update_matrices(const ocio::Config &config)
void IMB_colormanagement_view_items_add(EnumPropertyItem **items, int *totitem, const char *display_name)
static const char * imbuf_colorspace_name(const ImBuf *ibuf, const bool prefer_byte_buffer)
static bool get_display_emulation(const ColorManagedDisplaySettings &display_settings)
static char global_role_video_rec709[MAX_COLORSPACE_NAME]
static void colormanage_restore_ocio_env(const std::optional< std::string > &old_ocio_env)
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
CurveMapping * BKE_curvemapping_copy(const CurveMapping *cumap)
@ COLORMANAGE_VIEW_USE_WHITE_BALANCE
@ COLORMANAGE_VIEW_USE_CURVES
MINLINE void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
void IMB_buffer_float_from_byte(float *dest, const unsigned char *src, int width, int height, int dest_stride, int src_stride)
char * STRNCPY(char(&dst)[N], const char *src)
void IMB_colormanagement_colorspace_items_add(EnumPropertyItem **items, int *totitem)
void IMB_free_byte_pixels(ImBuf *ibuf)
void IMB_colormanagement_colorspace_from_ibuf_ftype(ColorManagedColorspaceSettings *colorspace_settings, ImBuf *ibuf)
void IMB_colormanagement_scene_linear_to_colorspace(float *buffer, int width, int height, int channels, const ColorSpace *colorspace)
std::string BKE_blender_project_path_resolve(StringRef path, const bke::BlenderProject &project)
const ColorSpace * IMB_colormanagement_space_from_cicp(const int cicp[4], ColorManagedFileOutput output)
static void do_display_buffer_apply_thread(DisplayBufferThread *handle)
static const float imb_working_space_compare_threshold
bool IMB_colormanagement_display_is_hdr(const ColorManagedDisplaySettings *display_settings, const char *view_name)
BLI_INLINE void IMB_colormanagement_xyz_to_scene_linear(float scene_linear[3], const float xyz[3])
int IMB_colormanagement_colorspace_get_named_index(const char *name)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void IMB_colormanagement_project_read_post(Main *bmain)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void IMB_colormanagement_finish_glsl_draw()
static void colormanagement_transform_ex(uchar *byte_buffer, float *float_buffer, int width, int height, int channels, const char *from_colorspace, const char *to_colorspace, bool predivide)
static void display_buffer_apply_threaded(ImBuf *ibuf, const float *buffer, uchar *byte_buffer, float *display_buffer, uchar *display_buffer_byte, ColormanageProcessor *cm_processor)
Vector< char > IMB_colormanagement_space_to_icc_profile(const ColorSpace *colorspace)
const char * IMB_colormanagement_display_get_default_view_transform_name(const ColorManagedDisplay *display)
const ImFileType * IMB_file_type_from_ibuf(const ImBuf *ibuf)
const char * IMB_colormanagement_view_get_raw_or_default_name(const char *display_name)
bool IMB_colormanagement_space_is_srgb(const ColorSpace *colorspace)
void IMB_colormanagement_look_items_add(EnumPropertyItem **items, int *totitem, const char *view_name)
int IMB_colormanagement_look_get_named_index(const char *name)
const char * IMB_colormanagement_colorspace_get_indexed_name(int index)
static void display_buffer_apply_get_linear_buffer(DisplayBufferThread *handle, int height, float *linear_buffer, bool *is_straight_alpha)
static const int CICP_TRC_BT709
StringRefNull IMB_colormanagement_config_path_get()
static const int CICP_RANGE_LIMITED
static const ColorSpace * video_rec709_colorspace()
void srgb_to_linearrgb_v3_v3(float linear[3], const float srgb[3])
bool IMB_colormanagement_display_is_wide_gamut(const ColorManagedDisplaySettings *display_settings, const char *view_name)
void BLI_mutex_unlock(ThreadMutex *mutex)
void IMB_premultiply_rect_float(float *rect_float, int channels, int w, int h)
bool IMB_alloc_byte_pixels(ImBuf *ibuf, bool initialize_pixels=true)
const char * IMB_colormanagement_look_validate_for_view(const char *view_name, const char *look_name)
void BLI_init_srgb_conversion()
void IMB_colormanagement_working_space_items_add(EnumPropertyItem **items, int *totitem)
static const int CICP_TRC_PQ
void IMB_colormanagement_transform_v4(float pixel[4], const char *from_colorspace, const char *to_colorspace)
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
float BKE_curvemap_evaluateF(const CurveMapping *cumap, const CurveMap *cuma, float value)
static Vector< ColorManagedConfigPath > colormanage_config_candidates_get(const Main *bmain)
static char global_role_scene_linear_default[MAX_COLORSPACE_NAME]
float3x3 global_scene_linear_to_xyz_default
static float cie_color_match[81][3]
static bool colormanage_check_display_settings(ColorManagedDisplaySettings *display_settings, const char *what, const ocio::Display *default_display, const CLG_Level log_level)
bool IMB_colormanagement_setup_glsl_draw_from_space(const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, const ColorSpace *from_colorspace, float dither, bool predivide, bool do_overlay_merge, ColorManagedDisplaySpace display_space=DISPLAY_SPACE_DRAW, float opacity=1.0f)
void colormanage_imbuf_make_linear(ImBuf *ibuf, const char *from_colorspace, const ColorManagedFileOutput output)
static const int CICP_TRC_LINEAR
const char * IMB_colormanagement_get_byte_colorspace(const ImBuf *ibuf)
static const int CICP_TRC_SRGB
@ COLOR_ROLE_ACES_INTERCHANGE
@ COLOR_ROLE_TEXTURE_PAINTING
@ COLOR_ROLE_SCENE_LINEAR
@ COLOR_ROLE_DEFAULT_SEQUENCER
@ COLOR_ROLE_DEFAULT_FLOAT
@ COLOR_ROLE_COLOR_PICKING
@ COLOR_ROLE_DEFAULT_BYTE
const char * IMB_colormanagement_display_get_indexed_name(int index)
auto BKE_blender_project_read_callback(const Main *bmain, Fn lambda)
static CurveMapping * update_glsl_curve_mapping(const ColorManagedViewSettings *view_settings)
void IMB_buffer_byte_from_float(unsigned char *dest, const float *src, int src_channels, float dither, bool predivide, int width, int height, int stride, int start_y=0)
bool IMB_colormanagement_space_to_cicp(const ColorSpace *colorspace, ColorManagedFileOutput output, bool rgb_matrix, int cicp[4])
void BKE_curvemapping_premultiply(CurveMapping *cumap, bool restore)
void BKE_curvemapping_free(CurveMapping *cumap)
static const char * colormanage_config_source_identifier(const ColorManagedConfigSource source)
void BLI_setenv(const char *env, const char *val) ATTR_NONNULL(1)
static bool colormanage_load_config(const ocio::Config &config, const bool validate_only=false)
void IMB_colormanagement_colorspace_interop_id_set(char *name, char *interop_id, int index)
void IMB_colormanagement_scene_linear_to_display_buffer(uint8_t *display_buffer, const float *linear_buffer, int width, int height, const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings)
void IMB_colormanagement_imbuf_to_byte_texture(unsigned char *out_buffer, int offset_x, int offset_y, int width, int height, const ImBuf *ibuf, bool store_premultiplied)
const char * IMB_colormanagement_working_space_get_default()
MINLINE void mul_v3_fl(float r[3], float f)
ImBuf * IMB_dupImBuf(const ImBuf *ibuf1)
static StringRef view_filter_for_look(StringRefNull view_name)
void colormanage_environment_setup_for_test(std::optional< std::string > blender_ocio_env, std::optional< std::string > ocio_env)
void colormanagement_init()
static void colormanage_set_ocio_env(const char *filepath, std::optional< std::string > &r_old_ocio_env)
static bool imb_colormanagement_working_space_set_from_matrix(Main *bmain, const char *name, const float3x3 &scene_linear_to_xyz, const bool report_missing)
void IMB_colormanagement_interop_id_items_add(EnumPropertyItem **items, int *totitem)
static char global_role_data[MAX_COLORSPACE_NAME]
void IMB_colormanagement_working_space_init_default(Main *bmain)
bool IMB_colormanagement_setup_glsl_draw(const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, float dither, bool predivide)
void IMB_float_from_byte(ImBuf *ibuf)
bool IMB_colormanagement_space_is_scene_linear(const ColorSpace *colorspace)
static pthread_mutex_t processor_lock
bool IMB_colormanagement_space_is_scene_linear_srgb(const ColorSpace *colorspace)
void IMB_colormanagement_colorspace_to_scene_linear_v3(float pixel[3], const ColorSpace *colorspace)
int IMB_colormanagement_view_get_id_by_name(const char *name)
std::optional< std::string > BKE_appdir_folder_id(int folder_id, const char *subfolder) ATTR_WARN_UNUSED_RESULT
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
static bool is_colorspace_same_as_display(const ColorSpace *colorspace, const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings)
static char global_role_aces_interchange[MAX_COLORSPACE_NAME]
const IDTypeInfo * BKE_idtype_get_info_from_id(const ID *id)
const char * IMB_colormanagement_view_get_name_by_id(int index)
void IMB_colormanagement_scene_linear_to_color_picking_v3(float color_picking[3], const float scene_linear[3])
void BLI_mutex_lock(ThreadMutex *mutex)
int IMB_colormanagement_working_space_get_named_index(const char *name)
static std::shared_ptr< const ocio::CPUProcessor > get_display_buffer_processor(const ColorManagedDisplaySettings &display_settings, const char *look, const char *view_transform, const float exposure, const float gamma, const float temperature, const float tint, const bool use_white_balance, const char *from_colorspace, const ColorManagedDisplaySpace target, const bool inverse=false)
static bool colormanage_use_look(const char *look_name, const char *view_name)
bool IMB_colormanagement_display_support_emulation(const ColorManagedDisplaySettings *display_settings, const char *view_name)
bool IMB_colormanagement_switch_config(const char *filepath)
bool colormanage_config_reload(Main *bmain)
static const float blackbody_table_b[7][4]
static const int CICP_PRI_REC709
void IMB_colormanagement_scene_linear_to_colorspace_v3(float pixel[3], const ColorSpace *colorspace)
BLI_INLINE void IMB_colormanagement_rec709_to_scene_linear(float scene_linear[3], const float rec709[3])
static char global_role_texture_painting[MAX_COLORSPACE_NAME]
ocio::ScopeInfo IMB_colormanagement_get_scope_info(const ColorManagedDisplaySettings *display_settings, const ColorManagedViewSettings *view_settings)
static Vector< char > imb_icc_profile_from_filepath(StringRef filepath)
static bool colormanage_check_colorspace_name(char *name, char *interop_id, const char *what, const CLG_Level log_level)
void DEG_id_tag_update(ID *id, unsigned int flags)
const char * IMB_colormanagement_role_colorspace_name_get(int role)
static const int CICP_MATRIX_REC2020_NCL
BMesh const char void * data
static const int CICP_TRC_G22
int IMB_colormanagement_colorspace_get_interop_id_index(const char *name, const char *interop_id)
static char global_role_scene_linear[MAX_COLORSPACE_NAME]
void IMB_colormanagement_transform_byte(unsigned char *buffer, int width, int height, int channels, const char *from_colorspace, const char *to_colorspace)
static void colormanage_free_config()
void IMB_colormanagement_validate_settings(const ColorManagedDisplaySettings *display_settings, ColorManagedViewSettings *view_settings)
const char * IMB_colormanagement_colorspace_get_family(const ColorSpace *colorspace)
void IMB_colormanagement_colorspace_settings_set(ColorManagedColorspaceSettings *settings, const char *name)
const ColorSpace * colormanage_colorspace_get_roled(const int role)
static void blackbody_temperature_to_rec709(float rec709[3], float t)
const char * IMB_colormanagement_space_from_filepath_rules(const char *filepath)
static const float blackbody_table_r[7][3]
ColorManagedConfigSource IMB_colormanagement_config_source_get()
const char * IMB_colormanagement_colorspace_get_name(const ColorSpace *colorspace)
const char * IMB_colormanagement_view_get_default_name(const char *display_name)
static void imb_colormanagement_working_space_set_from_file(Main *bmain, const bool report_missing)
int IMB_colormanagement_view_max_nits(const char *display_name, const char *view_name)
void IMB_buffer_float_rgba_from_float(float *dest, const float *src, int src_channels, int width, int height)
static const float blackbody_table_g[7][3]
static const int CICP_RANGE_FULL
static VectorSet< StringRefNull > & g_all_view_names()
static bool colormanage_check_view_settings(ColorManagedDisplaySettings *display_settings, ColorManagedViewSettings *view_settings, const char *what, const CLG_Level log_level)
static const int CICP_PRI_UNSPECIFIED
void IMB_colormanagement_working_space_convert(Main *bmain, const float3x3 ¤t_scene_linear_to_xyz, const float3x3 &new_xyz_to_scene_linear, bool depsgraph_tag=false, bool linked_only=false, bool editable_assets_only=false)
void IMB_colormanagement_wavelength_to_rgb(float r_dest[4], float value)
static struct blender::GlobalColorPickingState global_color_picking_state
void IMB_colormanagement_blackbody_temperature_to_rgb(float r_dest[4], float value)
MatBase< float, 3, 3 > float3x3
void IMB_colormanagement_display_to_scene_linear_v3(float pixel[3], const ColorManagedDisplay *display, ColorManagedDisplaySpace display_space=DISPLAY_SPACE_DRAW)
void IMB_colormanagement_init_untonemapped_view_settings(ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings)
void IMB_colormanagement_colorspace_to_scene_linear_v4(float pixel[4], bool predivide, const ColorSpace *colorspace)
bool IMB_colormanagement_setup_glsl_draw_ctx(const bContext *C, float dither, bool predivide)
void IMB_colormanagement_display_settings_from_ctx(const bContext *C, ColorManagedViewSettings **r_view_settings, ColorManagedDisplaySettings **r_display_settings)
bool IMB_colormanagement_working_space_set_from_name(const char *name)
ImBuf * IMB_colormanagement_imbuf_for_write(ImBuf *ibuf, bool save_as_render, bool allocate_result, const ImageFormatData *image_format)
bool BKE_imtype_requires_linear_float(char imtype)
void IMB_colormanagement_assign_byte_colorspace(ImBuf *ibuf, const char *name)
static char global_role_default_byte[MAX_COLORSPACE_NAME]
bool IMB_colormanagement_set_whitepoint(const float whitepoint[3], float &temperature, float &tint)
bool IMB_alpha_affects_rgb(const ImBuf *ibuf)
const char * IMB_colormanagement_srgb_colorspace_name_get()
static const int CICP_MATRIX_BT709
SpaceImage * CTX_wm_space_image(const bContext *C)
void IMB_colormanagement_file_save_post(Main *bmain)
float3x3 IMB_colormanagement_get_scene_linear_to_xyz()
void BKE_curvemapping_evaluate_premulRGBF(const CurveMapping *cumap, float vecout[3], const float vecin[3])
static char global_role_default_sequencer[MAX_COLORSPACE_NAME]
void IMB_colormanagement_undo_read_post(Main *bmain, const MainColorspace &old_colorspace)
const ColorSpace * IMB_colormanagement_space_from_interop_id(StringRefNull interop_id)
const ColorSpace * IMB_colormangement_display_get_color_space(const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings)
static ColorManagedStartupEnv & g_startup_env()
void IMB_colormanagement_scene_linear_to_display_v3(float pixel[3], const ColorManagedDisplay *display, ColorManagedDisplaySpace display_space=DISPLAY_SPACE_DRAW)
ocio::Config ColorManagedConfig
bool IMB_colormanagement_space_is_data(const ColorSpace *colorspace)
static void imb_colormanagement_working_space_init_startup(Main *bmain)
StringRefNull IMB_colormanagement_space_get_interop_id(const ColorSpace *colorspace)
static void colormanage_clear_config()
void IMB_colormanagement_color_picking_to_scene_linear_v3(float scene_linear[3], const float color_picking[3])
void IMB_colormanagement_blackbody_temperature_to_rgb_table(float *r_table, int width, float min, float max)
void IMB_colormanagement_file_read_post(Main *bmain, Main *old_bmain, bool is_startup, bool have_editable_assets)
void IMB_byte_from_float(ImBuf *ibuf)
float3x3 IMB_colormanagement_get_xyz_to_scene_linear()
const ColorSpace * colormanage_colorspace_get_named(const char *name)
static char global_role_default_float[MAX_COLORSPACE_NAME]
MINLINE float max_ff(float a, float b)
void colormanagement_exit()
const char * IMB_colormanagement_display_get_default_name()
const ColorSpace * IMB_colormanagement_space_get_named(const char *name)
static void colormanage_config_load_candidates(const Span< ColorManagedConfigPath > candidates)
static const int CICP_MATRIX_RGB
MINLINE void clamp_v3(float vec[3], float min, float max)
void IMB_colormanagement_colorspace_name_set(char *name, char *interop_id, const char *new_name)
static void do_display_buffer_apply_no_processor(DisplayBufferThread *handle)
ColorManagedConfig & IMB_colormanagement_get_config()
bool IMB_colormanagement_setup_glsl_draw_to_scene_linear(const char *from_colorspace_name, bool predivide)
const char * IMB_colormanagement_colorspace_get_description(const ColorSpace *colorspace)
static const int CICP_TRC_SMPTE428
const char * IMB_colormanagement_look_get_indexed_name(int index)
void IMB_colormanagement_wavelength_to_rgb_table(float *r_table, int width)
MINLINE void rgb_uchar_to_float(float r_col[3], const unsigned char col_ub[3])
static void colormanage_display_buffer_process(ImBuf *ibuf, float *display_buffer, uchar *display_buffer_byte, const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, const ColorManagedDisplaySpace display_space)
static float3 imb_working_space_convert(const float3x3 &m, const bool is_smaller_gamut, const float3 in_rgb)
@ COLORMANAGE_DISPLAY_EMULATION_OFF
@ COLORMANAGE_DISPLAY_EMULATION_AUTO
Scene * CTX_data_scene(const bContext *C)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
const ColorManagedDisplay * IMB_colormanagement_display_get_named(const char *name)
MINLINE void copy_v4_v4(float r[4], const float a[4])
void IMB_colormanagement_get_whitepoint(float temperature, float tint, float whitepoint[3])
static ImBuf * imbuf_ensure_editable(ImBuf *ibuf, ImBuf *colormanaged_ibuf, bool allocate_result)
static void processor_transform_apply_threaded(uchar *byte_buffer, float *float_buffer, int width, int height, int channels, ColormanageProcessor *cm_processor, bool predivide)
const char * IMB_colormanagement_working_space_get_indexed_name(int index)
static bool colormanage_role_color_space_name_get(const ocio::Config &config, char *colorspace_name, const char *role, const char *backup_role, const bool optional=false)
static std::unique_ptr< ocio::Config > & g_config()
static void colormanage_name_to_interop_id(const char *name, char *interop_id)
void IMB_alpha_under_color_float(float *rect_float, int x, int y, float backcol[3])
bool BLI_path_make_safe_filename(char *filename) ATTR_NONNULL(1)
@ DISPLAY_SPACE_IMAGE_OUTPUT
@ DISPLAY_SPACE_COLOR_INSPECTION
@ DISPLAY_SPACE_VIDEO_OUTPUT
VecBase< float, 3 > float3
void IMB_colormanagement_display_items_add(EnumPropertyItem **items, int *totitem)
void colormanage_imbuf_set_default_spaces(ImBuf *ibuf)
bool IMB_colormanagement_space_name_is_data(const char *name)
static const int CICP_TRC_HLG
static char global_role_color_picking[MAX_COLORSPACE_NAME]
static void display_buffer_init_handle(DisplayBufferThread *handle, int start_line, int tot_line, DisplayBufferInitData *init_data)
void IMB_colormanagement_transform_float(float *buffer, int width, int height, int channels, const char *from_colorspace, const char *to_colorspace, bool predivide)
static StringRefNull colormanage_find_matching_view_name(const ocio::Display *display, StringRefNull view_name)
static Vector< ColorManagedConfigPath > & g_config_requested()
static bool colormanage_compatible_look(const ocio::Look *look, StringRef view_filter)
bool IMB_colormanagement_setup_glsl_draw_from_space_ctx(const bContext *C, const ColorSpace *from_colorspace, float dither, bool predivide)
static const int CICP_TRC_UNSPECIFIED
static void processor_transform_init_handle(ProcessorTransformThread *handle, int start_line, int tot_line, ProcessorTransformInitData *init_data)
static const int CICP_PRI_P3D65
static bool imb_colormanagement_display_processor_needed(const ImBuf *ibuf, const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, const ColorManagedDisplaySpace display_space)
void IMB_colormanagement_colorspace_to_scene_linear(float *buffer, int width, int height, int channels, const ColorSpace *colorspace, bool predivide)
void IMB_colormanagement_imbuf_to_float_texture(float *out_buffer, int offset_x, int offset_y, int width, int height, const ImBuf *ibuf, bool store_premultiplied)
void IMB_colormanagement_check_file_config(Main *bmain)
const char * IMB_colormanagement_get_float_colorspace(const ImBuf *ibuf)
void IMB_colormanagement_pixel_to_display_space_v4(float result[4], const float pixel[4], const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, ColorManagedDisplaySpace display_space=DISPLAY_SPACE_DRAW)
void IMB_colormanagement_copy_settings(ImBuf *ibuf_src, ImBuf *ibuf_dst)
static const int CICP_PRI_XYZD65
bool IMB_colormanagement_space_name_is_scene_linear(const char *name)
MINLINE void straight_to_premul_v4(float color[4])
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
const char * BLI_getenv(const char *env) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
BLI_INLINE void IMB_colormanagement_scene_linear_to_xyz(float xyz[3], const float scene_linear[3])
MINLINE void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
ocio::ColorSpace ColorSpace
static const int CICP_PRI_REC2020
const char * IMB_colormanagement_look_get_default_name()
const char * IMB_colormanagement_working_space_get()
int IMB_colormanagement_display_get_named_index(const char *name)
ocio::Display ColorManagedDisplay
static void wavelength_to_xyz(float xyz[3], float lambda_nm)
bool IMB_colormanagement_space_name_is_srgb(const char *name)
static ColorManagedConfigPath & g_config_active()
static std::string colormanage_project_config_path_resolve(const StringRef path, const bke::BlenderProject &project)
MINLINE void premul_to_straight_v4_v4(float straight[4], const float premul[4])
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ImageFormatData im_format
std::string unresolved_path
friend bool operator==(const ColorManagedConfigPath &a, const ColorManagedConfigPath &b)
ColorManagedConfigSource source
eColorManageDisplay_Emulation emulation
std::optional< std::string > blender_ocio
std::optional< std::string > ocio
struct CurveMapping * curve_mapping
eColorManageView_Flag flag
const char * float_colorspace
const char * byte_colorspace
ColormanageProcessor * cm_processor
uchar * display_buffer_byte
const char * float_colorspace
const char * byte_colorspace
uchar * display_buffer_byte
ColormanageProcessor * cm_processor
ListBaseT< Strip > seqbase
GlobalColorPickingState()=default
std::shared_ptr< const ocio::CPUProcessor > cpu_processor_to
std::shared_ptr< const ocio::CPUProcessor > cpu_processor_from
int curve_mapping_timestamp
CurveMapping * orig_curve_mapping
CurveMapping * curve_mapping
IDTypeForeachColorFunction foreach_working_space_color
const ColorSpace * colorspace
const ColorSpace * colorspace
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
const ColorSpace & byte_colorspace() const
const uint8_t * byte_data() const
uint8_t * byte_data_for_write()
bool colorspace_is_data() const
const float * float_data() const
const ColorSpace & float_colorspace() const
float * float_data_for_write()
bool(*) save(ImBuf *ibuf, const char *filepath, ImBufFlags flags)
bke::library::LibraryRuntime * runtime
bool is_missing_opencolorio_config
float3x3 scene_linear_to_xyz
char scene_linear_name[64]
bool is_failed_opencolorio_config
MainColorspace colorspace
ListBaseT< Scene > scenes
static MatBase identity()
ImageFormatData im_format
ColorManagedViewSettings view_settings
ColorManagedDisplaySettings display_settings
ColorManagedColorspaceSettings sequencer_colorspace_settings
StringRefNull from_colorspace
bool use_display_emulation
bool use_display_emulation
CurveMapping * curve_mapping
StringRefNull from_colorspace