Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-06-13 16:58:01 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-06-13 16:58:01 +0400
commit91781c76c4b1bb3eecd31a2b482a4c87754cd2a7 (patch)
tree63c456bd7d3cf996307bc30b9bc3744b29887691 /source/blender/editors/space_view3d/view3d_draw.c
parentbe1b5f82cee09041fdee355697841ee92b31ef70 (diff)
framing options for camera background image: stretch/fit/crop
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_draw.c')
-rw-r--r--source/blender/editors/space_view3d/view3d_draw.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 6d9507ebff1..6ef5d538b24 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -1547,6 +1547,8 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
(bgpic->view & (1 << rv3d->view)) || /* check agaist flags */
(rv3d->persp == RV3D_CAMOB && bgpic->view == (1 << RV3D_VIEW_CAMERA)))
{
+ float image_aspect[2];
+
/* disable individual images */
if ((bgpic->flag & V3D_BGPIC_DISABLED))
continue;
@@ -1558,6 +1560,9 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
continue;
BKE_image_user_frame_calc(&bgpic->iuser, CFRA, 0);
ibuf = BKE_image_get_ibuf(ima, &bgpic->iuser);
+
+ image_aspect[0] = ima->aspx;
+ image_aspect[1] = ima->aspx;
}
else if (bgpic->source == V3D_BGPIC_MOVIE) {
clip = NULL;
@@ -1574,6 +1579,9 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
BKE_movieclip_user_set_frame(&bgpic->cuser, CFRA);
ibuf = BKE_movieclip_get_ibuf(clip, &bgpic->cuser);
+ image_aspect[0] = clip->aspx;
+ image_aspect[1] = clip->aspx;
+
/* working with ibuf from image and clip has got different workflow now.
* ibuf acquired from clip is referenced by cache system and should
* be dereferenced after usage. */
@@ -1609,6 +1617,38 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
x2 = ar->winrct.xmax;
y2 = ar->winrct.ymax;
}
+
+ /* aspect correction */
+ if (bgpic->flag & V3D_BGPIC_CAMERA_ASPECT)
+ {
+ /* apply aspect from clip */
+ const float w_src = ibuf->x * image_aspect[0];
+ const float h_src = ibuf->y * image_aspect[1];
+
+ /* destination aspect is already applied from the camera frame */
+ const float w_dst = x1 - x2;
+ const float h_dst = y1 - y2;
+
+ const float asp_src = w_src / h_src;
+ const float asp_dst = w_dst / h_dst;
+
+ if (fabsf(asp_src - asp_dst) >= FLT_EPSILON) {
+ if ((asp_src > asp_dst) == ((bgpic->flag & V3D_BGPIC_CAMERA_CROP) != 0)) {
+ /* fit X */
+ const float div = asp_src / asp_dst;
+ const float cent = (x1 + x2) / 2.0f;
+ x1 = ((x1 - cent) * div) + cent;
+ x2 = ((x2 - cent) * div) + cent;
+ }
+ else {
+ /* fit Y */
+ const float div = asp_dst / asp_src;
+ const float cent = (y1 + y2) / 2.0f;
+ y1 = ((y1 - cent) * div) + cent;
+ y2 = ((y2 - cent) * div) + cent;
+ }
+ }
+ }
}
else {
float sco[2];