Fix #34461: Inconsistent behavior of "Color Mix Node" and "Alpha Over Node"

Added compatibility option "Straight Alpha Output" to image input node

When this option is enabled, image input node will convert float buffer
to straight alpha.

This is not what you'll usually want with new alpha pipeline, nit this
is needed to preserve compatibility with older files saved in 2.65.
In that version byte image are resulting with straight alpha passing
to the compositor and alpha-overing required extra premultiplication
of inputs.

So, that's why Straight Alpha Output is needed -- it's set in versioning
code for byte node images so they'll still output straight alpha.

This option is currently only available in N-panel.

Additional change: added Alpha Mode for image input node to N-panel.
This commit is contained in:
Sergey Sharybin 2013-03-01 15:37:15 +00:00
parent 69f746d04c
commit f186f89a42
5 changed files with 49 additions and 2 deletions

@ -7355,6 +7355,23 @@ static void do_version_node_fix_translate_wrapping(void *UNUSED(data), ID *UNUSE
}
}
static void do_version_node_straight_image_alpha_workaround(void *data, ID *UNUSED(id), bNodeTree *ntree)
{
FileData *fd = (FileData *) data;
bNode *node;
for (node = ntree->nodes.first; node; node = node->next) {
if (node->type == CMP_NODE_IMAGE) {
Image *image = blo_do_versions_newlibadr(fd, ntree->id.lib, node->id);
if (image) {
if ((image->flag & IMA_DO_PREMUL) == 0 && image->alpha_mode == IMA_ALPHA_STRAIGHT)
node->custom1 |= CMP_NODE_IMAGE_USE_STRAIGHT_OUTPUT;
}
}
}
}
static void do_version_node_fix_internal_links_264(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
{
bNode *node;
@ -8648,6 +8665,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
Scene *scene;
Image *image, *nimage;
Tex *tex, *otex;
bNodeTreeType *ntreetype;
bNodeTree *ntree;
for (scene = main->scene.first; scene; scene = scene->id.next) {
Sequence *seq;
@ -8752,6 +8771,13 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
for (image = main->image.first; image; image = image->id.next)
image->flag &= ~IMA_DONE_TAG;
ntreetype = ntreeGetType(NTREE_COMPOSIT);
if (ntreetype && ntreetype->foreach_nodetree)
ntreetype->foreach_nodetree(main, fd, do_version_node_straight_image_alpha_workaround);
for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next)
do_version_node_straight_image_alpha_workaround(fd, NULL, ntree);
}
if (main->versionfile < 265 || (main->versionfile == 265 && main->subversionfile < 7)) {

@ -25,6 +25,7 @@
#include "COM_ExecutionSystem.h"
#include "COM_ImageOperation.h"
#include "COM_MultilayerImageOperation.h"
#include "COM_ConvertPremulToStraightOperation.h"
#include "BKE_node.h"
#include "BLI_utildefines.h"
@ -72,6 +73,7 @@ void ImageNode::convertToOperations(ExecutionSystem *graph, CompositorContext *c
ImageUser *imageuser = (ImageUser *)editorNode->storage;
int framenumber = context->getFramenumber();
int numberOfOutputs = this->getNumberOfOutputSockets();
bool outputStraightAlpha = editorNode->custom1 & CMP_NODE_IMAGE_USE_STRAIGHT_OUTPUT;
BKE_image_user_frame_calc(imageuser, context->getFramenumber(), 0);
/* force a load, we assume iuser index will be set OK anyway */
@ -138,7 +140,15 @@ void ImageNode::convertToOperations(ExecutionSystem *graph, CompositorContext *c
if (numberOfOutputs > 0) {
ImageOperation *operation = new ImageOperation();
if (outputImage->isConnected()) {
outputImage->relinkConnections(operation->getOutputSocket());
if (outputStraightAlpha) {
NodeOperation *alphaConvertOperation = new ConvertPremulToStraightOperation();
addLink(graph, operation->getOutputSocket(0), alphaConvertOperation->getInputSocket(0));
outputImage->relinkConnections(alphaConvertOperation->getOutputSocket());
graph->addOperation(alphaConvertOperation);
}
else {
outputImage->relinkConnections(operation->getOutputSocket());
}
}
operation->setImage(image);
operation->setImageUser(imageuser);

@ -1608,12 +1608,15 @@ static void node_composit_buts_image_details(uiLayout *layout, bContext *C, Poin
node_composit_buts_image(layout, C, ptr);
uiItemR(layout, ptr, "use_straight_alpha_output", 0, NULL, 0);
if (!node->id)
return;
imaptr = RNA_pointer_get(ptr, "image");
uiTemplateColorspaceSettings(layout, &imaptr, "colorspace_settings");
uiItemR(layout, &imaptr, "alpha_mode", 0, NULL, 0);
}
static void node_composit_buts_renderlayers(uiLayout *layout, bContext *C, PointerRNA *ptr)

@ -854,4 +854,7 @@ typedef struct NodeShaderNormalMap {
#define CMP_NODE_MASK_MBLUR_SAMPLES_MAX 64
/* image */
#define CMP_NODE_IMAGE_USE_STRAIGHT_OUTPUT 1
#endif

@ -2412,7 +2412,12 @@ static void def_cmp_image(StructRNA *srna)
RNA_def_property_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Image", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
prop = RNA_def_property(srna, "use_straight_alpha_output", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "custom1", CMP_NODE_IMAGE_USE_STRAIGHT_OUTPUT);
RNA_def_property_ui_text(prop, "Straight Alpha Output", "Put Node output buffer to straight alpha instead of premultiplied");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
/* NB: image user properties used in the UI are redefined in def_node_image_user,
* to trigger correct updates of the node editor. RNA design problem that prevents
* updates from nested structs ...