[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47912] trunk/blender/source/blender: new scaling options to scale footage without stretching - add stretch/fit/ crop to compositor scale node, default behavior isnt changed.
Campbell Barton
ideasman42 at gmail.com
Thu Jun 14 18:56:08 CEST 2012
Revision: 47912
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47912
Author: campbellbarton
Date: 2012-06-14 16:55:55 +0000 (Thu, 14 Jun 2012)
Log Message:
-----------
new scaling options to scale footage without stretching - add stretch/fit/crop to compositor scale node, default behavior isnt changed.
this is only added for the old compositor, will add to the new compositor next.
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/BKE_node.h
trunk/blender/source/blender/editors/space_node/drawnode.c
trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
trunk/blender/source/blender/nodes/composite/nodes/node_composite_scale.c
Modified: trunk/blender/source/blender/blenkernel/BKE_node.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_node.h 2012-06-14 16:15:37 UTC (rev 47911)
+++ trunk/blender/source/blender/blenkernel/BKE_node.h 2012-06-14 16:55:55 UTC (rev 47912)
@@ -693,6 +693,9 @@
#define CMP_SCALE_ABSOLUTE 1
#define CMP_SCALE_SCENEPERCENT 2
#define CMP_SCALE_RENDERPERCENT 3
+/* custom2 */
+#define CMP_SCALE_RENDERSIZE_FRAME_ASPECT (1 << 0)
+#define CMP_SCALE_RENDERSIZE_FRAME_CROP (1 << 1)
/* API */
Modified: trunk/blender/source/blender/editors/space_node/drawnode.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/drawnode.c 2012-06-14 16:15:37 UTC (rev 47911)
+++ trunk/blender/source/blender/editors/space_node/drawnode.c 2012-06-14 16:55:55 UTC (rev 47912)
@@ -2018,6 +2018,10 @@
static void node_composit_buts_scale(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
uiItemR(layout, ptr, "space", 0, "", ICON_NONE);
+
+ if (RNA_enum_get(ptr, "space") == CMP_SCALE_RENDERPERCENT) {
+ uiItemR(layout, ptr, "frame_method", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
+ }
}
static void node_composit_buts_rotate(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
Modified: trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_draw.c 2012-06-14 16:15:37 UTC (rev 47911)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_draw.c 2012-06-14 16:55:55 UTC (rev 47912)
@@ -1632,8 +1632,7 @@
}
/* aspect correction */
- if (bgpic->flag & V3D_BGPIC_CAMERA_ASPECT)
- {
+ 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];
Modified: trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_nodetree.c 2012-06-14 16:15:37 UTC (rev 47911)
+++ trunk/blender/source/blender/makesrna/intern/rna_nodetree.c 2012-06-14 16:55:55 UTC (rev 47912)
@@ -2077,20 +2077,35 @@
static void def_cmp_scale(StructRNA *srna)
{
PropertyRNA *prop;
-
+
static EnumPropertyItem space_items[] = {
- {0, "RELATIVE", 0, "Relative", ""},
- {1, "ABSOLUTE", 0, "Absolute", ""},
- {2, "SCENE_SIZE", 0, "Scene Size", ""},
- {3, "RENDER_SIZE", 0, "Render Size", ""},
+ {CMP_SCALE_RELATIVE, "RELATIVE", 0, "Relative", ""},
+ {CMP_SCALE_ABSOLUTE, "ABSOLUTE", 0, "Absolute", ""},
+ {CMP_SCALE_SCENEPERCENT, "SCENE_SIZE", 0, "Scene Size", ""},
+ {CMP_SCALE_RENDERPERCENT, "RENDER_SIZE", 0, "Render Size", ""},
{0, NULL, 0, NULL, NULL}
};
+ /* matching bgpic_camera_frame_items[] */
+ static const EnumPropertyItem space_frame_items[] = {
+ {0, "STRETCH", 0, "Stretch", ""},
+ {CMP_SCALE_RENDERSIZE_FRAME_ASPECT, "FIT", 0, "Fit", ""},
+ {CMP_SCALE_RENDERSIZE_FRAME_ASPECT | CMP_SCALE_RENDERSIZE_FRAME_CROP, "CROP", 0, "Crop", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+
prop = RNA_def_property(srna, "space", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "custom1");
RNA_def_property_enum_items(prop, space_items);
RNA_def_property_ui_text(prop, "Space", "Coordinate space to scale relative to");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+
+ /* 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, "custom2");
+ RNA_def_property_enum_items(prop, space_frame_items);
+ RNA_def_property_ui_text(prop, "Frame Method", "How the image fits in the camera frame");
+ RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
}
static void def_cmp_rotate(StructRNA *srna)
Modified: trunk/blender/source/blender/nodes/composite/nodes/node_composite_scale.c
===================================================================
--- trunk/blender/source/blender/nodes/composite/nodes/node_composite_scale.c 2012-06-14 16:15:37 UTC (rev 47911)
+++ trunk/blender/source/blender/nodes/composite/nodes/node_composite_scale.c 2012-06-14 16:55:55 UTC (rev 47912)
@@ -67,8 +67,44 @@
newy = cbuf->y * (rd->size / 100.0f);
}
else if (node->custom1 == CMP_SCALE_RENDERPERCENT) {
- newx = (rd->xsch * rd->size) / 100;
- newy = (rd->ysch * rd->size) / 100;
+ /* supports framing options */
+ if (node->custom2 & CMP_SCALE_RENDERSIZE_FRAME_ASPECT) {
+ /* apply aspect from clip */
+ const float w_src = cbuf->x;
+ const float h_src = cbuf->y;
+
+ /* destination aspect is already applied from the camera frame */
+ const float w_dst = (rd->xsch * rd->size) / 100;
+ const float h_dst = (rd->ysch * rd->size) / 100;
+
+ 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) == ((node->custom2 & CMP_SCALE_RENDERSIZE_FRAME_CROP) != 0)) {
+ /* fit X */
+ const float div = asp_src / asp_dst;
+ newx = w_dst * div;
+ newy = h_dst;
+ }
+ else {
+ /* fit Y */
+ const float div = asp_dst / asp_src;
+ newx = w_dst;
+ newy = h_dst * div;
+ }
+ }
+ else {
+ /* same as below - no aspect correction needed */
+ newx = w_dst;
+ newy = h_dst;
+ }
+ }
+ else {
+ /* stretch */
+ newx = (rd->xsch * rd->size) / 100;
+ newy = (rd->ysch * rd->size) / 100;
+ }
}
else { /* CMP_SCALE_ABSOLUTE */
newx = MAX2((int)in[1]->vec[0], 1);
More information about the Bf-blender-cvs
mailing list