mask editor now stores points/handles in 1:1 aspect, makes tool code _much_ more logical/easier.

This commit is contained in:
Campbell Barton
2012-05-18 08:59:05 +00:00
parent 7414ccfeeb
commit f21cd531d6
9 changed files with 136 additions and 22 deletions

View File

@@ -34,6 +34,8 @@ struct MaskShape;
struct MaskSpline;
struct MaskSplinePoint;
struct MaskSplinePointUW;
struct MovieClip;
struct MovieClipUser;
struct Scene;
/* shapes */
@@ -77,6 +79,9 @@ struct Mask *BKE_mask_new(const char *name);
void BKE_mask_free(struct Mask *mask);
void BKE_mask_unlink(struct Main *bmain, struct Mask *mask);
void BKE_mask_coord_from_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2]);
void BKE_mask_coord_to_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2]);
/* parenting */
void BKE_mask_evaluate_all_masks(struct Main *bmain, float ctime);

View File

@@ -52,6 +52,7 @@
#include "BKE_main.h"
#include "BKE_mask.h"
#include "BKE_tracking.h"
#include "BKE_movieclip.h"
#include "BKE_utildefines.h"
/* shapes */
@@ -727,6 +728,49 @@ void BKE_mask_unlink(Main *bmain, Mask *mask)
mask->id.us = 0;
}
void BKE_mask_coord_from_movieclip(MovieClip *clip, MovieClipUser *user, float r_co[2], const float co[2])
{
int width, height;
/* scaling for the clip */
BKE_movieclip_get_size(clip, user, &width, &height);
if (width == height) {
r_co[0] = co[0];
r_co[1] = co[1];
}
else if (width < height) {
r_co[0] = ((co[0] - 0.5f) * ((float)width / (float)height)) + 0.5f;
r_co[1] = co[1];
}
else { /* (width > height) */
r_co[0] = co[0];
r_co[1] = ((co[1] - 0.5f) * ((float)height / (float)width)) + 0.5f;
}
}
/* as above but divide */
void BKE_mask_coord_to_movieclip(MovieClip *clip, MovieClipUser *user, float r_co[2], const float co[2])
{
int width, height;
/* scaling for the clip */
BKE_movieclip_get_size(clip, user, &width, &height);
if (width == height) {
r_co[0] = co[0];
r_co[1] = co[1];
}
else if (width < height) {
r_co[0] = ((co[0] - 0.5f) / ((float)width / (float)height)) + 0.5f;
r_co[1] = co[1];
}
else { /* (width > height) */
r_co[0] = co[0];
r_co[1] = ((co[1] - 0.5f) / ((float)height / (float)width)) + 0.5f;
}
}
static void evaluate_mask_parent(MaskParent *parent, float ctime, float co[2])
{
if (!parent)
@@ -744,10 +788,12 @@ static void evaluate_mask_parent(MaskParent *parent, float ctime, float co[2])
if (ob) {
MovieTrackingTrack *track = BKE_tracking_named_track(tracking, ob, parent->sub_parent);
MovieClipUser user = {0};
user.framenr = ctime;
if (track) {
MovieTrackingMarker *marker = BKE_tracking_get_marker(track, ctime);
copy_v2_v2(co, marker->pos);
BKE_mask_coord_from_movieclip(clip, &user, co, marker->pos);
}
}
}

View File

@@ -81,6 +81,7 @@ void ED_mask_mouse_pos(bContext *C, wmEvent *event, float co[2])
if (sc) {
ED_clip_mouse_pos(C, event, co);
BKE_mask_coord_from_movieclip(sc->clip, &sc->user, co, co);
}
else {
/* possible other spaces from which mask editing is available */

View File

@@ -59,6 +59,7 @@
#include "clip_intern.h" // own include
#if 0
static int ED_space_clip_dopesheet_poll(bContext *C)
{
SpaceClip *sc = CTX_wm_space_clip(C);
@@ -73,6 +74,7 @@ static int ED_space_clip_dopesheet_poll(bContext *C)
return FALSE;
}
#endif
/********************** select channel operator *********************/

View File

@@ -268,10 +268,13 @@ void ED_space_clip_mask_aspect(SpaceClip *sc, float *aspx, float *aspy)
int w, h;
ED_space_clip_aspect(sc, aspx, aspy);
ED_space_clip_size(sc, &w, &h);
ED_space_clip_size(sc, &w, &h);
/* now this is not accounted for! */
#if 0
*aspx *= (float)w;
*aspy *= (float)h;
#endif
if(*aspx < *aspy) {
*aspy= *aspy / *aspx;

View File

@@ -1101,6 +1101,10 @@ static void clip_main_area_draw(const bContext *C, ARegion *ar)
int width, height;
float zoomx, zoomy, aspx, aspy;
/* frame image */
float maxdim;
float xofs, yofs;
/* find window pixel coordinates of origin */
UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x, &y);
@@ -1108,10 +1112,24 @@ static void clip_main_area_draw(const bContext *C, ARegion *ar)
ED_space_clip_zoom(sc, ar, &zoomx, &zoomy);
ED_space_clip_aspect(sc, &aspx, &aspy);
/* frame the image */
maxdim = maxf(width, height);
if (width == height) {
xofs = yofs = 0;
}
else if (width < height) {
xofs = ((height - width) / -2.0f) * zoomx;
yofs = 0.0f;
}
else { /* (width > height) */
xofs = 0.0f;
yofs = ((width - height) / -2.0f) * zoomy;
}
/* apply transformation so mask editing tools will assume drawing from the origin in normalized space */
glPushMatrix();
glTranslatef(x, y, 0);
glScalef(width*zoomx, height*zoomy, 0);
glTranslatef(x + xofs, y + yofs, 0);
glScalef(maxdim * zoomx, maxdim * zoomy, 0);
glMultMatrixf(sc->stabmat);
ED_mask_draw((bContext *)C, width*aspx, height*aspy, zoomx, zoomy);

View File

@@ -163,12 +163,22 @@ void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy)
else if (t->spacetype==SPACE_CLIP) {
View2D *v2d = t->view;
float divx, divy;
float mulx, muly;
divx = v2d->mask.xmax-v2d->mask.xmin;
divy = v2d->mask.ymax-v2d->mask.ymin;
r_vec[0] = (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
r_vec[1] = (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
mulx = (v2d->cur.xmax-v2d->cur.xmin);
muly = (v2d->cur.ymax-v2d->cur.ymin);
if (t->options & CTX_MASK) {
/* clamp w/h, mask only */
divx = divy = minf(divx, divy);
mulx = muly = minf(mulx, muly);
}
r_vec[0] = mulx * (dx) / divx;
r_vec[1] = muly * (dy) / divy;
r_vec[2] = 0.0f;
if (t->options & CTX_MASK) {
@@ -303,17 +313,22 @@ void applyAspectRatio(TransInfo *t, float vec[2])
if (t->options & (CTX_MOVIECLIP | CTX_MASK)) {
SpaceClip *sc = t->sa->spacedata.first;
float aspx, aspy;
int width, height;
ED_space_clip_size(sc, &width, &height);
if (t->options & CTX_MOVIECLIP)
if (t->options & CTX_MOVIECLIP) {
int width, height;
ED_space_clip_size(sc, &width, &height);
ED_space_clip_aspect(sc, &aspx, &aspy);
else if (t->options & CTX_MASK)
vec[0] *= width / aspx;
vec[1] *= height / aspy;
}
else if (t->options & CTX_MASK) {
ED_space_clip_mask_aspect(sc, &aspx, &aspy);
vec[0] *= width / aspx;
vec[1] *= height / aspy;
vec[0] /= aspx;
vec[1] /= aspy;
}
}
}
}
@@ -340,15 +355,22 @@ void removeAspectRatio(TransInfo *t, float vec[2])
if (t->options & (CTX_MOVIECLIP | CTX_MASK)) {
SpaceClip *sc = t->sa->spacedata.first;
float aspx, aspy;
int width, height;
if (t->options & CTX_MOVIECLIP)
if (t->options & CTX_MOVIECLIP) {
int width, height;
ED_space_clip_size(sc, &width, &height);
else if (t->options & CTX_MASK)
ED_space_clip_aspect(sc, &aspx, &aspy);
vec[0] *= aspx / width;
vec[1] *= aspy / height;
vec[0] *= aspx / width;
vec[1] *= aspy / height;
}
else if (t->options & CTX_MASK) {
ED_space_clip_aspect(sc, &aspx, &aspy);
ED_space_clip_mask_aspect(sc, &aspx, &aspy);
vec[0] *= aspx;
vec[1] *= aspy;
}
}
}
}

View File

@@ -5875,12 +5875,9 @@ static void MaskPointToTransData(SpaceClip *sc, MaskSplinePoint *point, TransDat
}
}
else {
int width, height;
tdm->is_handle = TRUE;
ED_space_clip_mask_size(sc, &width, &height);
BKE_mask_point_handle(point, width, height, tdm->handle);
BKE_mask_point_handle(point, aspx, aspy, tdm->handle);
copy_v2_v2(tdm->orig_handle, tdm->handle);

View File

@@ -94,6 +94,26 @@ static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
diff_points = BKE_mask_spline_differentiate(spline, &tot_diff_point);
/* TODO, make this optional! */
if (sx != sy) {
float *fp;
int i;
float asp;
if (sx < sy) {
fp = &diff_points[0];
asp = (float)sx / (float)sy;
}
else {
fp = &diff_points[1];
asp = (float)sy / (float)sx;
}
for (i = 0; i < tot_diff_point; i++, fp += 2) {
(*fp) = (((*fp) - 0.5f) / asp) + 0.5f;
}
}
if (tot_diff_point) {
PLX_raskterize(diff_points, tot_diff_point, res, sx, sy);