[Bf-blender-cvs] [4f602ff] master: Revert part of recent color-management commit

Campbell Barton noreply at git.blender.org
Thu Mar 19 04:16:09 CET 2015


Commit: 4f602ff943d91d0e6069e231916d2482ee859688
Author: Campbell Barton
Date:   Thu Mar 19 14:09:01 2015 +1100
Branches: master
https://developer.blender.org/rB4f602ff943d91d0e6069e231916d2482ee859688

Revert part of recent color-management commit

This adds back rgb_to_grayscale,
not all color is managed or depends on the current loaded blend file's CM options.

Noted in comments that this is only to be used outside the CM pipeline.

===================================================================

M	source/blender/blenlib/intern/math_color_inline.c
M	source/blender/editors/interface/interface_regions.c
M	source/blender/editors/interface/interface_widgets.c

===================================================================

diff --git a/source/blender/blenlib/intern/math_color_inline.c b/source/blender/blenlib/intern/math_color_inline.c
index 96aa4b5..0e955c1 100644
--- a/source/blender/blenlib/intern/math_color_inline.c
+++ b/source/blender/blenlib/intern/math_color_inline.c
@@ -200,6 +200,37 @@ MINLINE void cpack_cpy_3ub(unsigned char r_col[3], const unsigned int pack)
 	r_col[2] = ((pack) >> 16) & 0xFF;
 }
 
+
+/** \name RGB/Grayscale Functions
+ *
+ * \warning
+ * These are only an approximation,
+ * in almost _all_ cases, #IMB_colormanagement_get_luminance should be used instead.
+ * however for screen-only colors which don't depend on the currently loaded profile - this is preferred.
+ * Checking theme colors for contrast, etc. Basically anything outside the render pipeline.
+ *
+ * \{ */
+
+/* non-linear luma from ITU-R BT.601-2
+ * see: http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html#RTFToC11
+ * note: the values used for are not exact matches to those documented above,
+ * but they are from the same */
+MINLINE float rgb_to_grayscale(const float rgb[3])
+{
+	return 0.3f * rgb[0] + 0.58f * rgb[1] + 0.12f * rgb[2];
+}
+
+MINLINE unsigned char rgb_to_grayscale_byte(const unsigned char rgb[3])
+{
+	return (unsigned char)(((76  * (unsigned short)rgb[0]) +
+	                        (148 * (unsigned short)rgb[1]) +
+	                        (31  * (unsigned short)rgb[2])) / 255);
+}
+
+/** \} */
+
+
+
 MINLINE int compare_rgb_uchar(const unsigned char col_a[3], const unsigned char col_b[3], const int limit)
 {
 	const int r = (int)col_a[0] - (int)col_b[0];
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c
index adcd615..ae62b61 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -237,8 +237,8 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
 
 	/* find the brightness difference between background and text colors */
 	
-	tone_bg = IMB_colormanagement_get_luminance(background_color);
-	/* tone_fg = IMB_colormanagement_get_luminance(main_color); */
+	tone_bg = rgb_to_grayscale(background_color);
+	/* tone_fg = rgb_to_grayscale(main_color); */
 
 	/* mix the colors */
 	rgb_tint(value_color,  0.0f, 0.0f, tone_bg, 0.2f);  /* light grey */
@@ -261,7 +261,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
 
 			/* override text-style */
 			fstyle_header.shadow = 1;
-			fstyle_header.shadowcolor = IMB_colormanagement_get_luminance(tip_colors[UI_TIP_LC_MAIN]);
+			fstyle_header.shadowcolor = rgb_to_grayscale(tip_colors[UI_TIP_LC_MAIN]);
 			fstyle_header.shadx = fstyle_header.shady = 0;
 			fstyle_header.shadowalpha = 1.0f;
 
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 9020522..3d021e7 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -27,7 +27,6 @@
  *  \ingroup edinterface
  */
 
-
 #include <limits.h>
 #include <stdlib.h>
 #include <string.h>
@@ -56,8 +55,6 @@
 #include "UI_interface.h"
 #include "UI_interface_icons.h"
 
-#include "IMB_colormanagement.h"
-
 #include "interface_intern.h"
 
 #ifdef WITH_INPUT_IME
@@ -3028,7 +3025,7 @@ static void widget_swatch(uiBut *but, uiWidgetColors *wcol, rcti *rect, int stat
 		float width = rect->xmax - rect->xmin;
 		float height = rect->ymax - rect->ymin;
 		/* find color luminance and change it slightly */
-		float bw = IMB_colormanagement_get_luminance(col);
+		float bw = rgb_to_grayscale(col);
 
 		bw += (bw < 0.5f) ? 0.5f : -0.5f;




More information about the Bf-blender-cvs mailing list