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:
authorCampbell Barton <ideasman42@gmail.com>2015-03-19 06:09:01 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-03-19 06:12:51 +0300
commit4f602ff943d91d0e6069e231916d2482ee859688 (patch)
tree7efadce9699d7713447b368f9a18fff1b8b14c1c
parent255b07681acfe2ce8dd3af7d5b032d3c759cb93e (diff)
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.
-rw-r--r--source/blender/blenlib/intern/math_color_inline.c31
-rw-r--r--source/blender/editors/interface/interface_regions.c6
-rw-r--r--source/blender/editors/interface/interface_widgets.c5
3 files changed, 35 insertions, 7 deletions
diff --git a/source/blender/blenlib/intern/math_color_inline.c b/source/blender/blenlib/intern/math_color_inline.c
index 96aa4b55201..0e955c1602e 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 adcd615368b..ae62b61736a 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 9020522bb59..3d021e7dd10 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;