Example #1
0
static ImBuf *get_stable_cached_frame(MovieClip *clip, MovieClipUser *user, 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;

    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;

    /* 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(&clip->tracking, 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;
}
Example #2
0
static void node_composit_exec_stabilize2d(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
	if (in[0]->data && node->id) {
		RenderData *rd= data;
		MovieClip *clip= (MovieClip *)node->id;
		CompBuf *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA);
		CompBuf *stackbuf;
		float loc[2], scale, angle;

		BKE_tracking_stabilization_data(&clip->tracking, rd->cfra, cbuf->x, cbuf->y, loc, &scale, &angle);

		stackbuf= node_composit_transform(cbuf, loc[0], loc[1], angle, scale, node->custom1);

		/* pass on output and free */
		out[0]->data= stackbuf;

		if (cbuf!=in[0]->data)
			free_compbuf(cbuf);
	}
}
Example #3
0
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;

                BKE_tracking_stabilization_data(&clip->tracking, rd->cfra, 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);
        }
    }
}