add vector versions of hsv_to_rgb, rgb_to_hsv & rgb_to_hsv_compat
authorCampbell Barton <ideasman42@gmail.com>
Sat, 26 May 2012 11:01:01 +0000 (11:01 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 26 May 2012 11:01:01 +0000 (11:01 +0000)
13 files changed:
release/plugins/sequence/color-correction-hsv.c
source/blender/blenkernel/intern/image_gen.c
source/blender/blenlib/BLI_math_color.h
source/blender/blenlib/intern/math_color.c
source/blender/editors/animation/anim_ipo_utils.c
source/blender/editors/include/ED_anim_api.h
source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_handlers.c
source/blender/editors/interface/interface_regions.c
source/blender/editors/interface/interface_widgets.c
source/blender/imbuf/intern/divers.c
source/blender/modifiers/intern/MOD_weightvg_util.c
source/blender/python/mathutils/mathutils_Color.c

index b9ffd88..f77acd2 100644 (file)
 #include "plugin.h"
 #include <stdio.h>
 
-char name[]= "Color Correction";
+char name[] = "Color Correction";
 
-VarStruct varstr[]= {
-       { NUMSLI|FLO, "St Y:", 0.0,     -1.0,   1.0, "Setup Y"}, 
-       { NUMSLI|FLO, "Gn Y:",  1.0,    0.0,    10.0,"Gain Y"},
-       { NUMSLI|FLO, "Ga Y:", 1.0,     0.0,    10.0, "Gamma Y"},
+VarStruct varstr[] = {
+       { NUMSLI | FLO, "St Y:", 0.0, -1.0,   1.0, "Setup Y"},
+       { NUMSLI | FLO, "Gn Y:",  1.0,    0.0,    10.0, "Gain Y"},
+       { NUMSLI | FLO, "Ga Y:", 1.0, 0.0,    10.0, "Gamma Y"},
 
-       { NUMSLI|FLO, "Lo S:",  1.0,    0.0,    10.0,"Saturation Shadows"},
-       { NUMSLI|FLO, "Md S:",  1.0,    0.0,    10.0,"Saturation Midtones"},
-       { NUMSLI|FLO, "Hi S:",  1.0,    0.0,    10.0,"Saturation Highlights"},
+       { NUMSLI | FLO, "Lo S:",  1.0,    0.0,    10.0, "Saturation Shadows"},
+       { NUMSLI | FLO, "Md S:",  1.0,    0.0,    10.0, "Saturation Midtones"},
+       { NUMSLI | FLO, "Hi S:",  1.0,    0.0,    10.0, "Saturation Highlights"},
 
-       { NUMSLI|FLO, "MA S:",  1.0,    0.0,    10.0,"Master Saturation"}, 
+       { NUMSLI | FLO, "MA S:",  1.0,    0.0,    10.0, "Master Saturation"},
 
-       { NUMSLI|FLO, "Lo T:",  0.25, 0.0, 1.0,
+       { NUMSLI | FLO, "Lo T:",  0.25, 0.0, 1.0,
          "Saturation Shadow Thres"}, 
-       { NUMSLI|FLO, "Hi T:",  0.75, 0.0, 1.0,
+       { NUMSLI | FLO, "Hi T:",  0.75, 0.0, 1.0,
          "Saturation Highlights Thres"}, 
-       { TOG|INT,      "Debug", 0.0,   0.0,    1.0,   
+       { TOG | INT,  "Debug", 0.0,   0.0,    1.0,
          "Show curves as overlay"}, 
 };
 
@@ -58,25 +58,28 @@ float cfra;
 
 void plugin_seq_doit(Cast *, float, float, int, int, ImBuf *, ImBuf *, ImBuf *, ImBuf *);
 
-int plugin_seq_getversion(void) { return B_PLUGIN_VERSION;}
+int plugin_seq_getversion(void)
+{
+       return B_PLUGIN_VERSION;
+}
 void plugin_but_changed(int but) {}
 void plugin_init() {}
 
 void plugin_getinfo(PluginInfo *info)
 {
-       info->name= name;
-       info->nvars= sizeof(varstr)/sizeof(VarStruct);
-       info->cfra= &cfra;
+       info->name = name;
+       info->nvars = sizeof(varstr) / sizeof(VarStruct);
+       info->cfra = &cfra;
 
-       info->varstr= varstr;
+       info->varstr = varstr;
 
-       info->init= plugin_init;
-       info->seq_doit= (SeqDoit) plugin_seq_doit;
-       info->callback= plugin_but_changed;
+       info->init = plugin_init;
+       info->seq_doit = (SeqDoit) plugin_seq_doit;
+       info->callback = plugin_but_changed;
 }
 
-static void hsv_to_rgb (double  h, double  s, double  v,
-                       double *r, double *g, double *b)
+static void hsv_to_rgb(double h, double s, double v,
+                       double *r, double *g, double *b)
 {
        int i;
        double f, w, q, t;
@@ -90,8 +93,7 @@ static void hsv_to_rgb (double  h, double  s, double  v,
                *g = v;
                *b = v;
        }
-       else
-       {
+       else {
                if (h == 360.0)
                        h = 0.0;
                h = h / 60.0;
@@ -103,42 +105,42 @@ static void hsv_to_rgb (double  h, double  s, double  v,
                
                switch (i)
                {
-               case 0:
-                       *r = v;
-                       *g = t;
-                       *b = w;
-                       break;
-               case 1:
-                       *r = q;
-                       *g = v;
-                       *b = w;
-                       break;
-               case 2:
-                       *r = w;
-                       *g = v;
-                       *b = t;
-                       break;
-               case 3:
-                       *r = w;
-                       *g = q;
-                       *b = v;
-                       break;
-               case 4:
-                       *r = t;
-                       *g = w;
-                       *b = v;
-                       break;
-               case 5:
-                       *r = v;
-                       *g = w;
-                       *b = q;
-                       break;
+                       case 0:
+                               *r = v;
+                               *g = t;
+                               *b = w;
+                               break;
+                       case 1:
+                               *r = q;
+                               *g = v;
+                               *b = w;
+                               break;
+                       case 2:
+                               *r = w;
+                               *g = v;
+                               *b = t;
+                               break;
+                       case 3:
+                               *r = w;
+                               *g = q;
+                               *b = v;
+                               break;
+                       case 4:
+                               *r = t;
+                               *g = w;
+                               *b = v;
+                               break;
+                       case 5:
+                               *r = v;
+                               *g = w;
+                               *b = q;
+                               break;
                }
        }
 }
 
-static void rgb_to_hsv (double  r, double  g, double  b,
-                       double *h, double *s, double *v)
+static void rgb_to_hsv(double r, double g, double b,
+                       double *h, double *s, double *v)
 {
        double max, min, delta;
 
@@ -163,8 +165,7 @@ static void rgb_to_hsv (double  r, double  g, double  b,
        
        if (*s == 0.0)
                *h = -1.0;
-       else
-       {
+       else {
                delta = max - min;
                
                if (r == max)
@@ -182,7 +183,8 @@ static void rgb_to_hsv (double  r, double  g, double  b,
 }
 
 void plugin_seq_doit(Cast *cast, float facf0, float facf1, int width, 
-       int height, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *out, ImBuf *use) {
+                     int height, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *out, ImBuf *use)
+{
        char *dest, *src1;
        int x, y, c;
        double gamma_table[256];
@@ -192,18 +194,19 @@ void plugin_seq_doit(Cast *cast, float facf0, float facf1, int width,
        
        if (!ibuf1) return;
 
-       dest= (char *) out->rect;
-       src1= (char *) ibuf1->rect;
-       src1f= ibuf1->rect_float;
+       dest = (char *) out->rect;
+       src1 = (char *) ibuf1->rect;
+       src1f = ibuf1->rect_float;
 
        for (y = 0; y < 256; y++) {
                float v = 1.0 * y / 255;
                v += cast->setup_y;
                v *= cast->gain_y;
                v = pow(v, cast->gamma_y);
-               if ( v > 1.0) {
+               if (v > 1.0) {
                        v = 1.0;
-               } else if (v < 0.0) {
+               }
+               else if (v < 0.0) {
                        v = 0.0;
                }
                gamma_table[y] = v * 255;
@@ -214,9 +217,11 @@ void plugin_seq_doit(Cast *cast, float facf0, float facf1, int width,
                v *= cast->master_sat;
                if (y < cast->lo_thres * 255) {
                        v *= cast->sat_shadows;
-               } else if (y > cast->hi_thres * 255) {
+               }
+               else if (y > cast->hi_thres * 255) {
                        v *= cast->sat_highlights;
-               } else {
+               }
+               else {
                        v *= cast->sat_midtones;
                }
                uv_table[y] = v;
@@ -225,15 +230,15 @@ void plugin_seq_doit(Cast *cast, float facf0, float facf1, int width,
 
        for (y = 0; y < height; y++) {
                for (x = 0; x < width; x++) {
-                       double h,s,v,r,g,b;
+                       double h, s, v, r, g, b;
                        double fac;
 
                        if (ibuf1->rect_float) rgb_to_hsv(src1f[0], src1f[1],
-                               src1f[2],&h,&s,&v);
-                       else rgb_to_hsv((double) src1[0]/255.0,
-                                  (double) src1[1]/255.0,
-                                  (double) src1[2]/255.0,
-                                  &h, &s, &v);
+                                                             src1f[2], &h, &s, &v);
+                       else rgb_to_hsv((double) src1[0] / 255.0,
+                                           (double) src1[1] / 255.0,
+                                           (double) src1[2] / 255.0,
+                                           &h, &s, &v);
                        v = gamma_table[(int) (v * 255.0)] / 255.0;
 
                        fac = uv_table[(int) (255.0 * v)];
@@ -242,18 +247,19 @@ void plugin_seq_doit(Cast *cast, float facf0, float facf1, int width,
                        if (s >= 1.0) {
                                s = 1.0;
                        }
-                       hsv_to_rgb(h,s,v, &r, &g, &b);
+                       hsv_to_rgb(h, s, v, &r, &g, &b);
                        
                        if (out->rect_float) {
                                destf[0] = r;
                                destf[1] = g;
                                destf[2] = b;
                                destf = destf + 4;
-                               src1f +=4;
-                       } else {
-                               dest[0] = r*255.0;
-                               dest[1] = g*255.0;
-                               dest[2] = b*255.0;
+                               src1f += 4;
+                       }
+                       else {
+                               dest[0] = r * 255.0;
+                               dest[1] = g * 255.0;
+                               dest[2] = b * 255.0;
                                dest += 4;
                        }
 
@@ -262,7 +268,7 @@ void plugin_seq_doit(Cast *cast, float facf0, float facf1, int width,
        }
 
        if (cast->debug) {
-               dest= (char *) out->rect;
+               dest = (char *) out->rect;
                for (c = 0; c < 10; c++) {
                        x = 0;
                        for (y = 0; y < 256; y++) {
@@ -279,7 +285,7 @@ void plugin_seq_doit(Cast *cast, float facf0, float facf1, int width,
                for (c = 0; c < 10; c++) {
                        x = 0;
                        for (y = 0; y < 256; y++) {
-                               char val = uv_table[y] * 255.0/10.0;
+                               char val = uv_table[y] * 255.0 / 10.0;
                                while (x < y * width / 255) {
                                        *dest++ = val;
                                        *dest++ = val;
index f135beb..d460368 100644 (file)
@@ -78,7 +78,9 @@ void BKE_image_buf_fill_checker(unsigned char *rect, float *rect_float, int widt
        float *rect_float_orig = rect_float;
 
        
-       float h = 0.0, hoffs = 0.0, hue = 0.0, s = 0.9, v = 0.9, r, g, b;
+       float h = 0.0, hoffs = 0.0;
+       float hsv[3] = {0.0f, 0.9f, 0.9f};
+       float rgb[3];
 
        /* checkers */
        for (y = 0; y < height; y++) {
@@ -128,20 +130,20 @@ void BKE_image_buf_fill_checker(unsigned char *rect, float *rect_float, int widt
                                if ((fabs((x % checkerwidth) - (checkerwidth / 2)) < 1) ||
                                    (fabs((y % checkerwidth) - (checkerwidth / 2)) < 1))
                                {
-                                       hue = fmodf(fabs(h - hoffs), 1.0f);
-                                       hsv_to_rgb(hue, s, v, &r, &g, &b);
+                                       hsv[0] = fmodf(fabs(h - hoffs), 1.0f);
+                                       hsv_to_rgb_v(hsv, rgb);
                                        
                                        if (rect) {
-                                               rect[0] = (char)(r * 255.0f);
-                                               rect[1] = (char)(g * 255.0f);
-                                               rect[2] = (char)(b * 255.0f);
+                                               rect[0] = (char)(rgb[0] * 255.0f);
+                                               rect[1] = (char)(rgb[1] * 255.0f);
+                                               rect[2] = (char)(rgb[2] * 255.0f);
                                                rect[3] = 255;
                                        }
                                        
                                        if (rect_float) {
-                                               rect_float[0] = r;
-                                               rect_float[1] = g;
-                                               rect_float[2] = b;
+                                               rect_float[0] = rgb[0];
+                                               rect_float[1] = rgb[1];
+                                               rect_float[2] = rgb[2];
                                                rect_float[3] = 1.0f;
                                        }
                                }
@@ -162,33 +164,33 @@ void BKE_image_buf_fill_checker(unsigned char *rect, float *rect_float, int widt
 static void checker_board_color_fill(unsigned char *rect, float *rect_float, int width, int height)
 {
        int hue_step, y, x;
-       float hue, val, sat, r, g, b;
+       float hsv[3], rgb[3];
 
-       sat = 1.0;
+       hsv[1] = 1.0;
 
        hue_step = power_of_2_max_i(width / 8);
        if (hue_step < 8) hue_step = 8;
 
        for (y = 0; y < height; y++) {
 
-               val = 0.1 + (y * (0.4 / height)); /* use a number lower then 1.0 else its too bright */
+               hsv[2] = 0.1 + (y * (0.4 / height)); /* use a number lower then 1.0 else its too bright */
                for (x = 0; x < width; x++) {
-                       hue = (float)((double)(x / hue_step) * 1.0 / width * hue_step);
-                       hsv_to_rgb(hue, sat, val, &r, &g, &b);
+                       hsv[0] = (float)((double)(x / hue_step) * 1.0 / width * hue_step);
+                       hsv_to_rgb_v(hsv, rgb);
 
                        if (rect) {
-                               rect[0] = (char)(r * 255.0f);
-                               rect[1] = (char)(g * 255.0f);
-                               rect[2] = (char)(b * 255.0f);
+                               rect[0] = (char)(rgb[0] * 255.0f);
+                               rect[1] = (char)(rgb[1] * 255.0f);
+                               rect[2] = (char)(rgb[2] * 255.0f);
                                rect[3] = 255;
                                
                                rect += 4;
                        }
 
                        if (rect_float) {
-                               rect_float[0] = r;
-                               rect_float[1] = g;
-                               rect_float[2] = b;
+                               rect_float[0] = rgb[0];
+                               rect_float[1] = rgb[1];
+                               rect_float[2] = rgb[2];
                                rect_float[3] = 1.0f;
                                
                                rect_float += 4;
index afdb5d4..746a2b9 100644 (file)
@@ -54,6 +54,7 @@ extern "C" {
 /******************* Conversion to RGB ********************/
 
 void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b);
+void hsv_to_rgb_v(const float hsv[3], float r_rgb[3]);
 void hex_to_rgb(char *hexcol, float *r, float *g, float *b);
 void yuv_to_rgb(float y, float u, float v, float *lr, float *lg, float *lb);
 void ycc_to_rgb(float y, float cb, float cr, float *lr, float *lg, float *lb, int colorspace);
@@ -65,7 +66,9 @@ void cpack_to_rgb(unsigned int col, float *r, float *g, float *b);
 void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv);
 void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr, int colorspace);
 void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv);
+void rgb_to_hsv_v(const float rgb[3], float r_hsv[3]);
 void rgb_to_hsv_compat(float r, float g, float b, float *lh, float *ls, float *lv);
+void rgb_to_hsv_compat_v(const float rgb[3], float r_hsv[3]);
 unsigned int rgb_to_cpack(float r, float g, float b);
 unsigned int hsv_to_cpack(float h, float s, float v);
 
index abd9c1e..152fc98 100644 (file)
@@ -90,6 +90,12 @@ void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b)
        }
 }
 
+/* convenience function for now */
+void hsv_to_rgb_v(const float hsv[3], float r_rgb[3])
+{
+       hsv_to_rgb(hsv[0], hsv[1], hsv[2], &r_rgb[0], &r_rgb[1], &r_rgb[2]);
+}
+
 void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv)
 {
        float y, u, v;
@@ -252,6 +258,12 @@ void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv)
        *lv = v;
 }
 
+/* convenience function for now */
+void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
+{
+       rgb_to_hsv(rgb[0], rgb[1], rgb[2], &r_hsv[0], &r_hsv[1], &r_hsv[2]);
+}
+
 void rgb_to_hsv_compat(float r, float g, float b, float *lh, float *ls, float *lv)
 {
        float orig_h = *lh;
@@ -272,6 +284,12 @@ void rgb_to_hsv_compat(float r, float g, float b, float *lh, float *ls, float *l
        }
 }
 
+/* convenience function for now */
+void rgb_to_hsv_compat_v(const float rgb[3], float r_hsv[3])
+{
+       rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], &r_hsv[0], &r_hsv[1], &r_hsv[2]);
+}
+
 /*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)
index 593010f..a73651d 100644 (file)
@@ -191,9 +191,9 @@ int getname_anim_fcurve(char *name, ID *id, FCurve *fcu)
 
 /* used to determine the color of F-Curves with FCURVE_COLOR_AUTO_RAINBOW set */
 //void fcurve_rainbow (unsigned int cur, unsigned int tot, float *out)
-void getcolor_fcurve_rainbow(int cur, int tot, float *out)
+void getcolor_fcurve_rainbow(int cur, int tot, float out[3])
 {
-       float hue, val, sat, fac;
+       float hsv[3], fac;
        int grouping;
        
        /* we try to divide the color into groupings of n colors,
@@ -203,7 +203,7 @@ void getcolor_fcurve_rainbow(int cur, int tot, float *out)
         * so the base color is simply one of the three primary colors
         */
        grouping = (4 - (tot % 2));
-       hue = HSV_BANDWIDTH * (float)(cur % grouping);
+       hsv[0] = HSV_BANDWIDTH * (float)(cur % grouping);
        
        /* 'Value' (i.e. darkness) needs to vary so that larger sets of three will be 
         * 'darker' (i.e. smaller value), so that they don't look that similar to previous ones.
@@ -213,16 +213,15 @@ void getcolor_fcurve_rainbow(int cur, int tot, float *out)
        fac = ((float)cur / (float)tot) * 0.7f;
        
        /* the base color can get offset a bit so that the colors aren't so identical */
-       hue += fac * HSV_BANDWIDTH; 
-       if (hue > 1.0f) hue = fmod(hue, 1.0f);
+       hsv[0] += fac * HSV_BANDWIDTH;
+       if (hsv[0] > 1.0f) hsv[0] = fmod(hsv[0], 1.0f);
        
        /* saturation adjustments for more visible range */
-       if ((hue > 0.5f) && (hue < 0.8f)) sat = 0.5f;
-       else sat = 0.6f;
+       hsv[1] = ((hsv[0] > 0.5f) && (hsv[0] < 0.8f)) ? 0.5f : 0.6f;
        
        /* value is fixed at 1.0f, otherwise we cannot clearly see the curves... */
-       val = 1.0f;
+       hsv[2] = 1.0f;
        
        /* finally, conver this to RGB colors */
-       hsv_to_rgb(hue, sat, val, out, out + 1, out + 2);
+       hsv_to_rgb_v(hsv, out);
 }
index f4d922d..4f24d25 100644 (file)
@@ -509,7 +509,7 @@ short ANIM_fmodifiers_paste_from_buf(ListBase *modifiers, short replace);
 int getname_anim_fcurve(char *name, struct ID *id, struct FCurve *fcu);
 
 /* Automatically determine a color for the nth F-Curve */
-void getcolor_fcurve_rainbow(int cur, int tot, float *out);
+void getcolor_fcurve_rainbow(int cur, int tot, float out[3]);
 
 /* ----------------- NLA-Mapping ----------------------- */
 /* anim_draw.c */
index c0cd17d..5394cb4 100644 (file)
@@ -1437,15 +1437,15 @@ double ui_get_but_val(uiBut *but)
                }
        }
        else if (but->type == HSVSLI) {
-               float h, s, v, *fp;
+               float *fp, hsv[3];
                
                fp = (but->editvec) ? but->editvec : (float *)but->poin;
-               rgb_to_hsv(fp[0], fp[1], fp[2], &h, &s, &v);
+               rgb_to_hsv_v(fp, hsv);
 
                switch (but->str[0]) {
-                       case 'H': value = h; break;
-                       case 'S': value = s; break;
-                       case 'V': value = v; break;
+                       case 'H': value = hsv[0]; break;
+                       case 'S': value = hsv[1]; break;
+                       case 'V': value = hsv[2]; break;
                }
        } 
        else if (but->pointype == CHA) {
@@ -1513,18 +1513,18 @@ void ui_set_but_val(uiBut *but, double value)
        }
        else if (but->pointype == 0) ;
        else if (but->type == HSVSLI) {
-               float h, s, v, *fp;
+               float *fp, hsv[3];
                
                fp = (but->editvec) ? but->editvec : (float *)but->poin;
-               rgb_to_hsv(fp[0], fp[1], fp[2], &h, &s, &v);
+               rgb_to_hsv_v(fp, hsv);
                
                switch (but->str[0]) {
-                       case 'H': h = value; break;
-                       case 'S': s = value; break;
-                       case 'V': v = value; break;
+                       case 'H': hsv[0] = value; break;
+                       case 'S': hsv[1] = value; break;
+                       case 'V': hsv[2] = value; break;
                }
                
-               hsv_to_rgb(h, s, v, fp, fp + 1, fp + 2);
+               hsv_to_rgb_v(hsv, fp);
                
        }
        else {
index 91e6b3d..edb0bdc 100644 (file)
@@ -2953,14 +2953,14 @@ static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, wm
                                float col[3];
                                
                                ui_get_but_vectorf(but, col);
-                               rgb_to_hsv_compat(col[0], col[1], col[2], hsv, hsv + 1, hsv + 2);
+                               rgb_to_hsv_compat_v(col, hsv);
 
                                if (event->type == WHEELDOWNMOUSE)
                                        hsv[2] = CLAMPIS(hsv[2] - 0.05f, 0.0f, 1.0f);
                                else
                                        hsv[2] = CLAMPIS(hsv[2] + 0.05f, 0.0f, 1.0f);
                                
-                               hsv_to_rgb(hsv[0], hsv[1], hsv[2], data->vec, data->vec + 1, data->vec + 2);
+                               hsv_to_rgb_v(hsv, data->vec);
                                ui_set_but_vectorf(but, data->vec);
                                
                                button_activate_state(C, but, BUTTON_STATE_EXIT);
@@ -3106,7 +3106,7 @@ static int ui_numedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, int mx,
 
        ui_get_but_vectorf(but, rgb);
 
-       rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
+       rgb_to_hsv_compat_v(rgb, hsv);
 
        /* relative position within box */
        x = ((float)mx - but->x1) / (but->x2 - but->x1);
@@ -3152,7 +3152,7 @@ static int ui_numedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, int mx,
                        assert(!"invalid hsv type");
        }
 
-       hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb + 1, rgb + 2);
+       hsv_to_rgb_v(hsv, rgb);
        copy_v3_v3(data->vec, rgb);
 
        data->draglastx = mx;
@@ -3175,7 +3175,7 @@ static void ui_ndofedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, wmNDOF
        }
 
        ui_get_but_vectorf(but, rgb);
-       rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
+       rgb_to_hsv_compat_v(rgb, hsv);
        
        switch ((int)but->a1) {
                case UI_GRAD_SV:
@@ -3213,7 +3213,7 @@ static void ui_ndofedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, wmNDOF
                        assert(!"invalid hsv type");
        }
        
-       hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb + 1, rgb + 2);
+       hsv_to_rgb_v(hsv, rgb);
        copy_v3_v3(data->vec, rgb);
        ui_set_but_vectorf(but, data->vec);
 }
@@ -3265,12 +3265,15 @@ static int ui_do_but_HSVCUBE(bContext *C, uiBlock *block, uiBut *but, uiHandleBu
                                        def = MEM_callocN(sizeof(float) * len, "reset_defaults - float");
                                        
                                        RNA_property_float_get_default_array(&but->rnapoin, but->rnaprop, def);
-                                       rgb_to_hsv(def[0], def[1], def[2], def_hsv, def_hsv + 1, def_hsv + 2);
+                                       rgb_to_hsv_v(def, def_hsv);
                                        
                                        ui_get_but_vectorf(but, rgb);
-                                       rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
+                                       rgb_to_hsv_compat_v(rgb, hsv);
+
+                                       def_hsv[0] = hsv[0];
+                                       def_hsv[1] = hsv[1];
                                        
-                                       hsv_to_rgb(hsv[0], hsv[1], def_hsv[2], rgb, rgb + 1, rgb + 2);
+                                       hsv_to_rgb_v(def_hsv, rgb);
                                        ui_set_but_vectorf(but, rgb);
                                        
                                        RNA_property_update(C, &but->rnapoin, but->rnaprop);
@@ -3314,7 +3317,7 @@ static int ui_numedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, int mx
        
        ui_get_but_vectorf(but, rgb);
        copy_v3_v3(hsv, ui_block_hsv_get(but->block));
-       rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
+       rgb_to_hsv_compat_v(rgb, hsv);
        
        /* exception, when using color wheel in 'locked' value state:
         * allow choosing a hue for black values, by giving a tiny increment */
@@ -3334,7 +3337,7 @@ static int ui_numedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, int mx
        if (but->flag & UI_BUT_COLOR_CUBIC)
                hsv[1] = 1.0f - sqrt3f(1.0f - hsv[1]);
 
-       hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb + 1, rgb + 2);
+       hsv_to_rgb_v(hsv, rgb);
 
        if ((but->flag & UI_BUT_VEC_SIZE_LOCK) && (rgb[0] || rgb[1] || rgb[2])) {
                normalize_v3(rgb);
@@ -3357,7 +3360,7 @@ static void ui_ndofedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, wmND
        float sensitivity = (shift ? 0.15f : 0.3f) * ndof->dt;
        
        ui_get_but_vectorf(but, rgb);
-       rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
+       rgb_to_hsv_compat_v(rgb, hsv);
        
        /* Convert current colour on hue/sat disc to circular coordinates phi, r */
        phi = fmodf(hsv[0] + 0.25f, 1.0f) * -2.0f * (float)M_PI;
@@ -3391,7 +3394,7 @@ static void ui_ndofedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, wmND
                if (hsv[2] == 0.0f) hsv[2] = 0.0001f;
        }
        
-       hsv_to_rgb(hsv[0], hsv[1], hsv[2], data->vec, data->vec + 1, data->vec + 2);
+       hsv_to_rgb_v(hsv, data->vec);
        
        if ((but->flag & UI_BUT_VEC_SIZE_LOCK) && (data->vec[0] || data->vec[1] || data->vec[2])) {
                normalize_v3(data->vec);
@@ -3447,12 +3450,15 @@ static int ui_do_but_HSVCIRCLE(bContext *C, uiBlock *block, uiBut *but, uiHandle
                                def = MEM_callocN(sizeof(float) * len, "reset_defaults - float");
                                
                                RNA_property_float_get_default_array(&but->rnapoin, but->rnaprop, def);
-                               rgb_to_hsv(def[0], def[1], def[2], def_hsv, def_hsv + 1, def_hsv + 2);
+                               rgb_to_hsv_v(def, def_hsv);
                                
                                ui_get_but_vectorf(but, rgb);
-                               rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
+                               rgb_to_hsv_compat_v(rgb, hsv);
                                
-                               hsv_to_rgb(hsv[0], def_hsv[1], hsv[2], rgb, rgb + 1, rgb + 2);
+                               def_hsv[0] = hsv[0];
+                               def_hsv[2] = hsv[2];
+
+                               hsv_to_rgb_v(def_hsv, rgb);
                                ui_set_but_vectorf(but, rgb);
                                
                                RNA_property_update(C, &but->rnapoin, but->rnaprop);
index 5459f68..b690d1f 100644 (file)
@@ -339,13 +339,13 @@ static void rgb_tint(float col[3],
        float col_hsv_from[3];
        float col_hsv_to[3];
 
-       rgb_to_hsv(col[0], col[1], col[2],    col_hsv_from + 0, col_hsv_from + 1, col_hsv_from + 2);
+       rgb_to_hsv_v(col, col_hsv_from);
 
        col_hsv_to[0] = h;
        col_hsv_to[1] = h_strength;
        col_hsv_to[2] = (col_hsv_from[2] * (1.0f - v_strength)) + (v * v_strength);
 
-       hsv_to_rgb(col_hsv_to[0], col_hsv_to[1], col_hsv_to[2], col + 0, col + 1, col + 2);
+       hsv_to_rgb_v(col_hsv_to, col);
 }
 
 static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
@@ -1847,7 +1847,7 @@ void ui_set_but_hsv(uiBut *but)
        float col[3];
        float *hsv = ui_block_hsv_get(but->block);
        
-       hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col + 1, col + 2);
+       hsv_to_rgb_v(hsv, col);
        ui_set_but_vectorf(but, col);
 }
 
@@ -1860,7 +1860,7 @@ static void ui_update_block_buts_rgb(uiBlock *block, const float rgb[3])
        /* this is to keep the H and S value when V is equal to zero
         * and we are working in HSV mode, of course!
         */
-       rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
+       rgb_to_hsv_compat_v(rgb, hsv);
        
        // this updates button strings, is hackish... but button pointers are on stack of caller function
        for (bt = block->buttons.first; bt; bt = bt->next) {
@@ -1942,7 +1942,7 @@ static void do_hsv_rna_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg))
        float rgb[3];
        float *hsv = ui_block_hsv_get(but->block);
        
-       hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb + 1, rgb + 2);
+       hsv_to_rgb_v(hsv, rgb);
        
        ui_update_block_buts_rgb(but->block, rgb);
        
@@ -2157,7 +2157,7 @@ static void uiBlockPicker(uiBlock *block, float rgba[4], PointerRNA *ptr, Proper
        uiButSetFunc(bt, do_hex_rna_cb, bt, hexcol);
        uiDefBut(block, LABEL, 0, IFACE_("(Gamma Corrected)"), 0, -80, butwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
 
-       rgb_to_hsv(rgba[0], rgba[1], rgba[2], hsv, hsv + 1, hsv + 2);
+       rgb_to_hsv_v(rgba, hsv);
 
        picker_new_hide_reveal(block, colormode);
 }
@@ -2178,18 +2178,18 @@ static int ui_picker_small_wheel_cb(const bContext *UNUSED(C), uiBlock *block, w
                for (but = block->buttons.first; but; but = but->next) {
                        if (but->type == HSVCUBE && but->active == NULL) {
                                uiPopupBlockHandle *popup = block->handle;
-                               float col[3];
+                               float rgb[3];
                                float *hsv = ui_block_hsv_get(block);
                                
-                               ui_get_but_vectorf(but, col);
+                               ui_get_but_vectorf(but, rgb);
                                
-                               rgb_to_hsv_compat(col[0], col[1], col[2], hsv, hsv + 1, hsv + 2);
+                               rgb_to_hsv_compat_v(rgb, hsv);
                                hsv[2] = CLAMPIS(hsv[2] + add, 0.0f, 1.0f);
-                               hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col + 1, col + 2);
+                               hsv_to_rgb_v(hsv, rgb);
 
-                               ui_set_but_vectorf(but, col);
+                               ui_set_but_vectorf(but, rgb);
                                
-                               ui_update_block_buts_rgb(block, col);
+                               ui_update_block_buts_rgb(block, rgb);
                                if (popup)
                                        popup->menuretval = UI_RETURN_UPDATE;
                                
index 4d483b6..87c2f2d 100644 (file)
@@ -1885,7 +1885,7 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, rcti *rect)
        /* color */
        ui_get_but_vectorf(but, rgb);
        copy_v3_v3(hsv, ui_block_hsv_get(but->block));
-       rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
+       rgb_to_hsv_compat_v(rgb, hsv);
        copy_v3_v3(hsvo, hsv);
        
        /* exception: if 'lock' is set
@@ -1911,7 +1911,7 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, rcti *rect)
                ui_hsvcircle_vals_from_pos(hsv, hsv + 1, rect, centx + co * radius, centy + si * radius);
                CLAMP(hsv[2], 0.0f, 1.0f); /* for display only */
 
-               hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col + 1, col + 2);
+               hsv_to_rgb_v(hsv, col);
                glColor3fv(col);
                glVertex2f(centx + co * radius, centy + si * radius);
        }
@@ -2081,37 +2081,31 @@ void ui_draw_gradient(rcti *rect, const float hsv[3], int type, float alpha)
 
 static void ui_draw_but_HSVCUBE(uiBut *but, rcti *rect)
 {
-       float rgb[3], h, s, v;
+       float rgb[3];
        float x = 0.0f, y = 0.0f;
        float *hsv = ui_block_hsv_get(but->block);
-       float hsvn[3];
+       float hsv_n[3];
        
-       h = hsv[0];
-       s = hsv[1];
-       v = hsv[2];
+       copy_v3_v3(hsv_n, hsv);
        
        ui_get_but_vectorf(but, rgb);
-       rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], &h, &s, &v);
-
-       hsvn[0] = h;
-       hsvn[1] = s;
-       hsvn[2] = v;
+       rgb_to_hsv_compat_v(rgb, hsv_n);
        
-       ui_draw_gradient(rect, hsvn, but->a1, 1.f);
+       ui_draw_gradient(rect, hsv_n, but->a1, 1.0f);
        
        switch ((int)but->a1) {
                case UI_GRAD_SV:
-                       x = v; y = s; break;
+                       x = hsv_n[2]; y = hsv_n[1]; break;
                case UI_GRAD_HV:
-                       x = h; y = v; break;
+                       x = hsv_n[0]; y = hsv_n[2]; break;
                case UI_GRAD_HS:
-                       x = h; y = s; break;
+                       x = hsv_n[0]; y = hsv_n[1]; break;
                case UI_GRAD_H:
-                       x = h; y = 0.5; break;
+                       x = hsv_n[0]; y = 0.5; break;
                case UI_GRAD_S:
-                       x = s; y = 0.5; break;
+                       x = hsv_n[1]; y = 0.5; break;
                case UI_GRAD_V:
-                       x = v; y = 0.5; break;
+                       x = hsv_n[2]; y = 0.5; break;
        }
        
        /* cursor */
@@ -2140,7 +2134,7 @@ static void ui_draw_but_HSV_v(uiBut *but, rcti *rect)
                color_profile = BLI_PR_NONE;
 
        ui_get_but_vectorf(but, rgb);
-       rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
+       rgb_to_hsv_v(rgb, hsv);
        v = hsv[2];
        
        if (color_profile)
index 062c7a9..279fd5d 100644 (file)
@@ -764,7 +764,7 @@ void IMB_saturation(ImBuf *ibuf, float sat)
                float rgb[3];
                for (i = ibuf->x * ibuf->y; i > 0; i--, rct += 4) {
                        rgb_uchar_to_float(rgb, rct);
-                       rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
+                       rgb_to_hsv_v(rgb, hsv);
                        hsv_to_rgb(hsv[0], hsv[1] * sat, hsv[2], rgb, rgb + 1, rgb + 2);
                        rgb_float_to_uchar(rct, rgb);
                }
@@ -772,7 +772,7 @@ void IMB_saturation(ImBuf *ibuf, float sat)
 
        if (rctf) {
                for (i = ibuf->x * ibuf->y; i > 0; i--, rctf += 4) {
-                       rgb_to_hsv(rctf[0], rctf[1], rctf[2], hsv, hsv + 1, hsv + 2);
+                       rgb_to_hsv_v(rctf, hsv);
                        hsv_to_rgb(hsv[0], hsv[1] * sat, hsv[2], rctf, rctf + 1, rctf + 2);
                }
        }
index 5097ae8..81cdad0 100644 (file)
@@ -154,7 +154,7 @@ void weightvg_do_mask(int num, const int *indices, float *org_w, const float *ne
                for (i = 0; i < num; ++i) {
                        int idx = indices ? indices[i] : i;
                        TexResult texres;
-                       float h, s, v; /* For HSV color space. */
+                       float hsv[3]; /* For HSV color space. */
 
                        texres.nor = NULL;
                        get_texture_value(texture, tex_co[idx], &texres);
@@ -173,16 +173,16 @@ void weightvg_do_mask(int num, const int *indices, float *org_w, const float *ne
                                        org_w[i] = (new_w[i] * texres.tb * fact) + (org_w[i] * (1.0f - (texres.tb * fact)));
                                        break;
                                case MOD_WVG_MASK_TEX_USE_HUE:
-                                       rgb_to_hsv(texres.tr, texres.tg, texres.tb, &h, &s, &v);
-                                       org_w[i] = (new_w[i] * h * fact) + (org_w[i] * (1.0f - (h * fact)));
+                                       rgb_to_hsv_v(&texres.tr, hsv);
+                                       org_w[i] = (new_w[i] * hsv[0] * fact) + (org_w[i] * (1.0f - (hsv[0] * fact)));
                                        break;
                                case MOD_WVG_MASK_TEX_USE_SAT:
-                                       rgb_to_hsv(texres.tr, texres.tg, texres.tb, &h, &s, &v);
-                                       org_w[i] = (new_w[i] * s * fact) + (org_w[i] * (1.0f - (s * fact)));
+                                       rgb_to_hsv_v(&texres.tr, hsv);
+                                       org_w[i] = (new_w[i] * hsv[1] * fact) + (org_w[i] * (1.0f - (hsv[1] * fact)));
                                        break;
                                case MOD_WVG_MASK_TEX_USE_VAL:
-                                       rgb_to_hsv(texres.tr, texres.tg, texres.tb, &h, &s, &v);
-                                       org_w[i] = (new_w[i] * v * fact) + (org_w[i] * (1.0f - (v * fact)));
+                                       rgb_to_hsv_v(&texres.tr, hsv);
+                                       org_w[i] = (new_w[i] * hsv[2] * fact) + (org_w[i] * (1.0f - (hsv[2] * fact)));
                                        break;
                                case MOD_WVG_MASK_TEX_USE_ALPHA:
                                        org_w[i] = (new_w[i] * texres.ta * fact) + (org_w[i] * (1.0f - (texres.ta * fact)));
index 0f421f1..59c57e9 100644 (file)
@@ -723,10 +723,10 @@ static int Color_channel_hsv_set(ColorObject *self, PyObject *value, void *type)
        if (BaseMath_ReadCallback(self) == -1)
                return -1;
 
-       rgb_to_hsv(self->col[0], self->col[1], self->col[2], &(hsv[0]), &(hsv[1]), &(hsv[2]));
+       rgb_to_hsv_v(self->col, hsv);
        CLAMP(f, 0.0f, 1.0f);
        hsv[i] = f;
-       hsv_to_rgb(hsv[0], hsv[1], hsv[2], &(self->col[0]), &(self->col[1]), &(self->col[2]));
+       hsv_to_rgb_v(hsv, self->col);
 
        if (BaseMath_WriteCallback(self) == -1)
                return -1;
@@ -764,7 +764,7 @@ static int Color_hsv_set(ColorObject *self, PyObject *value, void *UNUSED(closur
        CLAMP(hsv[1], 0.0f, 1.0f);
        CLAMP(hsv[2], 0.0f, 1.0f);
 
-       hsv_to_rgb(hsv[0], hsv[1], hsv[2], &(self->col[0]), &(self->col[1]), &(self->col[2]));
+       hsv_to_rgb_v(hsv, self->col);
 
        if (BaseMath_WriteCallback(self) == -1)
                return -1;