forked from bartvdbraak/blender
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.
This commit is contained in:
parent
550824968c
commit
ffc9e340b1
@ -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 */
|
||||
|
@ -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)
|
||||
|
@ -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];
|
||||
|
@ -2079,10 +2079,18 @@ 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}
|
||||
};
|
||||
|
||||
@ -2091,6 +2099,13 @@ static void def_cmp_scale(StructRNA *srna)
|
||||
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)
|
||||
|
@ -67,9 +67,45 @@ 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) {
|
||||
/* 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);
|
||||
newy = MAX2((int)in[2]->vec[0], 1);
|
||||
|
Loading…
Reference in New Issue
Block a user