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