minor refactor for rect functions. more consistent naming.
[blender.git] / source / blender / compositor / operations / COM_KeyingScreenOperation.cpp
index 53572162b9ee1994e17a83e827a4aebbf9654029..87a8fd2275837bfe17086011f185d9b7b1133263 100644 (file)
@@ -104,10 +104,20 @@ KeyingScreenOperation::TriangulationData *KeyingScreenOperation::buildVoronoiTri
        /* count sites */
        for (track = (MovieTrackingTrack *) tracksbase->first, sites_total = 0; track; track = track->next) {
                MovieTrackingMarker *marker = BKE_tracking_marker_get(track, clip_frame);
+               float pos[2];
 
-               if ((marker->flag & MARKER_DISABLED) == 0) {
-                       sites_total++;
+               if (marker->flag & MARKER_DISABLED)
+                       continue;
+
+               add_v2_v2v2(pos, marker->pos, track->offset);
+
+               if (!IN_RANGE_INCL(pos[0], 0.0f, 1.0f) ||
+                   !IN_RANGE_INCL(pos[1], 0.0f, 1.0f))
+               {
+                       continue;
                }
+
+               sites_total++;
        }
 
        if (!sites_total)
@@ -128,10 +138,19 @@ KeyingScreenOperation::TriangulationData *KeyingScreenOperation::buildVoronoiTri
                VoronoiSite *site;
                ImBuf *pattern_ibuf;
                int j;
+               float pos[2];
 
                if (marker->flag & MARKER_DISABLED)
                        continue;
 
+               add_v2_v2v2(pos, marker->pos, track->offset);
+
+               if (!IN_RANGE_INCL(pos[0], 0.0f, 1.0f) ||
+                   !IN_RANGE_INCL(pos[1], 0.0f, 1.0f))
+               {
+                       continue;
+               }
+
                site = &sites[i];
 
                pattern_ibuf = BKE_tracking_get_pattern_imbuf(ibuf, track, marker, TRUE, FALSE);
@@ -153,8 +172,8 @@ KeyingScreenOperation::TriangulationData *KeyingScreenOperation::buildVoronoiTri
                mul_v3_fl(site->color, 1.0f / (pattern_ibuf->x * pattern_ibuf->y));
                IMB_freeImBuf(pattern_ibuf);
 
-               site->co[0] = marker->pos[0] * width;
-               site->co[1] = marker->pos[1] * height;
+               site->co[0] = pos[0] * width;
+               site->co[1] = pos[1] * height;
        }
 
        IMB_freeImBuf(ibuf);
@@ -198,7 +217,7 @@ KeyingScreenOperation::TriangulationData *KeyingScreenOperation::buildVoronoiTri
        return triangulation;
 }
 
-void *KeyingScreenOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers)
+void *KeyingScreenOperation::initializeTileData(rcti *rect)
 {
        TileData *tile_data;
        TriangulationData *triangulation;
@@ -223,12 +242,12 @@ void *KeyingScreenOperation::initializeTileData(rcti *rect, MemoryBuffer **memor
        if (!triangulation)
                return NULL;
 
-       BLI_init_rctf(&rect_float, rect->xmin, rect->xmax, rect->ymin, rect->ymax);
+       BLI_rctf_init(&rect_float, rect->xmin, rect->xmax, rect->ymin, rect->ymax);
 
        tile_data = (TileData *) MEM_callocN(sizeof(TileData), "keying screen tile data");
 
        for (i = 0; i < triangulation->triangles_total; i++) {
-               bool ok = BLI_isect_rctf(&rect_float, &triangulation->triangles_AABB[i], NULL);
+               bool ok = BLI_rctf_isect(&rect_float, &triangulation->triangles_AABB[i], NULL);
 
                if (ok) {
                        tile_data->triangles_total++;
@@ -253,7 +272,7 @@ void *KeyingScreenOperation::initializeTileData(rcti *rect, MemoryBuffer **memor
        return tile_data;
 }
 
-void KeyingScreenOperation::deinitializeTileData(rcti *rect, MemoryBuffer **memoryBuffers, void *data)
+void KeyingScreenOperation::deinitializeTileData(rcti *rect, void *data)
 {
        TileData *tile_data = (TileData *) data;
 
@@ -282,7 +301,7 @@ void KeyingScreenOperation::determineResolution(unsigned int resolution[], unsig
        }
 }
 
-void KeyingScreenOperation::executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data)
+void KeyingScreenOperation::executePixel(float *color, int x, int y, void *data)
 {
        color[0] = 0.0f;
        color[1] = 0.0f;
@@ -308,9 +327,11 @@ void KeyingScreenOperation::executePixel(float *color, int x, int y, MemoryBuffe
 
                                if (barycentric_coords_v2(a->co, b->co, c->co, co, w)) {
                                        if (barycentric_inside_triangle_v2(w)) {
-                                               color[0] += a->color[0] * w[0] + b->color[0] * w[1] + c->color[0] * w[2];
-                                               color[1] += a->color[1] * w[0] + b->color[1] * w[1] + c->color[1] * w[2];
-                                               color[2] += a->color[2] * w[0] + b->color[2] * w[1] + c->color[2] * w[2];
+                                               color[0] = a->color[0] * w[0] + b->color[0] * w[1] + c->color[0] * w[2];
+                                               color[1] = a->color[1] * w[0] + b->color[1] * w[1] + c->color[1] * w[2];
+                                               color[2] = a->color[2] * w[0] + b->color[2] * w[1] + c->color[2] * w[2];
+
+                                               break;
                                        }
                                }
                        }