60 for (
int y = 0;
y < height;
y++) {
61 const float *from = src + size_t(stride) *
y * src_channels;
62 uchar *to = dest + size_t(stride) *
y * 4;
63 if (src_channels == 1) {
65 for (
int x = 0;
x < width;
x++, from++, to += 4) {
69 else if (src_channels == 3) {
71 for (
int x = 0;
x < width;
x++, from += 3, to += 4) {
76 else if (src_channels == 4) {
78 if (dither && predivide) {
80 for (
int x = 0;
x < width;
x++, from += 4, to += 4) {
86 for (
int x = 0;
x < width;
x++, from += 4, to += 4) {
91 for (
int x = 0;
x < width;
x++, from += 4, to += 4) {
96 for (
int x = 0;
x < width;
x++, from += 4, to += 4) {
112 for (
int y = 0;
y < height;
y++) {
113 const float *from = src + size_t(width) *
y * src_channels;
114 uchar *to = dest + size_t(width) *
y * 4;
115 if (src_channels == 1) {
117 for (
int x = 0;
x < width;
x++, from++, to += 4) {
123 else if (src_channels == 3) {
125 for (
int x = 0;
x < width;
x++, from += 3, to += 4) {
132 else if (src_channels == 4) {
135 for (
int x = 0;
x < width;
x++, from += 4, to += 4) {
142 for (
int x = 0;
x < width;
x++, from += 4, to += 4) {
153 float *dest,
const uchar *src,
int width,
int height,
int dest_stride,
int src_stride)
155 for (
int y = 0;
y < height;
y++) {
156 const uchar *from = src + size_t(src_stride) *
y * 4;
157 float *to = dest + size_t(dest_stride) *
y * 4;
159 for (
int x = 0;
x < width;
x++, from += 4, to += 4) {
166 float *dest,
const float *src,
int src_channels,
int width,
int height)
168 if (src_channels == 1) {
170 for (
int y = 0;
y < height;
y++) {
171 const float *from = src + size_t(width) *
y;
172 float *to = dest + size_t(width) *
y * 4;
174 for (
int x = 0;
x < width;
x++, from++, to += 4) {
175 to[0] = to[1] = to[2] = to[3] = from[0];
179 else if (src_channels == 3) {
181 for (
int y = 0;
y < height;
y++) {
182 const float *from = src + size_t(width) *
y * 3;
183 float *to = dest + size_t(width) *
y * 4;
185 for (
int x = 0;
x < width;
x++, from += 3, to += 4) {
191 else if (src_channels == 4) {
193 for (
int y = 0;
y < height;
y++) {
194 const float *from = src + size_t(width) *
y * 4;
195 float *to = dest + size_t(width) *
y * 4;
196 memcpy(to, from,
sizeof(
float) *
size_t(4) * width);
202 float *dest,
const float *src,
int src_channels,
int width,
int height,
const char *
mask)
204 if (src_channels == 1) {
206 for (
int y = 0;
y < height;
y++) {
207 const float *from = src + size_t(width) *
y;
208 float *to = dest + size_t(width) *
y * 4;
210 for (
int x = 0;
x < width;
x++, from++, to += 4) {
212 to[0] = to[1] = to[2] = to[3] = from[0];
217 else if (src_channels == 3) {
219 for (
int y = 0;
y < height;
y++) {
220 const float *from = src + size_t(width) *
y * 3;
221 float *to = dest + size_t(width) *
y * 4;
223 for (
int x = 0;
x < width;
x++, from += 3, to += 4) {
231 else if (src_channels == 4) {
233 for (
int y = 0;
y < height;
y++) {
234 const float *from = src + size_t(width) *
y * 4;
235 float *to = dest + size_t(width) *
y * 4;
237 for (
int x = 0;
x < width;
x++, from += 4, to += 4) {
249 for (
int y : y_range) {
250 float *ptr = buffer + size_t(width) *
y * 4;
251 for (
int x = 0;
x < width;
x++, ptr += 4) {
268 if (float_data ==
nullptr) {
286 static constexpr int grain_size = 2048;
317 "Destination buffer should have a float buffer assigned.");
319 BLI_assert_msg(dst->
x == src->
x,
"Source and destination buffer should have the same dimension");
320 BLI_assert_msg(dst->
y == src->
y,
"Source and destination buffer should have the same dimension");
323 "Region to update should be clipped to the given buffers.");
325 "Region to update should be clipped to the given buffers.");
327 "Region to update should be clipped to the given buffers.");
329 "Region to update should be clipped to the given buffers.");
339 const uchar *src_ptr = byte_data + (region_to_update->xmin + y_range.first() * dst->x) * 4;
340 float *dst_ptr = float_data + (region_to_update->xmin + y_range.first() * dst->x) * 4;
343 IMB_buffer_float_from_byte(dst_ptr, src_ptr, region_width, y_range.size(), src->x, dst->x);
346 float *dst_ptr_line = dst_ptr;
347 for ([[maybe_unused]] const int64_t y : y_range) {
348 IMB_colormanagement_colorspace_to_scene_linear(
349 dst_ptr_line, region_width, 1, dst->channels, src->byte_buffer.colorspace, false);
350 if (premultiply_alpha) {
351 IMB_premultiply_rect_float(dst_ptr_line, dst->channels, region_width, 1);
353 dst_ptr_line += 4 * dst->x;
375 rcti region_to_update;
421 for ([[maybe_unused]]
const int64_t i : range) {
424 hsv_to_rgb(hsv[0], hsv[1] * sat, hsv[2], rgb + 0, rgb + 1, rgb + 2);
432 if (float_data !=
nullptr && ibuf->
channels >= 3) {
434 const int channels = ibuf->
channels;
435 float *ptr = float_data + range.
first() * channels;
437 for ([[maybe_unused]]
const int64_t i : range) {
439 hsv_to_rgb(hsv[0], hsv[1] * sat, hsv[2], ptr + 0, ptr + 1, ptr + 2);
Function declarations for filter.cc.
Read Blender memory allocation and freeing.
#define BLI_assert_msg(a, msg)
MutableSpan< T > as_mutable_span()
void apply(float *buffer, int width, int height, int channels, bool predivide) const
static ColormanageProcessor colorspace_processor_new(StringRefNull from_colorspace, StringRefNull to_colorspace)
constexpr int64_t first() const
constexpr int64_t size() const
constexpr IndexRange()=default
ColorSceneLinear4f< eAlpha::Premultiplied > premultiply_alpha(const ColorSceneLinear4f< Alpha > &color)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
void IMB_buffer_float_rgba_srgb_to_linear(float *buffer, int width, int height)
void IMB_float_from_byte_ex(ImBuf *dst, const ImBuf *src, const rcti *region_to_update)
MINLINE void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
void IMB_buffer_float_from_byte(float *dest, const unsigned char *src, int width, int height, int dest_stride, int src_stride)
void IMB_saturation(ImBuf *ibuf, float sat)
MINLINE unsigned char unit_float_to_uchar_clamp(float val)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void hsv_to_rgb(float h, float s, float v, float *r_r, float *r_g, float *r_b)
size_t IMB_get_pixel_count(const ImBuf *ibuf)
Get the length of the data of the given image buffer in pixels.
bool IMB_alloc_byte_pixels(ImBuf *ibuf, bool initialize_pixels=true)
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
BLI_INLINE unsigned char IMB_colormanagement_get_luminance_byte(const unsigned char rgb[3])
const char * IMB_colormanagement_get_byte_colorspace(const ImBuf *ibuf)
void IMB_buffer_byte_from_float(unsigned char *dest, const float *src, int src_channels, float dither, bool predivide, int width, int height, int stride, int start_y=0)
MINLINE void rgb_float_to_uchar(unsigned char r_col[3], const float col_f[3])
void IMB_buffer_byte_from_float_mask(unsigned char *dest, const float *src, int src_channels, float dither, int width, int height, const char *mask)
void IMB_float_from_byte(ImBuf *ibuf)
MINLINE float dither_random_value(int x, int y)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
void IMB_buffer_float_rgba_from_float(float *dest, const float *src, int src_channels, int width, int height)
void IMB_color_to_bw(ImBuf *ibuf)
MINLINE uchar ftochar(float value)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
void IMB_buffer_float_rgba_from_float_mask(float *dest, const float *src, int src_channels, int width, int height, const char *mask)
bool IMB_alpha_affects_rgb(const ImBuf *ibuf)
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
BLI_INLINE float IMB_colormanagement_get_luminance(const float rgb[3])
MINLINE void srgb_to_linearrgb_predivide_v4(float linear[4], const float srgb[4])
void IMB_byte_from_float(ImBuf *ibuf)
MINLINE void float_to_byte_dither_v4(uchar b[4], const float f[4], float dither, int x, int y)
MINLINE void rgb_uchar_to_float(float r_col[3], const unsigned char col_ub[3])
MINLINE void copy_v4_v4(float r[4], const float a[4])
bool IMB_alloc_float_pixels(ImBuf *ibuf, unsigned int channels, bool initialize_pixels=true)
void IMB_unpremultiply_rect_float(float *rect_float, int channels, int w, int h)
MINLINE void premul_float_to_straight_uchar(unsigned char *result, const float color[4])
const char * IMB_colormanagement_get_float_colorspace(const ImBuf *ibuf)
MINLINE void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
MINLINE void premul_to_straight_v4_v4(float straight[4], const float premul[4])
const ColorSpace * colorspace
ImBufFloatBuffer float_buffer
const uint8_t * byte_data() const
uint8_t * byte_data_for_write()
const float * float_data() const
float * float_data_for_write()