rename image type defines to be less ambiguous, also set BMP as not supporting alpha...
[blender.git] / source / blender / nodes / composite / nodes / node_composite_outputFile.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2006 Blender Foundation.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file blender/nodes/composite/nodes/node_composite_outputFile.c
29  *  \ingroup cmpnodes
30  */
31
32
33 #include "node_composite_util.h"
34
35 /* **************** OUTPUT FILE ******************** */
36 static bNodeSocketTemplate cmp_node_output_file_in[]= {
37         {       SOCK_RGBA, 1, "Image",          0.0f, 0.0f, 0.0f, 1.0f},
38         {       SOCK_FLOAT, 1, "Z",             0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE},
39         {       -1, 0, ""       }
40 };
41
42 static void node_composit_exec_output_file(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out))
43 {
44         /* image assigned to output */
45         /* stack order input sockets: col, alpha */
46         
47         if(in[0]->data) {
48                 RenderData *rd= data;
49                 NodeImageFile *nif= node->storage;
50                 if(nif->sfra!=nif->efra && (rd->cfra<nif->sfra || rd->cfra>nif->efra)) {
51                         return; /* BAIL OUT RETURN */
52                 }
53                 else if (!G.rendering) {
54                         /* only output files when rendering a sequence -
55                          * otherwise, it overwrites the output files just 
56                          * scrubbing through the timeline when the compositor updates */
57                         return;
58                 } else {
59                         Main *bmain= G.main; /* TODO, have this passed along */
60                         CompBuf *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA);
61                         ImBuf *ibuf= IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0);
62                         char string[256];
63                         
64                         ibuf->rect_float= cbuf->rect;
65                         ibuf->dither= rd->dither_intensity;
66                         
67                         if (rd->color_mgt_flag & R_COLOR_MANAGEMENT)
68                                 ibuf->profile = IB_PROFILE_LINEAR_RGB;
69                         
70                         if(in[1]->data) {
71                                 CompBuf *zbuf= in[1]->data;
72                                 if(zbuf->type==CB_VAL && zbuf->x==cbuf->x && zbuf->y==cbuf->y) {
73                                         nif->im_format.flag |= R_IMF_FLAG_ZBUF;
74                                         ibuf->zbuf_float= zbuf->rect;
75                                 }
76                         }
77                         
78                         BKE_makepicstring(string, nif->name, bmain->name, rd->cfra, nif->im_format.imtype, (rd->scemode & R_EXTENSION), TRUE);
79                         
80                         if(0 == BKE_write_ibuf(ibuf, string, &nif->im_format))
81                                 printf("Cannot save Node File Output to %s\n", string);
82                         else
83                                 printf("Saved: %s\n", string);
84                         
85                         IMB_freeImBuf(ibuf);    
86                         
87                         generate_preview(data, node, cbuf);
88                         
89                         if(in[0]->data != cbuf) 
90                                 free_compbuf(cbuf);
91                 }
92         }
93 }
94
95 static void node_composit_init_output_file(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
96 {
97         Scene *scene= (Scene *)node->id;
98         NodeImageFile *nif= MEM_callocN(sizeof(NodeImageFile), "node image file");
99         node->storage= nif;
100
101         if(scene) {
102                 BLI_strncpy(nif->name, scene->r.pic, sizeof(nif->name));
103                 nif->im_format= scene->r.im_format;
104                 if (BKE_imtype_is_movie(nif->im_format.imtype)) {
105                         nif->im_format.imtype= R_IMF_IMTYPE_OPENEXR;
106                 }
107                 nif->sfra= scene->r.sfra;
108                 nif->efra= scene->r.efra;
109         }
110 }
111
112 void register_node_type_cmp_output_file(bNodeTreeType *ttype)
113 {
114         static bNodeType ntype;
115
116         node_type_base(ttype, &ntype, CMP_NODE_OUTPUT_FILE, "File Output", NODE_CLASS_OUTPUT, NODE_PREVIEW|NODE_OPTIONS);
117         node_type_socket_templates(&ntype, cmp_node_output_file_in, NULL);
118         node_type_size(&ntype, 140, 80, 300);
119         node_type_init(&ntype, node_composit_init_output_file);
120         node_type_storage(&ntype, "NodeImageFile", node_free_standard_storage, node_copy_standard_storage);
121         node_type_exec(&ntype, node_composit_exec_output_file);
122
123         nodeRegisterType(ttype, &ntype);
124 }