From 6fb53f7c4207240805fa9fc6d3d2f406bb3ef474 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 30 May 2012 14:39:20 +0000 Subject: [PATCH] Several small fixes to nodes: - 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 --- .../blender/compositor/operations/COM_KeyingOperation.cpp | 8 ++++---- .../compositor/operations/COM_KeyingScreenOperation.cpp | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/source/blender/compositor/operations/COM_KeyingOperation.cpp b/source/blender/compositor/operations/COM_KeyingOperation.cpp index 43348568a5d..5f1c9d0640d 100644 --- a/source/blender/compositor/operations/COM_KeyingOperation.cpp +++ b/source/blender/compositor/operations/COM_KeyingOperation.cpp @@ -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); - } + } } diff --git a/source/blender/compositor/operations/COM_KeyingScreenOperation.cpp b/source/blender/compositor/operations/COM_KeyingScreenOperation.cpp index 456ab31db24..f9c9216b75a 100644 --- a/source/blender/compositor/operations/COM_KeyingScreenOperation.cpp +++ b/source/blender/compositor/operations/COM_KeyingScreenOperation.cpp @@ -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;