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
diff options
context:
space:
mode:
-rw-r--r--source/blender/blenkernel/BKE_image.h2
-rw-r--r--source/blender/blenkernel/intern/brush.c31
-rw-r--r--source/blender/blenkernel/intern/image_gen.c15
-rw-r--r--source/blender/blenkernel/intern/node.c5
-rw-r--r--source/blender/blenlib/BLI_math_color.h2
-rw-r--r--source/blender/blenlib/intern/math_color.c23
-rw-r--r--source/blender/editors/interface/interface_intern.h2
-rw-r--r--source/blender/editors/interface/interface_templates.c4
-rw-r--r--source/blender/editors/interface/interface_widgets.c2
-rw-r--r--source/blender/editors/object/object_bake.c6
-rw-r--r--source/blender/editors/space_view3d/drawmesh.c7
-rw-r--r--source/blender/imbuf/intern/divers.c47
-rw-r--r--source/blender/render/intern/source/rendercore.c11
13 files changed, 72 insertions, 85 deletions
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index c829fc69b05..5cdc3537f5b 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -186,7 +186,7 @@ void BKE_image_merge(struct Image *dest, struct Image *source);
int BKE_image_has_alpha(struct Image *image);
/* image_gen.c */
-void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, int height, float color[4]);
+void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, int height, const float color[4]);
void BKE_image_buf_fill_checker(unsigned char *rect, float *rect_float, int height, int width);
void BKE_image_buf_fill_checker_color(unsigned char *rect, float *rect_float, int height, int width);
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 362fa6e5e9a..f2514c1030b 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -527,7 +527,7 @@ void brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall,
float xy[2], rgba[4], *dstf;
int x, y, rowbytes, xoff, yoff, imbflag;
const int radius= brush_size(scene, brush);
- char *dst, crgb[3];
+ unsigned char *dst, crgb[3];
const float alpha= brush_alpha(scene, brush);
float brush_rgb[3];
@@ -571,10 +571,10 @@ void brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall,
}
else {
float alpha_f; /* final float alpha to convert to char */
- F3TOCHAR3(brush->rgb, crgb);
+ rgb_float_to_uchar(crgb, brush->rgb);
for (y=0; y < ibuf->y; y++) {
- dst = (char*)ibuf->rect + y*rowbytes;
+ dst = (unsigned char *)ibuf->rect + y*rowbytes;
for (x=0; x < ibuf->x; x++, dst+=4) {
xy[0] = x + xoff;
@@ -590,19 +590,15 @@ void brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall,
}
else if (texfall == 1) {
brush_sample_tex(scene, brush, xy, rgba, 0);
- dst[0] = FTOCHAR(rgba[0]);
- dst[1] = FTOCHAR(rgba[1]);
- dst[2] = FTOCHAR(rgba[2]);
- dst[3] = FTOCHAR(rgba[3]);
+ rgba_float_to_uchar(dst, rgba);
}
else if (texfall == 2) {
brush_sample_tex(scene, brush, xy, rgba, 0);
mul_v3_v3(rgba, brush->rgb);
alpha_f = rgba[3] * alpha * brush_curve_strength_clamp(brush, len_v2(xy), radius);
- dst[0] = FTOCHAR(rgba[0]);
- dst[1] = FTOCHAR(rgba[1]);
- dst[2] = FTOCHAR(rgba[2]);
+ rgb_float_to_uchar(dst, rgba);
+
dst[3] = FTOCHAR(alpha_f);
}
else {
@@ -843,7 +839,7 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, i
Brush *brush= painter->brush;
ImBuf *ibuf, *maskibuf, *texibuf;
float *bf, *mf, *tf, *otf=NULL, xoff, yoff, xy[2], rgba[4];
- char *b, *m, *t, *ot= NULL;
+ unsigned char *b, *m, *t, *ot= NULL;
int dotexold, origx= x, origy= y;
const int radius= brush_size(painter->scene, brush);
@@ -895,12 +891,12 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, i
}
else {
for (; y < h; y++) {
- b = (char*)ibuf->rect + (y*ibuf->x + origx)*4;
- t = (char*)texibuf->rect + (y*texibuf->x + origx)*4;
- m = (char*)maskibuf->rect + (y*maskibuf->x + origx)*4;
+ b = (unsigned char *)ibuf->rect + (y*ibuf->x + origx)*4;
+ t = (unsigned char *)texibuf->rect + (y*texibuf->x + origx)*4;
+ m = (unsigned char *)maskibuf->rect + (y*maskibuf->x + origx)*4;
if (dotexold)
- ot = (char*)oldtexibuf->rect + ((y - origy + yt)*oldtexibuf->x + xt)*4;
+ ot = (unsigned char *)oldtexibuf->rect + ((y - origy + yt)*oldtexibuf->x + xt)*4;
for (x=origx; x < w; x++, b+=4, m+=4, t+=4) {
if (dotexold) {
@@ -915,10 +911,7 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, i
xy[1] = y + yoff;
brush_sample_tex(scene, brush, xy, rgba, 0);
- t[0]= FTOCHAR(rgba[0]);
- t[1]= FTOCHAR(rgba[1]);
- t[2]= FTOCHAR(rgba[2]);
- t[3]= FTOCHAR(rgba[3]);
+ rgba_float_to_uchar(t, rgba);
}
b[0] = t[0]*m[0]/255;
diff --git a/source/blender/blenkernel/intern/image_gen.c b/source/blender/blenkernel/intern/image_gen.c
index a93d0221cf0..c6cb8c9582a 100644
--- a/source/blender/blenkernel/intern/image_gen.c
+++ b/source/blender/blenkernel/intern/image_gen.c
@@ -33,7 +33,7 @@
#include "BLI_math_base.h"
#include "BLF_api.h"
-void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, int height, float color[4])
+void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, int height, const float color[4])
{
int x, y;
@@ -41,22 +41,17 @@ void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width,
if(rect_float) {
for(y= 0; y<height; y++) {
for(x= 0; x<width; x++) {
- rect_float[0]= color[0];
- rect_float[1]= color[1];
- rect_float[2]= color[2];
- rect_float[3]= color[3];
+ copy_v4_v4(rect_float, color);
rect_float+= 4;
}
}
}
if(rect) {
- char ccol[4];
+ unsigned char ccol[4];
+
+ rgba_float_to_uchar(ccol, color);
- ccol[0]= (char)(color[0]*255.0f);
- ccol[1]= (char)(color[1]*255.0f);
- ccol[2]= (char)(color[2]*255.0f);
- ccol[3]= (char)(color[3]*255.0f);
for(y= 0; y<height; y++) {
for(x= 0; x<width; x++) {
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index 61111e82cc7..a2d7d9b502c 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -793,10 +793,7 @@ void nodeAddToPreview(bNode *node, float *col, int x, int y, int do_manage)
linearrgb_to_srgb_uchar4(tar, col);
}
else {
- tar[0]= FTOCHAR(col[0]);
- tar[1]= FTOCHAR(col[1]);
- tar[2]= FTOCHAR(col[2]);
- tar[3]= FTOCHAR(col[3]);
+ rgba_float_to_uchar(tar, col);
}
}
//else printf("prv out bound x y %d %d\n", x, y);
diff --git a/source/blender/blenlib/BLI_math_color.h b/source/blender/blenlib/BLI_math_color.h
index 1b8cc08abf7..453f1258272 100644
--- a/source/blender/blenlib/BLI_math_color.h
+++ b/source/blender/blenlib/BLI_math_color.h
@@ -102,7 +102,9 @@ void rgb_float_set_hue_float_offset(float * rgb, float hue_offset);
void rgb_byte_set_hue_float_offset(unsigned char * rgb, float hue_offset);
void rgb_uchar_to_float(float col_r[3], const unsigned char col_ub[3]);
+void rgba_uchar_to_float(float col_r[4], const unsigned char col_ub[4]);
void rgb_float_to_uchar(unsigned char col_r[3], const float col_f[3]);
+void rgba_float_to_uchar(unsigned char col_r[4], const float col_f[4]);
/***************** lift/gamma/gain / ASC-CDL conversion *****************/
diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c
index 31d69ba68b4..94dbdf9fe58 100644
--- a/source/blender/blenlib/intern/math_color.c
+++ b/source/blender/blenlib/intern/math_color.c
@@ -344,6 +344,14 @@ void rgb_uchar_to_float(float col_r[3], const unsigned char col_ub[3])
col_r[2]= ((float)col_ub[2]) / 255.0f;
}
+void rgba_uchar_to_float(float col_r[4], const unsigned char col_ub[4])
+{
+ col_r[0]= ((float)col_ub[0]) / 255.0f;
+ col_r[1]= ((float)col_ub[1]) / 255.0f;
+ col_r[2]= ((float)col_ub[2]) / 255.0f;
+ col_r[3]= ((float)col_ub[3]) / 255.0f;
+}
+
void rgb_float_to_uchar(unsigned char col_r[3], const float col_f[3])
{
int r, g, b;
@@ -357,6 +365,21 @@ void rgb_float_to_uchar(unsigned char col_r[3], const float col_f[3])
col_r[2]= (char)((b <= 0)? 0 : (b >= 255)? 255 : b);
}
+void rgba_float_to_uchar(unsigned char col_r[4], const float col_f[4])
+{
+ int r, g, b, a;
+
+ r= (int)(col_f[0] * 255.0f);
+ g= (int)(col_f[1] * 255.0f);
+ b= (int)(col_f[2] * 255.0f);
+ a= (int)(col_f[3] * 255.0f);
+
+ col_r[0]= (char)((r <= 0)? 0 : (r >= 255)? 255 : r);
+ col_r[1]= (char)((g <= 0)? 0 : (g >= 255)? 255 : g);
+ col_r[2]= (char)((b <= 0)? 0 : (b >= 255)? 255 : b);
+ col_r[3]= (char)((a <= 0)? 0 : (a >= 255)? 255 : a);
+}
+
/* ********************************* color transforms ********************************* */
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index e31d7e39d89..7d53e7acbc2 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -163,7 +163,7 @@ struct uiBut {
float hardmin, hardmax, softmin, softmax;
float a1, a2;
float aspect;
- char col[4];
+ unsigned char col[4];
uiButHandleFunc func;
void *func_arg1;
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 0862af2756a..a1eb20c32e2 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -2626,9 +2626,7 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
uiBlockBeginAlign(block);
but= uiDefBut(block, ROUNDBOX, 0, "", 0, 0, UI_UNIT_X+10, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "");
/* set the report's bg color in but->col - ROUNDBOX feature */
- but->col[0]= FTOCHAR(rti->col[0]);
- but->col[1]= FTOCHAR(rti->col[1]);
- but->col[2]= FTOCHAR(rti->col[2]);
+ rgb_float_to_uchar(but->col, rti->col);
but->col[3]= 255;
but= uiDefBut(block, ROUNDBOX, 0, "", UI_UNIT_X+10, 0, UI_UNIT_X+width, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "");
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index f5c62f65512..19acfaccaa3 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -2501,7 +2501,7 @@ static void widget_swatch(uiBut *but, uiWidgetColors *wcol, rcti *rect, int stat
if (color_profile)
linearrgb_to_srgb_v3_v3(col, col);
- F4TOCHAR4(col, wcol->inner);
+ rgba_float_to_uchar((unsigned char *)wcol->inner, col);
wcol->shaded = 0;
wcol->alpha_check = (wcol->inner[3] < 255);
diff --git a/source/blender/editors/object/object_bake.c b/source/blender/editors/object/object_bake.c
index a02b90a1d16..6ec778d7ee9 100644
--- a/source/blender/editors/object/object_bake.c
+++ b/source/blender/editors/object/object_bake.c
@@ -807,10 +807,8 @@ static void apply_tangmat_callback(DerivedMesh *lores_dm, DerivedMesh *hires_dm,
ibuf->userflags= IB_RECT_INVALID;
} else {
- char *rrgb= (char*)ibuf->rect + pixel*4;
- rrgb[0]= FTOCHAR(vec[0]);
- rrgb[1]= FTOCHAR(vec[1]);
- rrgb[2]= FTOCHAR(vec[2]);
+ unsigned char *rrgb= (unsigned char *)ibuf->rect + pixel*4;
+ rgb_float_to_uchar(rrgb, vec);
rrgb[3]= 255;
}
}
diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c
index b1842578c20..5f521cc3dd1 100644
--- a/source/blender/editors/space_view3d/drawmesh.c
+++ b/source/blender/editors/space_view3d/drawmesh.c
@@ -349,11 +349,8 @@ static void draw_textured_begin(Scene *scene, View3D *v3d, RegionView3D *rv3d, O
Gtexdraw.islit= GPU_scene_object_lights(scene, ob, v3d->lay, rv3d->viewmat, !rv3d->is_persp);
}
- obcol[0]= CLAMPIS(ob->col[0]*255, 0, 255);
- obcol[1]= CLAMPIS(ob->col[1]*255, 0, 255);
- obcol[2]= CLAMPIS(ob->col[2]*255, 0, 255);
- obcol[3]= CLAMPIS(ob->col[3]*255, 0, 255);
-
+ rgba_float_to_uchar(obcol, ob->col);
+
glCullFace(GL_BACK); glEnable(GL_CULL_FACE);
if(solidtex || v3d->drawtype==OB_TEXTURE) istex= 1;
else istex= 0;
diff --git a/source/blender/imbuf/intern/divers.c b/source/blender/imbuf/intern/divers.c
index 442309ccf7a..7e086716d3e 100644
--- a/source/blender/imbuf/intern/divers.c
+++ b/source/blender/imbuf/intern/divers.c
@@ -164,19 +164,6 @@ MINLINE unsigned char dither_value(unsigned short v_in, DitherContext *di, int i
/************************* Generic Buffer Conversion *************************/
-MINLINE void byte_to_float_v4(float f[4], const uchar b[4])
-{
- f[0]= b[0] * (1.0f/255.0f);
- f[1]= b[1] * (1.0f/255.0f);
- f[2]= b[2] * (1.0f/255.0f);
- f[3]= b[3] * (1.0f/255.0f);
-}
-
-MINLINE void float_to_byte_v4(uchar b[4], const float f[4])
-{
- F4TOCHAR4(f, b);
-}
-
MINLINE void ushort_to_byte_v4(uchar b[4], const unsigned short us[4])
{
b[0]= USHORTTOUCHAR(us[0]);
@@ -233,7 +220,7 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from,
if(profile_to == profile_from) {
/* no color space conversion */
for(x = 0; x < width; x++, from+=3, to+=4) {
- F3TOCHAR3(from, to);
+ rgb_float_to_uchar(to, from);
to[3] = 255;
}
}
@@ -241,7 +228,7 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from,
/* convert from linear to sRGB */
for(x = 0; x < width; x++, from+=3, to+=4) {
linearrgb_to_srgb_v3_v3(tmp, from);
- F3TOCHAR3(tmp, to);
+ rgb_float_to_uchar(to, tmp);
to[3] = 255;
}
}
@@ -249,7 +236,7 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from,
/* convert from sRGB to linear */
for(x = 0; x < width; x++, from+=3, to+=4) {
srgb_to_linearrgb_v3_v3(tmp, from);
- F3TOCHAR3(tmp, to);
+ rgb_float_to_uchar(to, tmp);
to[3] = 255;
}
}
@@ -267,7 +254,7 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from,
}
else {
for(x = 0; x < width; x++, from+=4, to+=4)
- float_to_byte_v4(to, from);
+ rgba_float_to_uchar(to, from);
}
}
else if(profile_to == IB_PROFILE_SRGB) {
@@ -316,13 +303,13 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from,
else if(predivide) {
for(x = 0; x < width; x++, from+=4, to+=4) {
srgb_to_linearrgb_predivide_v4(tmp, from);
- float_to_byte_v4(to, tmp);
+ rgba_float_to_uchar(to, tmp);
}
}
else {
for(x = 0; x < width; x++, from+=4, to+=4) {
srgb_to_linearrgb_v4(tmp, from);
- float_to_byte_v4(to, tmp);
+ rgba_float_to_uchar(to, tmp);
}
}
}
@@ -358,7 +345,7 @@ void IMB_buffer_float_from_byte(float *rect_to, const uchar *rect_from,
if(profile_to == profile_from) {
/* no color space conversion */
for(x = 0; x < width; x++, from+=4, to+=4)
- byte_to_float_v4(to, from);
+ rgba_uchar_to_float(to, from);
}
else if(profile_to == IB_PROFILE_LINEAR_RGB) {
/* convert sRGB to linear */
@@ -377,13 +364,13 @@ void IMB_buffer_float_from_byte(float *rect_to, const uchar *rect_from,
/* convert linear to sRGB */
if(predivide) {
for(x = 0; x < width; x++, from+=4, to+=4) {
- byte_to_float_v4(tmp, from);
+ rgba_uchar_to_float(tmp, from);
linearrgb_to_srgb_predivide_v4(to, tmp);
}
}
else {
for(x = 0; x < width; x++, from+=4, to+=4) {
- byte_to_float_v4(tmp, from);
+ rgba_uchar_to_float(tmp, from);
linearrgb_to_srgb_v4(to, tmp);
}
}
@@ -502,16 +489,16 @@ void IMB_buffer_byte_from_byte(uchar *rect_to, const uchar *rect_from,
/* convert to sRGB to linear */
if(predivide) {
for(x = 0; x < width; x++, from+=4, to+=4) {
- byte_to_float_v4(tmp, from);
+ rgba_uchar_to_float(tmp, from);
srgb_to_linearrgb_predivide_v4(tmp, tmp);
- float_to_byte_v4(to, tmp);
+ rgba_float_to_uchar(to, tmp);
}
}
else {
for(x = 0; x < width; x++, from+=4, to+=4) {
- byte_to_float_v4(tmp, from);
+ rgba_uchar_to_float(tmp, from);
srgb_to_linearrgb_v4(tmp, tmp);
- float_to_byte_v4(to, tmp);
+ rgba_float_to_uchar(to, tmp);
}
}
}
@@ -519,16 +506,16 @@ void IMB_buffer_byte_from_byte(uchar *rect_to, const uchar *rect_from,
/* convert from linear to sRGB */
if(predivide) {
for(x = 0; x < width; x++, from+=4, to+=4) {
- byte_to_float_v4(tmp, from);
+ rgba_uchar_to_float(tmp, from);
linearrgb_to_srgb_predivide_v4(tmp, tmp);
- float_to_byte_v4(to, tmp);
+ rgba_float_to_uchar(to, tmp);
}
}
else {
for(x = 0; x < width; x++, from+=4, to+=4) {
- byte_to_float_v4(tmp, from);
+ rgba_uchar_to_float(tmp, from);
linearrgb_to_srgb_v4(tmp, tmp);
- float_to_byte_v4(to, tmp);
+ rgba_float_to_uchar(to, tmp);
}
}
}
diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c
index c5d580b2e9f..773af96671a 100644
--- a/source/blender/render/intern/source/rendercore.c
+++ b/source/blender/render/intern/source/rendercore.c
@@ -2170,10 +2170,9 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int UNUSED(qua
if (ELEM(bs->type, RE_BAKE_ALL, RE_BAKE_TEXTURE) && (R.r.color_mgt_flag & R_COLOR_MANAGEMENT)) {
linearrgb_to_srgb_uchar3(col, shr.combined);
- } else {
- col[0]= FTOCHAR(shr.combined[0]);
- col[1]= FTOCHAR(shr.combined[1]);
- col[2]= FTOCHAR(shr.combined[2]);
+ }
+ else {
+ rgb_float_to_uchar(col, shr.combined);
}
if (ELEM(bs->type, RE_BAKE_ALL, RE_BAKE_TEXTURE)) {
@@ -2205,9 +2204,7 @@ static void bake_displacement(void *handle, ShadeInput *UNUSED(shi), float dist,
col[3]= 1.0f;
} else {
char *col= (char *)(bs->rect + bs->rectx*y + x);
- col[0]= FTOCHAR(disp);
- col[1]= FTOCHAR(disp);
- col[2]= FTOCHAR(disp);
+ col[0] = col[1] = col[2] = FTOCHAR(disp);
col[3]= 255;
}
if (bs->rect_mask) {