diff --git a/source/blender/alembic/intern/abc_customdata.cc b/source/blender/alembic/intern/abc_customdata.cc index b3b015c7abf..3b6c87ea1a0 100644 --- a/source/blender/alembic/intern/abc_customdata.cc +++ b/source/blender/alembic/intern/abc_customdata.cc @@ -31,6 +31,7 @@ extern "C" { #include "DNA_customdata_types.h" #include "DNA_meshdata_types.h" +#include "BLI_math_base.h" #include "BKE_customdata.h" } diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index 46b3748c7ce..65dcbf04913 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -224,29 +224,6 @@ extern "C" { b = tmp; \ } (void)0 - -#define FTOCHAR(val) ((CHECK_TYPE_INLINE(val, float)), \ - (char)(((val) <= 0.0f) ? 0 : (((val) > (1.0f - 0.5f / 255.0f)) ? 255 : ((255.0f * (val)) + 0.5f)))) -#define FTOUSHORT(val) ((CHECK_TYPE_INLINE(val, float)), \ - (unsigned short)((val >= 1.0f - 0.5f / 65535) ? 65535 : (val <= 0.0f) ? 0 : (val * 65535.0f + 0.5f))) -#define USHORTTOUCHAR(val) ((unsigned char)(((val) >= 65535 - 128) ? 255 : ((val) + 128) >> 8)) -#define F3TOCHAR3(v2, v1) { \ - (v1)[0] = FTOCHAR((v2[0])); \ - (v1)[1] = FTOCHAR((v2[1])); \ - (v1)[2] = FTOCHAR((v2[2])); \ -} (void)0 -#define F3TOCHAR4(v2, v1) { \ - (v1)[0] = FTOCHAR((v2[0])); \ - (v1)[1] = FTOCHAR((v2[1])); \ - (v1)[2] = FTOCHAR((v2[2])); \ - (v1)[3] = 255; \ -} (void)0 -#define F4TOCHAR4(v2, v1) { \ - (v1)[0] = FTOCHAR((v2[0])); \ - (v1)[1] = FTOCHAR((v2[1])); \ - (v1)[2] = FTOCHAR((v2[2])); \ - (v1)[3] = FTOCHAR((v2[3])); \ -} (void)0 #define VECCOPY(v1, v2) { \ *(v1) = *(v2); \ *(v1 + 1) = *(v2 + 1); \ diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index 4bedcbdf5bf..82ed6cd1cd1 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -513,6 +513,38 @@ MALWAYS_INLINE __m128 _bli_math_blend_sse(const __m128 mask, return _mm_or_ps(_mm_and_ps(mask, a), _mm_andnot_ps(mask, b)); } +/* Low level conversion functions */ +/* TODO: name sensibly. */ +MINLINE unsigned char FTOCHAR(float val) +{ + return (unsigned char)(((val <= 0.0f) ? 0 : ((val > (1.0f - 0.5f / 255.0f)) ? 255 : ((255.0f * val) + 0.5f)))); +} +#define FTOCHAR(val) ((CHECK_TYPE_INLINE(val, float)), FTOCHAR(val)) + +MINLINE unsigned short FTOUSHORT(float val) +{ + return (unsigned short)((val >= 1.0f - 0.5f / 65535) ? 65535 : (val <= 0.0f) ? 0 : (val * 65535.0f + 0.5f)); +} +#define FTOUSHORT(val) ((CHECK_TYPE_INLINE(val, float)), FTOUSHORT(val)) + +MINLINE unsigned char USHORTTOUCHAR(unsigned short val) +{ + return (unsigned char)(((val) >= 65535 - 128) ? 255 : ((val) + 128) >> 8); +} +#define USHORTTOUCHAR(val) ((CHECK_TYPE_INLINE(val, unsigned short)), USHORTTOUCHAR(val)) + +#define F3TOCHAR3(v2, v1) { \ + (v1)[0] = FTOCHAR((v2[0])); \ + (v1)[1] = FTOCHAR((v2[1])); \ + (v1)[2] = FTOCHAR((v2[2])); \ +} ((void)0) +#define F4TOCHAR4(v2, v1) { \ + (v1)[0] = FTOCHAR((v2[0])); \ + (v1)[1] = FTOCHAR((v2[1])); \ + (v1)[2] = FTOCHAR((v2[2])); \ + (v1)[3] = FTOCHAR((v2[3])); \ +} ((void)0) + #endif /* __SSE2__ */ #endif /* __MATH_BASE_INLINE_C__ */ diff --git a/source/blender/compositor/operations/COM_PreviewOperation.cpp b/source/blender/compositor/operations/COM_PreviewOperation.cpp index aa667884de6..2845b972f65 100644 --- a/source/blender/compositor/operations/COM_PreviewOperation.cpp +++ b/source/blender/compositor/operations/COM_PreviewOperation.cpp @@ -105,7 +105,7 @@ void PreviewOperation::executeRegion(rcti *rect, unsigned int /*tileNumber*/) color[3] = 1.0f; this->m_input->readSampled(color, rx, ry, COM_PS_NEAREST); IMB_colormanagement_processor_apply_v4(cm_processor, color); - F4TOCHAR4(color, this->m_outputBuffer + offset); + rgba_float_to_uchar(this->m_outputBuffer + offset, color); offset += 4; } } diff --git a/source/blender/imbuf/intern/filter.c b/source/blender/imbuf/intern/filter.c index 38609d0a342..27711618cee 100644 --- a/source/blender/imbuf/intern/filter.c +++ b/source/blender/imbuf/intern/filter.c @@ -34,6 +34,7 @@ #include "MEM_guardedalloc.h" #include "BLI_utildefines.h" +#include "BLI_math_base.h" #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" diff --git a/source/blender/imbuf/intern/scaling.c b/source/blender/imbuf/intern/scaling.c index ff92ce15811..1c0b47f7942 100644 --- a/source/blender/imbuf/intern/scaling.c +++ b/source/blender/imbuf/intern/scaling.c @@ -332,9 +332,9 @@ MINLINE void premul_ushort_to_straight_uchar(unsigned char *result, const unsign else { unsigned short alpha = color[3] / 256; - result[0] = USHORTTOUCHAR(color[0] / alpha * 256); - result[1] = USHORTTOUCHAR(color[1] / alpha * 256); - result[2] = USHORTTOUCHAR(color[2] / alpha * 256); + result[0] = USHORTTOUCHAR((ushort)(color[0] / alpha * 256)); + result[1] = USHORTTOUCHAR((ushort)(color[1] / alpha * 256)); + result[2] = USHORTTOUCHAR((ushort)(color[2] / alpha * 256)); result[3] = USHORTTOUCHAR(color[3]); } } diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index bc2c26c2b2b..7357712aaef 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -33,6 +33,7 @@ #include "DNA_object_types.h" #include "BLI_utildefines.h" +#include "BLI_math_base.h" #include "BKE_icons.h" #include "BKE_object.h" diff --git a/source/blender/makesrna/intern/rna_image.c b/source/blender/makesrna/intern/rna_image.c index cb71cf756ec..5bb38f29309 100644 --- a/source/blender/makesrna/intern/rna_image.c +++ b/source/blender/makesrna/intern/rna_image.c @@ -30,6 +30,7 @@ #include "DNA_scene_types.h" #include "BLI_utildefines.h" +#include "BLI_math_base.h" #include "BKE_context.h" #include "BKE_depsgraph.h"