Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Toenne <lukas.toenne@googlemail.com>2012-02-22 16:24:04 +0400
committerLukas Toenne <lukas.toenne@googlemail.com>2012-02-22 16:24:04 +0400
commit3bae60d0c9e7629d29d1569201dd07e968acd600 (patch)
tree7164d84e77bed4f92e2d935865be9cae1518b057 /source/blender/nodes
parentdadc2a26e33fc2046438d4532468783ed8485a6b (diff)
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of possible input slots. It has a base path string that can be set to a general base folder. Every input socket then uses its name as an extension of the base path for file organization. This can include further subfolders on top of the base path. Example: Base path: '/home/user/myproject' Input 1: 'Compo' Input 2: 'Diffuse/' Input 3: 'details/Normals' would create output files in /home/user/myproject: Compo0001.png, Compo0002.png, ... in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base given) in /home/user/myproject/details: Normals0001.png, Normals0002.png, ... Most settings for the node can be found in the sidebar (NKEY). New input sockets can be added with the "Add Input" button. There is a list of input sockets and below that the details for each socket can be changed, including the sub-path and filename. Sockets can be removed here as well. By default each socket uses the render settings file output format, but each can use its own format if necessary. To my knowledge this is the first node making use of such dynamic sockets in trunk. So this is also a design test, other nodes might use this in the future. Adding operator buttons on top of a node is a bit unwieldy atm, because all node operators generally work on selected and/or active node(s). The operator button would therefore either have to make sure the node is activated before the operator is called (block callback maybe?) OR it has to store the node name (risky, weak reference). For now it is only used in the sidebar, where only the active node's buttons are displayed. Also adds a new struct_type value to bNodeSocket, in order to distinguish different socket types with the same data type (file inputs are SOCK_RGBA color sockets). Would be nicer to use data type only for actual data evaluation, but used in too many places, this works ok for now.
Diffstat (limited to 'source/blender/nodes')
-rw-r--r--source/blender/nodes/NOD_composite.h1
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_outputFile.c182
2 files changed, 172 insertions, 11 deletions
diff --git a/source/blender/nodes/NOD_composite.h b/source/blender/nodes/NOD_composite.h
index 284b89bc095..e2bbaea8c7f 100644
--- a/source/blender/nodes/NOD_composite.h
+++ b/source/blender/nodes/NOD_composite.h
@@ -55,6 +55,7 @@ void register_node_type_cmp_composite(struct bNodeTreeType *ttype);
void register_node_type_cmp_viewer(struct bNodeTreeType *ttype);
void register_node_type_cmp_splitviewer(struct bNodeTreeType *ttype);
void register_node_type_cmp_output_file(struct bNodeTreeType *ttype);
+void register_node_type_cmp_output_multi_file(struct bNodeTreeType *ttype);
void register_node_type_cmp_view_levels(struct bNodeTreeType *ttype);
void register_node_type_cmp_curve_rgb(struct bNodeTreeType *ttype);
diff --git a/source/blender/nodes/composite/nodes/node_composite_outputFile.c b/source/blender/nodes/composite/nodes/node_composite_outputFile.c
index 50a196deb07..02df603f494 100644
--- a/source/blender/nodes/composite/nodes/node_composite_outputFile.c
+++ b/source/blender/nodes/composite/nodes/node_composite_outputFile.c
@@ -30,6 +30,11 @@
*/
+#include <string.h>
+#include "BLI_path_util.h"
+
+#include "BKE_utildefines.h"
+
#include "node_composite_util.h"
/* **************** OUTPUT FILE ******************** */
@@ -59,7 +64,7 @@ static void node_composit_exec_output_file(void *data, bNode *node, bNodeStack *
Main *bmain= G.main; /* TODO, have this passed along */
CompBuf *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA);
ImBuf *ibuf= IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0);
- char string[256];
+ char string[FILE_MAX];
ibuf->rect_float= cbuf->rect;
ibuf->dither= rd->dither_intensity;
@@ -92,21 +97,26 @@ static void node_composit_exec_output_file(void *data, bNode *node, bNodeStack *
}
}
-static void node_composit_init_output_file(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
+static void node_composit_mute_output_file(void *UNUSED(data), int UNUSED(thread),
+ struct bNode *UNUSED(node), void *UNUSED(nodedata),
+ struct bNodeStack **UNUSED(in), struct bNodeStack **UNUSED(out))
+{
+ /* nothing to do here */
+}
+
+static void node_composit_init_output_file(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *ntemp)
{
- Scene *scene= (Scene *)node->id;
+ RenderData *rd = &ntemp->scene->r;
NodeImageFile *nif= MEM_callocN(sizeof(NodeImageFile), "node image file");
node->storage= nif;
- if(scene) {
- BLI_strncpy(nif->name, scene->r.pic, sizeof(nif->name));
- nif->im_format= scene->r.im_format;
- if (BKE_imtype_is_movie(nif->im_format.imtype)) {
- nif->im_format.imtype= R_IMF_IMTYPE_OPENEXR;
- }
- nif->sfra= scene->r.sfra;
- nif->efra= scene->r.efra;
+ BLI_strncpy(nif->name, rd->pic, sizeof(nif->name));
+ nif->im_format= rd->im_format;
+ if (BKE_imtype_is_movie(nif->im_format.imtype)) {
+ nif->im_format.imtype= R_IMF_IMTYPE_OPENEXR;
}
+ nif->sfra= rd->sfra;
+ nif->efra= rd->efra;
}
void register_node_type_cmp_output_file(bNodeTreeType *ttype)
@@ -119,6 +129,156 @@ void register_node_type_cmp_output_file(bNodeTreeType *ttype)
node_type_init(&ntype, node_composit_init_output_file);
node_type_storage(&ntype, "NodeImageFile", node_free_standard_storage, node_copy_standard_storage);
node_type_exec(&ntype, node_composit_exec_output_file);
+ node_type_mute(&ntype, node_composit_mute_output_file, NULL);
+
+ nodeRegisterType(ttype, &ntype);
+}
+
+
+/* =============================================================================== */
+
+
+void ntreeCompositOutputMultiFileAddSocket(bNodeTree *ntree, bNode *node, ImageFormatData *im_format)
+{
+ bNodeSocket *sock = nodeAddSocket(ntree, node, SOCK_IN, "", SOCK_RGBA);
+
+ /* create format data for the input socket */
+ NodeImageMultiFileSocket *sockdata = MEM_callocN(sizeof(NodeImageMultiFileSocket), "socket image format");
+ sock->storage = sockdata;
+ sock->struct_type = SOCK_STRUCT_OUTPUT_MULTI_FILE;
+
+ if(im_format) {
+ sockdata->format= *im_format;
+ if (BKE_imtype_is_movie(sockdata->format.imtype)) {
+ sockdata->format.imtype= R_IMF_IMTYPE_OPENEXR;
+ }
+ }
+ /* use render data format by default */
+ sockdata->use_render_format = 1;
+}
+
+int ntreeCompositOutputMultiFileRemoveActiveSocket(bNodeTree *ntree, bNode *node)
+{
+ NodeImageMultiFile *nimf = node->storage;
+ bNodeSocket *sock = BLI_findlink(&node->inputs, nimf->active_input);
+
+ if (!sock)
+ return 0;
+
+ /* free format data */
+ MEM_freeN(sock->storage);
+
+ nodeRemoveSocket(ntree, node, sock);
+ return 1;
+}
+
+static void init_output_multi_file(bNodeTree *ntree, bNode* node, bNodeTemplate *ntemp)
+{
+ RenderData *rd = &ntemp->scene->r;
+ NodeImageMultiFile *nimf= MEM_callocN(sizeof(NodeImageMultiFile), "node image multi file");
+ node->storage= nimf;
+
+ BLI_strncpy(nimf->base_path, rd->pic, sizeof(nimf->base_path));
+
+ /* add one socket by default */
+ ntreeCompositOutputMultiFileAddSocket(ntree, node, &rd->im_format);
+}
+
+void free_output_multi_file(bNode *node)
+{
+ bNodeSocket *sock;
+
+ /* free storage data in sockets */
+ for (sock=node->inputs.first; sock; sock=sock->next) {
+ MEM_freeN(sock->storage);
+ }
+
+ MEM_freeN(node->storage);
+}
+
+void copy_output_multi_file(struct bNode *node, struct bNode *target)
+{
+ bNodeSocket *sock, *newsock;
+
+ target->storage = MEM_dupallocN(node->storage);
+
+ /* duplicate storage data in sockets */
+ for (sock=node->inputs.first, newsock=target->inputs.first; sock && newsock; sock=sock->next, newsock=newsock->next) {
+ newsock->storage = MEM_dupallocN(sock->storage);
+ }
+}
+
+static void exec_output_multi_file(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out))
+{
+ RenderData *rd= data;
+ NodeImageMultiFile *nimf= node->storage;
+ bNodeSocket *sock;
+ int i;
+
+ for (sock=node->inputs.first, i=0; sock; sock=sock->next, ++i) {
+ if (!in[i]->data)
+ continue;
+
+ if (!G.rendering) {
+ /* only output files when rendering a sequence -
+ * otherwise, it overwrites the output files just
+ * scrubbing through the timeline when the compositor updates */
+ return;
+ } else {
+ Main *bmain= G.main; /* TODO, have this passed along */
+ NodeImageMultiFileSocket *sockdata = sock->storage;
+ CompBuf *cbuf= typecheck_compbuf(in[i]->data, CB_RGBA);
+ ImBuf *ibuf= IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0);
+ ImageFormatData *format = (sockdata->use_render_format ? &rd->im_format : &sockdata->format);
+ char path[FILE_MAX];
+ char string[FILE_MAX];
+
+ ibuf->rect_float= cbuf->rect;
+ ibuf->dither= rd->dither_intensity;
+
+ if (rd->color_mgt_flag & R_COLOR_MANAGEMENT)
+ ibuf->profile = IB_PROFILE_LINEAR_RGB;
+
+ /* get full path */
+ BLI_join_dirfile(path, FILE_MAX, nimf->base_path, sock->name);
+
+ BKE_makepicstring(string, path, bmain->name, rd->cfra, format->imtype, (rd->scemode & R_EXTENSION), TRUE);
+
+ if(0 == BKE_write_ibuf(ibuf, string, format))
+ printf("Cannot save Node File Output to %s\n", string);
+ else
+ printf("Saved: %s\n", string);
+
+ IMB_freeImBuf(ibuf);
+
+ #if 0 /* XXX not used yet */
+ generate_preview(data, node, cbuf);
+ #endif
+
+ if(in[i]->data != cbuf)
+ free_compbuf(cbuf);
+ }
+ }
+}
+
+static void mute_output_multi_file(void *UNUSED(data), int UNUSED(thread),
+ struct bNode *UNUSED(node), void *UNUSED(nodedata),
+ struct bNodeStack **UNUSED(in), struct bNodeStack **UNUSED(out))
+{
+ /* nothing to do here */
+}
+
+void register_node_type_cmp_output_multi_file(bNodeTreeType *ttype)
+{
+ static bNodeType ntype;
+
+ node_type_base(ttype, &ntype, CMP_NODE_OUTPUT_MULTI_FILE, "Multi File Output", NODE_CLASS_OUTPUT, NODE_OPTIONS);
+ node_type_socket_templates(&ntype, NULL, NULL);
+ node_type_size(&ntype, 140, 80, 300);
+ node_type_init(&ntype, init_output_multi_file);
+ node_type_storage(&ntype, "NodeImageMultiFile", free_output_multi_file, copy_output_multi_file);
+ node_type_exec(&ntype, exec_output_multi_file);
+ node_type_mute(&ntype, mute_output_multi_file, NULL);
nodeRegisterType(ttype, &ntype);
}