Blender V5.0
fallback_cpu_processor.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include "BLI_assert.h"
8#include "BLI_math_color.h"
9
10#include "OCIO_cpu_processor.hh"
11#include "OCIO_packed_image.hh"
12
13namespace blender::ocio {
14
19 public:
20 bool is_noop() const override
21 {
22 return true;
23 }
24
25 void apply_rgb(float /*rgb*/[3]) const override {}
26 void apply_rgba(float /*rgba*/[4]) const override {}
27
28 void apply_rgba_predivide(float /*rgba*/[4]) const override {}
29
30 void apply(const PackedImage & /*image*/) const override {}
31 void apply_predivide(const PackedImage & /*image*/) const override {}
32};
33
37template<void (*pixel_processor)(float dst[3], const float src[3])>
39 public:
40 bool is_noop() const override
41 {
42 return false;
43 }
44
45 void apply_rgb(float rgb[3]) const override
46 {
47 pixel_processor(rgb, rgb);
48 }
49 void apply_rgba(float rgba[4]) const override
50 {
51 pixel_processor(rgba, rgba);
52 }
53
54 void apply_rgba_predivide(float rgba[4]) const override
55 {
56 if (rgba[3] == 1.0f || rgba[3] == 0.0f) {
57 pixel_processor(rgba, rgba);
58 return;
59 }
60
61 const float alpha = rgba[3];
62 const float inv_alpha = 1.0f / alpha;
63
64 rgba[0] *= inv_alpha;
65 rgba[1] *= inv_alpha;
66 rgba[2] *= inv_alpha;
67
68 pixel_processor(rgba, rgba);
69
70 rgba[0] *= alpha;
71 rgba[1] *= alpha;
72 rgba[2] *= alpha;
73 }
74
75 void apply(const PackedImage &image) const override
76 {
77 /* TODO(sergey): Stride not respected, channels must be 3 or 4, bit depth is float32. */
78
79 BLI_assert(image.get_num_channels() >= 3);
81
82 const int num_channels = image.get_num_channels();
83 const size_t width = image.get_width();
84 const size_t height = image.get_height();
85
86 float *pixels = static_cast<float *>(image.get_data());
87
88 for (size_t y = 0; y < height; y++) {
89 for (size_t x = 0; x < width; x++) {
90 float *pixel = pixels + num_channels * (y * width + x);
91 pixel_processor(pixel, pixel);
92 }
93 }
94 }
95
96 void apply_predivide(const PackedImage &image) const override
97 {
98 /* TODO(sergey): Stride not respected, channels must be 3 or 4, bit depth is float32. */
99
100 BLI_assert(image.get_num_channels() >= 3);
102
103 const int num_channels = image.get_num_channels();
104 if (num_channels < 4) {
105 apply(image);
106 return;
107 }
108
109 const size_t width = image.get_width();
110 const size_t height = image.get_height();
111
112 float *pixels = static_cast<float *>(image.get_data());
113
114 for (size_t y = 0; y < height; y++) {
115 for (size_t x = 0; x < width; x++) {
116 float *pixel = pixels + num_channels * (y * width + x);
118 }
119 }
120 }
121};
122
125
126} // namespace blender::ocio
#define BLI_assert(a)
Definition BLI_assert.h:46
void apply_rgba_predivide(float rgba[4]) const override
void apply(const PackedImage &image) const override
void apply_predivide(const PackedImage &image) const override
void apply_rgb(float rgb[3]) const override
void apply_rgba(float rgba[4]) const override
void apply(const PackedImage &) const override
void apply_predivide(const PackedImage &) const override
void apply_rgba_predivide(float[4]) const override
FallbackCustomCPUProcessor< linearrgb_to_srgb_v3_v3 > FallbackLinearRGBToSRGBCPUProcessor
FallbackCustomCPUProcessor< srgb_to_linearrgb_v3_v3 > FallbackSRGBToLinearRGBCPUProcessor