From f0de61c19e51617f3ca89cc1ef5242f7319454b6 Mon Sep 17 00:00:00 2001 From: Aras Pranckevicius Date: Thu, 19 Sep 2024 19:26:59 +0300 Subject: [PATCH] Cleanup: early outs in IMB_colormanagement functions on error conditions Suggested by Sergey in another PR: https://projects.blender.org/blender/blender/pulls/127467#issuecomment-1297753 --- .../blender/imbuf/intern/colormanagement.cc | 125 ++++++++---------- 1 file changed, 54 insertions(+), 71 deletions(-) diff --git a/source/blender/imbuf/intern/colormanagement.cc b/source/blender/imbuf/intern/colormanagement.cc index 5ce6e67d36f..ce22596b89f 100644 --- a/source/blender/imbuf/intern/colormanagement.cc +++ b/source/blender/imbuf/intern/colormanagement.cc @@ -2250,118 +2250,101 @@ void IMB_colormanagement_transform_v4(float pixel[4], void IMB_colormanagement_colorspace_to_scene_linear_v3(float pixel[3], ColorSpace *colorspace) { - OCIO_ConstCPUProcessorRcPtr *processor; - - if (!colorspace) { - /* should never happen */ + if (colorspace == nullptr) { /* should never happen */ printf("%s: perform conversion from unknown color space\n", __func__); return; } - - processor = colorspace_to_scene_linear_cpu_processor(colorspace); - - if (processor != nullptr) { - OCIO_cpuProcessorApplyRGB(processor, pixel); + OCIO_ConstCPUProcessorRcPtr *processor = colorspace_to_scene_linear_cpu_processor(colorspace); + if (processor == nullptr) { + return; } + OCIO_cpuProcessorApplyRGB(processor, pixel); } void IMB_colormanagement_scene_linear_to_colorspace_v3(float pixel[3], ColorSpace *colorspace) { - OCIO_ConstCPUProcessorRcPtr *processor; - - if (!colorspace) { - /* should never happen */ + if (colorspace == nullptr) { /* should never happen */ printf("%s: perform conversion from unknown color space\n", __func__); return; } - - processor = colorspace_from_scene_linear_cpu_processor(colorspace); - - if (processor != nullptr) { - OCIO_cpuProcessorApplyRGB(processor, pixel); + OCIO_ConstCPUProcessorRcPtr *processor = colorspace_from_scene_linear_cpu_processor(colorspace); + if (processor == nullptr) { + return; } + OCIO_cpuProcessorApplyRGB(processor, pixel); } void IMB_colormanagement_colorspace_to_scene_linear_v4(float pixel[4], bool predivide, ColorSpace *colorspace) { - OCIO_ConstCPUProcessorRcPtr *processor; - - if (!colorspace) { - /* should never happen */ + if (colorspace == nullptr) { /* should never happen */ printf("%s: perform conversion from unknown color space\n", __func__); return; } - - processor = colorspace_to_scene_linear_cpu_processor(colorspace); - - if (processor != nullptr) { - if (predivide) { - OCIO_cpuProcessorApplyRGBA_predivide(processor, pixel); - } - else { - OCIO_cpuProcessorApplyRGBA(processor, pixel); - } + OCIO_ConstCPUProcessorRcPtr *processor = colorspace_to_scene_linear_cpu_processor(colorspace); + if (processor == nullptr) { + return; + } + if (predivide) { + OCIO_cpuProcessorApplyRGBA_predivide(processor, pixel); + } + else { + OCIO_cpuProcessorApplyRGBA(processor, pixel); } } void IMB_colormanagement_colorspace_to_scene_linear( float *buffer, int width, int height, int channels, ColorSpace *colorspace, bool predivide) { - OCIO_ConstCPUProcessorRcPtr *processor; - - if (!colorspace) { - /* should never happen */ + if (colorspace == nullptr) { /* should never happen */ printf("%s: perform conversion from unknown color space\n", __func__); return; } - - processor = colorspace_to_scene_linear_cpu_processor(colorspace); - - if (processor != nullptr) { - OCIO_PackedImageDesc *img; - - img = OCIO_createOCIO_PackedImageDesc(buffer, - width, - height, - channels, - sizeof(float), - size_t(channels) * sizeof(float), - size_t(channels) * sizeof(float) * width); - - if (predivide) { - OCIO_cpuProcessorApply_predivide(processor, img); - } - else { - OCIO_cpuProcessorApply(processor, img); - } - - OCIO_PackedImageDescRelease(img); + OCIO_ConstCPUProcessorRcPtr *processor = colorspace_to_scene_linear_cpu_processor(colorspace); + if (processor == nullptr) { + return; } + OCIO_PackedImageDesc *img = OCIO_createOCIO_PackedImageDesc(buffer, + width, + height, + channels, + sizeof(float), + size_t(channels) * sizeof(float), + size_t(channels) * sizeof(float) * + width); + + if (predivide) { + OCIO_cpuProcessorApply_predivide(processor, img); + } + else { + OCIO_cpuProcessorApply(processor, img); + } + + OCIO_PackedImageDescRelease(img); } void IMB_colormanagement_scene_linear_to_colorspace( float *buffer, int width, int height, int channels, ColorSpace *colorspace) { - if (!colorspace) { - /* should never happen */ + if (colorspace == nullptr) { /* should never happen */ printf("%s: perform conversion from unknown color space\n", __func__); return; } OCIO_ConstCPUProcessorRcPtr *processor = colorspace_from_scene_linear_cpu_processor(colorspace); - if (processor != nullptr) { - OCIO_PackedImageDesc *img = OCIO_createOCIO_PackedImageDesc(buffer, - width, - height, - channels, - sizeof(float), - size_t(channels) * sizeof(float), - size_t(channels) * sizeof(float) * - width); - OCIO_cpuProcessorApply(processor, img); - OCIO_PackedImageDescRelease(img); + if (processor == nullptr) { + return; } + OCIO_PackedImageDesc *img = OCIO_createOCIO_PackedImageDesc(buffer, + width, + height, + channels, + sizeof(float), + size_t(channels) * sizeof(float), + size_t(channels) * sizeof(float) * + width); + OCIO_cpuProcessorApply(processor, img); + OCIO_PackedImageDescRelease(img); } void IMB_colormanagement_imbuf_to_byte_texture(uchar *out_buffer,