Fix T52531: Blender 2D stabilisation node issue when autoscale is selected
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 4 Sep 2017 14:40:55 +0000 (16:40 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 4 Sep 2017 14:41:28 +0000 (16:41 +0200)
Threading conflict, should be safe for 2.79.

source/blender/compositor/operations/COM_MovieClipAttributeOperation.cpp
source/blender/compositor/operations/COM_MovieClipAttributeOperation.h

index 41f7da7c49fe8e5c13502a8c1629489a8f6e6ace..0c2da8415f88521cc0af2aa8e8d05e106fc10d06 100644 (file)
@@ -28,55 +28,58 @@ extern "C" {
 MovieClipAttributeOperation::MovieClipAttributeOperation() : NodeOperation()
 {
        this->addOutputSocket(COM_DT_VALUE);
-       this->m_valueSet = false;
        this->m_framenumber = 0;
        this->m_attribute = MCA_X;
        this->m_invert = false;
 }
 
-void MovieClipAttributeOperation::executePixelSampled(float output[4],
-                                                      float /*x*/, float /*y*/,
-                                                      PixelSampler /*sampler*/)
+void MovieClipAttributeOperation::initExecution()
 {
-       /* TODO(sergey): This code isn't really thread-safe. */
-       if (!this->m_valueSet) {
-               float loc[2], scale, angle;
-               loc[0] = 0.0f;
-               loc[1] = 0.0f;
-               scale = 1.0f;
-               angle = 0.0f;
-               if (this->m_clip) {
-                       int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(this->m_clip, this->m_framenumber);
-                       BKE_tracking_stabilization_data_get(this->m_clip, clip_framenr, getWidth(), getHeight(), loc, &scale, &angle);
-               }
-               switch (this->m_attribute) {
-                       case MCA_SCALE:
-                               this->m_value = scale;
-                               break;
-                       case MCA_ANGLE:
-                               this->m_value = angle;
-                               break;
-                       case MCA_X:
-                               this->m_value = loc[0];
-                               break;
-                       case MCA_Y:
-                               this->m_value = loc[1];
-                               break;
+       float loc[2], scale, angle;
+       loc[0] = 0.0f;
+       loc[1] = 0.0f;
+       scale = 1.0f;
+       angle = 0.0f;
+       int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(
+               this->m_clip, this->m_framenumber);
+       BKE_tracking_stabilization_data_get(this->m_clip,
+                                           clip_framenr,
+                                           getWidth(), getHeight(),
+                                           loc, &scale, &angle);
+       switch (this->m_attribute) {
+               case MCA_SCALE:
+                       this->m_value = scale;
+                       break;
+               case MCA_ANGLE:
+                       this->m_value = angle;
+                       break;
+               case MCA_X:
+                       this->m_value = loc[0];
+                       break;
+               case MCA_Y:
+                       this->m_value = loc[1];
+                       break;
+       }
+       if (this->m_invert) {
+               if (this->m_attribute != MCA_SCALE) {
+                       this->m_value = -this->m_value;
                }
-               if (this->m_invert) {
-                       if (this->m_attribute != MCA_SCALE) {
-                               this->m_value = -this->m_value;
-                       }
-                       else {
-                               this->m_value = 1.0f / this->m_value;
-                       }
+               else {
+                       this->m_value = 1.0f / this->m_value;
                }
-               this->m_valueSet = true;
        }
+}
+
+void MovieClipAttributeOperation::executePixelSampled(float output[4],
+                                                      float /*x*/, float /*y*/,
+                                                      PixelSampler /*sampler*/)
+{
        output[0] = this->m_value;
 }
 
-void MovieClipAttributeOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
+void MovieClipAttributeOperation::determineResolution(
+        unsigned int resolution[2],
+        unsigned int preferredResolution[2])
 {
        resolution[0] = preferredResolution[0];
        resolution[1] = preferredResolution[1];
index 731b9debaf0eb106e41eae3ccc00d9eb37eab15b..659f54c1ca264b5bd39fa30248425f041ea21834 100644 (file)
@@ -39,16 +39,18 @@ class MovieClipAttributeOperation : public NodeOperation {
 private:
        MovieClip *m_clip;
        float m_value;
-       bool m_valueSet;
        int m_framenumber;
        bool m_invert;
        MovieClipAttribute m_attribute;
+
 public:
        /**
         * Default constructor
         */
        MovieClipAttributeOperation();
-       
+
+       void initExecution();
+
        /**
         * the inner loop of this program
         */