36 di = MEM_cnew<DitherContext>(
"dithering context");
69#define USHORTTOFLOAT(val) (float(val) / 65535.0f)
97 const float *rect_from,
111 float inv_width = 1.0f / width;
112 float inv_height = 1.0f / height;
122 for (y = 0; y < height; y++) {
123 float t = y * inv_height;
125 if (channels_from == 1) {
127 const float *from = rect_from + size_t(stride_from) *
y;
128 uchar *to = rect_to + size_t(stride_to) * y * 4;
130 for (x = 0; x < width; x++, from++, to += 4) {
134 else if (channels_from == 3) {
136 const float *from = rect_from + size_t(stride_from) * y * 3;
137 uchar *to = rect_to + size_t(stride_to) * y * 4;
139 if (profile_to == profile_from) {
141 for (x = 0; x < width; x++, from += 3, to += 4) {
148 for (x = 0; x < width; x++, from += 3, to += 4) {
156 for (x = 0; x < width; x++, from += 3, to += 4) {
163 else if (channels_from == 4) {
165 const float *from = rect_from + size_t(stride_from) * y * 4;
166 uchar *to = rect_to + size_t(stride_to) * y * 4;
168 if (profile_to == profile_from) {
170 if (dither && predivide) {
172 for (x = 0; x < width; x++, from += 4, to += 4) {
178 for (x = 0; x < width; x++, from += 4, to += 4) {
182 else if (predivide) {
183 for (x = 0; x < width; x++, from += 4, to += 4) {
188 for (x = 0; x < width; x++, from += 4, to += 4) {
198 if (dither && predivide) {
199 for (x = 0; x < width; x++, from += 4, to += 4) {
206 for (x = 0; x < width; x++, from += 4, to += 4) {
211 else if (predivide) {
212 for (x = 0; x < width; x++, from += 4, to += 4) {
219 for (x = 0; x < width; x++, from += 4, to += 4) {
227 if (dither && predivide) {
228 for (x = 0; x < width; x++, from += 4, to += 4) {
234 for (x = 0; x < width; x++, from += 4, to += 4) {
239 else if (predivide) {
240 for (x = 0; x < width; x++, from += 4, to += 4) {
246 for (x = 0; x < width; x++, from += 4, to += 4) {
261 const float *rect_from,
273 float inv_width = 1.0f / width, inv_height = 1.0f / height;
279 for (y = 0; y < height; y++) {
280 float t = y * inv_height;
282 if (channels_from == 1) {
284 const float *from = rect_from + size_t(stride_from) *
y;
285 uchar *to = rect_to + size_t(stride_to) * y * 4;
287 for (x = 0; x < width; x++, from++, to += 4) {
293 else if (channels_from == 3) {
295 const float *from = rect_from + size_t(stride_from) * y * 3;
296 uchar *to = rect_to + size_t(stride_to) * y * 4;
298 for (x = 0; x < width; x++, from += 3, to += 4) {
305 else if (channels_from == 4) {
307 const float *from = rect_from + size_t(stride_from) * y * 4;
308 uchar *to = rect_to + size_t(stride_to) * y * 4;
310 if (dither && predivide) {
312 for (x = 0; x < width; x++, from += 4, to += 4) {
320 for (x = 0; x < width; x++, from += 4, to += 4) {
326 else if (predivide) {
327 for (x = 0; x < width; x++, from += 4, to += 4) {
334 for (x = 0; x < width; x++, from += 4, to += 4) {
349 const uchar *rect_from,
366 for (y = 0; y < height; y++) {
367 const uchar *from = rect_from + size_t(stride_from) * y * 4;
368 float *to = rect_to + size_t(stride_to) * y * 4;
370 if (profile_to == profile_from) {
372 for (x = 0; x < width; x++, from += 4, to += 4) {
379 for (x = 0; x < width; x++, from += 4, to += 4) {
384 for (x = 0; x < width; x++, from += 4, to += 4) {
392 for (x = 0; x < width; x++, from += 4, to += 4) {
398 for (x = 0; x < width; x++, from += 4, to += 4) {
408 const float *rect_from,
424 if (channels_from == 1) {
426 for (y = 0; y < height; y++) {
427 const float *from = rect_from + size_t(stride_from) *
y;
428 float *to = rect_to + size_t(stride_to) * y * 4;
430 for (x = 0; x < width; x++, from++, to += 4) {
431 to[0] = to[1] = to[2] = to[3] = from[0];
435 else if (channels_from == 3) {
437 for (y = 0; y < height; y++) {
438 const float *from = rect_from + size_t(stride_from) * y * 3;
439 float *to = rect_to + size_t(stride_to) * y * 4;
441 if (profile_to == profile_from) {
443 for (x = 0; x < width; x++, from += 3, to += 4) {
450 for (x = 0; x < width; x++, from += 3, to += 4) {
457 for (x = 0; x < width; x++, from += 3, to += 4) {
464 else if (channels_from == 4) {
466 for (y = 0; y < height; y++) {
467 const float *from = rect_from + size_t(stride_from) * y * 4;
468 float *to = rect_to + size_t(stride_to) * y * 4;
470 if (profile_to == profile_from) {
472 memcpy(to, from,
sizeof(
float) *
size_t(4) * width);
477 for (x = 0; x < width; x++, from += 4, to += 4) {
482 for (x = 0; x < width; x++, from += 4, to += 4) {
490 for (x = 0; x < width; x++, from += 4, to += 4) {
495 for (x = 0; x < width; x++, from += 4, to += 4) {
518 const int num_scanlines = 1;
520 size_t offset_from = size_t(scanline) * data->
stride_from * data->channels_from;
521 size_t offset_to = size_t(scanline) * data->stride_to * data->channels_from;
523 data->rect_from + offset_from,
535 const float *rect_from,
545 if (
size_t(width) * height < 64 * 64) {
560 data.rect_from = rect_from;
561 data.channels_from = channels_from;
562 data.profile_to = profile_to;
563 data.profile_from = profile_from;
564 data.predivide = predivide;
566 data.stride_to = stride_to;
567 data.stride_from = stride_from;
573 const float *rect_from,
583 if (channels_from == 1) {
585 for (y = 0; y < height; y++) {
586 const float *from = rect_from + size_t(stride_from) *
y;
587 float *to = rect_to + size_t(stride_to) * y * 4;
589 for (x = 0; x < width; x++, from++, to += 4) {
591 to[0] = to[1] = to[2] = to[3] = from[0];
596 else if (channels_from == 3) {
598 for (y = 0; y < height; y++) {
599 const float *from = rect_from + size_t(stride_from) * y * 3;
600 float *to = rect_to + size_t(stride_to) * y * 4;
602 for (x = 0; x < width; x++, from += 3, to += 4) {
610 else if (channels_from == 4) {
612 for (y = 0; y < height; y++) {
613 const float *from = rect_from + size_t(stride_from) * y * 4;
614 float *to = rect_to + size_t(stride_to) * y * 4;
616 for (x = 0; x < width; x++, from += 4, to += 4) {
626 const uchar *rect_from,
643 for (y = 0; y < height; y++) {
644 const uchar *from = rect_from + size_t(stride_from) * y * 4;
645 uchar *to = rect_to + size_t(stride_to) * y * 4;
647 if (profile_to == profile_from) {
649 memcpy(to, from,
sizeof(
uchar[4]) * width);
654 for (x = 0; x < width; x++, from += 4, to += 4) {
661 for (x = 0; x < width; x++, from += 4, to += 4) {
671 for (x = 0; x < width; x++, from += 4, to += 4) {
678 for (x = 0; x < width; x++, from += 4, to += 4) {
722 buffer, ibuf->
x, ibuf->
y, ibuf->
channels, from_colorspace, to_colorspace, predivide);
751 "Destination buffer should have a float buffer assigned.");
753 "Source buffer should have a byte buffer assigned.");
754 BLI_assert_msg(dst->
x == src->
x,
"Source and destination buffer should have the same dimension");
755 BLI_assert_msg(dst->
y == src->
y,
"Source and destination buffer should have the same dimension");
758 "Region to update should be clipped to the given buffers.");
760 "Region to update should be clipped to the given buffers.");
762 "Region to update should be clipped to the given buffers.");
764 "Region to update should be clipped to the given buffers.");
767 rect_float += (region_to_update->
xmin + region_to_update->
ymin * dst->
x) * 4;
769 rect += (region_to_update->
xmin + region_to_update->
ymin * dst->
x) * 4;
785 float *float_ptr = rect_float;
786 for (
int i = 0; i < region_height; i++) {
789 float_ptr += 4 * dst->
x;
794 float_ptr = rect_float;
795 for (
int i = 0; i < region_height; i++) {
797 float_ptr += 4 * dst->
x;
814 if (rect_float ==
nullptr) {
816 rect_float =
static_cast<float *
>(
MEM_callocN(size,
"IMB_float_from_rect"));
818 if (rect_float ==
nullptr) {
827 rcti region_to_update;
878 hsv_to_rgb(hsv[0], hsv[1] * sat, hsv[2], rgb + 0, rgb + 1, rgb + 2);
887 const int channels = ibuf->
channels;
#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 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 float dither_random_value(float s, float t)
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[3])
BLI_INLINE float IMB_colormanagement_get_luminance(const float rgb[3])
const char * IMB_colormanagement_role_colorspace_name_get(int role)
@ COLOR_ROLE_DEFAULT_BYTE
@ COLOR_ROLE_SCENE_LINEAR
void IMB_colormanagement_transform(float *buffer, int width, int height, int channels, const char *from_colorspace, const char *to_colorspace, bool predivide)
void IMB_colormanagement_colorspace_to_scene_linear(float *buffer, int width, int height, int channels, ColorSpace *colorspace, bool predivide)
Function declarations for filter.cc.
size_t IMB_get_rect_len(const ImBuf *ibuf)
Get the length of the rect of the given image buffer in terms of pixels.
void IMB_assign_float_buffer(ImBuf *ibuf, float *buffer_data, ImBufOwnership ownership)
void IMB_processor_apply_threaded_scanlines(int total_scanlines, ScanlineThreadFunc do_thread, void *custom_data)
bool imb_addrectImBuf(ImBuf *ibuf, bool initialize_pixels=true)
Contains defines and structs used throughout the imbuf module.
#define IB_PROFILE_LINEAR_RGB
@ IB_alphamode_channel_packed
Read Guarded memory(de)allocation.
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a producing a negative Combine Generate a color from its and blue channels(Deprecated)") DefNode(ShaderNode
local_group_size(16, 16) .push_constant(Type b
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_rect_from_float(ImBuf *ibuf)
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)
void IMB_float_from_rect_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], DitherContext *di, float s, float t)
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_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)
static DitherContext * create_dither_context(float dither)
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])
static void imb_buffer_float_from_float_thread_do(void *data_v, int scanline)
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)
static void clear_dither_context(DitherContext *di)
void IMB_float_from_rect(ImBuf *ibuf)
MINLINE void ushort_to_byte_dither_v4(uchar b[4], const ushort us[4], DitherContext *di, float s, float t)
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_freeN(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
void *(* MEM_dupallocN)(const void *vmemh)
#define unit_float_to_uchar_clamp(val)
#define unit_ushort_to_uchar(val)
char name[MAX_COLORSPACE_NAME]
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer