Fix T47210: Compostiting, Bad AA using distort + undistort nodes
authorSergey Sharybin <sergey.vfx@gmail.com>
Sun, 24 Jan 2016 19:25:38 +0000 (00:25 +0500)
committerSergey Sharybin <sergey.vfx@gmail.com>
Sun, 24 Jan 2016 19:25:38 +0000 (00:25 +0500)
Compositor tried to be too much smart and avoid unneeded re-calculations of
the distortion model, but the way it was implemented is by falling back to
the nearest interpolation first.

We can't really cheat here, better to just look into faster models estimation.

source/blender/compositor/operations/COM_MovieDistortionOperation.h

index 85f075ab65aab55741d70779f188261405188d40..38b1dbfa8569bad29c820d3af9640e0a35fd9574 100644 (file)
@@ -47,11 +47,9 @@ private:
        int m_calibration_width;
        int m_calibration_height;
        bool m_inverted;
-       float *m_buffer;
-       int *m_bufferCalculated;
        double timeLastUsage;
        int m_margin[2];
-       
+
 public:
        DistortionCache(MovieClip *movieclip,
                        int width, int height,
@@ -73,28 +71,14 @@ public:
                this->m_calibration_width = calibration_width;
                this->m_calibration_height = calibration_height;
                this->m_inverted = inverted;
-               this->m_bufferCalculated = (int *)MEM_callocN(sizeof(int) * this->m_width * this->m_height, __func__);
-               this->m_buffer = (float *)MEM_mallocN(sizeof(float) * this->m_width * this->m_height * 2, __func__);
                copy_v2_v2_int(this->m_margin, margin);
                this->updateLastUsage();
        }
-       
-       ~DistortionCache() {
-               if (this->m_buffer) {
-                       MEM_freeN(this->m_buffer);
-                       this->m_buffer = NULL;
-               }
-               
-               if (this->m_bufferCalculated) {
-                       MEM_freeN(this->m_bufferCalculated);
-                       this->m_bufferCalculated = NULL;
-               }
-       }
-       
+
        void updateLastUsage() {
                this->timeLastUsage = PIL_check_seconds_timer();
        }
-       
+
        inline double getTimeLastUsage() {
                return this->timeLastUsage;
        }
@@ -119,43 +103,38 @@ public:
                       this->m_calibration_width == calibration_width &&
                       this->m_calibration_height == claibration_height;
        }
-       
-       void getUV(MovieTracking *trackingData, int x, int y, float *u, float *v)
+
+       void getUV(MovieTracking *trackingData,
+                  float x,
+                  float y,
+                  float *r_u,
+                  float *r_v)
        {
                if (x < 0 || x >= this->m_width || y < 0 || y >= this->m_height) {
-                       *u = x;
-                       *v = y;
+                       *r_u = x;
+                       *r_v = y;
                }
                else {
-                       int offset = y * this->m_width + x;
-                       int offset2 = offset * 2;
-
-                       if (!this->m_bufferCalculated[offset]) {
-                               //float overscan = 0.0f;
-                               const float w = (float)this->m_width /* / (1 + overscan) */;
-                               const float h = (float)this->m_height /* / (1 + overscan) */;
-                               const float aspx = w / (float)this->m_calibration_width;
-                               const float aspy = h / (float)this->m_calibration_height;
-                               float in[2];
-                               float out[2];
-
-                               in[0] = (x /* - 0.5 * overscan * w */) / aspx;
-                               in[1] = (y /* - 0.5 * overscan * h */) / aspy / this->m_pixel_aspect;
-
-                               if (this->m_inverted) {
-                                       BKE_tracking_undistort_v2(trackingData, in, out);
-                               }
-                               else {
-                                       BKE_tracking_distort_v2(trackingData, in, out);
-                               }
-
-                               this->m_buffer[offset2] = out[0] * aspx /* + 0.5 * overscan * w */;
-                               this->m_buffer[offset2 + 1] = (out[1] * aspy /* + 0.5 * overscan * h */) * this->m_pixel_aspect;
-
-                               this->m_bufferCalculated[offset] = 1;
+                       /* float overscan = 0.0f; */
+                       const float w = (float)this->m_width /* / (1 + overscan) */;
+                       const float h = (float)this->m_height /* / (1 + overscan) */;
+                       const float aspx = w / (float)this->m_calibration_width;
+                       const float aspy = h / (float)this->m_calibration_height;
+                       float in[2];
+                       float out[2];
+
+                       in[0] = (x /* - 0.5 * overscan * w */) / aspx;
+                       in[1] = (y /* - 0.5 * overscan * h */) / aspy / this->m_pixel_aspect;
+
+                       if (this->m_inverted) {
+                               BKE_tracking_undistort_v2(trackingData, in, out);
+                       }
+                       else {
+                               BKE_tracking_distort_v2(trackingData, in, out);
                        }
-                       *u = this->m_buffer[offset2];
-                       *v = this->m_buffer[offset2 + 1];
+
+                       *r_u = out[0] * aspx /* + 0.5 * overscan * w */;
+                       *r_v = (out[1] * aspy /* + 0.5 * overscan * h */) * this->m_pixel_aspect;
                }
        }