void TrackPositionOperation::initExecution() { MovieTracking *tracking = NULL; MovieClipUser user = {0}; MovieTrackingObject *object; zero_v2(this->m_markerPos); zero_v2(this->m_relativePos); if (!this->m_movieClip) return; tracking = &this->m_movieClip->tracking; BKE_movieclip_user_set_frame(&user, this->m_framenumber); BKE_movieclip_get_size(this->m_movieClip, &user, &this->m_width, &this->m_height); object = BKE_tracking_object_get_named(tracking, this->m_trackingObjectName); if (object) { MovieTrackingTrack *track; track = BKE_tracking_track_get_named(tracking, object, this->m_trackName); if (track) { MovieTrackingMarker *marker; int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(this->m_movieClip, this->m_framenumber); marker = BKE_tracking_marker_get(track, clip_framenr); copy_v2_v2(this->m_markerPos, marker->pos); if (this->m_position == CMP_TRACKPOS_RELATIVE_START) { int i; for (i = 0; i < track->markersnr; i++) { marker = &track->markers[i]; if ((marker->flag & MARKER_DISABLED) == 0) { copy_v2_v2(this->m_relativePos, marker->pos); break; } } } else if (this->m_position == CMP_TRACKPOS_RELATIVE_FRAME) { int relative_clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(this->m_movieClip, this->m_relativeFrame); marker = BKE_tracking_marker_get(track, relative_clip_framenr); copy_v2_v2(this->m_relativePos, marker->pos); } } } }
void PlaneTrackCommonOperation::initExecution() { MovieTracking *tracking; MovieTrackingObject *object; memset(this->m_corners, 0, sizeof(this->m_corners)); memset(this->m_frameSpaceCorners, 0, sizeof(this->m_frameSpaceCorners)); if (!this->m_movieClip) return; tracking = &this->m_movieClip->tracking; object = BKE_tracking_object_get_named(tracking, this->m_trackingObjectName); if (object) { MovieTrackingPlaneTrack *plane_track; plane_track = BKE_tracking_plane_track_get_named(tracking, object, this->m_planeTrackName); if (plane_track) { MovieTrackingPlaneMarker *plane_marker; int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(this->m_movieClip, this->m_framenumber); plane_marker = BKE_tracking_plane_marker_get(plane_track, clip_framenr); memcpy(this->m_corners, plane_marker->corners, sizeof(this->m_corners)); } } for (int i = 0; i < 4; i++) { this->m_frameSpaceCorners[i][0] = this->m_corners[i][0] * this->getWidth(); this->m_frameSpaceCorners[i][1] = this->m_corners[i][1] * this->getHeight(); } }
void MovieClipAttributeOperation::executePixelSampled(float output[4], float /*x*/, float /*y*/, PixelSampler /*sampler*/) { 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->tracking, 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; } this->m_valueSet = true; } output[0] = this->m_value; }
static void rna_Mask_update_parent(Main *bmain, Scene *scene, PointerRNA *ptr) { MaskParent *parent = ptr->data; if (parent->id) { if (GS(parent->id->name) == ID_MC) { MovieClip *clip = (MovieClip *) parent->id; MovieTracking *tracking = &clip->tracking; MovieTrackingObject *object = BKE_tracking_object_get_named(tracking, parent->parent); if (object) { MovieTrackingTrack *track = BKE_tracking_track_get_named(tracking, object, parent->sub_parent); if (track) { int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, scene->r.cfra); MovieTrackingMarker *marker = BKE_tracking_marker_get(track, clip_framenr); float marker_pos_ofs[2], parmask_pos[2]; MovieClipUser user = {0}; BKE_movieclip_user_set_frame(&user, scene->r.cfra); add_v2_v2v2(marker_pos_ofs, marker->pos, track->offset); BKE_mask_coord_from_movieclip(clip, &user, parmask_pos, marker_pos_ofs); copy_v2_v2(parent->parent_orig, parmask_pos); } } } } rna_Mask_update_data(bmain, scene, ptr); }
/* return current frame number in clip space */ int ED_space_clip_get_clip_frame_number(SpaceClip *sc) { MovieClip *clip = ED_space_clip_get_clip(sc); /* Caller must ensure space does have a valid clip, otherwise it will crash, see T45017. */ return BKE_movieclip_remap_scene_to_clip_frame(clip, sc->user.framenr); }
static ImBuf *get_stable_cached_frame(MovieClip *clip, MovieClipUser *user, ImBuf *reference_ibuf, int framenr, int postprocess_flag) { MovieClipCache *cache = clip->cache; MovieTracking *tracking = &clip->tracking; ImBuf *stableibuf; float tloc[2], tscale, tangle; short proxy = IMB_PROXY_NONE; int render_flag = 0; int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, framenr); if (clip->flag & MCLIP_USE_PROXY) { proxy = rendersize_to_proxy(user, clip->flag); render_flag = user->render_flag; } /* there's no cached frame or it was calculated for another frame */ if (!cache->stabilized.ibuf || cache->stabilized.framenr != framenr) return NULL; if (cache->stabilized.reference_ibuf != reference_ibuf) return NULL; /* cached ibuf used different proxy settings */ if (cache->stabilized.render_flag != render_flag || cache->stabilized.proxy != proxy) return NULL; if (cache->stabilized.postprocess_flag != postprocess_flag) return NULL; /* stabilization also depends on pixel aspect ratio */ if (cache->stabilized.aspect != tracking->camera.pixel_aspect) return NULL; if (cache->stabilized.filter != tracking->stabilization.filter) return NULL; stableibuf = cache->stabilized.ibuf; BKE_tracking_stabilization_data_get(&clip->tracking, clip_framenr, stableibuf->x, stableibuf->y, tloc, &tscale, &tangle); /* check for stabilization parameters */ if (tscale != cache->stabilized.scale || tangle != cache->stabilized.angle || !equals_v2v2(tloc, cache->stabilized.loc)) { return NULL; } IMB_refImBuf(stableibuf); return stableibuf; }
void KeyingScreenOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { resolution[0] = 0; resolution[1] = 0; if (this->m_movieClip) { MovieClipUser user = {0}; int width, height; int clip_frame = BKE_movieclip_remap_scene_to_clip_frame(this->m_movieClip, this->m_framenumber); BKE_movieclip_user_set_frame(&user, clip_frame); BKE_movieclip_get_size(this->m_movieClip, &user, &width, &height); resolution[0] = width; resolution[1] = height; } }
static ImBuf *put_stabilized_frame_to_cache(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, int framenr, int postprocess_flag) { MovieClipCache *cache = clip->cache; MovieTracking *tracking = &clip->tracking; ImBuf *stableibuf; float tloc[2], tscale, tangle; int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, framenr); stableibuf = BKE_tracking_stabilize_frame(&clip->tracking, clip_framenr, ibuf, tloc, &tscale, &tangle); copy_v2_v2(cache->stabilized.loc, tloc); cache->stabilized.reference_ibuf = ibuf; cache->stabilized.scale = tscale; cache->stabilized.angle = tangle; cache->stabilized.framenr = framenr; cache->stabilized.aspect = tracking->camera.pixel_aspect; cache->stabilized.filter = tracking->stabilization.filter; if (clip->flag & MCLIP_USE_PROXY) { cache->stabilized.proxy = rendersize_to_proxy(user, clip->flag); cache->stabilized.render_flag = user->render_flag; } else { cache->stabilized.proxy = IMB_PROXY_NONE; cache->stabilized.render_flag = 0; } cache->stabilized.postprocess_flag = postprocess_flag; if (cache->stabilized.ibuf) IMB_freeImBuf(cache->stabilized.ibuf); cache->stabilized.ibuf = stableibuf; IMB_refImBuf(stableibuf); return stableibuf; }
static void node_composit_exec_movieclip(void *data, bNode *node, bNodeStack **UNUSED(in), bNodeStack **out) { if (node->id) { RenderData *rd = data; MovieClip *clip = (MovieClip *)node->id; MovieClipUser *user = (MovieClipUser *)node->storage; CompBuf *stackbuf = NULL; BKE_movieclip_user_set_frame(user, rd->cfra); stackbuf = node_composit_get_movieclip(rd, clip, user); if (stackbuf) { MovieTrackingStabilization *stab = &clip->tracking.stabilization; /* put image on stack */ out[0]->data = stackbuf; if (stab->flag & TRACKING_2D_STABILIZATION) { float loc[2], scale, angle; int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, rd->cfra); BKE_tracking_stabilization_data_get(&clip->tracking, clip_framenr, stackbuf->x, stackbuf->y, loc, &scale, &angle); out[1]->vec[0] = loc[0]; out[2]->vec[0] = loc[1]; out[3]->vec[0] = scale; out[4]->vec[0] = angle; } /* generate preview */ generate_preview(data, node, stackbuf); } } }
void MovieClipAttributeOperation::initExecution() { 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; } else { this->m_value = 1.0f / this->m_value; } } }
void BKE_movieclip_update_scopes(MovieClip *clip, MovieClipUser *user, MovieClipScopes *scopes) { if (scopes->ok) return; if (scopes->track_preview) { IMB_freeImBuf(scopes->track_preview); scopes->track_preview = NULL; } if (scopes->track_search) { IMB_freeImBuf(scopes->track_search); scopes->track_search = NULL; } scopes->marker = NULL; scopes->track = NULL; scopes->track_locked = true; if (clip) { MovieTrackingTrack *act_track = BKE_tracking_track_get_active(&clip->tracking); if (act_track) { MovieTrackingTrack *track = act_track; int framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, user->framenr); MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr); scopes->marker = marker; scopes->track = track; if (marker->flag & MARKER_DISABLED) { scopes->track_disabled = true; } else { ImBuf *ibuf = BKE_movieclip_get_ibuf(clip, user); scopes->track_disabled = false; if (ibuf && (ibuf->rect || ibuf->rect_float)) { MovieTrackingMarker undist_marker = *marker; if (user->render_flag & MCLIP_PROXY_RENDER_UNDISTORT) { int width, height; float aspy = 1.0f / clip->tracking.camera.pixel_aspect; BKE_movieclip_get_size(clip, user, &width, &height); undist_marker.pos[0] *= width; undist_marker.pos[1] *= height * aspy; BKE_tracking_undistort_v2(&clip->tracking, undist_marker.pos, undist_marker.pos); undist_marker.pos[0] /= width; undist_marker.pos[1] /= height * aspy; } scopes->track_search = BKE_tracking_get_search_imbuf(ibuf, track, &undist_marker, true, true); scopes->undist_marker = undist_marker; scopes->frame_width = ibuf->x; scopes->frame_height = ibuf->y; scopes->use_track_mask = track->flag & TRACK_PREVIEW_ALPHA; } IMB_freeImBuf(ibuf); } if ((track->flag & TRACK_LOCKED) == 0) { float pat_min[2], pat_max[2]; scopes->track_locked = false; /* XXX: would work fine with non-transformed patterns, but would likely fail * with transformed patterns, but that would be easier to debug when * we'll have real pattern sampling (at least to test) */ BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max); scopes->slide_scale[0] = pat_max[0] - pat_min[0]; scopes->slide_scale[1] = pat_max[1] - pat_min[1]; } } } scopes->framenr = user->framenr; scopes->ok = true; }
void MovieClipNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const { NodeOutput *outputMovieClip = this->getOutputSocket(0); NodeOutput *alphaMovieClip = this->getOutputSocket(1); NodeOutput *offsetXMovieClip = this->getOutputSocket(2); NodeOutput *offsetYMovieClip = this->getOutputSocket(3); NodeOutput *scaleMovieClip = this->getOutputSocket(4); NodeOutput *angleMovieClip = this->getOutputSocket(5); bNode *editorNode = this->getbNode(); MovieClip *movieClip = (MovieClip *)editorNode->id; MovieClipUser *movieClipUser = (MovieClipUser *)editorNode->storage; bool cacheFrame = !context.isRendering(); ImBuf *ibuf = NULL; if (movieClip) { if (cacheFrame) ibuf = BKE_movieclip_get_ibuf(movieClip, movieClipUser); else ibuf = BKE_movieclip_get_ibuf_flag(movieClip, movieClipUser, movieClip->flag, MOVIECLIP_CACHE_SKIP); } // always connect the output image MovieClipOperation *operation = new MovieClipOperation(); operation->setMovieClip(movieClip); operation->setMovieClipUser(movieClipUser); operation->setFramenumber(context.getFramenumber()); operation->setCacheFrame(cacheFrame); converter.addOperation(operation); converter.mapOutputSocket(outputMovieClip, operation->getOutputSocket()); converter.addPreview(operation->getOutputSocket()); MovieClipAlphaOperation *alphaOperation = new MovieClipAlphaOperation(); alphaOperation->setMovieClip(movieClip); alphaOperation->setMovieClipUser(movieClipUser); alphaOperation->setFramenumber(context.getFramenumber()); alphaOperation->setCacheFrame(cacheFrame); converter.addOperation(alphaOperation); converter.mapOutputSocket(alphaMovieClip, alphaOperation->getOutputSocket()); MovieTrackingStabilization *stab = &movieClip->tracking.stabilization; float loc[2], scale, angle; loc[0] = 0.0f; loc[1] = 0.0f; scale = 1.0f; angle = 0.0f; if (ibuf) { if (stab->flag & TRACKING_2D_STABILIZATION) { int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(movieClip, context.getFramenumber()); BKE_tracking_stabilization_data_get(&movieClip->tracking, clip_framenr, ibuf->x, ibuf->y, loc, &scale, &angle); } } converter.addOutputValue(offsetXMovieClip, loc[0]); converter.addOutputValue(offsetYMovieClip, loc[1]); converter.addOutputValue(scaleMovieClip, scale); converter.addOutputValue(angleMovieClip, angle); if (ibuf) { IMB_freeImBuf(ibuf); } }
/* return current frame number in clip space */ int ED_space_clip_get_clip_frame_number(SpaceClip *sc) { MovieClip *clip = ED_space_clip_get_clip(sc); return BKE_movieclip_remap_scene_to_clip_frame(clip, sc->user.framenr); }
KeyingScreenOperation::TriangulationData *KeyingScreenOperation::buildVoronoiTriangulation() { MovieClipUser user = {0}; TriangulationData *triangulation; MovieTracking *tracking = &this->m_movieClip->tracking; MovieTrackingTrack *track; VoronoiSite *sites, *site; ImBuf *ibuf; ListBase *tracksbase; ListBase edges = {NULL, NULL}; int sites_total; int i; int width = this->getWidth(); int height = this->getHeight(); int clip_frame = BKE_movieclip_remap_scene_to_clip_frame(this->m_movieClip, this->m_framenumber); if (this->m_trackingObject[0]) { MovieTrackingObject *object = BKE_tracking_object_get_named(tracking, this->m_trackingObject); if (!object) return NULL; tracksbase = BKE_tracking_object_get_tracks(tracking, object); } else tracksbase = BKE_tracking_get_active_tracks(tracking); /* 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) 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) return NULL; BKE_movieclip_user_set_frame(&user, clip_frame); ibuf = BKE_movieclip_get_ibuf(this->m_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; for (track = (MovieTrackingTrack *) tracksbase->first, site = sites; track; track = track->next) { MovieTrackingMarker *marker = BKE_tracking_marker_get(track, clip_frame); 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; } pattern_ibuf = BKE_tracking_get_pattern_imbuf(ibuf, track, marker, TRUE, FALSE); zero_v3(site->color); if (pattern_ibuf) { for (j = 0; j < pattern_ibuf->x * pattern_ibuf->y; j++) { if (pattern_ibuf->rect_float) { add_v3_v3(site->color, &pattern_ibuf->rect_float[4 * j]); } else { unsigned char *rrgb = (unsigned char *)pattern_ibuf->rect; site->color[0] += srgb_to_linearrgb((float)rrgb[4 * j + 0] / 255.0f); site->color[1] += srgb_to_linearrgb((float)rrgb[4 * j + 1] / 255.0f); site->color[2] += srgb_to_linearrgb((float)rrgb[4 * j + 2] / 255.0f); } } mul_v3_fl(site->color, 1.0f / (pattern_ibuf->x * pattern_ibuf->y)); IMB_freeImBuf(pattern_ibuf); } site->co[0] = pos[0] * width; site->co[1] = pos[1] * height; site++; } IMB_freeImBuf(ibuf); BLI_voronoi_compute(sites, sites_total, width, height, &edges); BLI_voronoi_triangulate(sites, sites_total, &edges, width, height, &triangulation->triangulated_points, &triangulation->triangulated_points_total, &triangulation->triangles, &triangulation->triangles_total); MEM_freeN(sites); BLI_freelistN(&edges); if (triangulation->triangles_total) { rctf *rect; rect = triangulation->triangles_AABB = (rctf *) MEM_callocN(sizeof(rctf) * triangulation->triangles_total, "voronoi triangulation AABB"); for (i = 0; i < triangulation->triangles_total; i++, rect++) { int *triangle = triangulation->triangles[i]; VoronoiTriangulationPoint *a = &triangulation->triangulated_points[triangle[0]], *b = &triangulation->triangulated_points[triangle[1]], *c = &triangulation->triangulated_points[triangle[2]]; float min[2], max[2]; INIT_MINMAX2(min, max); minmax_v2v2_v2(min, max, a->co); minmax_v2v2_v2(min, max, b->co); minmax_v2v2_v2(min, max, c->co); rect->xmin = min[0]; rect->ymin = min[1]; rect->xmax = max[0]; rect->ymax = max[1]; } } return triangulation; }