new scaling options to scale footage without stretching - add stretch/fit/crop to...
authorCampbell Barton <ideasman42@gmail.com>
Thu, 14 Jun 2012 16:55:55 +0000 (16:55 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 14 Jun 2012 16:55:55 +0000 (16:55 +0000)
this is only added for the old compositor, will add to the new compositor next.

source/blender/blenkernel/BKE_node.h
source/blender/editors/space_node/drawnode.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/makesrna/intern/rna_nodetree.c
source/blender/nodes/composite/nodes/node_composite_scale.c

index c856d40..b3f17c0 100644 (file)
@@ -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 */
index 033bfd1..e48dd39 100644 (file)
@@ -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)
index 5073eca..1f7dfef 100644 (file)
@@ -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];
index 762e5ef..9567226 100644 (file)
@@ -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)
index 69d76ed..fd4bd64 100644 (file)
@@ -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);