Blender  V2.59
CMP_util.h
Go to the documentation of this file.
00001 /*
00002  * $Id: CMP_util.h 35237 2011-02-27 20:13:22Z jesterking $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version. 
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2006 Blender Foundation.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029 
00035 #ifndef CMP_NODE_UTILS_H_
00036 #define CMP_NODE_UTILS_H_
00037 
00038 #include <stdlib.h>
00039 #include <string.h>
00040 #include <math.h>
00041 
00042 #include "MEM_guardedalloc.h"
00043 
00044 #include "DNA_camera_types.h" /* qdn: defocus node, need camera info */
00045 #include "DNA_color_types.h"
00046 #include "DNA_ID.h"
00047 #include "DNA_image_types.h"
00048 #include "DNA_material_types.h"
00049 #include "DNA_node_types.h"
00050 #include "DNA_object_types.h"
00051 #include "DNA_scene_types.h"
00052 #include "DNA_texture_types.h"
00053 
00054 #include "BLI_math.h"
00055 #include "BLI_blenlib.h"
00056 #include "BLI_rand.h"
00057 #include "BLI_threads.h"
00058 #include "BLI_utildefines.h"
00059 #include "BLI_utildefines.h"
00060 
00061 #include "BKE_blender.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_node.h"
00068 #include "BKE_texture.h"
00069 
00070 #include "BKE_library.h"
00071 #include "BKE_object.h"
00072 
00073 #include "../CMP_node.h"
00074 #include "node_util.h"
00075 
00076 #include "IMB_imbuf_types.h"
00077 #include "IMB_imbuf.h"
00078 
00079 #include "RE_pipeline.h"
00080 #include "RE_shader_ext.h"
00081 #include "RE_render_ext.h"
00082 
00083 /* *************************** operations support *************************** */
00084 
00085 /* general signal that's in output sockets, and goes over the wires */
00086 typedef struct CompBuf {
00087         float *rect;
00088         int x, y, xrad, yrad;
00089         short type, malloc;
00090         rcti disprect;          /* cropped part of image */
00091         int xof, yof;           /* relative to center of target image */
00092         
00093         void (*rect_procedural)(struct CompBuf *, float *, float, float);
00094         float procedural_size[3], procedural_offset[3];
00095         int procedural_type;
00096         bNode *node;            /* only in use for procedural bufs */
00097         
00098         struct CompBuf *next, *prev;    /* for pass-on, works nicer than reference counting */
00099 } CompBuf;
00100 
00101 /* defines also used for pixel size */
00102 #define CB_RGBA         4
00103 #define CB_VEC4         4
00104 #define CB_VEC3         3
00105 #define CB_VEC2         2
00106 #define CB_VAL          1
00107 
00108 /* defines for RGBA channels */
00109 #define CHAN_R  0
00110 #define CHAN_G  1
00111 #define CHAN_B  2
00112 #define CHAN_A  3
00113 
00114 
00115 
00116 CompBuf *alloc_compbuf(int sizex, int sizey, int type, int alloc);
00117 CompBuf *dupalloc_compbuf(CompBuf *cbuf);
00118 CompBuf *pass_on_compbuf(CompBuf *cbuf);
00119 void free_compbuf(CompBuf *cbuf);
00120 void print_compbuf(char *str, CompBuf *cbuf);
00121 void compbuf_set_node(struct CompBuf *cbuf, struct bNode *node);
00122 void node_compo_pass_on(struct bNode *node, struct bNodeStack **nsin, struct bNodeStack **nsout);
00123 
00124 CompBuf *get_cropped_compbuf(rcti *drect, float *rectf, int rectx, int recty, int type);
00125 CompBuf *scalefast_compbuf(CompBuf *inbuf, int newx, int newy);
00126 CompBuf *typecheck_compbuf(CompBuf *inbuf, int type);
00127 void typecheck_compbuf_color(float *out, float *in, int outtype, int intype);
00128 
00129 /* **************************************************** */
00130 
00131 /* Pixel-to-Pixel operation, 1 Image in, 1 out */
00132 void composit1_pixel_processor(bNode *node, CompBuf *out, CompBuf *src_buf, float *src_col,
00133                                                                           void (*func)(bNode *, float *, float *), 
00134                                                                           int src_type);
00135 /* Pixel-to-Pixel operation, 2 Images in, 1 out */
00136 void composit2_pixel_processor(bNode *node, CompBuf *out, CompBuf *src_buf, float *src_col,
00137                                                                           CompBuf *fac_buf, float *fac, void (*func)(bNode *, float *, float *, float *), 
00138                                                                           int src_type, int fac_type);
00139 
00140 /* Pixel-to-Pixel operation, 3 Images in, 1 out */
00141 void composit3_pixel_processor(bNode *node, CompBuf *out, CompBuf *src1_buf, float *src1_col, CompBuf *src2_buf, float *src2_col, 
00142                                                                           CompBuf *fac_buf, float *fac, void (*func)(bNode *, float *, float *, float *, float *), 
00143                                                                           int src1_type, int src2_type, int fac_type);
00144 
00145 /* Pixel-to-Pixel operation, 4 Images in, 1 out */
00146 void composit4_pixel_processor(bNode *node, CompBuf *out, CompBuf *src1_buf, float *src1_col, CompBuf *fac1_buf, float *fac1, 
00147                                                                           CompBuf *src2_buf, float *src2_col, CompBuf *fac2_buf, float *fac2, 
00148                                                                           void (*func)(bNode *, float *, float *, float *, float *, float *), 
00149                                                                           int src1_type, int fac1_type, int src2_type, int fac2_type);
00150 
00151 CompBuf *valbuf_from_rgbabuf(CompBuf *cbuf, int channel);
00152 void generate_preview(void *data, bNode *node, CompBuf *stackbuf);
00153 
00154 void do_copy_rgba(bNode *node, float *out, float *in);
00155 void do_copy_rgb(bNode *node, float *out, float *in);
00156 void do_copy_value(bNode *node, float *out, float *in);
00157 void do_copy_a_rgba(bNode *node, float *out, float *in, float *fac);
00158 
00159 void do_rgba_to_yuva(bNode *node, float *out, float *in);
00160 void do_rgba_to_hsva(bNode *node, float *out, float *in);
00161 void do_rgba_to_ycca(bNode *node, float *out, float *in);
00162 void do_yuva_to_rgba(bNode *node, float *out, float *in);
00163 void do_hsva_to_rgba(bNode *node, float *out, float *in);
00164 void do_ycca_to_rgba(bNode *node, float *out, float *in);
00165 
00166 void gamma_correct_compbuf(CompBuf *img, int inversed);
00167 void premul_compbuf(CompBuf *img, int inversed);
00168 void convolve(CompBuf* dst, CompBuf* in1, CompBuf* in2);
00169 
00170 extern void node_ID_title_cb(void *node_v, void *unused_v);
00171 
00172 
00173 /* utility functions used by glare, tonemap and lens distortion */
00174 /* soms macros for color handling */
00175 typedef float fRGB[4];
00176 /* clear color */
00177 #define fRGB_clear(c) { c[0]=c[1]=c[2]=0.f; }
00178 /* copy c2 to c1 */
00179 #define fRGB_copy(c1, c2) { c1[0]=c2[0];  c1[1]=c2[1];  c1[2]=c2[2]; c1[3]=c2[3]; }
00180 /* add c2 to c1 */
00181 #define fRGB_add(c1, c2) { c1[0]+=c2[0];  c1[1]+=c2[1];  c1[2]+=c2[2]; }
00182 /* subtract c2 from c1 */
00183 #define fRGB_sub(c1, c2) { c1[0]-=c2[0];  c1[1]-=c2[1];  c1[2]-=c2[2]; }
00184 /* multiply c by float value s */
00185 #define fRGB_mult(c, s) { c[0]*=s;  c[1]*=s;  c[2]*=s; }
00186 /* multiply c2 by s and add to c1 */
00187 #define fRGB_madd(c1, c2, s) { c1[0]+=c2[0]*s;  c1[1]+=c2[1]*s;  c1[2]+=c2[2]*s; }
00188 /* multiply c2 by color c1 */
00189 #define fRGB_colormult(c, cs) { c[0]*=cs[0];  c[1]*=cs[1];  c[2]*=cs[2]; }
00190 /* multiply c2 by color c3 and add to c1 */
00191 #define fRGB_colormadd(c1, c2, c3) { c1[0]+=c2[0]*c3[0];  c1[1]+=c2[1]*c3[1];  c1[2]+=c2[2]*c3[2]; }
00192 /* multiply c2 by color rgb, rgb as separate arguments */
00193 #define fRGB_rgbmult(c, r, g, b) { c[0]*=(r);  c[1]*=(g);  c[2]*=(b); }
00194 /* swap colors c1 & c2 */
00195 #define fRGB_swap(c1, c2) { float _t=c1[0];  c1[0]=c2[0];  c2[0]=_t;\
00196                                                                   _t=c1[1];  c1[1]=c2[1];  c2[1]=_t;\
00197                                                                   _t=c1[2];  c1[2]=c2[2];  c2[2]=_t;\
00198                                                                   _t=c1[3];  c1[3]=c2[3];  c3[3]=_t;}
00199 
00200 void qd_getPixel(CompBuf* src, int x, int y, float* col);
00201 void qd_setPixel(CompBuf* src, int x, int y, float* col);
00202 void qd_addPixel(CompBuf* src, int x, int y, float* col);
00203 void qd_multPixel(CompBuf* src, int x, int y, float f);
00204 void qd_getPixelLerpWrap(CompBuf* src, float u, float v, float* col);
00205 void qd_getPixelLerp(CompBuf* src, float u, float v, float* col);
00206 void qd_getPixelLerpChan(CompBuf* src, float u, float v, int chan, float* out);
00207 CompBuf* qd_downScaledCopy(CompBuf* src, int scale);
00208 void IIR_gauss(CompBuf* src, float sigma, int chan, int xy);
00209 /* end utility funcs */
00210 
00211 #endif