speedup to inpaint node in my tests was about ~30% for an optimized build.
authorCampbell Barton <ideasman42@gmail.com>
Tue, 7 Aug 2012 09:20:30 +0000 (09:20 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 7 Aug 2012 09:20:30 +0000 (09:20 +0000)
also replace MIN/MAX2 with inline functions in transform.

source/blender/compositor/operations/COM_InpaintOperation.cpp
source/blender/compositor/operations/COM_InpaintOperation.h
source/blender/editors/transform/transform_conversions.c

index 5b21273e4ab435874f9e1fc19e3d97b16b32ef03..6e198f223f98d0a1baf56c2afc004fd5cd430cde 100644 (file)
@@ -77,26 +77,15 @@ void InpaintSimpleOperation::clamp_xy(int & x, int & y)
        }
 }
 
-float InpaintSimpleOperation::get(int x, int y, int component) 
+float *InpaintSimpleOperation::get_pixel(int x, int y)
 {
        int width = this->getWidth();
 
        ASSERT_XY_RANGE(x, y);
 
-       return this->m_cached_buffer[
+       return &this->m_cached_buffer[
                   y * width * COM_NUMBER_OF_CHANNELS
-                  + x * COM_NUMBER_OF_CHANNELS + component];
-}
-
-void InpaintSimpleOperation::set(int x, int y, int component, float v) 
-{
-       int width = this->getWidth();
-
-       ASSERT_XY_RANGE(x, y);
-
-       this->m_cached_buffer[
-           y * width * COM_NUMBER_OF_CHANNELS
-           + x * COM_NUMBER_OF_CHANNELS + component] = v;
+                  + x * COM_NUMBER_OF_CHANNELS];
 }
 
 int InpaintSimpleOperation::mdist(int x, int y) 
@@ -141,7 +130,7 @@ void InpaintSimpleOperation::calc_manhatten_distance()
                for (int i = 0; i < width; i++) {
                        int r = 0;
                        /* no need to clamp here */
-                       if (get(i, j, 3) < 1.0f) {
+                       if (this->get_pixel(i, j)[3] < 1.0f) {
                                r = width + height;
                                if (i > 0) 
                                        r = mini(r, m[j * width + i - 1] + 1);
@@ -197,9 +186,10 @@ void InpaintSimpleOperation::pix_step(int x, int y)
                for (int dy = -1; dy <= 1; dy++) {
                        if (dx != 0 && dy != 0) {
 
-                           int x_ofs = x + dx;
+                               int x_ofs = x + dx;
                                int y_ofs = y + dy;
-                               clamp_xy(x_ofs, y_ofs);
+
+                               this->clamp_xy(x_ofs, y_ofs);
 
                                if (this->mdist(x_ofs, y_ofs) < d) {
 
@@ -212,20 +202,14 @@ void InpaintSimpleOperation::pix_step(int x, int y)
                                                weight = M_SQRT1_2;  /* 1.0f / sqrt(2) */
                                        }
 
-                                       for (int c = 0; c < 3; c++) {
-                                               float fk = this->get(x_ofs, y_ofs, c);
-
-                                               pix[c] += fk * weight;
-                                       }
+                                       madd_v3_v3fl(pix, this->get_pixel(x_ofs, y_ofs), weight);
                                        n += weight;
                                }
                        }
                }
        }
 
-       for (int c = 0; c < 3; c++) {
-               this->set(x, y, c, pix[c] / n);
-       }
+       mul_v3_v3fl(this->get_pixel(x, y), pix, 1.0f / n);
 }
 
 void *InpaintSimpleOperation::initializeTileData(rcti *rect)
@@ -258,10 +242,8 @@ void *InpaintSimpleOperation::initializeTileData(rcti *rect)
 
 void InpaintSimpleOperation::executePixel(float *color, int x, int y, void *data)
 {
-       clamp_xy(x, y);
-       for (int c = 0; c < 3; c++) {
-               color[c] = get(x, y, c);
-       }
+       this->clamp_xy(x, y);
+       copy_v3_v3(color, this->get_pixel(x, y));
        color[3] = 1.0f;
 }
 
index 0ff65174161e043b2eacbd1eefa7b83f470eca5b..2f066e19065c44c261e33f200fe1d11e70e377aa 100644 (file)
@@ -64,11 +64,10 @@ public:
 
 private:
        void calc_manhatten_distance();
-       void clamp_xy(int & x, int & y);
-       float get(int x, int y, int component);
-       void set(int x, int y, int component, float v);
+       void clamp_xy(int &x, int &y);
+       float *get_pixel(int x, int y);
        int mdist(int x, int y);
-       bool next_pixel(int & x, int & y, int & curr, int iters);
+       bool next_pixel(int &x, int &y, int &curr, int iters);
        void pix_step(int x, int y);
 };
 
index f5d9612e8327e67dd2b03196b74bf0cb3bd47488..6db3ba7c4931bb54b9c8dfdab56d90a0088778b9 100644 (file)
@@ -2509,8 +2509,8 @@ void clipUVData(TransInfo *t)
                if ((td->flag & TD_SKIP) || (!td->loc))
                        continue;
 
-               td->loc[0] = MIN2(MAX2(0.0f, td->loc[0]), aspx);
-               td->loc[1] = MIN2(MAX2(0.0f, td->loc[1]), aspy);
+               td->loc[0] = minf(maxf(0.0f, td->loc[0]), aspx);
+               td->loc[1] = minf(maxf(0.0f, td->loc[1]), aspy);
        }
 }
 
@@ -4258,7 +4258,7 @@ static void freeSeqData(TransInfo *t)
                                                for (a = 0; a < t->total; a++, td++) {
                                                        seq = ((TransDataSeq *)td->extra)->seq;
                                                        if ((seq != seq_prev)) {
-                                                               minframe = MIN2(minframe, seq->startdisp);
+                                                               minframe = mini(minframe, seq->startdisp);
                                                        }
                                                }