diff options
author | Monique Dewanchand <mdewanchand> | 2020-11-30 09:55:30 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2020-11-30 10:00:40 +0300 |
commit | c751d40e070c6df907a526d7e3e17fc10611191e (patch) | |
tree | c1e2566c22944baf0ab89ac1ac29990a80de46ba /source/blender/compositor/nodes/COM_ScaleNode.cpp | |
parent | f38cd7e1885e1a255728f42c660223c5285f9685 (diff) |
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
Diffstat (limited to 'source/blender/compositor/nodes/COM_ScaleNode.cpp')
-rw-r--r-- | source/blender/compositor/nodes/COM_ScaleNode.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/source/blender/compositor/nodes/COM_ScaleNode.cpp b/source/blender/compositor/nodes/COM_ScaleNode.cpp index e57c30cff29..9ffcd5306b0 100644 --- a/source/blender/compositor/nodes/COM_ScaleNode.cpp +++ b/source/blender/compositor/nodes/COM_ScaleNode.cpp @@ -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); |