/* Get grayscale float search buffer for given marker and frame. */ static float *track_get_search_floatbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTrackingMarker *marker, int *width_r, int *height_r) { ImBuf *searchibuf; float *gray_pixels; int width, height; searchibuf = BKE_tracking_get_search_imbuf(ibuf, track, marker, false, true); if (!searchibuf) { *width_r = 0; *height_r = 0; return NULL; } width = searchibuf->x; height = searchibuf->y; gray_pixels = MEM_callocN(width * height * sizeof(float), "tracking floatBuf"); if (searchibuf->rect_float) { float_rgba_to_gray(searchibuf->rect_float, gray_pixels, width * height, 0.2126f, 0.7152f, 0.0722f); } else { uint8_rgba_to_float_gray((unsigned char *)searchibuf->rect, gray_pixels, width * height, 0.2126f, 0.7152f, 0.0722f); } IMB_freeImBuf(searchibuf); *width_r = width; *height_r = height; return gray_pixels; }
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; }