Merging r50049 through r50076 from trunk into soc-2011-tomato
[blender.git] / source / blender / blenkernel / intern / colortools.c
index 3b24ac0f856e19c7cd40d0dfbece5b730f238f79..0df27532af2b7860a2b44404dcff2c4d9c052cc4 100644 (file)
@@ -146,21 +146,31 @@ CurveMapping *curvemapping_copy(CurveMapping *cumap)
        return NULL;
 }
 
-void curvemapping_set_black_white(CurveMapping *cumap, const float black[3], const float white[3])
+void curvemapping_set_black_white_ex(const float black[3], const float white[3], float r_bwmul[3])
 {
        int a;
-       
-       if (white)
+
+       for (a = 0; a < 3; a++) {
+               const float delta = white[a] - black[a];
+               if (delta != 0.0f) {
+                       r_bwmul[a] = 1.0f / delta;
+               }
+               else {
+                       r_bwmul[a] = 0.0f;
+               }
+       }
+}
+
+void curvemapping_set_black_white(CurveMapping *cumap, const float black[3], const float white[3])
+{
+       if (white) {
                copy_v3_v3(cumap->white, white);
-       if (black)
+       }
+       if (black) {
                copy_v3_v3(cumap->black, black);
-       
-       for (a = 0; a < 3; a++) {
-               if (cumap->white[a] == cumap->black[a])
-                       cumap->bwmul[a] = 0.0f;
-               else
-                       cumap->bwmul[a] = 1.0f / (cumap->white[a] - cumap->black[a]);
-       }       
+       }
+
+       curvemapping_set_black_white_ex(cumap->black, cumap->white, cumap->bwmul);
 }
 
 /* ***************** operations on single curve ************* */
@@ -193,7 +203,7 @@ void curvemap_remove_point(CurveMap *cuma, CurveMapPoint *point)
 }
 
 /* removes with flag set */
-void curvemap_remove(CurveMap *cuma, int flag)
+void curvemap_remove(CurveMap *cuma, const short flag)
 {
        CurveMapPoint *cmp = MEM_mallocN((cuma->totpoint) * sizeof(CurveMapPoint), "curve points");
        int a, b, removed = 0;
@@ -702,12 +712,12 @@ void curvemapping_changed(CurveMapping *cumap, int rem_doubles)
                        dy = cmp[a].y - cmp[a + 1].y;
                        if (sqrtf(dx * dx + dy * dy) < thresh) {
                                if (a == 0) {
-                                       cmp[a + 1].flag |= 2;
+                                       cmp[a + 1].flag |= CUMA_VECTOR;
                                        if (cmp[a + 1].flag & CUMA_SELECT)
                                                cmp[a].flag |= CUMA_SELECT;
                                }
                                else {
-                                       cmp[a].flag |= 2;
+                                       cmp[a].flag |= CUMA_VECTOR;
                                        if (cmp[a].flag & CUMA_SELECT)
                                                cmp[a + 1].flag |= CUMA_SELECT;
                                }
@@ -727,7 +737,7 @@ void curvemapping_changed_all(CurveMapping *cumap)
        for (a = 0; a < CM_TOT; a++) {
                if (cumap->cm[a].curve) {
                        cumap->cur = a;
-                       curvemapping_changed(cumap, 0);
+                       curvemapping_changed(cumap, FALSE);
                }
        }
 
@@ -786,20 +796,29 @@ void curvemapping_evaluateRGBF(CurveMapping *cumap, float vecout[3], const float
        vecout[2] = curvemapping_evaluateF(cumap, 2, curvemapping_evaluateF(cumap, 3, vecin[2]));
 }
 
+/** same as #curvemapping_evaluate_premulRGBF
+ * but black/bwmul are passed as args for the compositor
+ * where they can change per pixel.
+ *
+ * Use in conjunction with #curvemapping_set_black_white_ex
+ *
+ * \param black Use instead of cumap->black
+ * \param bwmul Use instead of cumap->bwmul
+ */
+void curvemapping_evaluate_premulRGBF_ex(CurveMapping *cumap, float vecout[3], const float vecin[3],
+                                         const float black[3], const float bwmul[3])
+{
+       vecout[0] = curvemap_evaluateF(&cumap->cm[0], (vecin[0] - black[0]) * bwmul[0]);
+       vecout[1] = curvemap_evaluateF(&cumap->cm[1], (vecin[1] - black[1]) * bwmul[1]);
+       vecout[2] = curvemap_evaluateF(&cumap->cm[2], (vecin[2] - black[2]) * bwmul[2]);
+}
 
 /* RGB with black/white points and premult. tables are checked */
 void curvemapping_evaluate_premulRGBF(CurveMapping *cumap, float vecout[3], const float vecin[3])
 {
-       float fac;
-       
-       fac = (vecin[0] - cumap->black[0]) * cumap->bwmul[0];
-       vecout[0] = curvemap_evaluateF(cumap->cm, fac);
-       
-       fac = (vecin[1] - cumap->black[1]) * cumap->bwmul[1];
-       vecout[1] = curvemap_evaluateF(cumap->cm + 1, fac);
-       
-       fac = (vecin[2] - cumap->black[2]) * cumap->bwmul[2];
-       vecout[2] = curvemap_evaluateF(cumap->cm + 2, fac);
+       vecout[0] = curvemap_evaluateF(&cumap->cm[0], (vecin[0] - cumap->black[0]) * cumap->bwmul[0]);
+       vecout[1] = curvemap_evaluateF(&cumap->cm[1], (vecin[1] - cumap->black[1]) * cumap->bwmul[1]);
+       vecout[2] = curvemap_evaluateF(&cumap->cm[2], (vecin[2] - cumap->black[2]) * cumap->bwmul[2]);
 }
 
 /* same as above, byte version */