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
This commit is contained in:
Aras Pranckevicius
2024-09-19 19:26:59 +03:00
parent 67f0358a0a
commit f0de61c19e

View File

@@ -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,