2
* $Id: CMP_util.h 14352 2008-04-07 15:21:25Z blendix $
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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): none yet.
27
* ***** END GPL LICENSE BLOCK *****
30
#ifndef CMP_NODE_UTILS_H_
31
#define CMP_NODE_UTILS_H_
37
#include "MEM_guardedalloc.h"
39
#include "DNA_camera_types.h" /* qdn: defocus node, need camera info */
40
#include "DNA_action_types.h"
41
#include "DNA_color_types.h"
42
#include "DNA_ipo_types.h"
44
#include "DNA_image_types.h"
45
#include "DNA_material_types.h"
46
#include "DNA_node_types.h"
47
#include "DNA_object_types.h"
48
#include "DNA_scene_types.h"
49
#include "DNA_space_types.h"
50
#include "DNA_screen_types.h"
51
#include "DNA_texture_types.h"
52
#include "DNA_userdef_types.h"
54
#include "BKE_blender.h"
55
#include "BKE_colortools.h"
56
#include "BKE_global.h"
57
#include "BKE_image.h"
59
#include "BKE_material.h"
60
#include "BKE_texture.h"
61
#include "BKE_utildefines.h"
62
#include "BKE_library.h"
63
#include "BKE_object.h"
65
#include "../CMP_node.h"
66
#include "node_util.h"
69
#include "BIF_glutil.h"
70
#include "BIF_interface.h"
71
#include "BIF_interface_icons.h"
72
#include "BIF_language.h"
73
#include "BIF_mywindow.h"
74
#include "BIF_previewrender.h"
75
#include "BIF_resources.h"
76
#include "BIF_screen.h"
77
#include "BIF_space.h"
79
#include "BLI_arithb.h"
80
#include "BLI_blenlib.h"
82
#include "BLI_threads.h"
84
#include "IMB_imbuf_types.h"
85
#include "IMB_imbuf.h"
87
#include "BSE_drawipo.h"
91
#include "RE_pipeline.h"
92
#include "RE_shader_ext.h"
93
#include "RE_render_ext.h"
99
/* *************************** operations support *************************** */
101
/* general signal that's in output sockets, and goes over the wires */
102
typedef struct CompBuf {
104
int x, y, xrad, yrad;
106
rcti disprect; /* cropped part of image */
107
int xof, yof; /* relative to center of target image */
109
void (*rect_procedural)(struct CompBuf *, float *, float, float);
110
float procedural_size[3], procedural_offset[3];
112
bNode *node; /* only in use for procedural bufs */
114
struct CompBuf *next, *prev; /* for pass-on, works nicer than reference counting */
117
/* defines also used for pixel size */
124
/* defines for RGBA channels */
132
CompBuf *alloc_compbuf(int sizex, int sizey, int type, int alloc);
133
CompBuf *dupalloc_compbuf(CompBuf *cbuf);
134
CompBuf *pass_on_compbuf(CompBuf *cbuf);
135
void free_compbuf(CompBuf *cbuf);
136
void print_compbuf(char *str, CompBuf *cbuf);
137
void node_compo_pass_on(struct bNode *node, struct bNodeStack **nsin, struct bNodeStack **nsout);
139
CompBuf *get_cropped_compbuf(rcti *drect, float *rectf, int rectx, int recty, int type);
140
CompBuf *scalefast_compbuf(CompBuf *inbuf, int newx, int newy);
141
CompBuf *typecheck_compbuf(CompBuf *inbuf, int type);
142
void typecheck_compbuf_color(float *out, float *in, int outtype, int intype);
143
float *compbuf_get_pixel(CompBuf *cbuf, float *rectf, int x, int y, int xrad, int yrad);
145
/* **************************************************** */
147
/* Pixel-to-Pixel operation, 1 Image in, 1 out */
148
void composit1_pixel_processor(bNode *node, CompBuf *out, CompBuf *src_buf, float *src_col,
149
void (*func)(bNode *, float *, float *),
151
/* Pixel-to-Pixel operation, 2 Images in, 1 out */
152
void composit2_pixel_processor(bNode *node, CompBuf *out, CompBuf *src_buf, float *src_col,
153
CompBuf *fac_buf, float *fac, void (*func)(bNode *, float *, float *, float *),
154
int src_type, int fac_type);
156
/* Pixel-to-Pixel operation, 3 Images in, 1 out */
157
void composit3_pixel_processor(bNode *node, CompBuf *out, CompBuf *src1_buf, float *src1_col, CompBuf *src2_buf, float *src2_col,
158
CompBuf *fac_buf, float *fac, void (*func)(bNode *, float *, float *, float *, float *),
159
int src1_type, int src2_type, int fac_type);
161
/* Pixel-to-Pixel operation, 4 Images in, 1 out */
162
void composit4_pixel_processor(bNode *node, CompBuf *out, CompBuf *src1_buf, float *src1_col, CompBuf *fac1_buf, float *fac1,
163
CompBuf *src2_buf, float *src2_col, CompBuf *fac2_buf, float *fac2,
164
void (*func)(bNode *, float *, float *, float *, float *, float *),
165
int src1_type, int fac1_type, int src2_type, int fac2_type);
167
CompBuf *valbuf_from_rgbabuf(CompBuf *cbuf, int channel);
168
void generate_preview(bNode *node, CompBuf *stackbuf);
170
void do_copy_rgba(bNode *node, float *out, float *in);
171
void do_copy_rgb(bNode *node, float *out, float *in);
172
void do_copy_value(bNode *node, float *out, float *in);
173
void do_copy_a_rgba(bNode *node, float *out, float *in, float *fac);
175
void do_rgba_to_yuva(bNode *node, float *out, float *in);
176
void do_rgba_to_hsva(bNode *node, float *out, float *in);
177
void do_rgba_to_ycca(bNode *node, float *out, float *in);
178
void do_yuva_to_rgba(bNode *node, float *out, float *in);
179
void do_hsva_to_rgba(bNode *node, float *out, float *in);
180
void do_ycca_to_rgba(bNode *node, float *out, float *in);
182
void gamma_correct_compbuf(CompBuf *img, int inversed);
183
void premul_compbuf(CompBuf *img, int inversed);
184
void convolve(CompBuf* dst, CompBuf* in1, CompBuf* in2);
186
extern void node_ID_title_cb(void *node_v, void *unused_v);
189
/* utility functions used by glare, tonemap and lense distortion */
190
/* soms macros for color handling */
191
typedef float fRGB[4];
193
#define fRGB_clear(c) { c[0]=c[1]=c[2]=0.f; }
195
#define fRGB_copy(c1, c2) { c1[0]=c2[0]; c1[1]=c2[1]; c1[2]=c2[2]; }
197
#define fRGB_add(c1, c2) { c1[0]+=c2[0]; c1[1]+=c2[1]; c1[2]+=c2[2]; }
198
/* subtract c2 from c1 */
199
#define fRGB_sub(c1, c2) { c1[0]-=c2[0]; c1[1]-=c2[1]; c1[2]-=c2[2]; }
200
/* multiply c by float value s */
201
#define fRGB_mult(c, s) { c[0]*=s; c[1]*=s; c[2]*=s; }
202
/* multiply c2 by s and add to c1 */
203
#define fRGB_madd(c1, c2, s) { c1[0]+=c2[0]*s; c1[1]+=c2[1]*s; c1[2]+=c2[2]*s; }
204
/* multiply c2 by color c1 */
205
#define fRGB_colormult(c, cs) { c[0]*=cs[0]; c[1]*=cs[1]; c[2]*=cs[2]; }
206
/* multiply c2 by color c3 and add to c1 */
207
#define fRGB_colormadd(c1, c2, c3) { c1[0]+=c2[0]*c3[0]; c1[1]+=c2[1]*c3[1]; c1[2]+=c2[2]*c3[2]; }
208
/* multiply c2 by color rgb, rgb as separate arguments */
209
#define fRGB_rgbmult(c, r, g, b) { c[0]*=(r); c[1]*=(g); c[2]*=(b); }
210
/* swap colors c1 & c2 */
211
#define fRGB_swap(c1, c2) { float _t=c1[0]; c1[0]=c2[0]; c2[0]=_t;\
212
_t=c1[1]; c1[1]=c2[1]; c2[1]=_t;\
213
_t=c1[2]; c1[2]=c2[2]; c2[2]=_t; }
215
void qd_getPixel(CompBuf* src, int x, int y, float* col);
216
void qd_setPixel(CompBuf* src, int x, int y, float* col);
217
void qd_addPixel(CompBuf* src, int x, int y, float* col);
218
void qd_multPixel(CompBuf* src, int x, int y, float f);
219
void qd_getPixelLerpWrap(CompBuf* src, float u, float v, float* col);
220
void qd_getPixelLerp(CompBuf* src, float u, float v, float* col);
221
void qd_getPixelLerpChan(CompBuf* src, float u, float v, int chan, float* out);
222
CompBuf* qd_downScaledCopy(CompBuf* src, int scale);
223
void IIR_gauss(CompBuf* src, float sigma, int chan, int xy);
224
/* end utility funcs */