Cleanup hardcoded render percentage to factor conversion

During revision of {D8952} one of the comments was to make a function that converts the render percentage to a factor. This to avoid code duplication. However the duplicated code was already all over the compositor code. So in order to avoid this code duplication for {D8952} I propose to first cleanup the duplicated code and build patch {D8952} based on this clean up.

The method that converts the render percentage to a factor is put in the CompositorContext. Why? The CompositorContext keeps DNA information like the renderdata. DNA, and thus the CompositorContext, keeps the size of the render resolution in percentage (user oriented). The compositor needs the size of the render resolution as a factor. So the CompositorContext seems like the obvious place to have this conversion method.

Why not in de NodeBase? The method could've been added to the nodebase, but I wanted to keep the nodebase as clean as possible and not put simple "conversion" methods into this base class. Also I didn't really like the call flow: you'd always have to get the renderdata size from the context and then convert.
Putting it in the CompositorContext avoids this extra invoke of a call.

Why not in the Converter? See nodebase. And the Converter seems more like a class for "structural" and complex node tree conversions. Not the simple conversions.

Reviewed By: Sergey Sharybin

Differential Revision: https://developer.blender.org/D9566
This commit is contained in:
Monique Dewanchand 2020-11-30 07:55:30 +01:00 committed by Jeroen Bakker
parent f38cd7e188
commit c751d40e07
Notes: blender-bot 2023-02-14 03:31:57 +01:00
Referenced by issue #83275, Excluding a collection crashes with viewport statistics enabled
9 changed files with 31 additions and 16 deletions

@ -1 +1 @@
Subproject commit 848613f1edf09495bb764144461730662ac0b061
Subproject commit ae7e6c215c9fc715cdedbc1c1e33e946fc90b496

@ -1 +1 @@
Subproject commit 35c23b4db494e58538a677c4fb0ec9ec1e8ffaa8
Subproject commit 866dcad5aa6e45737f0634b835adcbc0871201e5

View File

@ -267,4 +267,13 @@ class CompositorContext {
{
return (this->getbNodeTree()->flag & NTREE_COM_GROUPNODE_BUFFER) != 0;
}
/**
* \brief Get the render percentage as a factor.
* The compositor uses a factor i.o. a percentage.
*/
float getRenderPercentageAsFactor() const
{
return m_rd->size * 0.01f;
}
};

View File

@ -52,13 +52,14 @@ void BoxMaskNode::convertToOperations(NodeConverter &converter,
/* Scale that image up to render resolution */
const RenderData *rd = context.getRenderData();
const float render_size_factor = context.getRenderPercentageAsFactor();
ScaleFixedSizeOperation *scaleOperation = new ScaleFixedSizeOperation();
scaleOperation->setIsAspect(false);
scaleOperation->setIsCrop(false);
scaleOperation->setOffset(0.0f, 0.0f);
scaleOperation->setNewWidth(rd->xsch * rd->size / 100.0f);
scaleOperation->setNewHeight(rd->ysch * rd->size / 100.0f);
scaleOperation->setNewWidth(rd->xsch * render_size_factor);
scaleOperation->setNewHeight(rd->ysch * render_size_factor);
scaleOperation->getInputSocket(0)->setResizeMode(COM_SC_NO_RESIZE);
converter.addOperation(scaleOperation);

View File

@ -52,12 +52,14 @@ void EllipseMaskNode::convertToOperations(NodeConverter &converter,
/* Scale that image up to render resolution */
const RenderData *rd = context.getRenderData();
const float render_size_factor = context.getRenderPercentageAsFactor();
ScaleFixedSizeOperation *scaleOperation = new ScaleFixedSizeOperation();
scaleOperation->setIsAspect(false);
scaleOperation->setIsCrop(false);
scaleOperation->setOffset(0.0f, 0.0f);
scaleOperation->setNewWidth(rd->xsch * rd->size / 100.0f);
scaleOperation->setNewHeight(rd->ysch * rd->size / 100.0f);
scaleOperation->setNewWidth(rd->xsch * render_size_factor);
scaleOperation->setNewHeight(rd->ysch * render_size_factor);
scaleOperation->getInputSocket(0)->setResizeMode(COM_SC_NO_RESIZE);
converter.addOperation(scaleOperation);

View File

@ -31,6 +31,7 @@ void MaskNode::convertToOperations(NodeConverter &converter,
const CompositorContext &context) const
{
const RenderData *rd = context.getRenderData();
const float render_size_factor = context.getRenderPercentageAsFactor();
NodeOutput *outputMask = this->getOutputSocket(0);
@ -46,12 +47,12 @@ void MaskNode::convertToOperations(NodeConverter &converter,
operation->setMaskHeight(data->size_y);
}
else if (editorNode->custom1 & CMP_NODEFLAG_MASK_FIXED_SCENE) {
operation->setMaskWidth(data->size_x * (rd->size / 100.0f));
operation->setMaskHeight(data->size_y * (rd->size / 100.0f));
operation->setMaskWidth(data->size_x * render_size_factor);
operation->setMaskHeight(data->size_y * render_size_factor);
}
else {
operation->setMaskWidth(rd->xsch * rd->size / 100.0f);
operation->setMaskHeight(rd->ysch * rd->size / 100.0f);
operation->setMaskWidth(rd->xsch * render_size_factor);
operation->setMaskHeight(rd->ysch * render_size_factor);
}
operation->setMask(mask);

View File

@ -54,7 +54,7 @@ void ScaleNode::convertToOperations(NodeConverter &converter,
}
case CMP_SCALE_SCENEPERCENT: {
SetValueOperation *scaleFactorOperation = new SetValueOperation();
scaleFactorOperation->setValue(context.getRenderData()->size / 100.0f);
scaleFactorOperation->setValue(context.getRenderPercentageAsFactor());
converter.addOperation(scaleFactorOperation);
ScaleOperation *operation = new ScaleOperation();
@ -71,13 +71,14 @@ void ScaleNode::convertToOperations(NodeConverter &converter,
}
case CMP_SCALE_RENDERPERCENT: {
const RenderData *rd = context.getRenderData();
const float render_size_factor = context.getRenderPercentageAsFactor();
ScaleFixedSizeOperation *operation = new ScaleFixedSizeOperation();
/* framing options */
operation->setIsAspect((bnode->custom2 & CMP_SCALE_RENDERSIZE_FRAME_ASPECT) != 0);
operation->setIsCrop((bnode->custom2 & CMP_SCALE_RENDERSIZE_FRAME_CROP) != 0);
operation->setOffset(bnode->custom3, bnode->custom4);
operation->setNewWidth(rd->xsch * rd->size / 100.0f);
operation->setNewHeight(rd->ysch * rd->size / 100.0f);
operation->setNewWidth(rd->xsch * render_size_factor);
operation->setNewHeight(rd->ysch * render_size_factor);
operation->getInputSocket(0)->setResizeMode(COM_SC_NO_RESIZE);
converter.addOperation(operation);

View File

@ -42,8 +42,9 @@ void TranslateNode::convertToOperations(NodeConverter &converter,
TranslateOperation *operation = new TranslateOperation();
if (data->relative) {
const RenderData *rd = context.getRenderData();
float fx = rd->xsch * rd->size / 100.0f;
float fy = rd->ysch * rd->size / 100.0f;
const float render_size_factor = context.getRenderPercentageAsFactor();
float fx = rd->xsch * render_size_factor;
float fy = rd->ysch * render_size_factor;
operation->setFactorXY(fx, fy);
}

@ -1 +1 @@
Subproject commit 660be0ca10abc8261178159afcd1032be662e386
Subproject commit d7d7e9d41f7499aa4639f96c843156ff834385ba