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 #ifndef NODE_COMPOSITE_UTIL_H_ 00034 #define NODE_COMPOSITE_UTIL_H_ 00035 00036 #include <stdlib.h> 00037 #include <string.h> 00038 #include <math.h> 00039 00040 #include "MEM_guardedalloc.h" 00041 00042 #include "DNA_camera_types.h" /* qdn: defocus node, need camera info */ 00043 #include "DNA_color_types.h" 00044 #include "DNA_ID.h" 00045 #include "DNA_image_types.h" 00046 #include "DNA_material_types.h" 00047 #include "DNA_movieclip_types.h" 00048 #include "DNA_node_types.h" 00049 #include "DNA_object_types.h" 00050 #include "DNA_scene_types.h" 00051 #include "DNA_texture_types.h" 00052 00053 #include "BLI_math.h" 00054 #include "BLI_blenlib.h" 00055 #include "BLI_rand.h" 00056 #include "BLI_threads.h" 00057 #include "BLI_utildefines.h" 00058 #include "BLI_utildefines.h" 00059 00060 #include "BKE_blender.h" 00061 #include "BKE_camera.h" 00062 #include "BKE_colortools.h" 00063 #include "BKE_global.h" 00064 #include "BKE_image.h" 00065 #include "BKE_main.h" 00066 #include "BKE_material.h" 00067 #include "BKE_movieclip.h" 00068 #include "BKE_node.h" 00069 #include "BKE_texture.h" 00070 #include "BKE_tracking.h" 00071 00072 #include "BKE_library.h" 00073 #include "BKE_object.h" 00074 00075 #include "node_util.h" 00076 00077 #include "IMB_imbuf_types.h" 00078 #include "IMB_imbuf.h" 00079 00080 #include "RE_pipeline.h" 00081 #include "RE_shader_ext.h" 00082 #include "RE_render_ext.h" 00083 00084 /* only for forward declarations */ 00085 #include "NOD_composite.h" 00086 00087 00088 /* *************************** operations support *************************** */ 00089 00090 /* general signal that's in output sockets, and goes over the wires */ 00091 typedef struct CompBuf { 00092 float *rect; 00093 int x, y, xrad, yrad; 00094 short type, malloc; 00095 rcti disprect; /* cropped part of image */ 00096 int xof, yof; /* relative to center of target image */ 00097 00098 void (*rect_procedural)(struct CompBuf *, float *, float, float); 00099 float procedural_size[3], procedural_offset[3]; 00100 int procedural_type; 00101 bNode *node; /* only in use for procedural bufs */ 00102 00103 struct CompBuf *next, *prev; /* for pass-on, works nicer than reference counting */ 00104 } CompBuf; 00105 00106 /* defines also used for pixel size */ 00107 #define CB_RGBA 4 00108 #define CB_VEC4 4 00109 #define CB_VEC3 3 00110 #define CB_VEC2 2 00111 #define CB_VAL 1 00112 00113 /* defines for RGBA channels */ 00114 #define CHAN_R 0 00115 #define CHAN_G 1 00116 #define CHAN_B 2 00117 #define CHAN_A 3 00118 00119 00120 00121 CompBuf *alloc_compbuf(int sizex, int sizey, int type, int alloc); 00122 CompBuf *dupalloc_compbuf(CompBuf *cbuf); 00123 CompBuf *pass_on_compbuf(CompBuf *cbuf); 00124 void free_compbuf(CompBuf *cbuf); 00125 void print_compbuf(char *str, CompBuf *cbuf); 00126 void compbuf_set_node(struct CompBuf *cbuf, struct bNode *node); 00127 void node_compo_pass_on(void *data, int thread, struct bNode *node, void *nodedata, struct bNodeStack **in, struct bNodeStack **out); 00128 00129 CompBuf *get_cropped_compbuf(rcti *drect, float *rectf, int rectx, int recty, int type); 00130 CompBuf *scalefast_compbuf(CompBuf *inbuf, int newx, int newy); 00131 CompBuf *typecheck_compbuf(CompBuf *inbuf, int type); 00132 void typecheck_compbuf_color(float *out, float *in, int outtype, int intype); 00133 00134 /* **************************************************** */ 00135 00136 float *compbuf_get_pixel(CompBuf *cbuf, float *defcol, float *use, int x, int y, int xrad, int yrad); 00137 00138 /* Pixel-to-Pixel operation, 1 Image in, 1 out */ 00139 void composit1_pixel_processor(bNode *node, CompBuf *out, CompBuf *src_buf, float *src_col, 00140 void (*func)(bNode *, float *, float *), 00141 int src_type); 00142 /* Pixel-to-Pixel operation, 2 Images in, 1 out */ 00143 void composit2_pixel_processor(bNode *node, CompBuf *out, CompBuf *src_buf, float *src_col, 00144 CompBuf *fac_buf, float *fac, void (*func)(bNode *, float *, float *, float *), 00145 int src_type, int fac_type); 00146 00147 /* Pixel-to-Pixel operation, 3 Images in, 1 out */ 00148 void composit3_pixel_processor(bNode *node, CompBuf *out, CompBuf *src1_buf, float *src1_col, CompBuf *src2_buf, float *src2_col, 00149 CompBuf *fac_buf, float *fac, void (*func)(bNode *, float *, float *, float *, float *), 00150 int src1_type, int src2_type, int fac_type); 00151 00152 /* Pixel-to-Pixel operation, 4 Images in, 1 out */ 00153 void composit4_pixel_processor(bNode *node, CompBuf *out, CompBuf *src1_buf, float *src1_col, CompBuf *fac1_buf, float *fac1, 00154 CompBuf *src2_buf, float *src2_col, CompBuf *fac2_buf, float *fac2, 00155 void (*func)(bNode *, float *, float *, float *, float *, float *), 00156 int src1_type, int fac1_type, int src2_type, int fac2_type); 00157 00158 CompBuf *valbuf_from_rgbabuf(CompBuf *cbuf, int channel); 00159 void generate_preview(void *data, bNode *node, CompBuf *stackbuf); 00160 00161 void do_copy_rgba(bNode *node, float *out, float *in); 00162 void do_copy_rgb(bNode *node, float *out, float *in); 00163 void do_copy_value(bNode *node, float *out, float *in); 00164 void do_copy_a_rgba(bNode *node, float *out, float *in, float *fac); 00165 00166 void do_rgba_to_yuva(bNode *node, float *out, float *in); 00167 void do_rgba_to_hsva(bNode *node, float *out, float *in); 00168 void do_rgba_to_ycca(bNode *node, float *out, float *in); 00169 void do_yuva_to_rgba(bNode *node, float *out, float *in); 00170 void do_hsva_to_rgba(bNode *node, float *out, float *in); 00171 void do_ycca_to_rgba(bNode *node, float *out, float *in); 00172 00173 void gamma_correct_compbuf(CompBuf *img, int inversed); 00174 void premul_compbuf(CompBuf *img, int inversed); 00175 void convolve(CompBuf* dst, CompBuf* in1, CompBuf* in2); 00176 00177 extern void node_ID_title_cb(void *node_v, void *unused_v); 00178 00179 00180 /* utility functions used by glare, tonemap and lens distortion */ 00181 /* soms macros for color handling */ 00182 typedef float fRGB[4]; 00183 /* clear color */ 00184 #define fRGB_clear(c) { c[0]=c[1]=c[2]=0.f; } 00185 /* copy c2 to c1 */ 00186 #define fRGB_copy(c1, c2) { c1[0]=c2[0]; c1[1]=c2[1]; c1[2]=c2[2]; c1[3]=c2[3]; } 00187 /* add c2 to c1 */ 00188 #define fRGB_add(c1, c2) { c1[0]+=c2[0]; c1[1]+=c2[1]; c1[2]+=c2[2]; } 00189 /* subtract c2 from c1 */ 00190 #define fRGB_sub(c1, c2) { c1[0]-=c2[0]; c1[1]-=c2[1]; c1[2]-=c2[2]; } 00191 /* multiply c by float value s */ 00192 #define fRGB_mult(c, s) { c[0]*=s; c[1]*=s; c[2]*=s; } 00193 /* multiply c2 by s and add to c1 */ 00194 #define fRGB_madd(c1, c2, s) { c1[0]+=c2[0]*s; c1[1]+=c2[1]*s; c1[2]+=c2[2]*s; } 00195 /* multiply c2 by color c1 */ 00196 #define fRGB_colormult(c, cs) { c[0]*=cs[0]; c[1]*=cs[1]; c[2]*=cs[2]; } 00197 /* multiply c2 by color c3 and add to c1 */ 00198 #define fRGB_colormadd(c1, c2, c3) { c1[0]+=c2[0]*c3[0]; c1[1]+=c2[1]*c3[1]; c1[2]+=c2[2]*c3[2]; } 00199 /* multiply c2 by color rgb, rgb as separate arguments */ 00200 #define fRGB_rgbmult(c, r, g, b) { c[0]*=(r); c[1]*=(g); c[2]*=(b); } 00201 /* swap colors c1 & c2 */ 00202 #define fRGB_swap(c1, c2) { float _t=c1[0]; c1[0]=c2[0]; c2[0]=_t;\ 00203 _t=c1[1]; c1[1]=c2[1]; c2[1]=_t;\ 00204 _t=c1[2]; c1[2]=c2[2]; c2[2]=_t;\ 00205 _t=c1[3]; c1[3]=c2[3]; c3[3]=_t;} 00206 00207 void qd_getPixel(CompBuf* src, int x, int y, float* col); 00208 void qd_setPixel(CompBuf* src, int x, int y, float* col); 00209 void qd_addPixel(CompBuf* src, int x, int y, float* col); 00210 void qd_multPixel(CompBuf* src, int x, int y, float f); 00211 void qd_getPixelLerpWrap(CompBuf* src, float u, float v, float* col); 00212 void qd_getPixelLerp(CompBuf* src, float u, float v, float* col); 00213 void qd_getPixelLerpChan(CompBuf* src, float u, float v, int chan, float* out); 00214 CompBuf* qd_downScaledCopy(CompBuf* src, int scale); 00215 void IIR_gauss(CompBuf* src, float sigma, int chan, int xy); 00216 /* end utility funcs */ 00217 00218 /* transformations */ 00219 00220 #define CMP_SCALE_MAX 12000 00221 00222 CompBuf* node_composit_transform(CompBuf *cbuf, float x, float y, float angle, float scale, int filter_type); 00223 float *node_composit_get_float_buffer(RenderData *rd, ImBuf *ibuf, int *alloc); 00224 00225 #endif