4 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
20 * The Original Code is Copyright (C) 2006 Blender Foundation.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): Blender Foundation,
28 * ***** END GPL LICENSE BLOCK *****
31 /** \file blender/nodes/composite/nodes/node_composite_movieundistort.c
36 #include "node_composite_util.h"
38 /* **************** Translate ******************** */
40 static bNodeSocketTemplate cmp_node_movieundistort_in[]= {
41 { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
45 static bNodeSocketTemplate cmp_node_movieundistort_out[]= {
46 { SOCK_RGBA, 0, "Image"},
50 static void node_composit_exec_movieundistort(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
52 if(in[0]->data && node->id) {
53 MovieClip *clip= (MovieClip *)node->id;
54 CompBuf *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA);
55 CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 0);
58 ibuf= IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0);
62 MovieClipUser *user= (MovieClipUser *)node->storage;
63 float aspy= 1.f/clip->tracking.camera.pixel_aspect;
64 int scaled= 0, width, height;
66 ibuf->rect_float= cbuf->rect;
68 BKE_movieclip_acquire_size(clip, user, &width, &height);
71 if(ibuf->x!=width || ibuf->y!=height) {
72 /* TODO: not sure this is really needed, but distortion coefficients are
73 calculated using camera resolution, so if image with other resolution
74 is passed to undistortion node, it'll be undistorted correct (but quality can hurt)
75 This is also needed to deal when camera pixel aspect isn't 1. Problems in this case
76 are caused because of how aspect x/y are calculating. Currently. projeciton
77 matrices and reconstruction stuff are supposing that aspect x is always 1 and
78 aspect y is less than 1 (if x resolution is larger than y resolution) */
80 IMB_scaleImBuf(ibuf, width, height);
84 obuf= BKE_tracking_undistort(&clip->tracking, ibuf);
87 IMB_scaleImBuf(obuf, cbuf->x, cbuf->y);
89 stackbuf->rect= obuf->rect_float;
92 obuf->mall&= ~IB_rectfloat;
93 obuf->rect_float= NULL;
99 /* pass on output and free */
100 out[0]->data= stackbuf;
102 if(cbuf!=in[0]->data)
107 void register_node_type_cmp_movieundistort(ListBase *lb)
109 static bNodeType ntype;
111 node_type_base(&ntype, CMP_NODE_MOVIEUNDISTORT, "Movie Undistort", NODE_CLASS_DISTORT, NODE_OPTIONS);
112 node_type_socket_templates(&ntype, cmp_node_movieundistort_in, cmp_node_movieundistort_out);
113 node_type_size(&ntype, 140, 100, 320);
114 node_type_exec(&ntype, node_composit_exec_movieundistort);
116 nodeRegisterType(lb, &ntype);