45#define USHORTTOFLOAT(val) (float(val) / 65535.0f)
72 const float *rect_from,
91 for (
y = 0;
y < height;
y++) {
92 if (channels_from == 1) {
94 const float *from = rect_from + size_t(stride_from) *
y;
95 uchar *to = rect_to + size_t(stride_to) *
y * 4;
97 for (
x = 0;
x < width;
x++, from++, to += 4) {
101 else if (channels_from == 3) {
103 const float *from = rect_from + size_t(stride_from) *
y * 3;
104 uchar *to = rect_to + size_t(stride_to) *
y * 4;
106 if (profile_to == profile_from) {
108 for (
x = 0;
x < width;
x++, from += 3, to += 4) {
115 for (
x = 0;
x < width;
x++, from += 3, to += 4) {
123 for (
x = 0;
x < width;
x++, from += 3, to += 4) {
130 else if (channels_from == 4) {
132 const float *from = rect_from + size_t(stride_from) *
y * 4;
133 uchar *to = rect_to + size_t(stride_to) *
y * 4;
135 if (profile_to == profile_from) {
137 if (dither && predivide) {
139 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
145 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
149 else if (predivide) {
150 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
155 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
165 if (dither && predivide) {
166 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
173 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
178 else if (predivide) {
179 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
186 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
194 if (dither && predivide) {
195 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
201 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
206 else if (predivide) {
207 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
213 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
224 const float *rect_from,
236 for (
y = 0;
y < height;
y++) {
237 if (channels_from == 1) {
239 const float *from = rect_from + size_t(stride_from) *
y;
240 uchar *to = rect_to + size_t(stride_to) *
y * 4;
242 for (
x = 0;
x < width;
x++, from++, to += 4) {
248 else if (channels_from == 3) {
250 const float *from = rect_from + size_t(stride_from) *
y * 3;
251 uchar *to = rect_to + size_t(stride_to) *
y * 4;
253 for (
x = 0;
x < width;
x++, from += 3, to += 4) {
260 else if (channels_from == 4) {
262 const float *from = rect_from + size_t(stride_from) *
y * 4;
263 uchar *to = rect_to + size_t(stride_to) *
y * 4;
265 if (dither && predivide) {
267 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
275 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
281 else if (predivide) {
282 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
289 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
300 const uchar *rect_from,
317 for (
y = 0;
y < height;
y++) {
318 const uchar *from = rect_from + size_t(stride_from) *
y * 4;
319 float *to = rect_to + size_t(stride_to) *
y * 4;
321 if (profile_to == profile_from) {
323 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
330 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
335 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
343 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
349 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
359 const float *rect_from,
375 if (channels_from == 1) {
377 for (
y = 0;
y < height;
y++) {
378 const float *from = rect_from + size_t(stride_from) *
y;
379 float *to = rect_to + size_t(stride_to) *
y * 4;
381 for (
x = 0;
x < width;
x++, from++, to += 4) {
382 to[0] = to[1] = to[2] = to[3] = from[0];
386 else if (channels_from == 3) {
388 for (
y = 0;
y < height;
y++) {
389 const float *from = rect_from + size_t(stride_from) *
y * 3;
390 float *to = rect_to + size_t(stride_to) *
y * 4;
392 if (profile_to == profile_from) {
394 for (
x = 0;
x < width;
x++, from += 3, to += 4) {
401 for (
x = 0;
x < width;
x++, from += 3, to += 4) {
408 for (
x = 0;
x < width;
x++, from += 3, to += 4) {
415 else if (channels_from == 4) {
417 for (
y = 0;
y < height;
y++) {
418 const float *from = rect_from + size_t(stride_from) *
y * 4;
419 float *to = rect_to + size_t(stride_to) *
y * 4;
421 if (profile_to == profile_from) {
423 memcpy(to, from,
sizeof(
float) *
size_t(4) * width);
428 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
433 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
441 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
446 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
456 const float *rect_from,
468 int64_t offset_from = y_range.
first() * stride_from * channels_from;
471 rect_from + offset_from,
484 const float *rect_from,
494 if (channels_from == 1) {
496 for (
y = 0;
y < height;
y++) {
497 const float *from = rect_from + size_t(stride_from) *
y;
498 float *to = rect_to + size_t(stride_to) *
y * 4;
500 for (
x = 0;
x < width;
x++, from++, to += 4) {
502 to[0] = to[1] = to[2] = to[3] = from[0];
507 else if (channels_from == 3) {
509 for (
y = 0;
y < height;
y++) {
510 const float *from = rect_from + size_t(stride_from) *
y * 3;
511 float *to = rect_to + size_t(stride_to) *
y * 4;
513 for (
x = 0;
x < width;
x++, from += 3, to += 4) {
521 else if (channels_from == 4) {
523 for (
y = 0;
y < height;
y++) {
524 const float *from = rect_from + size_t(stride_from) *
y * 4;
525 float *to = rect_to + size_t(stride_to) *
y * 4;
527 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
537 const uchar *rect_from,
554 for (
y = 0;
y < height;
y++) {
555 const uchar *from = rect_from + size_t(stride_from) *
y * 4;
556 uchar *to = rect_to + size_t(stride_to) *
y * 4;
558 if (profile_to == profile_from) {
560 memcpy(to, from,
sizeof(
uchar[4]) * width);
565 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
572 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
582 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
589 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
633 from_colorspace, to_colorspace);
640 static constexpr int grain_size = 2048;
669 if (processor !=
nullptr) {
682 "Destination buffer should have a float buffer assigned.");
684 "Source buffer should have a byte buffer assigned.");
685 BLI_assert_msg(dst->
x == src->
x,
"Source and destination buffer should have the same dimension");
686 BLI_assert_msg(dst->
y == src->
y,
"Source and destination buffer should have the same dimension");
689 "Region to update should be clipped to the given buffers.");
691 "Region to update should be clipped to the given buffers.");
693 "Region to update should be clipped to the given buffers.");
695 "Region to update should be clipped to the given buffers.");
703 const uchar *src_ptr = src->byte_buffer.data;
704 src_ptr += (region_to_update->xmin + y_range.first() * dst->x) * 4;
705 float *dst_ptr = dst->float_buffer.data;
706 dst_ptr += (region_to_update->xmin + y_range.first() * dst->x) * 4;
709 IMB_buffer_float_from_byte(dst_ptr,
720 float *dst_ptr_line = dst_ptr;
721 for ([[maybe_unused]] const int64_t y : y_range) {
722 IMB_colormanagement_colorspace_to_scene_linear(
723 dst_ptr_line, region_width, 1, dst->channels, src->byte_buffer.colorspace, false);
724 if (premultiply_alpha) {
725 IMB_premultiply_rect_float(dst_ptr_line, dst->channels, region_width, 1);
727 dst_ptr_line += 4 * dst->x;
746 rcti region_to_update;
794 for ([[maybe_unused]]
const int64_t i : range) {
797 hsv_to_rgb(hsv[0], hsv[1] * sat, hsv[2], rgb + 0, rgb + 1, rgb + 2);
806 const int channels = ibuf->
channels;
809 for ([[maybe_unused]]
const int64_t i : range) {
#define BLI_assert_msg(a, msg)
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
MINLINE void srgb_to_linearrgb_uchar4_predivide(float linear[4], const unsigned char srgb[4])
MINLINE void rgb_uchar_to_float(float r_col[3], const unsigned char col_ub[3])
MINLINE void linearrgb_to_srgb_ushort4(unsigned short srgb[4], const float linear[4])
void linearrgb_to_srgb_v3_v3(float srgb[3], const float linear[3])
MINLINE void linearrgb_to_srgb_predivide_v4(float srgb[4], const float linear[4])
void hsv_to_rgb(float h, float s, float v, float *r_r, float *r_g, float *r_b)
MINLINE float dither_random_value(int x, int y)
MINLINE void srgb_to_linearrgb_uchar4(float linear[4], const unsigned char srgb[4])
MINLINE void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
MINLINE void rgb_float_to_uchar(unsigned char r_col[3], const float col_f[3])
MINLINE void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
MINLINE void srgb_to_linearrgb_v4(float linear[4], const float srgb[4])
MINLINE void premul_to_straight_v4_v4(float straight[4], const float premul[4])
void srgb_to_linearrgb_v3_v3(float linear[3], const float srgb[3])
MINLINE void linearrgb_to_srgb_v4(float srgb[4], const float linear[4])
MINLINE void srgb_to_linearrgb_predivide_v4(float linear[4], const float srgb[4])
MINLINE void premul_float_to_straight_uchar(unsigned char *result, const float color[4])
MINLINE void copy_v4_v4(float r[4], const float a[4])
MINLINE void copy_v3_v3(float r[3], const float a[3])
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
BLI_INLINE unsigned char IMB_colormanagement_get_luminance_byte(const unsigned char rgb[3])
ColormanageProcessor * IMB_colormanagement_colorspace_processor_new(const char *from_colorspace, const char *to_colorspace)
@ COLOR_ROLE_DEFAULT_BYTE
@ COLOR_ROLE_SCENE_LINEAR
bool IMB_colormanagement_processor_is_noop(ColormanageProcessor *cm_processor)
void IMB_colormanagement_processor_apply(ColormanageProcessor *cm_processor, float *buffer, int width, int height, int channels, bool predivide)
BLI_INLINE float IMB_colormanagement_get_luminance(const float rgb[3])
const char * IMB_colormanagement_role_colorspace_name_get(int role)
void IMB_colormanagement_processor_free(ColormanageProcessor *cm_processor)
Function declarations for filter.cc.
bool IMB_alloc_byte_pixels(ImBuf *ibuf, bool initialize_pixels=true)
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_float_pixels(ImBuf *ibuf, const unsigned int channels, bool initialize_pixels=true)
#define IB_PROFILE_LINEAR_RGB
@ IB_alphamode_channel_packed
Read Guarded memory(de)allocation.
MutableSpan< T > as_mutable_span()
constexpr int64_t first() const
constexpr int64_t size() const
constexpr const char * c_str() const
virtual StringRefNull name() const =0
void IMB_buffer_float_from_float_mask(float *rect_to, const float *rect_from, int channels_from, int width, int height, int stride_to, int stride_from, char *mask)
#define USHORTTOFLOAT(val)
void IMB_float_from_byte_ex(ImBuf *dst, const ImBuf *src, const rcti *region_to_update)
MINLINE void float_to_byte_dither_v4(uchar b[4], const float f[4], float dither, int x, int y)
MINLINE void ushort_to_byte_dither_v4(uchar b[4], const ushort us[4], float dither, int x, int y)
void IMB_buffer_byte_from_float_mask(uchar *rect_to, const float *rect_from, int channels_from, float dither, bool predivide, int width, int height, int stride_to, int stride_from, char *mask)
bool IMB_alpha_affects_rgb(const ImBuf *ibuf)
void IMB_byte_from_float(ImBuf *ibuf)
void IMB_buffer_float_from_float(float *rect_to, const float *rect_from, int channels_from, int profile_to, int profile_from, bool predivide, int width, int height, int stride_to, int stride_from)
void IMB_color_to_bw(ImBuf *ibuf)
void IMB_buffer_float_from_byte(float *rect_to, const uchar *rect_from, int profile_to, int profile_from, bool predivide, int width, int height, int stride_to, int stride_from)
void IMB_buffer_float_from_float_threaded(float *rect_to, const float *rect_from, int channels_from, int profile_to, int profile_from, bool predivide, int width, int height, int stride_to, int stride_from)
void IMB_saturation(ImBuf *ibuf, float sat)
MINLINE uchar ftochar(float value)
MINLINE void ushort_to_byte_v4(uchar b[4], const ushort us[4])
void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from, int channels_from, float dither, int profile_to, int profile_from, bool predivide, int width, int height, int stride_to, int stride_from, int start_y)
void IMB_buffer_byte_from_byte(uchar *rect_to, const uchar *rect_from, int profile_to, int profile_from, bool predivide, int width, int height, int stride_to, int stride_from)
void IMB_float_from_byte(ImBuf *ibuf)
void IMB_unpremultiply_rect_float(float *rect_float, int channels, int w, int h)
MINLINE unsigned char unit_ushort_to_uchar(unsigned short val)
MINLINE unsigned char unit_float_to_uchar_clamp(float val)
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
const ColorSpace * colorspace
const ColorSpace * colorspace
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer