81
85
static char global_role_default_float[MAX_COLORSPACE_NAME];
82
86
static char global_role_default_sequencer[MAX_COLORSPACE_NAME];
84
static ListBase global_colorspaces = {NULL};
85
static ListBase global_displays = {NULL};
86
static ListBase global_views = {NULL};
88
static ListBase global_colorspaces = {NULL, NULL};
89
static ListBase global_displays = {NULL, NULL};
90
static ListBase global_views = {NULL, NULL};
91
static ListBase global_looks = {NULL, NULL};
88
93
static int global_tot_colorspace = 0;
89
94
static int global_tot_display = 0;
90
95
static int global_tot_view = 0;
96
static int global_tot_looks = 0;
92
98
/* lock used by pre-cached processors getters, so processor wouldn't
93
99
* be created several times
107
113
OCIO_ConstProcessorRcPtr *processor;
109
115
/* Settings of processor for comparison. */
116
char look[MAX_COLORSPACE_NAME];
110
117
char view[MAX_COLORSPACE_NAME];
111
118
char display[MAX_COLORSPACE_NAME];
112
119
char input[MAX_COLORSPACE_NAME];
203
212
typedef struct ColormnaageCacheData {
204
213
int flag; /* view flags of cached buffer */
214
int look; /* Additional artistics transform */
205
215
float exposure; /* exposure value cached buffer is calculated with */
206
216
float gamma; /* gamma value cached buffer is calculated with */
217
float dither; /* dither value cached buffer is calculated with */
207
218
CurveMapping *curve_mapping; /* curve mapping used for cached buffer */
208
219
int curve_mapping_timestamp; /* time stamp of curve mapping used for cached buffer */
209
220
} ColormnaageCacheData;
282
293
ibuf->colormanage_cache->data = data;
285
static void colormanage_view_settings_to_cache(ColormanageCacheViewSettings *cache_view_settings,
296
static void colormanage_view_settings_to_cache(ImBuf *ibuf,
297
ColormanageCacheViewSettings *cache_view_settings,
286
298
const ColorManagedViewSettings *view_settings)
300
int look = IMB_colormanagement_look_get_named_index(view_settings->look);
288
301
int view = IMB_colormanagement_view_get_named_index(view_settings->view_transform);
303
cache_view_settings->look = look;
290
304
cache_view_settings->view = view;
291
305
cache_view_settings->exposure = view_settings->exposure;
292
306
cache_view_settings->gamma = view_settings->gamma;
307
cache_view_settings->dither = ibuf->dither;
293
308
cache_view_settings->flag = view_settings->flag;
294
309
cache_view_settings->curve_mapping = view_settings->curve_mapping;
365
380
cache_data = colormanage_cachedata_get(cache_ibuf);
367
if (cache_data->exposure != view_settings->exposure ||
382
if (cache_data->look != view_settings->look ||
383
cache_data->exposure != view_settings->exposure ||
368
384
cache_data->gamma != view_settings->gamma ||
385
cache_data->dither != view_settings->dither ||
369
386
cache_data->flag != view_settings->flag ||
370
387
cache_data->curve_mapping != curve_mapping ||
371
388
cache_data->curve_mapping_timestamp != curve_mapping_timestamp)
410
427
/* store data which is needed to check whether cached buffer could be used for color managed display settings */
411
428
cache_data = MEM_callocN(sizeof(ColormnaageCacheData), "color manage cache imbuf data");
429
cache_data->look = view_settings->look;
412
430
cache_data->exposure = view_settings->exposure;
413
431
cache_data->gamma = view_settings->gamma;
432
cache_data->dither = view_settings->dither;
414
433
cache_data->flag = view_settings->flag;
415
434
cache_data->curve_mapping = curve_mapping;
416
435
cache_data->curve_mapping_timestamp = curve_mapping_timestamp;
455
474
static void colormanage_load_config(OCIO_ConstConfigRcPtr *config)
457
int tot_colorspace, tot_display, tot_display_view, index, viewindex, viewindex2;
476
int tot_colorspace, tot_display, tot_display_view, tot_looks;
477
int index, viewindex, viewindex2;
458
478
const char *name;
470
490
for (index = 0 ; index < tot_colorspace; index++) {
471
491
OCIO_ConstColorSpaceRcPtr *ocio_colorspace;
472
492
const char *description;
473
int is_invertible, is_data;
493
bool is_invertible, is_data;
475
495
name = OCIO_configGetColorSpaceNameByIndex(config, index);
521
541
global_tot_display = tot_display;
544
tot_looks = OCIO_configGetNumLooks(config);
545
colormanage_look_add("None", "", true);
546
for (index = 0; index < tot_looks; index++) {
547
OCIO_ConstLookRcPtr *ocio_look;
548
const char *process_space;
550
name = OCIO_configGetLookNameByIndex(config, index);
551
ocio_look = OCIO_configGetLook(config, name);
552
process_space = OCIO_lookGetProcessSpace(ocio_look);
553
OCIO_lookRelease(ocio_look);
555
colormanage_look_add(name, process_space, false);
524
559
static void colormanage_free_config(void)
708
static OCIO_ConstProcessorRcPtr *create_display_buffer_processor(const char *view_transform,
746
static OCIO_ConstProcessorRcPtr *create_display_buffer_processor(const char *look,
747
const char *view_transform,
709
748
const char *display,
710
749
float exposure, float gamma,
711
750
const char *from_colorspace)
713
752
OCIO_ConstConfigRcPtr *config = OCIO_getCurrentConfig();
714
753
OCIO_DisplayTransformRcPtr *dt;
715
754
OCIO_ConstProcessorRcPtr *processor;
755
ColorManagedLook *look_descr = colormanage_look_get_named(look);
717
757
dt = OCIO_createDisplayTransform();
720
760
OCIO_displayTransformSetView(dt, view_transform);
721
761
OCIO_displayTransformSetDisplay(dt, display);
763
if (look_descr->is_noop == false) {
764
OCIO_displayTransformSetLooksOverrideEnabled(dt, true);
765
OCIO_displayTransformSetLooksOverride(dt, look);
723
768
/* fstop exposure control */
724
769
if (exposure != 0.0f) {
725
770
OCIO_MatrixTransformRcPtr *mt;
872
917
view_settings->view_transform[0] = '\0';
919
BLI_strncpy(view_settings->look, "None", sizeof(view_settings->look));
874
920
view_settings->flag = 0;
875
921
view_settings->gamma = 1.0f;
876
922
view_settings->exposure = 0.0f;
923
969
imb_freerectImBuf(ibuf);
925
971
IMB_colormanagement_transform(ibuf->rect_float, ibuf->x, ibuf->y, ibuf->channels,
926
from_colorspace, to_colorspace, TRUE);
972
from_colorspace, to_colorspace, true);
954
1000
ColorManagedDisplay *display;
955
1001
ColorManagedView *default_view = NULL;
1002
ColorManagedLook *default_look = (ColorManagedLook *) global_looks.first;
957
1004
if (view_settings->view_transform[0] == '\0') {
958
1005
display = colormanage_display_get_named(display_settings->display_device);
1031
if (view_settings->look[0] == '\0') {
1032
BLI_strncpy(view_settings->look, default_look->name, sizeof(view_settings->look));
1035
ColorManagedLook *look = colormanage_look_get_named(view_settings->look);
1037
printf("Color management: %s look \"%s\" not found, setting default \"%s\".\n",
1038
what, view_settings->look, default_look->name);
1040
BLI_strncpy(view_settings->look, default_look->name, sizeof(view_settings->look));
984
1044
/* OCIO_TODO: move to do_versions() */
985
1045
if (view_settings->exposure == 0.0f && view_settings->gamma == 0.0f) {
986
1046
view_settings->exposure = 0.0f;
1133
1194
ibuf->colormanage_flag &= ~IMB_COLORMANAGE_IS_DATA;
1197
const char *IMB_colormanagement_get_float_colorspace(ImBuf *ibuf)
1199
if (ibuf->float_colorspace) {
1200
return ibuf->float_colorspace->name;
1203
return IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_SCENE_LINEAR);
1207
const char *IMB_colormanagement_get_rect_colorspace(ImBuf *ibuf)
1209
return ibuf->rect_colorspace->name;
1136
1212
/*********************** Threaded display buffer transform routines *************************/
1138
1214
typedef struct DisplayBufferThread {
1180
1256
int channels = ibuf->channels;
1181
1257
float dither = ibuf->dither;
1182
int is_data = ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA;
1258
bool is_data = (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) != 0;
1184
1260
int offset = channels * start_line * ibuf->x;
1185
1261
int display_buffer_byte_offset = DISPLAY_BUFFER_CHANNELS * start_line * ibuf->x;
1224
1300
int buffer_size = channels * width * height;
1226
int is_data = handle->is_data;
1227
int is_data_display = handle->cm_processor->is_data_result;
1302
bool is_data = handle->is_data;
1303
bool is_data_display = handle->cm_processor->is_data_result;
1229
1305
linear_buffer = MEM_callocN(buffer_size * sizeof(float), "color conversion linear buffer");
1257
1333
if (!is_data && !is_data_display) {
1258
1334
/* convert float buffer to scene linear space */
1259
1335
IMB_colormanagement_transform(linear_buffer, width, height, channels,
1260
from_colorspace, to_colorspace, FALSE);
1336
from_colorspace, to_colorspace, false);
1263
1339
*is_straight_alpha = true;
1277
1353
if (!is_data && !is_data_display) {
1278
1354
IMB_colormanagement_transform(linear_buffer, width, height, channels,
1279
from_colorspace, to_colorspace, TRUE);
1355
from_colorspace, to_colorspace, true);
1282
1358
*is_straight_alpha = false;
1309
1385
int width = handle->width;
1310
1386
int height = handle->tot_line;
1311
1387
float dither = handle->dither;
1312
int is_data = handle->is_data;
1388
bool is_data = handle->is_data;
1314
1390
if (cm_processor == NULL) {
1315
1391
if (display_buffer_byte) {
1402
1478
display_buffer_init_handle, do_display_buffer_apply_thread);
1405
static int is_ibuf_rect_in_display_space(ImBuf *ibuf, const ColorManagedViewSettings *view_settings,
1406
const ColorManagedDisplaySettings *display_settings)
1481
static bool is_ibuf_rect_in_display_space(ImBuf *ibuf, const ColorManagedViewSettings *view_settings,
1482
const ColorManagedDisplaySettings *display_settings)
1408
1484
if ((view_settings->flag & COLORMANAGE_VIEW_USE_CURVES) == 0 &&
1409
1485
view_settings->exposure == 0.0f &&
1413
1489
const char *to_colorspace = display_transform_get_colorspace_name(view_settings, display_settings);
1415
1491
if (to_colorspace && !strcmp(from_colorspace, to_colorspace))
1422
1498
static void colormanage_display_buffer_process_ex(ImBuf *ibuf, float *display_buffer, unsigned char *display_buffer_byte,
1424
1500
const ColorManagedDisplaySettings *display_settings)
1426
1502
ColormanageProcessor *cm_processor = NULL;
1427
int skip_transform = FALSE;
1503
bool skip_transform = false;
1429
1505
/* if we're going to transform byte buffer, check whether transformation would
1430
1506
* happen to the same color space as byte buffer itself is
1435
1511
skip_transform = is_ibuf_rect_in_display_space(ibuf, view_settings, display_settings);
1438
if (skip_transform == FALSE)
1514
if (skip_transform == false)
1439
1515
cm_processor = IMB_colormanagement_display_processor_new(view_settings, display_settings);
1441
1517
display_buffer_apply_threaded(ibuf, ibuf->rect_float, (unsigned char *) ibuf->rect,
1481
1557
int channels = init_data->channels;
1482
1558
int width = init_data->width;
1483
int predivide = init_data->predivide;
1559
bool predivide = init_data->predivide;
1485
1561
int offset = channels * start_line * width;
1506
1582
int channels = handle->channels;
1507
1583
int width = handle->width;
1508
1584
int height = handle->tot_line;
1509
int predivide = handle->predivide;
1585
bool predivide = handle->predivide;
1511
1587
IMB_colormanagement_processor_apply(handle->cm_processor, buffer, width, height, channels, predivide);
1516
1592
static void processor_transform_apply_threaded(float *buffer, int width, int height, int channels,
1517
ColormanageProcessor *cm_processor, int predivide)
1593
ColormanageProcessor *cm_processor, bool predivide)
1519
1595
ProcessorTransformInitData init_data;
1534
1610
/* convert the whole buffer from specified by name color space to another - internal implementation */
1535
1611
static void colormanagement_transform_ex(float *buffer, int width, int height, int channels, const char *from_colorspace,
1536
const char *to_colorspace, int predivide, int do_threaded)
1612
const char *to_colorspace, bool predivide, bool do_threaded)
1538
1614
ColormanageProcessor *cm_processor;
1561
1637
/* convert the whole buffer from specified by name color space to another */
1562
1638
void IMB_colormanagement_transform(float *buffer, int width, int height, int channels,
1563
const char *from_colorspace, const char *to_colorspace, int predivide)
1639
const char *from_colorspace, const char *to_colorspace, bool predivide)
1565
colormanagement_transform_ex(buffer, width, height, channels, from_colorspace, to_colorspace, predivide, FALSE);
1641
colormanagement_transform_ex(buffer, width, height, channels, from_colorspace, to_colorspace, predivide, false);
1568
1644
/* convert the whole buffer from specified by name color space to another
1569
1645
* will do threaded conversion
1571
1647
void IMB_colormanagement_transform_threaded(float *buffer, int width, int height, int channels,
1572
const char *from_colorspace, const char *to_colorspace, int predivide)
1648
const char *from_colorspace, const char *to_colorspace, bool predivide)
1574
colormanagement_transform_ex(buffer, width, height, channels, from_colorspace, to_colorspace, predivide, TRUE);
1650
colormanagement_transform_ex(buffer, width, height, channels, from_colorspace, to_colorspace, predivide, true);
1577
1653
void IMB_colormanagement_transform_v4(float pixel[4], const char *from_colorspace, const char *to_colorspace)
1632
1708
OCIO_processorApplyRGB(processor, pixel);
1635
void IMB_colormanagement_colorspace_to_scene_linear_v4(float pixel[4], int predivide, ColorSpace *colorspace)
1711
void IMB_colormanagement_colorspace_to_scene_linear_v4(float pixel[4], bool predivide, ColorSpace *colorspace)
1637
1713
OCIO_ConstProcessorRcPtr *processor;
1655
void IMB_colormanagement_colorspace_to_scene_linear(float *buffer, int width, int height, int channels, struct ColorSpace *colorspace, int predivide)
1731
void IMB_colormanagement_colorspace_to_scene_linear(float *buffer, int width, int height, int channels, struct ColorSpace *colorspace, bool predivide)
1657
1733
OCIO_ConstProcessorRcPtr *processor;
1733
1809
static void colormanagement_imbuf_make_display_space(ImBuf *ibuf, const ColorManagedViewSettings *view_settings,
1734
const ColorManagedDisplaySettings *display_settings, int make_byte)
1810
const ColorManagedDisplaySettings *display_settings, bool make_byte)
1736
1812
if (!ibuf->rect && make_byte)
1737
1813
imb_addrectImBuf(ibuf);
1749
1825
void IMB_colormanagement_imbuf_make_display_space(ImBuf *ibuf, const ColorManagedViewSettings *view_settings,
1750
1826
const ColorManagedDisplaySettings *display_settings)
1752
colormanagement_imbuf_make_display_space(ibuf, view_settings, display_settings, FALSE);
1828
colormanagement_imbuf_make_display_space(ibuf, view_settings, display_settings, false);
1755
1831
/* prepare image buffer to be saved on disk, applying color management if needed
1763
1839
* in image format write callback and if float_colorspace is not NULL, no color
1764
1840
* space transformation should be applied on this buffer.
1766
ImBuf *IMB_colormanagement_imbuf_for_write(ImBuf *ibuf, int save_as_render, int allocate_result, const ColorManagedViewSettings *view_settings,
1842
ImBuf *IMB_colormanagement_imbuf_for_write(ImBuf *ibuf, bool save_as_render, bool allocate_result, const ColorManagedViewSettings *view_settings,
1767
1843
const ColorManagedDisplaySettings *display_settings, ImageFormatData *image_format_data)
1769
1845
ImBuf *colormanaged_ibuf = ibuf;
1770
int do_colormanagement;
1846
bool do_colormanagement;
1771
1847
bool is_movie = BKE_imtype_is_movie(image_format_data->imtype);
1772
int requires_linear_float = BKE_imtype_requires_linear_float(image_format_data->imtype);
1773
int do_alpha_under = image_format_data->planes != R_IMF_PLANES_RGBA;
1848
bool requires_linear_float = BKE_imtype_requires_linear_float(image_format_data->imtype);
1849
bool do_alpha_under = image_format_data->planes != R_IMF_PLANES_RGBA;
1775
1851
do_colormanagement = save_as_render && (is_movie || !requires_linear_float);
1877
1953
cm_processor = IMB_colormanagement_display_processor_new(view_settings, display_settings);
1879
1955
processor_transform_apply_threaded(display_buffer_float, width, height, channels,
1880
cm_processor, TRUE);
1956
cm_processor, true);
1882
1958
IMB_buffer_byte_from_float(display_buffer, display_buffer_float,
1883
1959
channels, dither, IB_PROFILE_SRGB, IB_PROFILE_SRGB,
1954
2030
return (unsigned char *) ibuf->rect;
1957
colormanage_view_settings_to_cache(&cache_view_settings, applied_view_settings);
2033
colormanage_view_settings_to_cache(ibuf, &cache_view_settings, applied_view_settings);
1958
2034
colormanage_display_settings_to_cache(&cache_display_settings, display_settings);
1960
2036
if (ibuf->invalid_rect.xmin != ibuf->invalid_rect.xmax) {
1963
2039
ibuf->x, 0, 0, applied_view_settings, display_settings,
1964
2040
ibuf->invalid_rect.xmin, ibuf->invalid_rect.ymin,
1965
2041
ibuf->invalid_rect.xmax, ibuf->invalid_rect.ymax,
1969
2045
BLI_rcti_init(&ibuf->invalid_rect, 0, 0, 0, 0);
2019
2095
void IMB_display_buffer_transform_apply(unsigned char *display_buffer, float *linear_buffer, int width, int height,
2020
2096
int channels, const ColorManagedViewSettings *view_settings,
2021
const ColorManagedDisplaySettings *display_settings, int predivide)
2097
const ColorManagedDisplaySettings *display_settings, bool predivide)
2023
2099
if (global_tot_display == 0 || global_tot_view == 0) {
2024
2100
IMB_buffer_byte_from_float(display_buffer, linear_buffer, channels, 0.0f, IB_PROFILE_SRGB, IB_PROFILE_LINEAR_RGB, FALSE,
2283
ColorSpace *colormanage_colorspace_add(const char *name, const char *description, int is_invertible, int is_data)
2359
ColorSpace *colormanage_colorspace_add(const char *name, const char *description, bool is_invertible, bool is_data)
2285
2361
ColorSpace *colorspace, *prev_space;
2286
2362
int counter = 1;
2342
2418
ColorSpace *colormanage_colorspace_get_indexed(int index)
2344
/* display indices are 1-based */
2420
/* color space indices are 1-based */
2345
2421
return BLI_findlink(&global_colorspaces, index - 1);
2465
/*********************** Looks functions *************************/
2467
ColorManagedLook *colormanage_look_add(const char *name, const char *process_space, bool is_noop)
2469
ColorManagedLook *look;
2470
int index = global_tot_looks;
2472
look = MEM_callocN(sizeof(ColorManagedLook), "ColorManagedLook");
2473
look->index = index + 1;
2474
BLI_strncpy(look->name, name, sizeof(look->name));
2475
BLI_strncpy(look->process_space, process_space, sizeof(look->process_space));
2476
look->is_noop = is_noop;
2478
BLI_addtail(&global_looks, look);
2485
ColorManagedLook *colormanage_look_get_named(const char *name)
2487
ColorManagedLook *look;
2489
for (look = global_looks.first; look; look = look->next) {
2490
if (!strcmp(look->name, name)) {
2498
ColorManagedLook *colormanage_look_get_indexed(int index)
2500
/* look indices are 1-based */
2501
return BLI_findlink(&global_looks, index - 1);
2504
int IMB_colormanagement_look_get_named_index(const char *name)
2506
ColorManagedLook *look;
2508
look = colormanage_look_get_named(name);
2517
const char *IMB_colormanagement_look_get_indexed_name(int index)
2519
ColorManagedLook *look;
2521
look = colormanage_look_get_indexed(index);
2389
2530
/*********************** RNA helper functions *************************/
2391
2532
void IMB_colormanagement_display_items_add(EnumPropertyItem **items, int *totitem)
2578
void IMB_colormanagement_look_items_add(struct EnumPropertyItem **items, int *totitem)
2580
ColorManagedLook *look;
2582
for (look = global_looks.first; look; look = look->next) {
2583
EnumPropertyItem item;
2585
item.value = look->index;
2586
item.name = look->name;
2587
item.identifier = look->name;
2589
item.description = "";
2591
RNA_enum_item_add(items, totitem, &item);
2437
2595
void IMB_colormanagement_colorspace_items_add(EnumPropertyItem **items, int *totitem)
2439
2597
ColorSpace *colorspace;
2479
2637
float *display_buffer_float = NULL;
2480
2638
const int width = xmax - xmin;
2481
2639
const int height = ymax - ymin;
2482
int is_data = ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA;
2640
bool is_data = (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) != 0;
2484
2642
if (dither != 0.0f) {
2485
2643
/* cm_processor is NULL in cases byte_buffer's space matches display
2560
2718
void IMB_partial_display_buffer_update(ImBuf *ibuf, const float *linear_buffer, const unsigned char *byte_buffer,
2561
2719
int stride, int offset_x, int offset_y, const ColorManagedViewSettings *view_settings,
2562
2720
const ColorManagedDisplaySettings *display_settings,
2563
int xmin, int ymin, int xmax, int ymax, int update_orig_byte_buffer)
2721
int xmin, int ymin, int xmax, int ymax, bool update_orig_byte_buffer)
2565
2723
if ((ibuf->rect && ibuf->rect_float) || update_orig_byte_buffer) {
2566
2724
/* update byte buffer created by legacy color management */
2583
2741
unsigned char *display_buffer = NULL;
2584
2742
int view_flag, display_index, buffer_width;
2586
colormanage_view_settings_to_cache(&cache_view_settings, view_settings);
2744
colormanage_view_settings_to_cache(ibuf, &cache_view_settings, view_settings);
2587
2745
colormanage_display_settings_to_cache(&cache_display_settings, display_settings);
2589
2747
view_flag = 1 << (cache_view_settings.view - 1);
2608
2766
if (display_buffer) {
2609
2767
ColormanageProcessor *cm_processor = NULL;
2610
int skip_transform = 0;
2768
bool skip_transform = false;
2612
2770
/* byte buffer is assumed to be in imbuf's rect space, so if byte buffer
2613
2771
* is known we could skip display->linear->display conversion in case
2666
2824
if (display_space)
2667
2825
cm_processor->is_data_result = display_space->is_data;
2669
cm_processor->processor = create_display_buffer_processor(applied_view_settings->view_transform, display_settings->display_device,
2670
applied_view_settings->exposure, applied_view_settings->gamma,
2827
cm_processor->processor = create_display_buffer_processor(applied_view_settings->look,
2828
applied_view_settings->view_transform,
2829
display_settings->display_device,
2830
applied_view_settings->exposure,
2831
applied_view_settings->gamma,
2671
2832
global_role_scene_linear);
2673
2834
if (applied_view_settings->flag & COLORMANAGE_VIEW_USE_CURVES) {
2674
2835
cm_processor->curve_mapping = curvemapping_copy(applied_view_settings->curve_mapping);
2675
curvemapping_premultiply(cm_processor->curve_mapping, FALSE);
2836
curvemapping_premultiply(cm_processor->curve_mapping, false);
2678
2839
return cm_processor;
2723
2884
void IMB_colormanagement_processor_apply(ColormanageProcessor *cm_processor, float *buffer, int width, int height,
2724
int channels, int predivide)
2885
int channels, bool predivide)
2726
2887
/* apply curve mapping */
2727
2888
if (cm_processor->curve_mapping) {
2771
2932
return !(global_glsl_state.exposure == view_settings->exposure &&
2772
2933
global_glsl_state.gamma == view_settings->gamma &&
2934
STREQ(global_glsl_state.look, view_settings->look) &&
2773
2935
STREQ(global_glsl_state.view, view_settings->view_transform) &&
2774
2936
STREQ(global_glsl_state.display, display_settings->display_device) &&
2775
2937
STREQ(global_glsl_state.input, from_colorspace));
2786
2948
check_glsl_display_processor_changed(view_settings, display_settings, from_colorspace))
2788
2950
/* Store settings of processor for further comparison. */
2789
strcpy(global_glsl_state.view, view_settings->view_transform);
2790
strcpy(global_glsl_state.display, display_settings->display_device);
2791
strcpy(global_glsl_state.input, from_colorspace);
2951
BLI_strncpy(global_glsl_state.look, view_settings->look, MAX_COLORSPACE_NAME);
2952
BLI_strncpy(global_glsl_state.view, view_settings->view_transform, MAX_COLORSPACE_NAME);
2953
BLI_strncpy(global_glsl_state.display, display_settings->display_device, MAX_COLORSPACE_NAME);
2954
BLI_strncpy(global_glsl_state.input, from_colorspace, MAX_COLORSPACE_NAME);
2792
2955
global_glsl_state.exposure = view_settings->exposure;
2793
2956
global_glsl_state.gamma = view_settings->gamma;
2799
2962
/* We're using display OCIO processor, no RGB curves yet. */
2800
2963
global_glsl_state.processor =
2801
create_display_buffer_processor(global_glsl_state.view,
2964
create_display_buffer_processor(global_glsl_state.look,
2965
global_glsl_state.view,
2802
2966
global_glsl_state.display,
2803
2967
global_glsl_state.exposure,
2804
2968
global_glsl_state.gamma,
2973
bool IMB_colormanagement_support_glsl_draw(const ColorManagedViewSettings *view_settings,
2976
/* curves not supported yet */
2978
if (view_settings && (view_settings->flag & COLORMANAGE_VIEW_USE_CURVES))
2981
return OCIO_supportGLSLDraw();
2810
2985
* Configures GLSL shader for conversion from specified to
2811
2986
* display color space
2819
2994
* This is low-level function, use glaDrawImBuf_glsl_ctx if you
2820
2995
* only need to display given image buffer
2822
int IMB_colormanagement_setup_glsl_draw_from_space(const ColorManagedViewSettings *view_settings,
2823
const ColorManagedDisplaySettings *display_settings,
2824
struct ColorSpace *from_colorspace, int predivide)
2997
bool IMB_colormanagement_setup_glsl_draw_from_space(const ColorManagedViewSettings *view_settings,
2998
const ColorManagedDisplaySettings *display_settings,
2999
struct ColorSpace *from_colorspace, bool predivide,
2826
3002
ColorManagedViewSettings default_view_settings;
2827
3003
const ColorManagedViewSettings *applied_view_settings;
2841
3017
/* RGB curves mapping is not supported on GPU yet. */
2842
if (applied_view_settings->flag & COLORMANAGE_VIEW_USE_CURVES)
3019
if (applied_view_settings->flag & COLORMANAGE_VIEW_USE_CURVES)
2845
3022
/* Make sure OCIO processor is up-to-date. */
2846
3023
update_glsl_display_processor(applied_view_settings, display_settings,
2852
3029
/* Configures GLSL shader for conversion from scene linear to display space */
2853
int IMB_colormanagement_setup_glsl_draw(const ColorManagedViewSettings *view_settings,
2854
const ColorManagedDisplaySettings *display_settings,
3030
bool IMB_colormanagement_setup_glsl_draw(const ColorManagedViewSettings *view_settings,
3031
const ColorManagedDisplaySettings *display_settings,
3032
bool predivide, bool skip_curves)
2857
3034
return IMB_colormanagement_setup_glsl_draw_from_space(view_settings, display_settings,
3035
NULL, predivide, skip_curves);
2861
3038
/* Same as setup_glsl_draw_from_space, but color management settings are guessing from a given context */
2862
int IMB_colormanagement_setup_glsl_draw_from_space_ctx(const struct bContext *C, struct ColorSpace *from_colorspace, int predivide)
3039
bool IMB_colormanagement_setup_glsl_draw_from_space_ctx(const struct bContext *C, struct ColorSpace *from_colorspace, bool predivide)
2864
3041
ColorManagedViewSettings *view_settings;
2865
3042
ColorManagedDisplaySettings *display_settings;
2867
3044
IMB_colormanagement_display_settings_from_ctx(C, &view_settings, &display_settings);
2869
return IMB_colormanagement_setup_glsl_draw_from_space(view_settings, display_settings, from_colorspace, predivide);
3046
return IMB_colormanagement_setup_glsl_draw_from_space(view_settings, display_settings, from_colorspace, predivide, false);
2872
3049
/* Same as setup_glsl_draw, but color management settings are guessing from a given context */
2873
int IMB_colormanagement_setup_glsl_draw_ctx(const bContext *C, int predivide)
3050
bool IMB_colormanagement_setup_glsl_draw_ctx(const bContext *C, bool predivide)
2875
3052
return IMB_colormanagement_setup_glsl_draw_from_space_ctx(C, NULL, predivide);
2896
3073
* When there's no need to apply transform on 2D textures, use
2897
3074
* IMB_colormanagement_finish_glsl_transform().
2899
int IMB_colormanagement_setup_transform_from_role_glsl(int role, int predivide)
3076
bool IMB_colormanagement_setup_transform_from_role_glsl(int role, bool predivide)
2901
3078
OCIO_ConstProcessorRcPtr *processor;
2902
3079
ColorSpace *colorspace;