Blender V2.61 - r43446

node_composite_movieclip.c

Go to the documentation of this file.
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) 2011 Blender Foundation.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): Blender Foundation,
00024  *                 Sergey Sharybin
00025  *
00026  * ***** END GPL LICENSE BLOCK *****
00027  */
00028 
00034 #include "node_composite_util.h"
00035 
00036 static bNodeSocketTemplate cmp_node_movieclip_out[]= {
00037     {   SOCK_RGBA,      0,  "Image"},
00038     {   SOCK_FLOAT,     1,  "Offset X"},
00039     {   SOCK_FLOAT,     1,  "Offset Y"},
00040     {   SOCK_FLOAT,     1,  "Scale"},
00041     {   SOCK_FLOAT,     1,  "Angle"},
00042     {   -1, 0, ""   }
00043 };
00044 
00045 static CompBuf *node_composit_get_movieclip(RenderData *rd, MovieClip *clip, MovieClipUser *user)
00046 {
00047     ImBuf *ibuf;
00048     CompBuf *stackbuf;
00049     int type;
00050 
00051     float *rect;
00052     int alloc= FALSE;
00053 
00054     ibuf= BKE_movieclip_get_ibuf(clip, user);
00055 
00056     if(ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL)) {
00057         IMB_freeImBuf(ibuf);
00058         return NULL;
00059     }
00060 
00061     if (ibuf->rect_float == NULL || ibuf->userflags&IB_RECT_INVALID) {
00062         IMB_float_from_rect(ibuf);
00063         ibuf->userflags&= ~IB_RECT_INVALID;
00064     }
00065 
00066     /* now we need a float buffer from the image with matching color management */
00067     if(ibuf->channels == 4) {
00068         rect= node_composit_get_float_buffer(rd, ibuf, &alloc);
00069     }
00070     else {
00071         /* non-rgba passes can't use color profiles */
00072         rect= ibuf->rect_float;
00073     }
00074     /* done coercing into the correct color management */
00075 
00076     if(!alloc) {
00077         rect= MEM_dupallocN(rect);
00078         alloc= 1;
00079     }
00080 
00081     type= ibuf->channels;
00082 
00083     if(rd->scemode & R_COMP_CROP) {
00084         stackbuf= get_cropped_compbuf(&rd->disprect, rect, ibuf->x, ibuf->y, type);
00085         if(alloc)
00086             MEM_freeN(rect);
00087     }
00088     else {
00089         /* we put imbuf copy on stack, cbuf knows rect is from other ibuf when freed! */
00090         stackbuf= alloc_compbuf(ibuf->x, ibuf->y, type, FALSE);
00091         stackbuf->rect= rect;
00092         stackbuf->malloc= alloc;
00093     }
00094 
00095     IMB_freeImBuf(ibuf);
00096 
00097     return stackbuf;
00098 }
00099 
00100 static void node_composit_exec_movieclip(void *data, bNode *node, bNodeStack **UNUSED(in), bNodeStack **out)
00101 {
00102     if(node->id) {
00103         RenderData *rd= data;
00104         MovieClip *clip= (MovieClip *)node->id;
00105         MovieClipUser *user= (MovieClipUser *)node->storage;
00106         CompBuf *stackbuf= NULL;
00107 
00108         BKE_movieclip_user_set_frame(user, rd->cfra);
00109 
00110         stackbuf= node_composit_get_movieclip(rd, clip, user);
00111 
00112         if (stackbuf) {
00113             MovieTrackingStabilization *stab= &clip->tracking.stabilization;
00114 
00115             /* put image on stack */
00116             out[0]->data= stackbuf;
00117 
00118             if(stab->flag&TRACKING_2D_STABILIZATION) {
00119                 float loc[2], scale, angle;
00120 
00121                 BKE_tracking_stabilization_data(&clip->tracking, rd->cfra, stackbuf->x, stackbuf->y,
00122                             loc, &scale, &angle);
00123 
00124                 out[1]->vec[0]= loc[0];
00125                 out[2]->vec[0]= loc[1];
00126 
00127                 out[3]->vec[0]= scale;
00128                 out[4]->vec[0]= angle;
00129             }
00130 
00131             /* generate preview */
00132             generate_preview(data, node, stackbuf);
00133         }
00134     }
00135 }
00136 
00137 static void init(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
00138 {
00139     MovieClipUser *user= MEM_callocN(sizeof(MovieClipUser), "node movie clip user");
00140 
00141     node->storage= user;
00142     user->framenr= 1;
00143 }
00144 
00145 void register_node_type_cmp_movieclip(bNodeTreeType *ttype)
00146 {
00147     static bNodeType ntype;
00148 
00149     node_type_base(ttype, &ntype, CMP_NODE_MOVIECLIP, "Movie Clip", NODE_CLASS_INPUT, NODE_PREVIEW|NODE_OPTIONS);
00150     node_type_socket_templates(&ntype, NULL, cmp_node_movieclip_out);
00151     node_type_size(&ntype, 120, 80, 300);
00152     node_type_init(&ntype, init);
00153     node_type_storage(&ntype, "MovieClipUser", node_free_standard_storage, node_copy_standard_storage);
00154     node_type_exec(&ntype, node_composit_exec_movieclip);
00155 
00156     nodeRegisterType(ttype, &ntype);
00157 }