From ffc9e340b12ffbebbf193f573a3bbe072b9f5df6 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 14 Jun 2012 16:55:55 +0000 Subject: [PATCH] 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. --- source/blender/blenkernel/BKE_node.h | 3 ++ source/blender/editors/space_node/drawnode.c | 4 ++ .../editors/space_view3d/view3d_draw.c | 3 +- source/blender/makesrna/intern/rna_nodetree.c | 25 +++++++++--- .../composite/nodes/node_composite_scale.c | 40 ++++++++++++++++++- 5 files changed, 66 insertions(+), 9 deletions(-) diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index c856d407f05..b3f17c06d5c 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -693,6 +693,9 @@ void ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct GPUMaterial *mat); #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 */ diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 033bfd165c2..e48dd39022e 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -2018,6 +2018,10 @@ static void node_composit_buts_file_output_details(uiLayout *layout, bContext *C 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) diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 5073eca96ad..1f7dfef3871 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -1632,8 +1632,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d, } /* 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]; diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 762e5ef0dfa..9567226f722 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -2077,20 +2077,35 @@ static void def_cmp_dilate_erode(StructRNA *srna) 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) diff --git a/source/blender/nodes/composite/nodes/node_composite_scale.c b/source/blender/nodes/composite/nodes/node_composite_scale.c index 69d76ed03e0..fd4bd643126 100644 --- a/source/blender/nodes/composite/nodes/node_composite_scale.c +++ b/source/blender/nodes/composite/nodes/node_composite_scale.c @@ -67,8 +67,44 @@ static void node_composit_exec_scale(void *data, bNode *node, bNodeStack **in, b 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);