Several small fixes to nodes:
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 30 May 2012 14:39:20 +0000 (14:39 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 30 May 2012 14:39:20 +0000 (14:39 +0000)
- Code formation fix in keying node
- Fixed crash when creating keying screen for frame where there's no movie
- Attempt to improve keying node to handle alpha on hair better

source/blender/compositor/operations/COM_KeyingOperation.cpp
source/blender/compositor/operations/COM_KeyingScreenOperation.cpp

index 43348568a5d0adaedc99c0b80bd4dc6b7a1698a0..5f1c9d0640da1717b2171cb26fa24707a8778f51 100644 (file)
@@ -47,7 +47,7 @@ static float get_pixel_saturation(float *pixel, float screen_balance)
        float mid = pixel[0] + pixel[1] + pixel[2] - min - max;
        float val = (1.0f - screen_balance) * min + screen_balance * mid;
 
-       return max - val;
+       return (max - val) * (1.0f - val) * (1.0f - val);
 }
 
 KeyingOperation::KeyingOperation(): NodeOperation()
@@ -92,7 +92,7 @@ void KeyingOperation::executePixel(float *color, float x, float y, PixelSampler
        if (primary_channel != screen_primary_channel) {
                /* different main channel means pixel is on foreground */
                color[0] = 1.0f;
-        }
+       }
         else if (saturation >= screen_saturation) {
                /* saturation of main channel is more than screen, definitely a background */
                color[0] = 0.0f;
@@ -102,7 +102,7 @@ void KeyingOperation::executePixel(float *color, float x, float y, PixelSampler
 
                distance = 1.0f - saturation / screen_saturation;
 
-               color[0] = distance;
+               color[0] = distance * distance;
 
                if (color[0] < this->clipBlack)
                        color[0] = 0.0f;
@@ -110,5 +110,5 @@ void KeyingOperation::executePixel(float *color, float x, float y, PixelSampler
                        color[0] = 1.0f;
                else
                        color[0] = (color[0] - this->clipBlack) / (this->clipWhite - this->clipBlack);
-        }
+       }
 }
index 456ab31db2435ebe94e3bbe18fc6fa4933c1b87c..f9c9216b75a40b9af57390c60af6307402e448c8 100644 (file)
@@ -102,11 +102,14 @@ KeyingScreenOperation::TriangulationData *KeyingScreenOperation::buildVoronoiTri
        if (!sites_total)
                return NULL;
 
-       triangulation = (TriangulationData *) MEM_callocN(sizeof(TriangulationData), "keying screen triangulation data");
-
        BKE_movieclip_user_set_frame(&user, framenumber);
        ibuf = BKE_movieclip_get_ibuf(movieClip, &user);
 
+       if (!ibuf)
+               return NULL;
+
+       triangulation = (TriangulationData *) MEM_callocN(sizeof(TriangulationData), "keying screen triangulation data");
+
        sites = (VoronoiSite *) MEM_callocN(sizeof(VoronoiSite) * sites_total, "keyingscreen voronoi sites");
        track = (MovieTrackingTrack *) tracksbase->first;
        i = 0;