diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-12-16 16:35:20 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-12-16 16:38:13 +0400 |
commit | 3f0bae965b519392c672edf93396397342d92f54 (patch) | |
tree | 2bc047dd159e290d41813801f58e4d24b40632ce | |
parent | 63eb863d8da4daa8c003211ee0048c8ad10b87af (diff) |
Color management: use fallback mode if there're no displays/views
Before this it was a runtime check for number of displays/views
which is rather really annoying.
This simplifies code a bit and allows to do some more tricks
in other patches.
-rw-r--r-- | source/blender/imbuf/intern/colormanagement.c | 195 |
1 files changed, 85 insertions, 110 deletions
diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c index a2e2fab7ba1..139354c0afc 100644 --- a/source/blender/imbuf/intern/colormanagement.c +++ b/source/blender/imbuf/intern/colormanagement.c @@ -583,6 +583,8 @@ static void colormanage_free_config(void) colorspace = colorspace_next; } + global_colorspaces.first = global_colorspaces.last = NULL; + global_tot_colorspace = 0; /* free displays */ display = global_displays.first; @@ -602,12 +604,16 @@ static void colormanage_free_config(void) MEM_freeN(display); display = display_next; } + global_displays.first = global_displays.last = NULL; + global_tot_display = 0; /* free views */ BLI_freelistN(&global_views); + global_tot_view = 0; /* free looks */ BLI_freelistN(&global_looks); + global_tot_looks = 0; OCIO_exit(); } @@ -660,6 +666,18 @@ void colormanagement_init(void) OCIO_configRelease(config); } + /* If there're no valid display/views, use fallback mode. */ + if (global_tot_display == 0 || global_tot_view == 0) { + printf("Color management: no displays/views in the config, using fallback mode instead\n"); + + /* Free old config. */ + colormanage_free_config(); + + /* Initialize fallback config. */ + config = OCIO_configCreateFallback(); + colormanage_load_config(config); + } + BLI_init_srgb_conversion(); } @@ -1839,14 +1857,8 @@ static void colormanagement_imbuf_make_display_space(ImBuf *ibuf, const ColorMan if (!ibuf->rect && make_byte) imb_addrectImBuf(ibuf); - if (global_tot_display == 0 || global_tot_view == 0) { - IMB_buffer_float_from_float(ibuf->rect_float, ibuf->rect_float, ibuf->channels, IB_PROFILE_SRGB, IB_PROFILE_LINEAR_RGB, - TRUE, ibuf->x, ibuf->y, ibuf->x, ibuf->x); - } - else { - colormanage_display_buffer_process_ex(ibuf, ibuf->rect_float, (unsigned char *)ibuf->rect, - view_settings, display_settings); - } + colormanage_display_buffer_process_ex(ibuf, ibuf->rect_float, (unsigned char *)ibuf->rect, + view_settings, display_settings); } void IMB_colormanagement_imbuf_make_display_space(ImBuf *ibuf, const ColorManagedViewSettings *view_settings, @@ -1990,122 +2002,91 @@ void IMB_colormanagement_buffer_make_display_space(float *buffer, unsigned char IMB_colormanagement_processor_free(cm_processor); } -static void imbuf_verify_float(ImBuf *ibuf) -{ - /* multiple threads could request for display buffer at once and in case - * view transform is not used it'll lead to display buffer calculated - * several times - * it is harmless, but would take much more time (assuming thread lock - * happens faster than running float->byte conversion for average image) - */ - BLI_lock_thread(LOCK_COLORMANAGE); - - if (ibuf->rect_float && (ibuf->rect == NULL || (ibuf->userflags & (IB_DISPLAY_BUFFER_INVALID | IB_RECT_INVALID)))) { - IMB_rect_from_float(ibuf); - - ibuf->userflags &= ~(IB_RECT_INVALID | IB_DISPLAY_BUFFER_INVALID); - } - - BLI_unlock_thread(LOCK_COLORMANAGE); -} - /*********************** Public display buffers interfaces *************************/ /* acquire display buffer for given image buffer using specified view and display settings */ unsigned char *IMB_display_buffer_acquire(ImBuf *ibuf, const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, void **cache_handle) { + unsigned char *display_buffer; + int buffer_size; + ColormanageCacheViewSettings cache_view_settings; + ColormanageCacheDisplaySettings cache_display_settings; + ColorManagedViewSettings default_view_settings; + const ColorManagedViewSettings *applied_view_settings; + *cache_handle = NULL; if (!ibuf->x || !ibuf->y) return NULL; - if (global_tot_display == 0 || global_tot_view == 0) { - /* if there's no view transform or display transforms, fallback to standard sRGB/linear conversion - * the same logic would be used if OCIO is disabled + if (view_settings) { + applied_view_settings = view_settings; + } + else { + /* if no view settings were specified, use default display transformation + * this happens for images which don't want to be displayed with render settings */ - imbuf_verify_float(ibuf); - - return (unsigned char *) ibuf->rect; + init_default_view_settings(display_settings, &default_view_settings); + applied_view_settings = &default_view_settings; } - else { - unsigned char *display_buffer; - int buffer_size; - ColormanageCacheViewSettings cache_view_settings; - ColormanageCacheDisplaySettings cache_display_settings; - ColorManagedViewSettings default_view_settings; - const ColorManagedViewSettings *applied_view_settings; - if (view_settings) { - applied_view_settings = view_settings; - } - else { - /* if no view settings were specified, use default display transformation - * this happens for images which don't want to be displayed with render settings - */ + /* early out: no float buffer and byte buffer is already in display space, + * let's just use if + */ + if (ibuf->rect_float == NULL && ibuf->rect_colorspace && ibuf->channels == 4) { + if (is_ibuf_rect_in_display_space(ibuf, applied_view_settings, display_settings)) + return (unsigned char *) ibuf->rect; + } - init_default_view_settings(display_settings, &default_view_settings); - applied_view_settings = &default_view_settings; - } + colormanage_view_settings_to_cache(ibuf, &cache_view_settings, applied_view_settings); + colormanage_display_settings_to_cache(&cache_display_settings, display_settings); - /* early out: no float buffer and byte buffer is already in display space, - * let's just use if - */ - if (ibuf->rect_float == NULL && ibuf->rect_colorspace && ibuf->channels == 4) { - if (is_ibuf_rect_in_display_space(ibuf, applied_view_settings, display_settings)) - return (unsigned char *) ibuf->rect; + if (ibuf->invalid_rect.xmin != ibuf->invalid_rect.xmax) { + if ((ibuf->userflags & IB_DISPLAY_BUFFER_INVALID) == 0) { + IMB_partial_display_buffer_update(ibuf, ibuf->rect_float, (unsigned char *) ibuf->rect, + ibuf->x, 0, 0, applied_view_settings, display_settings, + ibuf->invalid_rect.xmin, ibuf->invalid_rect.ymin, + ibuf->invalid_rect.xmax, ibuf->invalid_rect.ymax, + false); } - colormanage_view_settings_to_cache(ibuf, &cache_view_settings, applied_view_settings); - colormanage_display_settings_to_cache(&cache_display_settings, display_settings); - - if (ibuf->invalid_rect.xmin != ibuf->invalid_rect.xmax) { - if ((ibuf->userflags & IB_DISPLAY_BUFFER_INVALID) == 0) { - IMB_partial_display_buffer_update(ibuf, ibuf->rect_float, (unsigned char *) ibuf->rect, - ibuf->x, 0, 0, applied_view_settings, display_settings, - ibuf->invalid_rect.xmin, ibuf->invalid_rect.ymin, - ibuf->invalid_rect.xmax, ibuf->invalid_rect.ymax, - false); - } - - BLI_rcti_init(&ibuf->invalid_rect, 0, 0, 0, 0); - } + BLI_rcti_init(&ibuf->invalid_rect, 0, 0, 0, 0); + } - BLI_lock_thread(LOCK_COLORMANAGE); + BLI_lock_thread(LOCK_COLORMANAGE); - /* ensure color management bit fields exists */ - if (!ibuf->display_buffer_flags) { - if (global_tot_display) - ibuf->display_buffer_flags = MEM_callocN(sizeof(unsigned int) * global_tot_display, "imbuf display_buffer_flags"); - } - else if (ibuf->userflags & IB_DISPLAY_BUFFER_INVALID) { - /* all display buffers were marked as invalid from other areas, - * now propagate this flag to internal color management routines - */ - memset(ibuf->display_buffer_flags, 0, global_tot_display * sizeof(unsigned int)); + /* ensure color management bit fields exists */ + if (!ibuf->display_buffer_flags) { + ibuf->display_buffer_flags = MEM_callocN(sizeof(unsigned int) * global_tot_display, "imbuf display_buffer_flags"); + } + else if (ibuf->userflags & IB_DISPLAY_BUFFER_INVALID) { + /* all display buffers were marked as invalid from other areas, + * now propagate this flag to internal color management routines + */ + memset(ibuf->display_buffer_flags, 0, global_tot_display * sizeof(unsigned int)); - ibuf->userflags &= ~IB_DISPLAY_BUFFER_INVALID; - } + ibuf->userflags &= ~IB_DISPLAY_BUFFER_INVALID; + } - display_buffer = colormanage_cache_get(ibuf, &cache_view_settings, &cache_display_settings, cache_handle); + display_buffer = colormanage_cache_get(ibuf, &cache_view_settings, &cache_display_settings, cache_handle); - if (display_buffer) { - BLI_unlock_thread(LOCK_COLORMANAGE); - return display_buffer; - } + if (display_buffer) { + BLI_unlock_thread(LOCK_COLORMANAGE); + return display_buffer; + } - buffer_size = DISPLAY_BUFFER_CHANNELS * ibuf->x * ibuf->y * sizeof(char); - display_buffer = MEM_callocN(buffer_size, "imbuf display buffer"); + buffer_size = DISPLAY_BUFFER_CHANNELS * ibuf->x * ibuf->y * sizeof(char); + display_buffer = MEM_callocN(buffer_size, "imbuf display buffer"); - colormanage_display_buffer_process(ibuf, display_buffer, applied_view_settings, display_settings); + colormanage_display_buffer_process(ibuf, display_buffer, applied_view_settings, display_settings); - colormanage_cache_put(ibuf, &cache_view_settings, &cache_display_settings, display_buffer, cache_handle); + colormanage_cache_put(ibuf, &cache_view_settings, &cache_display_settings, display_buffer, cache_handle); - BLI_unlock_thread(LOCK_COLORMANAGE); + BLI_unlock_thread(LOCK_COLORMANAGE); - return display_buffer; - } + return display_buffer; } /* same as IMB_display_buffer_acquire but gets view and display settings from context */ @@ -2123,26 +2104,20 @@ void IMB_display_buffer_transform_apply(unsigned char *display_buffer, float *li int channels, const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, bool predivide) { - if (global_tot_display == 0 || global_tot_view == 0) { - IMB_buffer_byte_from_float(display_buffer, linear_buffer, channels, 0.0f, IB_PROFILE_SRGB, IB_PROFILE_LINEAR_RGB, FALSE, - width, height, width, width); - } - else { - float *buffer; - ColormanageProcessor *cm_processor = IMB_colormanagement_display_processor_new(view_settings, display_settings); + float *buffer; + ColormanageProcessor *cm_processor = IMB_colormanagement_display_processor_new(view_settings, display_settings); - buffer = MEM_callocN(channels * width * height * sizeof(float), "display transform temp buffer"); - memcpy(buffer, linear_buffer, channels * width * height * sizeof(float)); + buffer = MEM_callocN(channels * width * height * sizeof(float), "display transform temp buffer"); + memcpy(buffer, linear_buffer, channels * width * height * sizeof(float)); - IMB_colormanagement_processor_apply(cm_processor, buffer, width, height, channels, predivide); + IMB_colormanagement_processor_apply(cm_processor, buffer, width, height, channels, predivide); - IMB_colormanagement_processor_free(cm_processor); + IMB_colormanagement_processor_free(cm_processor); - IMB_buffer_byte_from_float(display_buffer, buffer, channels, 0.0f, IB_PROFILE_SRGB, IB_PROFILE_SRGB, - FALSE, width, height, width, width); + IMB_buffer_byte_from_float(display_buffer, buffer, channels, 0.0f, IB_PROFILE_SRGB, IB_PROFILE_SRGB, + FALSE, width, height, width, width); - MEM_freeN(buffer); - } + MEM_freeN(buffer); } void IMB_display_buffer_release(void *cache_handle) |