Blender  V2.59
CMP_outputFile.c
Go to the documentation of this file.
00001 /*
00002  * $Id: CMP_outputFile.c 36385 2011-04-30 05:26:09Z campbellbarton $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version. 
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2006 Blender Foundation.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029 
00035 #include "../CMP_util.h"
00036 
00037 /* **************** OUTPUT FILE ******************** */
00038 static bNodeSocketType cmp_node_output_file_in[]= {
00039         {       SOCK_RGBA, 1, "Image",          0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00040         {       SOCK_VALUE, 1, "Z",             0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00041         {       -1, 0, ""       }
00042 };
00043 
00044 static void node_composit_exec_output_file(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out))
00045 {
00046         /* image assigned to output */
00047         /* stack order input sockets: col, alpha */
00048         
00049         if(in[0]->data) {
00050                 RenderData *rd= data;
00051                 NodeImageFile *nif= node->storage;
00052                 if(nif->sfra!=nif->efra && (rd->cfra<nif->sfra || rd->cfra>nif->efra)) {
00053                         return; /* BAIL OUT RETURN */
00054                 }
00055                 else if (!G.rendering) {
00056                         /* only output files when rendering a sequence -
00057                          * otherwise, it overwrites the output files just 
00058                          * scrubbing through the timeline when the compositor updates */
00059                         return;
00060                 } else {
00061                         CompBuf *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA);
00062                         ImBuf *ibuf= IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0);
00063                         char string[256];
00064                         
00065                         ibuf->rect_float= cbuf->rect;
00066                         ibuf->dither= rd->dither_intensity;
00067                         
00068                         if (rd->color_mgt_flag & R_COLOR_MANAGEMENT)
00069                                 ibuf->profile = IB_PROFILE_LINEAR_RGB;
00070                         
00071                         if(in[1]->data) {
00072                                 CompBuf *zbuf= in[1]->data;
00073                                 if(zbuf->type==CB_VAL && zbuf->x==cbuf->x && zbuf->y==cbuf->y) {
00074                                         nif->subimtype|= R_OPENEXR_ZBUF;
00075                                         ibuf->zbuf_float= zbuf->rect;
00076                                 }
00077                         }
00078                         
00079                         BKE_makepicstring(string, nif->name, rd->cfra, nif->imtype, (rd->scemode & R_EXTENSION), TRUE);
00080                         
00081                         if(0 == BKE_write_ibuf(ibuf, string, nif->imtype, nif->subimtype, nif->imtype==R_OPENEXR?nif->codec:nif->quality))
00082                                 printf("Cannot save Node File Output to %s\n", string);
00083                         else
00084                                 printf("Saved: %s\n", string);
00085                         
00086                         IMB_freeImBuf(ibuf);    
00087                         
00088                         generate_preview(data, node, cbuf);
00089                         
00090                         if(in[0]->data != cbuf) 
00091                                 free_compbuf(cbuf);
00092                 }
00093         }
00094 }
00095 
00096 static void node_composit_init_output_file(bNode *node)
00097 {
00098         Scene *scene= (Scene *)node->id;
00099         NodeImageFile *nif= MEM_callocN(sizeof(NodeImageFile), "node image file");
00100         node->storage= nif;
00101 
00102         if(scene) {
00103                 BLI_strncpy(nif->name, scene->r.pic, sizeof(nif->name));
00104                 nif->imtype= scene->r.imtype;
00105                 nif->subimtype= scene->r.subimtype;
00106                 nif->quality= scene->r.quality;
00107                 nif->sfra= scene->r.sfra;
00108                 nif->efra= scene->r.efra;
00109         }
00110 }
00111 
00112 void register_node_type_cmp_output_file(ListBase *lb)
00113 {
00114         static bNodeType ntype;
00115 
00116         node_type_base(&ntype, CMP_NODE_OUTPUT_FILE, "File Output", NODE_CLASS_OUTPUT, NODE_PREVIEW|NODE_OPTIONS,
00117                 cmp_node_output_file_in, NULL);
00118         node_type_size(&ntype, 140, 80, 300);
00119         node_type_init(&ntype, node_composit_init_output_file);
00120         node_type_storage(&ntype, "NodeImageFile", node_free_standard_storage, node_copy_standard_storage);
00121         node_type_exec(&ntype, node_composit_exec_output_file);
00122 
00123         nodeRegisterType(lb, &ntype);
00124 }
00125 
00126 
00127