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 /source/blender/blenlib/intern/math_color_inline.c
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.
Diffstat (limited to 'source/blender/blenlib/intern/math_color_inline.c')
-rw-r--r--source/blender/blenlib/intern/math_color_inline.c31
1 files changed, 31 insertions, 0 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];