Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-05-07 19:02:48 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-05-07 19:02:48 +0300
commitb49184b608df297195c5f0e81da4d8d9ddfb9213 (patch)
treec2624887be563319a7138516d2fcc6100acdb2c6 /source
parentf62b826533422e5de3b08601e5511c233deda529 (diff)
parentf74d85ffc8232a859b1419f5dc25b244ae04375f (diff)
Merge branch 'master' into blender2.8
Diffstat (limited to 'source')
-rw-r--r--source/blender/alembic/intern/abc_customdata.cc14
-rw-r--r--source/blender/alembic/intern/abc_mesh.cc2
-rw-r--r--source/blender/blenkernel/intern/colortools.c6
-rw-r--r--source/blender/blenkernel/intern/dynamicpaint.c4
-rw-r--r--source/blender/blenkernel/intern/seqmodifier.c2
-rw-r--r--source/blender/blenlib/intern/math_base_inline.c31
-rw-r--r--source/blender/blenlib/intern/math_color.c4
-rw-r--r--source/blender/blenlib/intern/math_color_inline.c28
-rw-r--r--source/blender/collada/MeshImporter.cpp12
-rw-r--r--source/blender/editors/interface/interface_templates.c2
-rw-r--r--source/blender/editors/interface/interface_widgets.c2
-rw-r--r--source/blender/editors/interface/resources.c2
-rw-r--r--source/blender/editors/sculpt_paint/paint_image_2d.c2
-rw-r--r--source/blender/editors/sculpt_paint/paint_image_proj.c10
-rw-r--r--source/blender/editors/space_sequencer/sequencer_scopes.c8
-rw-r--r--source/blender/gpu/intern/gpu_buffers.c4
-rw-r--r--source/blender/imbuf/intern/colormanagement.c2
-rw-r--r--source/blender/imbuf/intern/colormanagement_inline.c2
-rw-r--r--source/blender/imbuf/intern/divers.c18
-rw-r--r--source/blender/imbuf/intern/filter.c6
-rw-r--r--source/blender/imbuf/intern/png.c2
-rw-r--r--source/blender/imbuf/intern/rectop.c8
-rw-r--r--source/blender/imbuf/intern/scaling.c16
-rw-r--r--source/blender/imbuf/intern/tiff.c2
-rw-r--r--source/blender/makesrna/intern/makesrna.c2
-rw-r--r--source/blender/makesrna/intern/rna_ID.c2
-rw-r--r--source/blender/makesrna/intern/rna_image.c2
-rw-r--r--source/blender/modifiers/intern/MOD_particleinstance.c2
-rw-r--r--source/blender/render/intern/source/multires_bake.c6
29 files changed, 101 insertions, 102 deletions
diff --git a/source/blender/alembic/intern/abc_customdata.cc b/source/blender/alembic/intern/abc_customdata.cc
index 3b6c87ea1a0..b98d82f0c7d 100644
--- a/source/blender/alembic/intern/abc_customdata.cc
+++ b/source/blender/alembic/intern/abc_customdata.cc
@@ -362,9 +362,9 @@ static void read_custom_data_mcols(const std::string & iobject_full_name,
bounds_warning_given);
const Imath::C3f &color = (*c3f_ptr)[color_index];
- cface->a = FTOCHAR(color[0]);
- cface->r = FTOCHAR(color[1]);
- cface->g = FTOCHAR(color[2]);
+ cface->a = unit_float_to_uchar_clamp(color[0]);
+ cface->r = unit_float_to_uchar_clamp(color[1]);
+ cface->g = unit_float_to_uchar_clamp(color[2]);
cface->b = 255;
}
else {
@@ -375,10 +375,10 @@ static void read_custom_data_mcols(const std::string & iobject_full_name,
bounds_warning_given);
const Imath::C4f &color = (*c4f_ptr)[color_index];
- cface->a = FTOCHAR(color[0]);
- cface->r = FTOCHAR(color[1]);
- cface->g = FTOCHAR(color[2]);
- cface->b = FTOCHAR(color[3]);
+ cface->a = unit_float_to_uchar_clamp(color[0]);
+ cface->r = unit_float_to_uchar_clamp(color[1]);
+ cface->g = unit_float_to_uchar_clamp(color[2]);
+ cface->b = unit_float_to_uchar_clamp(color[3]);
}
}
}
diff --git a/source/blender/alembic/intern/abc_mesh.cc b/source/blender/alembic/intern/abc_mesh.cc
index 52d14f84728..56fa0a93532 100644
--- a/source/blender/alembic/intern/abc_mesh.cc
+++ b/source/blender/alembic/intern/abc_mesh.cc
@@ -1325,7 +1325,7 @@ void AbcSubDReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelec
MEdge *edge = find_edge(edges, mesh->totedge, (*indices)[i], (*indices)[i + 1]);
if (edge) {
- edge->crease = FTOCHAR((*sharpnesses)[s]);
+ edge->crease = unit_float_to_uchar_clamp((*sharpnesses)[s]);
}
}
diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c
index e7fa4cee587..337d1a1a149 100644
--- a/source/blender/blenkernel/intern/colortools.c
+++ b/source/blender/blenkernel/intern/colortools.c
@@ -955,9 +955,9 @@ void curvemapping_evaluate_premulRGB(const CurveMapping *cumap, unsigned char ve
curvemapping_evaluate_premulRGBF(cumap, vecout, vecin);
- vecout_byte[0] = FTOCHAR(vecout[0]);
- vecout_byte[1] = FTOCHAR(vecout[1]);
- vecout_byte[2] = FTOCHAR(vecout[2]);
+ vecout_byte[0] = unit_float_to_uchar_clamp(vecout[0]);
+ vecout_byte[1] = unit_float_to_uchar_clamp(vecout[1]);
+ vecout_byte[2] = unit_float_to_uchar_clamp(vecout[2]);
}
int curvemapping_RGBA_does_something(const CurveMapping *cumap)
diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c
index c91d3b32e75..0135abc7edb 100644
--- a/source/blender/blenkernel/intern/dynamicpaint.c
+++ b/source/blender/blenkernel/intern/dynamicpaint.c
@@ -1810,7 +1810,7 @@ static void dynamic_paint_apply_surface_vpaint_cb(
}
/* apply wetness */
if (mloopcol_wet) {
- const char c = FTOCHAR(pPoint[v_index].wetness);
+ const char c = unit_float_to_uchar_clamp(pPoint[v_index].wetness);
mloopcol_wet[l_index].r = c;
mloopcol_wet[l_index].g = c;
mloopcol_wet[l_index].b = c;
@@ -1840,7 +1840,7 @@ static void dynamic_paint_apply_surface_vpaint_cb(
rgb_float_to_uchar((unsigned char *)&mloopcol_preview[l_index].r, c);
}
else {
- const char c = FTOCHAR(pPoint[v_index].wetness);
+ const char c = unit_float_to_uchar_clamp(pPoint[v_index].wetness);
mloopcol_preview[l_index].r = c;
mloopcol_preview[l_index].g = c;
mloopcol_preview[l_index].b = c;
diff --git a/source/blender/blenkernel/intern/seqmodifier.c b/source/blender/blenkernel/intern/seqmodifier.c
index e2f74dbab3c..4a483d439e4 100644
--- a/source/blender/blenkernel/intern/seqmodifier.c
+++ b/source/blender/blenkernel/intern/seqmodifier.c
@@ -532,7 +532,7 @@ static void brightcontrast_apply_threaded(int width, int height, unsigned char *
v = (float) pixel[c] / 255.0f * (1.0f - t) + v * t;
}
- pixel[c] = FTOCHAR(v);
+ pixel[c] = unit_float_to_uchar_clamp(v);
}
}
else if (rect_float) {
diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c
index 82ed6cd1cd1..268279f98b1 100644
--- a/source/blender/blenlib/intern/math_base_inline.c
+++ b/source/blender/blenlib/intern/math_base_inline.c
@@ -514,35 +514,34 @@ MALWAYS_INLINE __m128 _bli_math_blend_sse(const __m128 mask,
}
/* Low level conversion functions */
-/* TODO: name sensibly. */
-MINLINE unsigned char FTOCHAR(float val)
+MINLINE unsigned char unit_float_to_uchar_clamp(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))
+#define unit_float_to_uchar_clamp(val) ((CHECK_TYPE_INLINE(val, float)), unit_float_to_uchar_clamp(val))
-MINLINE unsigned short FTOUSHORT(float val)
+MINLINE unsigned short unit_float_to_ushort_clamp(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))
+#define unit_float_to_ushort_clamp(val) ((CHECK_TYPE_INLINE(val, float)), unit_float_to_ushort_clamp(val))
-MINLINE unsigned char USHORTTOUCHAR(unsigned short val)
+MINLINE unsigned char unit_ushort_to_uchar(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 unit_ushort_to_uchar(val) ((CHECK_TYPE_INLINE(val, unsigned short)), unit_ushort_to_uchar(val))
-#define F3TOCHAR3(v2, v1) { \
- (v1)[0] = FTOCHAR((v2[0])); \
- (v1)[1] = FTOCHAR((v2[1])); \
- (v1)[2] = FTOCHAR((v2[2])); \
+#define unit_float_to_uchar_clamp_v3(v1, v2) { \
+ (v1)[0] = unit_float_to_uchar_clamp((v2[0])); \
+ (v1)[1] = unit_float_to_uchar_clamp((v2[1])); \
+ (v1)[2] = unit_float_to_uchar_clamp((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])); \
+#define unit_float_to_uchar_clamp_v4(v1, v2) { \
+ (v1)[0] = unit_float_to_uchar_clamp((v2[0])); \
+ (v1)[1] = unit_float_to_uchar_clamp((v2[1])); \
+ (v1)[2] = unit_float_to_uchar_clamp((v2[2])); \
+ (v1)[3] = unit_float_to_uchar_clamp((v2[3])); \
} ((void)0)
#endif /* __SSE2__ */
diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c
index 2a6f28ef6ee..9399646bedf 100644
--- a/source/blender/blenlib/intern/math_color.c
+++ b/source/blender/blenlib/intern/math_color.c
@@ -441,12 +441,12 @@ void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
void rgb_float_to_uchar(unsigned char r_col[3], const float col_f[3])
{
- F3TOCHAR3(col_f, r_col);
+ unit_float_to_uchar_clamp_v3(r_col, col_f);
}
void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
{
- F4TOCHAR4(col_f, r_col);
+ unit_float_to_uchar_clamp_v4(r_col, col_f);
}
/* ********************************* color transforms ********************************* */
diff --git a/source/blender/blenlib/intern/math_color_inline.c b/source/blender/blenlib/intern/math_color_inline.c
index bc3a1ee3e90..d8e5d530b25 100644
--- a/source/blender/blenlib/intern/math_color_inline.c
+++ b/source/blender/blenlib/intern/math_color_inline.c
@@ -117,7 +117,7 @@ MINLINE void linearrgb_to_srgb_uchar3(unsigned char srgb[3], const float linear[
float srgb_f[3];
linearrgb_to_srgb_v3_v3(srgb_f, linear);
- F3TOCHAR3(srgb_f, srgb);
+ unit_float_to_uchar_clamp_v3(srgb, srgb_f);
}
MINLINE void linearrgb_to_srgb_uchar4(unsigned char srgb[4], const float linear[4])
@@ -125,7 +125,7 @@ MINLINE void linearrgb_to_srgb_uchar4(unsigned char srgb[4], const float linear[
float srgb_f[4];
linearrgb_to_srgb_v4(srgb_f, linear);
- F4TOCHAR4(srgb_f, srgb);
+ unit_float_to_uchar_clamp_v4(srgb, srgb_f);
}
/* predivide versions to work on associated/pre-multiplied alpha. if this should
@@ -204,7 +204,7 @@ MINLINE void linearrgb_to_srgb_ushort4(unsigned short srgb[4], const float linea
srgb[0] = to_srgb_table_lookup(linear[0]);
srgb[1] = to_srgb_table_lookup(linear[1]);
srgb[2] = to_srgb_table_lookup(linear[2]);
- srgb[3] = FTOUSHORT(linear[3]);
+ srgb[3] = unit_float_to_ushort_clamp(linear[3]);
}
MINLINE void srgb_to_linearrgb_uchar4(float linear[4], const unsigned char srgb[4])
@@ -334,9 +334,9 @@ MINLINE void float_to_byte_dither_v3(unsigned char b[3], const float f[3], float
{
float dither_value = dither_random_value(s, t) * 0.005f * dither;
- b[0] = FTOCHAR(dither_value + f[0]);
- b[1] = FTOCHAR(dither_value + f[1]);
- b[2] = FTOCHAR(dither_value + f[2]);
+ b[0] = unit_float_to_uchar_clamp(dither_value + f[0]);
+ b[1] = unit_float_to_uchar_clamp(dither_value + f[1]);
+ b[2] = unit_float_to_uchar_clamp(dither_value + f[2]);
}
/**************** Alpha Transformations *****************/
@@ -391,19 +391,19 @@ MINLINE void straight_uchar_to_premul_float(float result[4], const unsigned char
MINLINE void premul_float_to_straight_uchar(unsigned char *result, const float color[4])
{
if (color[3] == 0.0f || color[3] == 1.0f) {
- result[0] = FTOCHAR(color[0]);
- result[1] = FTOCHAR(color[1]);
- result[2] = FTOCHAR(color[2]);
- result[3] = FTOCHAR(color[3]);
+ result[0] = unit_float_to_uchar_clamp(color[0]);
+ result[1] = unit_float_to_uchar_clamp(color[1]);
+ result[2] = unit_float_to_uchar_clamp(color[2]);
+ result[3] = unit_float_to_uchar_clamp(color[3]);
}
else {
const float alpha_inv = 1.0f / color[3];
/* hopefully this would be optimized */
- result[0] = FTOCHAR(color[0] * alpha_inv);
- result[1] = FTOCHAR(color[1] * alpha_inv);
- result[2] = FTOCHAR(color[2] * alpha_inv);
- result[3] = FTOCHAR(color[3]);
+ result[0] = unit_float_to_uchar_clamp(color[0] * alpha_inv);
+ result[1] = unit_float_to_uchar_clamp(color[1] * alpha_inv);
+ result[2] = unit_float_to_uchar_clamp(color[2] * alpha_inv);
+ result[3] = unit_float_to_uchar_clamp(color[3]);
}
}
diff --git a/source/blender/collada/MeshImporter.cpp b/source/blender/collada/MeshImporter.cpp
index 10b9745a6b9..4c6d00a79cb 100644
--- a/source/blender/collada/MeshImporter.cpp
+++ b/source/blender/collada/MeshImporter.cpp
@@ -185,9 +185,9 @@ void VCOLDataWrapper::get_vcol(int v_index, MLoopCol *mloopcol)
COLLADAFW::ArrayPrimitiveType<float> *values = mVData->getFloatValues();
if (values->empty() || values->getCount() <= (v_index * stride + 2)) return; // xxx need to create an eror instead
- mloopcol->r = FTOCHAR((*values)[v_index * stride]);
- mloopcol->g = FTOCHAR((*values)[v_index * stride + 1]);
- mloopcol->b = FTOCHAR((*values)[v_index * stride + 2]);
+ mloopcol->r = unit_float_to_uchar_clamp((*values)[v_index * stride]);
+ mloopcol->g = unit_float_to_uchar_clamp((*values)[v_index * stride + 1]);
+ mloopcol->b = unit_float_to_uchar_clamp((*values)[v_index * stride + 2]);
}
break;
@@ -196,9 +196,9 @@ void VCOLDataWrapper::get_vcol(int v_index, MLoopCol *mloopcol)
COLLADAFW::ArrayPrimitiveType<double> *values = mVData->getDoubleValues();
if (values->empty() || values->getCount() <= (v_index * stride + 2)) return; // xxx need to create an eror instead
- mloopcol->r = FTOCHAR((*values)[v_index * stride]);
- mloopcol->g = FTOCHAR((*values)[v_index * stride + 1]);
- mloopcol->b = FTOCHAR((*values)[v_index * stride + 2]);
+ mloopcol->r = unit_float_to_uchar_clamp((*values)[v_index * stride]);
+ mloopcol->g = unit_float_to_uchar_clamp((*values)[v_index * stride + 1]);
+ mloopcol->b = unit_float_to_uchar_clamp((*values)[v_index * stride + 2]);
}
break;
default:
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 9167bc43f4a..857ca0a9d96 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -4241,7 +4241,7 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
but = uiDefBut(block, UI_BTYPE_ROUNDBOX, 0, "", UI_UNIT_X + 10, 0, UI_UNIT_X + width, UI_UNIT_Y,
NULL, 0.0f, 0.0f, 0, 0, "");
- but->col[0] = but->col[1] = but->col[2] = FTOCHAR(rti->grayscale);
+ but->col[0] = but->col[1] = but->col[2] = unit_float_to_uchar_clamp(rti->grayscale);
but->col[3] = 255;
UI_block_align_end(block);
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 60f555a6188..b1cacdc5db6 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -987,7 +987,7 @@ static void shadecolors4(char coltop[4], char coldown[4], const char *color, sho
static void round_box_shade_col4_r(unsigned char r_col[4], const char col1[4], const char col2[4], const float fac)
{
- const int faci = FTOCHAR(fac);
+ const int faci = unit_float_to_uchar_clamp(fac);
const int facm = 255 - faci;
r_col[0] = (faci * col1[0] + facm * col2[0]) / 256;
diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c
index 602a88daa14..c78342a0713 100644
--- a/source/blender/editors/interface/resources.c
+++ b/source/blender/editors/interface/resources.c
@@ -1549,7 +1549,7 @@ void UI_GetThemeColorBlendShade3ubv(int colorid1, int colorid2, float fac, int o
blend[1] = offset + floorf((1.0f - fac) * cp1[1] + fac * cp2[1]);
blend[2] = offset + floorf((1.0f - fac) * cp1[2] + fac * cp2[2]);
- F3TOCHAR3(blend, col);
+ unit_float_to_uchar_clamp_v3(col, blend);
}
void UI_GetThemeColorShade4ubv(int colorid, int offset, unsigned char col[4])
diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c b/source/blender/editors/sculpt_paint/paint_image_2d.c
index 83a5a0d0b1b..c2ce9d83782 100644
--- a/source/blender/editors/sculpt_paint/paint_image_2d.c
+++ b/source/blender/editors/sculpt_paint/paint_image_2d.c
@@ -433,7 +433,7 @@ static ImBuf *brush_painter_imbuf_new(BrushPainter *painter, int size, float pre
unsigned char *dst = (unsigned char *)ibuf->rect + (y * size + x) * 4;
rgb_float_to_uchar(dst, rgba);
- dst[3] = FTOCHAR(rgba[3]);
+ dst[3] = unit_float_to_uchar_clamp(rgba[3]);
}
}
}
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index cacb75b2668..8c148dcb313 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -112,10 +112,10 @@
static void partial_redraw_array_init(ImagePaintPartialRedraw *pr);
/* Defines and Structs */
-/* FTOCHAR as inline function */
+/* unit_float_to_uchar_clamp as inline function */
BLI_INLINE unsigned char f_to_char(const float val)
{
- return FTOCHAR(val);
+ return unit_float_to_uchar_clamp(val);
}
/* ProjectionPaint defines */
@@ -4378,7 +4378,7 @@ static void do_projectpaint_draw(
float_to_byte_dither_v3(rgba_ub, rgb, dither, u, v);
}
else {
- F3TOCHAR3(rgb, rgba_ub);
+ unit_float_to_uchar_clamp_v3(rgba_ub, rgb);
}
rgba_ub[3] = f_to_char(mask);
@@ -4582,9 +4582,9 @@ static void *do_projectpaint_thread(void *ph_v)
float_to_byte_dither_v3(projPixel->newColor.ch, color_f, ps->dither, projPixel->x_px, projPixel->y_px);
}
else {
- F3TOCHAR3(color_f, projPixel->newColor.ch);
+ unit_float_to_uchar_clamp_v3(projPixel->newColor.ch, color_f);
}
- projPixel->newColor.ch[3] = FTOCHAR(color_f[3]);
+ projPixel->newColor.ch[3] = unit_float_to_uchar_clamp(color_f[3]);
IMB_blend_color_byte(projPixel->pixel.ch_pt, projPixel->origColor.ch_pt,
projPixel->newColor.ch, ps->blend);
}
diff --git a/source/blender/editors/space_sequencer/sequencer_scopes.c b/source/blender/editors/space_sequencer/sequencer_scopes.c
index c5d6edadb53..8c57089f7ab 100644
--- a/source/blender/editors/space_sequencer/sequencer_scopes.c
+++ b/source/blender/editors/space_sequencer/sequencer_scopes.c
@@ -402,10 +402,10 @@ static void draw_zebra_float(ImBuf *src, ImBuf *ibuf, float perc)
}
}
- *o++ = FTOCHAR(r);
- *o++ = FTOCHAR(g);
- *o++ = FTOCHAR(b);
- *o++ = FTOCHAR(a);
+ *o++ = unit_float_to_uchar_clamp(r);
+ *o++ = unit_float_to_uchar_clamp(g);
+ *o++ = unit_float_to_uchar_clamp(b);
+ *o++ = unit_float_to_uchar_clamp(a);
}
}
}
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index bbee252cd20..9d2a0ceef4d 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -452,7 +452,7 @@ void GPU_pbvh_grid_buffers_update(
diffuse_color, color_ub);
}
else {
- F3TOCHAR3(diffuse_color, color_ub);
+ unit_float_to_uchar_clamp_v3(color_ub, diffuse_color);
}
GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col, vbo_index, color_ub);
}
@@ -495,7 +495,7 @@ void GPU_pbvh_grid_buffers_update(
color_ub);
}
else {
- F3TOCHAR3(diffuse_color, color_ub);
+ unit_float_to_uchar_clamp_v3(color_ub, diffuse_color);
}
GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col, vbo_index, color_ub);
}
diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c
index b2197ecb3b5..7c7c3a7ba45 100644
--- a/source/blender/imbuf/intern/colormanagement.c
+++ b/source/blender/imbuf/intern/colormanagement.c
@@ -2870,7 +2870,7 @@ static void partial_buffer_update_rect(ImBuf *ibuf,
display_buffer[display_index] =
display_buffer[display_index + 1] =
display_buffer[display_index + 2] =
- display_buffer[display_index + 3] = FTOCHAR(pixel[0]);
+ display_buffer[display_index + 3] = unit_float_to_uchar_clamp(pixel[0]);
}
}
}
diff --git a/source/blender/imbuf/intern/colormanagement_inline.c b/source/blender/imbuf/intern/colormanagement_inline.c
index 8382e2a9bfa..4a55f8f86ae 100644
--- a/source/blender/imbuf/intern/colormanagement_inline.c
+++ b/source/blender/imbuf/intern/colormanagement_inline.c
@@ -59,7 +59,7 @@ unsigned char IMB_colormanagement_get_luminance_byte(const unsigned char rgb[3])
rgb_uchar_to_float(rgbf, rgb);
val = dot_v3v3(imbuf_luma_coefficients, rgbf);
- return FTOCHAR(val);
+ return unit_float_to_uchar_clamp(val);
}
#endif /* __IMB_COLORMANAGEMENT_INLINE_H__ */
diff --git a/source/blender/imbuf/intern/divers.c b/source/blender/imbuf/intern/divers.c
index 62fd623ecfa..769d53a44ef 100644
--- a/source/blender/imbuf/intern/divers.c
+++ b/source/blender/imbuf/intern/divers.c
@@ -127,15 +127,15 @@ static void clear_dither_context(DitherContext *di)
MINLINE void ushort_to_byte_v4(uchar b[4], const unsigned short us[4])
{
- b[0] = USHORTTOUCHAR(us[0]);
- b[1] = USHORTTOUCHAR(us[1]);
- b[2] = USHORTTOUCHAR(us[2]);
- b[3] = USHORTTOUCHAR(us[3]);
+ b[0] = unit_ushort_to_uchar(us[0]);
+ b[1] = unit_ushort_to_uchar(us[1]);
+ b[2] = unit_ushort_to_uchar(us[2]);
+ b[3] = unit_ushort_to_uchar(us[3]);
}
MINLINE unsigned char ftochar(float value)
{
- return FTOCHAR(value);
+ return unit_float_to_uchar_clamp(value);
}
MINLINE void ushort_to_byte_dither_v4(uchar b[4], const unsigned short us[4], DitherContext *di, float s, float t)
@@ -146,7 +146,7 @@ MINLINE void ushort_to_byte_dither_v4(uchar b[4], const unsigned short us[4], Di
b[0] = ftochar(dither_value + USHORTTOFLOAT(us[0]));
b[1] = ftochar(dither_value + USHORTTOFLOAT(us[1]));
b[2] = ftochar(dither_value + USHORTTOFLOAT(us[2]));
- b[3] = USHORTTOUCHAR(us[3]);
+ b[3] = unit_ushort_to_uchar(us[3]);
#undef USHORTTOFLOAT
}
@@ -158,7 +158,7 @@ MINLINE void float_to_byte_dither_v4(uchar b[4], const float f[4], DitherContext
b[0] = ftochar(dither_value + f[0]);
b[1] = ftochar(dither_value + f[1]);
b[2] = ftochar(dither_value + f[2]);
- b[3] = FTOCHAR(f[3]);
+ b[3] = unit_float_to_uchar_clamp(f[3]);
}
/* float to byte pixels, output 4-channel RGBA */
@@ -188,7 +188,7 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from,
uchar *to = rect_to + ((size_t)stride_to) * y * 4;
for (x = 0; x < width; x++, from++, to += 4)
- to[0] = to[1] = to[2] = to[3] = FTOCHAR(from[0]);
+ to[0] = to[1] = to[2] = to[3] = unit_float_to_uchar_clamp(from[0]);
}
else if (channels_from == 3) {
/* RGB input */
@@ -339,7 +339,7 @@ void IMB_buffer_byte_from_float_mask(uchar *rect_to, const float *rect_from,
for (x = 0; x < width; x++, from++, to += 4)
if (*mask++ == FILTER_MASK_USED)
- to[0] = to[1] = to[2] = to[3] = FTOCHAR(from[0]);
+ to[0] = to[1] = to[2] = to[3] = unit_float_to_uchar_clamp(from[0]);
}
else if (channels_from == 3) {
/* RGB input */
diff --git a/source/blender/imbuf/intern/filter.c b/source/blender/imbuf/intern/filter.c
index 27711618cee..93b605b74f6 100644
--- a/source/blender/imbuf/intern/filter.c
+++ b/source/blender/imbuf/intern/filter.c
@@ -661,9 +661,9 @@ void IMB_unpremultiply_rect(unsigned int *rect, char planes, int w, int h)
for (y = 0; y < h; y++) {
for (x = 0; x < w; x++, cp += 4) {
val = cp[3] != 0 ? 1.0f / (float)cp[3] : 1.0f;
- cp[0] = FTOCHAR(cp[0] * val);
- cp[1] = FTOCHAR(cp[1] * val);
- cp[2] = FTOCHAR(cp[2] * val);
+ cp[0] = unit_float_to_uchar_clamp(cp[0] * val);
+ cp[1] = unit_float_to_uchar_clamp(cp[1] * val);
+ cp[2] = unit_float_to_uchar_clamp(cp[2] * val);
}
}
}
diff --git a/source/blender/imbuf/intern/png.c b/source/blender/imbuf/intern/png.c
index 29fbe79d8db..8ac206a97ea 100644
--- a/source/blender/imbuf/intern/png.c
+++ b/source/blender/imbuf/intern/png.c
@@ -124,7 +124,7 @@ static float channel_colormanage_noop(float value)
/* wrap to avoid macro calling functions multiple times */
BLI_INLINE unsigned short ftoshort(float val)
{
- return FTOUSHORT(val);
+ return unit_float_to_ushort_clamp(val);
}
int imb_savepng(struct ImBuf *ibuf, const char *name, int flags)
diff --git a/source/blender/imbuf/intern/rectop.c b/source/blender/imbuf/intern/rectop.c
index c4325caac91..2fe17ee56c6 100644
--- a/source/blender/imbuf/intern/rectop.c
+++ b/source/blender/imbuf/intern/rectop.c
@@ -841,12 +841,12 @@ void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height,
unsigned char chr = 0, chg = 0, chb = 0;
float fr = 0, fg = 0, fb = 0;
- const int alphaint = FTOCHAR(a);
+ const int alphaint = unit_float_to_uchar_clamp(a);
if (a == 1.0f) {
- chr = FTOCHAR(col[0]);
- chg = FTOCHAR(col[1]);
- chb = FTOCHAR(col[2]);
+ chr = unit_float_to_uchar_clamp(col[0]);
+ chg = unit_float_to_uchar_clamp(col[1]);
+ chb = unit_float_to_uchar_clamp(col[2]);
}
else {
fr = col[0] * a;
diff --git a/source/blender/imbuf/intern/scaling.c b/source/blender/imbuf/intern/scaling.c
index 1c0b47f7942..4b528160fb7 100644
--- a/source/blender/imbuf/intern/scaling.c
+++ b/source/blender/imbuf/intern/scaling.c
@@ -324,18 +324,18 @@ MINLINE void straight_uchar_to_premul_ushort(unsigned short result[4], const uns
MINLINE void premul_ushort_to_straight_uchar(unsigned char *result, const unsigned short color[4])
{
if (color[3] <= 255) {
- result[0] = USHORTTOUCHAR(color[0]);
- result[1] = USHORTTOUCHAR(color[1]);
- result[2] = USHORTTOUCHAR(color[2]);
- result[3] = USHORTTOUCHAR(color[3]);
+ result[0] = unit_ushort_to_uchar(color[0]);
+ result[1] = unit_ushort_to_uchar(color[1]);
+ result[2] = unit_ushort_to_uchar(color[2]);
+ result[3] = unit_ushort_to_uchar(color[3]);
}
else {
unsigned short alpha = color[3] / 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]);
+ result[0] = unit_ushort_to_uchar((ushort)(color[0] / alpha * 256));
+ result[1] = unit_ushort_to_uchar((ushort)(color[1] / alpha * 256));
+ result[2] = unit_ushort_to_uchar((ushort)(color[2] / alpha * 256));
+ result[3] = unit_ushort_to_uchar(color[3]);
}
}
diff --git a/source/blender/imbuf/intern/tiff.c b/source/blender/imbuf/intern/tiff.c
index afd28bb570b..a68b2aa966b 100644
--- a/source/blender/imbuf/intern/tiff.c
+++ b/source/blender/imbuf/intern/tiff.c
@@ -869,7 +869,7 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags)
}
for (i = 0; i < samplesperpixel; i++, to_i++)
- to16[to_i] = FTOUSHORT(rgb[i]);
+ to16[to_i] = unit_float_to_ushort_clamp(rgb[i]);
}
else {
for (i = 0; i < samplesperpixel; i++, to_i++, from_i++)
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index 40028eec4c8..0b2efe27059 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -970,7 +970,7 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr
fprintf(f, ";\n");
}
else if (rna_color_quantize(prop, dp)) {
- fprintf(f, " data->%s[i] = FTOCHAR(values[i]);\n", dp->dnaname);
+ fprintf(f, " data->%s[i] = unit_float_to_uchar_clamp(values[i]);\n", dp->dnaname);
}
else {
if (dp->dnatype)
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index 8ff46d4d17a..27c3cee422c 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -679,7 +679,7 @@ static void rna_ImagePreview_pixels_float_set(PointerRNA *ptr, const float *valu
}
for (i = 0; i < len; i++) {
- data[i] = FTOCHAR(values[i]);
+ data[i] = unit_float_to_uchar_clamp(values[i]);
}
prv_img->flag[size] |= PRV_USER_EDITED;
}
diff --git a/source/blender/makesrna/intern/rna_image.c b/source/blender/makesrna/intern/rna_image.c
index 4ed035c4e86..c554ab8e0fd 100644
--- a/source/blender/makesrna/intern/rna_image.c
+++ b/source/blender/makesrna/intern/rna_image.c
@@ -396,7 +396,7 @@ static void rna_Image_pixels_set(PointerRNA *ptr, const float *values)
}
else {
for (i = 0; i < size; i++)
- ((unsigned char *)ibuf->rect)[i] = FTOCHAR(values[i]);
+ ((unsigned char *)ibuf->rect)[i] = unit_float_to_uchar_clamp(values[i]);
}
ibuf->userflags |= IB_BITMAPDIRTY | IB_DISPLAY_BUFFER_INVALID | IB_MIPMAP_INVALID;
diff --git a/source/blender/modifiers/intern/MOD_particleinstance.c b/source/blender/modifiers/intern/MOD_particleinstance.c
index b93e567fe56..651a5a96676 100644
--- a/source/blender/modifiers/intern/MOD_particleinstance.c
+++ b/source/blender/modifiers/intern/MOD_particleinstance.c
@@ -197,7 +197,7 @@ static bool particle_skip(ParticleInstanceModifierData *pimd, ParticleSystem *ps
static void store_float_in_vcol(MLoopCol *vcol, float float_value)
{
- const uchar value = FTOCHAR(float_value);
+ const uchar value = unit_float_to_uchar_clamp(float_value);
vcol->r = vcol->g = vcol->b = value;
vcol->a = 1.0f;
}
diff --git a/source/blender/render/intern/source/multires_bake.c b/source/blender/render/intern/source/multires_bake.c
index 9fb7e718b18..d506028e306 100644
--- a/source/blender/render/intern/source/multires_bake.c
+++ b/source/blender/render/intern/source/multires_bake.c
@@ -784,7 +784,7 @@ static void apply_heights_callback(DerivedMesh *lores_dm, DerivedMesh *hires_dm,
}
else {
char *rrgb = (char *)ibuf->rect + pixel * 4;
- rrgb[0] = rrgb[1] = rrgb[2] = FTOCHAR(len);
+ rrgb[0] = rrgb[1] = rrgb[2] = unit_float_to_uchar_clamp(len);
rrgb[3] = 255;
}
}
@@ -1158,7 +1158,7 @@ static void apply_ao_callback(DerivedMesh *lores_dm, DerivedMesh *hires_dm, void
}
else {
unsigned char *rrgb = (unsigned char *) ibuf->rect + pixel * 4;
- rrgb[0] = rrgb[1] = rrgb[2] = FTOCHAR(value);
+ rrgb[0] = rrgb[1] = rrgb[2] = unit_float_to_uchar_clamp(value);
rrgb[3] = 255;
}
}
@@ -1215,7 +1215,7 @@ static void bake_ibuf_normalize_displacement(ImBuf *ibuf, float *displacement, c
if (ibuf->rect) {
unsigned char *cp = (unsigned char *) (ibuf->rect + i);
- cp[0] = cp[1] = cp[2] = FTOCHAR(normalized_displacement);
+ cp[0] = cp[1] = cp[2] = unit_float_to_uchar_clamp(normalized_displacement);
cp[3] = 255;
}
}