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.
This commit is contained in:
@@ -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];
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user