diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-06-13 16:58:01 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-06-13 16:58:01 +0400 |
commit | 91781c76c4b1bb3eecd31a2b482a4c87754cd2a7 (patch) | |
tree | 63c456bd7d3cf996307bc30b9bc3744b29887691 /source/blender | |
parent | be1b5f82cee09041fdee355697841ee92b31ef70 (diff) |
framing options for camera background image: stretch/fit/crop
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw.c | 40 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_view3d_types.h | 18 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_space.c | 27 |
3 files changed, 80 insertions, 5 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]; diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h index e89cc751a69..487c0d97e5e 100644 --- a/source/blender/makesdna/DNA_view3d_types.h +++ b/source/blender/makesdna/DNA_view3d_types.h @@ -311,11 +311,19 @@ typedef struct View3D { /* #define V3D_CALC_MANIPULATOR 4 */ /*UNUSED*/ /* BGPic->flag */ -/* may want to use 1 for select ?*/ -#define V3D_BGPIC_EXPANDED 2 -#define V3D_BGPIC_CAMERACLIP 4 -#define V3D_BGPIC_DISABLED 8 -#define V3D_BGPIC_FOREGROUND 16 +/* may want to use 1 for select ? */ +enum { + V3D_BGPIC_EXPANDED = (1 << 1), + V3D_BGPIC_CAMERACLIP = (1 << 2), + V3D_BGPIC_DISABLED = (1 << 3), + V3D_BGPIC_FOREGROUND = (1 << 4), + + /* Camera framing options */ + V3D_BGPIC_CAMERA_ASPECT = (1 << 5), /* don't stretch to fit the camera view */ + V3D_BGPIC_CAMERA_CROP = (1 << 6) /* crop out the image */ +}; + +#define V3D_BGPIC_EXPANDED (V3D_BGPIC_EXPANDED | V3D_BGPIC_CAMERACLIP) /* BGPic->source */ /* may want to use 1 for select ?*/ diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 50a682f56bd..30b06017568 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -1297,6 +1297,19 @@ static void rna_def_background_image(BlenderRNA *brna) {0, NULL, 0, NULL, NULL} }; + static const EnumPropertyItem bgpic_camera_frame_items[] = { + {0, "STRETCH", 0, "Stretch", ""}, + {V3D_BGPIC_CAMERA_ASPECT, "FIT", 0, "Fit", ""}, + {V3D_BGPIC_CAMERA_ASPECT | V3D_BGPIC_CAMERA_CROP, "CROP", 0, "Crop", ""}, + {0, NULL, 0, NULL, NULL} + }; + + static const EnumPropertyItem bgpic_draw_depth_items[] = { + {0, "BACK", 0, "Back", ""}, + {V3D_BGPIC_FOREGROUND, "FRONT", 0, "Front", ""}, + {0, NULL, 0, NULL, NULL} + }; + srna = RNA_def_struct(brna, "BackgroundImage", NULL); RNA_def_struct_sdna(srna, "BGpic"); RNA_def_struct_ui_text(srna, "Background Image", "Image and settings for display in the 3d View background"); @@ -1381,6 +1394,20 @@ static void rna_def_background_image(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_BGPIC_FOREGROUND); RNA_def_property_ui_text(prop, "Show On Foreground", "Show this image in front of objects in viewport"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + + /* expose 1 flag as a enum of 2 items */ + prop = RNA_def_property(srna, "draw_depth", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag"); + RNA_def_property_enum_items(prop, bgpic_draw_depth_items); + RNA_def_property_ui_text(prop, "Depth", "Draw under or over everything"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + + /* expose 2 flags as a enum of 3 items */ + prop = RNA_def_property(srna, "frame_method", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag"); + RNA_def_property_enum_items(prop, bgpic_camera_frame_items); + RNA_def_property_ui_text(prop, "Frame Method", "How the image fits in the camera frame"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); } static void rna_def_backgroundImages(BlenderRNA *brna, PropertyRNA *cprop) |