Revision: 49227
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49227
Author:   campbellbarton
Date:     2012-07-25 20:39:49 +0000 (Wed, 25 Jul 2012)
Log Message:
-----------
mask/image viewer now works with non 1:1 image aspect, editing masks in the 
image viewer should be generally usable now though still some TODO's left.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_mask.h
    trunk/blender/source/blender/blenkernel/intern/mask.c
    trunk/blender/source/blender/blenkernel/intern/movieclip.c
    trunk/blender/source/blender/editors/include/ED_image.h
    trunk/blender/source/blender/editors/mask/mask_edit.c
    trunk/blender/source/blender/editors/space_image/image_edit.c

Modified: trunk/blender/source/blender/blenkernel/BKE_mask.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_mask.h  2012-07-25 20:28:06 UTC 
(rev 49226)
+++ trunk/blender/source/blender/blenkernel/BKE_mask.h  2012-07-25 20:39:49 UTC 
(rev 49227)
@@ -127,7 +127,9 @@
 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 */
 

Modified: trunk/blender/source/blender/blenkernel/intern/mask.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mask.c       2012-07-25 
20:28:06 UTC (rev 49226)
+++ trunk/blender/source/blender/blenkernel/intern/mask.c       2012-07-25 
20:39:49 UTC (rev 49227)
@@ -1494,49 +1494,65 @@
        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])
 {
        if (!parent)

Modified: trunk/blender/source/blender/blenkernel/intern/movieclip.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/movieclip.c  2012-07-25 
20:28:06 UTC (rev 49226)
+++ trunk/blender/source/blender/blenkernel/intern/movieclip.c  2012-07-25 
20:39:49 UTC (rev 49227)
@@ -1074,7 +1074,7 @@
        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);

Modified: trunk/blender/source/blender/editors/include/ED_image.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_image.h     2012-07-25 
20:28:06 UTC (rev 49226)
+++ trunk/blender/source/blender/editors/include/ED_image.h     2012-07-25 
20:39:49 UTC (rev 49227)
@@ -39,6 +39,7 @@
 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_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);

Modified: trunk/blender/source/blender/editors/mask/mask_edit.c
===================================================================
--- trunk/blender/source/blender/editors/mask/mask_edit.c       2012-07-25 
20:28:06 UTC (rev 49226)
+++ trunk/blender/source/blender/editors/mask/mask_edit.c       2012-07-25 
20:39:49 UTC (rev 49227)
@@ -110,8 +110,15 @@
                        }
                        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:

Modified: trunk/blender/source/blender/editors/space_image/image_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_edit.c       
2012-07-25 20:28:06 UTC (rev 49226)
+++ trunk/blender/source/blender/editors/space_image/image_edit.c       
2012-07-25 20:39:49 UTC (rev 49227)
@@ -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 @@
        *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));

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to