diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_mask.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mask.c | 54 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/movieclip.c | 2 | ||||
-rw-r--r-- | source/blender/editors/include/ED_image.h | 2 | ||||
-rw-r--r-- | source/blender/editors/mask/mask_edit.c | 9 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_edit.c | 16 |
6 files changed, 64 insertions, 21 deletions
diff --git a/source/blender/blenkernel/BKE_mask.h b/source/blender/blenkernel/BKE_mask.h index 9a4f30c853f..98cab2e4062 100644 --- a/source/blender/blenkernel/BKE_mask.h +++ b/source/blender/blenkernel/BKE_mask.h @@ -127,7 +127,9 @@ 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_from_frame(float r_co[2], const float co[2], const float frame_size[2]); void BKE_mask_coord_to_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2]); +void BKE_mask_coord_to_frame(float r_co[2], const float co[2], const float frame_size[2]); /* parenting */ diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c index 6d49137d892..d963d46569a 100644 --- a/source/blender/blenkernel/intern/mask.c +++ b/source/blender/blenkernel/intern/mask.c @@ -1494,48 +1494,64 @@ 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]) +void BKE_mask_coord_from_frame(float r_co[2], const float co[2], const float frame_size[2]) { - int width, height; - - /* scaling for the clip */ - BKE_movieclip_get_size(clip, user, &width, &height); - - if (width == height) { + if (frame_size[0] == frame_size[1]) { 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; + else if (frame_size[0] < frame_size[1]) { + r_co[0] = ((co[0] - 0.5f) * (frame_size[0] / frame_size[1])) + 0.5f; r_co[1] = co[1]; } - else { /* (width > height) */ + else { /* (frame_size[0] > frame_size[1]) */ r_co[0] = co[0]; - r_co[1] = ((co[1] - 0.5f) * ((float)height / (float)width)) + 0.5f; + r_co[1] = ((co[1] - 0.5f) * (frame_size[1] / frame_size[0])) + 0.5f; } } - -/* as above but divide */ -void BKE_mask_coord_to_movieclip(MovieClip *clip, MovieClipUser *user, float r_co[2], const float co[2]) +void BKE_mask_coord_from_movieclip(MovieClip *clip, MovieClipUser *user, float r_co[2], const float co[2]) { int width, height; + float frame_size[2]; /* scaling for the clip */ BKE_movieclip_get_size(clip, user, &width, &height); - if (width == height) { + frame_size[0] = (float)width; + frame_size[1] = (float)height; + + BKE_mask_coord_from_frame(r_co, co, frame_size); +} + +/* as above but divide */ +void BKE_mask_coord_to_frame(float r_co[2], const float co[2], const float frame_size[2]) +{ + if (frame_size[0] == frame_size[1]) { 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; + else if (frame_size[0] < frame_size[1]) { + r_co[0] = ((co[0] - 0.5f) / (frame_size[0] / frame_size[1])) + 0.5f; r_co[1] = co[1]; } - else { /* (width > height) */ + else { /* (frame_size[0] > frame_size[1]) */ r_co[0] = co[0]; - r_co[1] = ((co[1] - 0.5f) / ((float)height / (float)width)) + 0.5f; + r_co[1] = ((co[1] - 0.5f) / (frame_size[1] / frame_size[0])) + 0.5f; } } +void BKE_mask_coord_to_movieclip(MovieClip *clip, MovieClipUser *user, float r_co[2], const float co[2]) +{ + int width, height; + float frame_size[2]; + + /* scaling for the clip */ + BKE_movieclip_get_size(clip, user, &width, &height); + + frame_size[0] = (float)width; + frame_size[1] = (float)height; + + BKE_mask_coord_to_frame(r_co, co, frame_size); +} static int BKE_mask_evaluate_parent(MaskParent *parent, float ctime, float r_co[2]) { diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index de367b6b4d0..045f0adaf41 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -1074,7 +1074,7 @@ void BKE_movieclip_reload(MovieClip *clip) else clip->source = MCLIP_SRC_SEQUENCE; - clip->lastsize[0] = clip->lastsize[1] = 0; + clip->lastsize[0] = clip->lastsize[1] = IMG_SIZE_FALLBACK; movieclip_load_get_szie(clip); movieclip_calc_length(clip); diff --git a/source/blender/editors/include/ED_image.h b/source/blender/editors/include/ED_image.h index b31d52a6644..393a400b7bd 100644 --- a/source/blender/editors/include/ED_image.h +++ b/source/blender/editors/include/ED_image.h @@ -39,6 +39,7 @@ struct ToolSettings; struct uiBlock; struct wmWindowManager; struct ARegion; +struct wmEvent; /* image_edit.c, exported for transform */ struct Image *ED_space_image(struct SpaceImage *sima); @@ -61,6 +62,7 @@ void ED_space_image_uv_sculpt_update(struct wmWindowManager *wm, struct ToolSett void ED_image_get_size(struct Image *ima, int *width, int *height); void ED_image_get_aspect(struct Image *ima, float *aspx, float *aspy); void ED_image_get_uv_aspect(struct Image *ima, float *aspx, float *aspy); +void ED_image_mouse_pos(struct SpaceImage *sima, struct ARegion *ar, struct wmEvent *event, float co[2]); int ED_space_image_show_render(struct SpaceImage *sima); int ED_space_image_show_paint(struct SpaceImage *sima); diff --git a/source/blender/editors/mask/mask_edit.c b/source/blender/editors/mask/mask_edit.c index 6667b9b69a5..6a5e5c03345 100644 --- a/source/blender/editors/mask/mask_edit.c +++ b/source/blender/editors/mask/mask_edit.c @@ -110,8 +110,15 @@ void ED_mask_mouse_pos(const bContext *C, wmEvent *event, float co[2]) } case SPACE_IMAGE: { + int width, height; + float frame_size[2]; + SpaceImage *sima = sa->spacedata.first; ARegion *ar = CTX_wm_region(C); - UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &co[0], &co[1]); + ED_space_image_get_size(sima, &width, &height); + frame_size[0] = width; + frame_size[1] = height; + ED_image_mouse_pos(sima, ar, event, co); + BKE_mask_coord_from_frame(co, co, frame_size); break; } default: diff --git a/source/blender/editors/space_image/image_edit.c b/source/blender/editors/space_image/image_edit.c index 8ae2b76cd4e..f80210fe4d7 100644 --- a/source/blender/editors/space_image/image_edit.c +++ b/source/blender/editors/space_image/image_edit.c @@ -47,6 +47,8 @@ #include "ED_screen.h" #include "ED_uvedit.h" +#include "UI_view2d.h" + #include "WM_api.h" #include "WM_types.h" @@ -250,6 +252,20 @@ void ED_image_get_uv_aspect(Image *ima, float *aspx, float *aspy) *aspy *= (float)h; } +void ED_image_mouse_pos(SpaceImage *sima, ARegion *ar, wmEvent *event, float co[2]) +{ + int sx, sy, width, height; + float zoomx, zoomy; + + ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy); + ED_space_image_get_size(sima, &width, &height); + + UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &sx, &sy); + + co[0] = ((event->mval[0] - sx) / zoomx) / width; + co[1] = ((event->mval[1] - sy) / zoomy) / height; +} + int ED_space_image_show_render(SpaceImage *sima) { return (sima->image && ELEM(sima->image->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE)); |