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 {
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]);
}
}
}
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]);
}
}
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)
}
/* 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;
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;
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) {
}
/* 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__ */
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 ********************************* */
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])
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
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])
{
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 *****************/
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]);
}
}
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;
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:
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);
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;
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]);
}
}
}
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 */
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);
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);
}
}
}
- *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);
}
}
}
diffuse_color, vd->color);
}
else {
- F3TOCHAR3(diffuse_color, vd->color);
+ unit_float_to_uchar_clamp_v3(vd->color, diffuse_color);
}
}
}
vd->color);
}
else {
- F3TOCHAR3(diffuse_color, vd->color);
+ unit_float_to_uchar_clamp_v3(vd->color, diffuse_color);
}
}
}
p = pixels = MEM_callocN(sizeof(unsigned char) * len, "GPUTexturePixels");
for (int a = 0; a < len; a++, p++, fp++)
- *p = FTOCHAR((*fp));
+ *p = unit_float_to_uchar_clamp((*fp));
return pixels;
}
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]);
}
}
}
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__ */
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)
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
}
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 */
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 */
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 */
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);
}
}
}
/* 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)
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;
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]);
}
}
}
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++)
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)
}
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;
}
}
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;
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;
}
}
if (ELEM(bs->type, RE_BAKE_ALL, RE_BAKE_TEXTURE, RE_BAKE_VERTEX_COLORS)) {
- col[3] = FTOCHAR(shr.alpha);
+ col[3] = unit_float_to_uchar_clamp(shr.alpha);
}
else {
col[3] = 255;
else {
/* Target is char (LDR). */
unsigned char col[4];
- col[0] = col[1] = col[2] = FTOCHAR(disp);
+ col[0] = col[1] = col[2] = unit_float_to_uchar_clamp(disp);
col[3] = 255;
if (bs->vcol) {
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;
}
}
else {
char *rrgb = (char *)ibuf->rect + index * 4;
- rrgb[0] = FTOCHAR(deriv_x);
- rrgb[1] = FTOCHAR(deriv_y);
+ rrgb[0] = unit_float_to_uchar_clamp(deriv_x);
+ rrgb[1] = unit_float_to_uchar_clamp(deriv_y);
rrgb[2] = 0;
rrgb[3] = 255;
}
}
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;
}
}
}
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;
}
}