44#define USHORTTOFLOAT(val) (float(val) / 65535.0f)
71 const float *rect_from,
90 for (
y = 0;
y < height;
y++) {
91 if (channels_from == 1) {
93 const float *from = rect_from + size_t(stride_from) *
y;
94 uchar *to = rect_to + size_t(stride_to) *
y * 4;
96 for (
x = 0;
x < width;
x++, from++, to += 4) {
100 else if (channels_from == 3) {
102 const float *from = rect_from + size_t(stride_from) *
y * 3;
103 uchar *to = rect_to + size_t(stride_to) *
y * 4;
105 if (profile_to == profile_from) {
107 for (
x = 0;
x < width;
x++, from += 3, to += 4) {
114 for (
x = 0;
x < width;
x++, from += 3, to += 4) {
122 for (
x = 0;
x < width;
x++, from += 3, to += 4) {
129 else if (channels_from == 4) {
131 const float *from = rect_from + size_t(stride_from) *
y * 4;
132 uchar *to = rect_to + size_t(stride_to) *
y * 4;
134 if (profile_to == profile_from) {
136 if (dither && predivide) {
138 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
144 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
148 else if (predivide) {
149 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
154 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
164 if (dither && predivide) {
165 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
172 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
177 else if (predivide) {
178 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
185 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
193 if (dither && predivide) {
194 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
200 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
205 else if (predivide) {
206 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
212 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
223 const float *rect_from,
235 for (
y = 0;
y < height;
y++) {
236 if (channels_from == 1) {
238 const float *from = rect_from + size_t(stride_from) *
y;
239 uchar *to = rect_to + size_t(stride_to) *
y * 4;
241 for (
x = 0;
x < width;
x++, from++, to += 4) {
247 else if (channels_from == 3) {
249 const float *from = rect_from + size_t(stride_from) *
y * 3;
250 uchar *to = rect_to + size_t(stride_to) *
y * 4;
252 for (
x = 0;
x < width;
x++, from += 3, to += 4) {
259 else if (channels_from == 4) {
261 const float *from = rect_from + size_t(stride_from) *
y * 4;
262 uchar *to = rect_to + size_t(stride_to) *
y * 4;
264 if (dither && predivide) {
266 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
274 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
280 else if (predivide) {
281 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
288 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
299 const uchar *rect_from,
316 for (
y = 0;
y < height;
y++) {
317 const uchar *from = rect_from + size_t(stride_from) *
y * 4;
318 float *to = rect_to + size_t(stride_to) *
y * 4;
320 if (profile_to == profile_from) {
322 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
329 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
334 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
342 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
348 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
358 const float *rect_from,
374 if (channels_from == 1) {
376 for (
y = 0;
y < height;
y++) {
377 const float *from = rect_from + size_t(stride_from) *
y;
378 float *to = rect_to + size_t(stride_to) *
y * 4;
380 for (
x = 0;
x < width;
x++, from++, to += 4) {
381 to[0] = to[1] = to[2] = to[3] = from[0];
385 else if (channels_from == 3) {
387 for (
y = 0;
y < height;
y++) {
388 const float *from = rect_from + size_t(stride_from) *
y * 3;
389 float *to = rect_to + size_t(stride_to) *
y * 4;
391 if (profile_to == profile_from) {
393 for (
x = 0;
x < width;
x++, from += 3, to += 4) {
400 for (
x = 0;
x < width;
x++, from += 3, to += 4) {
407 for (
x = 0;
x < width;
x++, from += 3, to += 4) {
414 else if (channels_from == 4) {
416 for (
y = 0;
y < height;
y++) {
417 const float *from = rect_from + size_t(stride_from) *
y * 4;
418 float *to = rect_to + size_t(stride_to) *
y * 4;
420 if (profile_to == profile_from) {
422 memcpy(to, from,
sizeof(
float) *
size_t(4) * width);
427 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
432 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
440 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
445 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
455 const float *rect_from,
467 int64_t offset_from = y_range.
first() * stride_from * channels_from;
470 rect_from + offset_from,
483 const float *rect_from,
493 if (channels_from == 1) {
495 for (
y = 0;
y < height;
y++) {
496 const float *from = rect_from + size_t(stride_from) *
y;
497 float *to = rect_to + size_t(stride_to) *
y * 4;
499 for (
x = 0;
x < width;
x++, from++, to += 4) {
501 to[0] = to[1] = to[2] = to[3] = from[0];
506 else if (channels_from == 3) {
508 for (
y = 0;
y < height;
y++) {
509 const float *from = rect_from + size_t(stride_from) *
y * 3;
510 float *to = rect_to + size_t(stride_to) *
y * 4;
512 for (
x = 0;
x < width;
x++, from += 3, to += 4) {
520 else if (channels_from == 4) {
522 for (
y = 0;
y < height;
y++) {
523 const float *from = rect_from + size_t(stride_from) *
y * 4;
524 float *to = rect_to + size_t(stride_to) *
y * 4;
526 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
536 const uchar *rect_from,
553 for (
y = 0;
y < height;
y++) {
554 const uchar *from = rect_from + size_t(stride_from) *
y * 4;
555 uchar *to = rect_to + size_t(stride_to) *
y * 4;
557 if (profile_to == profile_from) {
559 memcpy(to, from,
sizeof(
uchar[4]) * width);
564 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
571 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
581 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
588 for (
x = 0;
x < width;
x++, from += 4, to += 4) {
632 buffer, ibuf->
x, ibuf->
y, ibuf->
channels, from_colorspace, to_colorspace, predivide);
661 "Destination buffer should have a float buffer assigned.");
663 "Source buffer should have a byte buffer assigned.");
664 BLI_assert_msg(dst->
x == src->
x,
"Source and destination buffer should have the same dimension");
665 BLI_assert_msg(dst->
y == src->
y,
"Source and destination buffer should have the same dimension");
668 "Region to update should be clipped to the given buffers.");
670 "Region to update should be clipped to the given buffers.");
672 "Region to update should be clipped to the given buffers.");
674 "Region to update should be clipped to the given buffers.");
677 rect_float += (region_to_update->
xmin + region_to_update->
ymin * dst->
x) * 4;
679 rect += (region_to_update->
xmin + region_to_update->
ymin * dst->
x) * 4;
695 float *float_ptr = rect_float;
696 for (
int i = 0;
i < region_height;
i++) {
699 float_ptr += 4 * dst->
x;
704 float_ptr = rect_float;
705 for (
int i = 0;
i < region_height;
i++) {
707 float_ptr += 4 * dst->
x;
724 if (rect_float ==
nullptr) {
727 if (rect_float ==
nullptr) {
736 rcti region_to_update;
784 for ([[maybe_unused]]
const int64_t i : range) {
787 hsv_to_rgb(hsv[0], hsv[1] * sat, hsv[2], rgb + 0, rgb + 1, rgb + 2);
796 const int channels = ibuf->
channels;
799 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 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 srgb_to_linearrgb_v4(float linear[4], const float srgb[4])
void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
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])
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])
void rgb_uchar_to_float(float r_col[3], const unsigned char col_ub[3])
void rgb_float_to_uchar(unsigned char r_col[3], const float col_f[3])
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])
void IMB_colormanagement_colorspace_to_scene_linear(float *buffer, int width, int height, int channels, const ColorSpace *colorspace, bool predivide)
void IMB_colormanagement_transform_float(float *buffer, int width, int height, int channels, const char *from_colorspace, const char *to_colorspace, bool predivide)
@ COLOR_ROLE_DEFAULT_BYTE
@ COLOR_ROLE_SCENE_LINEAR
BLI_INLINE float IMB_colormanagement_get_luminance(const float rgb[3])
const char * IMB_colormanagement_role_colorspace_name_get(int role)
Function declarations for filter.cc.
void IMB_assign_float_buffer(ImBuf *ibuf, float *buffer_data, ImBufOwnership ownership)
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.
#define IB_PROFILE_LINEAR_RGB
@ IB_alphamode_channel_packed
Read Guarded memory(de)allocation.
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)
void IMB_premultiply_rect_float(float *rect_float, int channels, int w, int h)
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
void * MEM_dupallocN(const void *vmemh)
void MEM_freeN(void *vmemh)
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