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:
authorNicholas Bishop <nicholasbishop@gmail.com>2010-10-19 04:45:37 +0400
committerNicholas Bishop <nicholasbishop@gmail.com>2010-10-19 04:45:37 +0400
commita377a7edf67869722c585086ac6ab1f295cbff87 (patch)
tree1736de08fe9174761607dce5d54a16af25eba049 /source/blender/blenlib/intern/math_color.c
parent08232350d5797302e3638e69ec78657d853976aa (diff)
parentb743454ce1c361e6161da8ae5f840c2befe3a081 (diff)
svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r32300:32571soc-2010-nicolasbishop
Diffstat (limited to 'source/blender/blenlib/intern/math_color.c')
-rw-r--r--source/blender/blenlib/intern/math_color.c34
1 files changed, 31 insertions, 3 deletions
diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c
index 2b6a091cc8d..c481744156a 100644
--- a/source/blender/blenlib/intern/math_color.c
+++ b/source/blender/blenlib/intern/math_color.c
@@ -25,6 +25,7 @@
* ***** END GPL LICENSE BLOCK *****
* */
+#include <assert.h>
#include "BLI_math.h"
@@ -133,6 +134,8 @@ void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr, in
cb=(-0.16874f*sr)-(0.33126f*sg)+(0.5f*sb)+128.0f;
cr=(0.5f*sr)-(0.41869f*sg)-(0.08131f*sb)+128.0f;
break;
+ default:
+ assert(!"invalid colorspace");
}
*ly=y;
@@ -163,6 +166,8 @@ void ycc_to_rgb(float y, float cb, float cr, float *lr, float *lg, float *lb, in
g=y-0.34414f*cb - 0.71414f*cr + 135.45984f;
b=y+1.772f*cb - 226.816f;
break;
+ default:
+ assert(!"invalid colorspace");
}
*lr=r/255.0f;
*lg=g/255.0f;
@@ -172,13 +177,16 @@ void ycc_to_rgb(float y, float cb, float cr, float *lr, float *lg, float *lb, in
void hex_to_rgb(char *hexcol, float *r, float *g, float *b)
{
unsigned int ri, gi, bi;
-
+
if (hexcol[0] == '#') hexcol++;
-
- if (sscanf(hexcol, "%02x%02x%02x", &ri, &gi, &bi)) {
+
+ if (sscanf(hexcol, "%02x%02x%02x", &ri, &gi, &bi)==3) {
*r = ri / 255.0f;
*g = gi / 255.0f;
*b = bi / 255.0f;
+ CLAMP(*r, 0.0f, 1.0f);
+ CLAMP(*g, 0.0f, 1.0f);
+ CLAMP(*b, 0.0f, 1.0f);
}
}
@@ -227,6 +235,26 @@ void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv)
*lv = v;
}
+void rgb_to_hsv_compat(float r, float g, float b, float *lh, float *ls, float *lv)
+{
+ float orig_h= *lh;
+ float orig_s= *ls;
+
+ rgb_to_hsv(r, g, b, lh, ls, lv);
+
+ if(*lv <= 0.0f) {
+ *lh= orig_h;
+ *ls= orig_s;
+ }
+ else if (*ls <= 0.0f) {
+ *lh= orig_h;
+ }
+
+ if(*lh==0.0f && orig_h >= 1.0f) {
+ *lh= 1.0f;
+ }
+}
+
/*http://brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html */
void xyz_to_rgb(float xc, float yc, float zc, float *r, float *g, float *b, int colorspace)