2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2006 Blender Foundation.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): none yet.
25 * ***** END GPL LICENSE BLOCK *****
28 /** \file blender/nodes/composite/node_composite_util.h
33 #ifndef __NODE_COMPOSITE_UTIL_H__
34 #define __NODE_COMPOSITE_UTIL_H__
40 #include "MEM_guardedalloc.h"
42 #include "DNA_camera_types.h" /* qdn: defocus node, need camera info */
43 #include "DNA_color_types.h"
45 #include "DNA_image_types.h"
46 #include "DNA_material_types.h"
47 #include "DNA_movieclip_types.h"
48 #include "DNA_node_types.h"
49 #include "DNA_object_types.h"
50 #include "DNA_scene_types.h"
51 #include "DNA_texture_types.h"
54 #include "BLI_blenlib.h"
56 #include "BLI_threads.h"
57 #include "BLI_utildefines.h"
58 #include "BLI_utildefines.h"
60 #include "BLF_translation.h"
62 #include "BKE_blender.h"
63 #include "BKE_camera.h"
64 #include "BKE_colortools.h"
65 #include "BKE_global.h"
66 #include "BKE_image.h"
68 #include "BKE_material.h"
69 #include "BKE_movieclip.h"
71 #include "BKE_texture.h"
72 #include "BKE_tracking.h"
74 #include "BKE_library.h"
75 #include "BKE_object.h"
77 #include "node_util.h"
79 #include "IMB_imbuf_types.h"
80 #include "IMB_imbuf.h"
82 #include "RE_pipeline.h"
83 #include "RE_shader_ext.h"
84 #include "RE_render_ext.h"
86 /* only for forward declarations */
87 #include "NOD_composite.h"
90 /* *************************** operations support *************************** */
92 /* general signal that's in output sockets, and goes over the wires */
93 typedef struct CompBuf {
97 rcti disprect; /* cropped part of image */
98 int xof, yof; /* relative to center of target image */
100 void (*rect_procedural)(struct CompBuf *, float *, float, float);
101 float procedural_size[3], procedural_offset[3];
103 bNode *node; /* only in use for procedural bufs */
105 struct CompBuf *next, *prev; /* for pass-on, works nicer than reference counting */
108 /* defines also used for pixel size */
115 /* defines for RGBA channels */
123 CompBuf *alloc_compbuf(int sizex, int sizey, int type, int alloc);
124 CompBuf *dupalloc_compbuf(CompBuf *cbuf);
125 CompBuf *pass_on_compbuf(CompBuf *cbuf);
126 void free_compbuf(CompBuf *cbuf);
127 void print_compbuf(char *str, CompBuf *cbuf);
128 void compbuf_set_node(struct CompBuf *cbuf, struct bNode *node);
130 CompBuf *get_cropped_compbuf(rcti *drect, float *rectf, int rectx, int recty, int type);
131 CompBuf *scalefast_compbuf(CompBuf *inbuf, int newx, int newy);
132 CompBuf *typecheck_compbuf(CompBuf *inbuf, int type);
133 void typecheck_compbuf_color(float *out, float *in, int outtype, int intype);
135 /* **************************************************** */
137 float *compbuf_get_pixel(CompBuf *cbuf, float *defcol, float *use, int x, int y, int xrad, int yrad);
139 /* Pixel-to-Pixel operation, 1 Image in, 1 out */
140 void composit1_pixel_processor(bNode *node, CompBuf *out, CompBuf *src_buf, float *src_col,
141 void (*func)(bNode *, float *, float *),
143 /* Pixel-to-Pixel operation, 2 Images in, 1 out */
144 void composit2_pixel_processor(bNode *node, CompBuf *out, CompBuf *src_buf, float *src_col,
145 CompBuf *fac_buf, float *fac, void (*func)(bNode *, float *, float *, float *),
146 int src_type, int fac_type);
148 /* Pixel-to-Pixel operation, 3 Images in, 1 out */
149 void composit3_pixel_processor(bNode *node, CompBuf *out, CompBuf *src1_buf, float *src1_col, CompBuf *src2_buf, float *src2_col,
150 CompBuf *fac_buf, float *fac, void (*func)(bNode *, float *, float *, float *, float *),
151 int src1_type, int src2_type, int fac_type);
153 /* Pixel-to-Pixel operation, 4 Images in, 1 out */
154 void composit4_pixel_processor(bNode *node, CompBuf *out, CompBuf *src1_buf, float *src1_col, CompBuf *fac1_buf, float *fac1,
155 CompBuf *src2_buf, float *src2_col, CompBuf *fac2_buf, float *fac2,
156 void (*func)(bNode *, float *, float *, float *, float *, float *),
157 int src1_type, int fac1_type, int src2_type, int fac2_type);
159 CompBuf *valbuf_from_rgbabuf(CompBuf *cbuf, int channel);
160 void valbuf_to_rgbabuf(CompBuf *valbuf, CompBuf *cbuf, int channel);
161 void generate_preview(void *data, bNode *node, CompBuf *stackbuf);
163 void do_copy_rgba(bNode *node, float *out, float *in);
164 void do_copy_rgb(bNode *node, float *out, float *in);
165 void do_copy_value(bNode *node, float *out, float *in);
166 void do_copy_a_rgba(bNode *node, float *out, float *in, float *fac);
168 void do_rgba_to_yuva(bNode *node, float *out, float *in);
169 void do_rgba_to_hsva(bNode *node, float *out, float *in);
170 void do_rgba_to_ycca(bNode *node, float *out, float *in);
171 void do_yuva_to_rgba(bNode *node, float *out, float *in);
172 void do_hsva_to_rgba(bNode *node, float *out, float *in);
173 void do_ycca_to_rgba(bNode *node, float *out, float *in);
175 void gamma_correct_compbuf(CompBuf *img, int inversed);
176 void premul_compbuf(CompBuf *img, int inversed);
177 void convolve(CompBuf* dst, CompBuf* in1, CompBuf* in2);
179 extern void node_ID_title_cb(void *node_v, void *unused_v);
182 /* utility functions used by glare, tonemap and lens distortion */
183 /* soms macros for color handling */
184 typedef float fRGB[4];
186 #define fRGB_clear(c) { c[0]=c[1]=c[2]=0.f; } (void)0
188 #define fRGB_copy(c1, c2) { c1[0]=c2[0]; c1[1]=c2[1]; c1[2]=c2[2]; c1[3]=c2[3]; } (void)0
190 #define fRGB_add(c1, c2) { c1[0]+=c2[0]; c1[1]+=c2[1]; c1[2]+=c2[2]; } (void)0
191 /* subtract c2 from c1 */
192 #define fRGB_sub(c1, c2) { c1[0]-=c2[0]; c1[1]-=c2[1]; c1[2]-=c2[2]; } (void)0
193 /* multiply c by float value s */
194 #define fRGB_mult(c, s) { c[0]*=s; c[1]*=s; c[2]*=s; } (void)0
195 /* multiply c2 by s and add to c1 */
196 #define fRGB_madd(c1, c2, s) { c1[0]+=c2[0]*s; c1[1]+=c2[1]*s; c1[2]+=c2[2]*s; } (void)0
197 /* multiply c2 by color c1 */
198 #define fRGB_colormult(c, cs) { c[0]*=cs[0]; c[1]*=cs[1]; c[2]*=cs[2]; } (void)0
199 /* multiply c2 by color c3 and add to c1 */
200 #define fRGB_colormadd(c1, c2, c3) { c1[0]+=c2[0]*c3[0]; c1[1]+=c2[1]*c3[1]; c1[2]+=c2[2]*c3[2]; } (void)0
201 /* multiply c2 by color rgb, rgb as separate arguments */
202 #define fRGB_rgbmult(c, r, g, b) { c[0]*=(r); c[1]*=(g); c[2]*=(b); } (void)0
203 /* swap colors c1 & c2 */
204 #define fRGB_swap(c1, c2) { float _t=c1[0]; c1[0]=c2[0]; c2[0]=_t;\
205 _t=c1[1]; c1[1]=c2[1]; c2[1]=_t;\
206 _t=c1[2]; c1[2]=c2[2]; c2[2]=_t;\
207 _t=c1[3]; c1[3]=c2[3]; c3[3]=_t;\
210 void qd_getPixel(CompBuf* src, int x, int y, float* col);
211 void qd_setPixel(CompBuf* src, int x, int y, float* col);
212 void qd_addPixel(CompBuf* src, int x, int y, float* col);
213 void qd_multPixel(CompBuf* src, int x, int y, float f);
214 void qd_getPixelLerpWrap(CompBuf* src, float u, float v, float* col);
215 void qd_getPixelLerp(CompBuf* src, float u, float v, float* col);
216 void qd_getPixelLerpChan(CompBuf* src, float u, float v, int chan, float* out);
217 CompBuf* qd_downScaledCopy(CompBuf* src, int scale);
218 void IIR_gauss(CompBuf* src, float sigma, int chan, int xy);
219 /* end utility funcs */
221 /* transformations */
223 #define CMP_SCALE_MAX 12000
225 CompBuf* node_composit_transform(CompBuf *cbuf, float x, float y, float angle, float scale, int filter_type);
226 void node_composit_blur_single_image(bNode *node, int filtertype, int sizex, int sizey, CompBuf *new, CompBuf *img, float scale);
227 void node_composite_morpho_dilate(CompBuf *cbuf);
228 void node_composite_morpho_erode(CompBuf *cbuf);
229 float *node_composit_get_float_buffer(RenderData *rd, ImBuf *ibuf, int *alloc);