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