Node Bugfixes:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 7 Oct 2009 22:05:30 +0000 (22:05 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 7 Oct 2009 22:05:30 +0000 (22:05 +0000)
* Compo node backdrop works again.
* Compo node previews and backdrop now get correct color management
  float to byte conversion.
* Compo nodes got unecessarily recalculated while moving nodes.
* Fix compo node viewer nodes not getting activated correctly.
* Main compo node preview render computations are now outside of
  mutex lock, so better for multithreading.
* Tex node outputs did not work in some files loaded from 2.4.
* Change RNA updates to take into account groups that may be shared
  between multiple node trees.

30 files changed:
source/blender/blenkernel/intern/node.c
source/blender/editors/include/ED_node.h
source/blender/editors/space_node/drawnode.c
source/blender/editors/space_node/node_draw.c
source/blender/editors/space_node/node_edit.c
source/blender/editors/space_node/node_intern.h
source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/transform/transform.c
source/blender/makesdna/DNA_node_types.h
source/blender/makesrna/intern/rna_nodetree.c
source/blender/nodes/intern/CMP_nodes/CMP_blur.c
source/blender/nodes/intern/CMP_nodes/CMP_channelMatte.c
source/blender/nodes/intern/CMP_nodes/CMP_chromaMatte.c
source/blender/nodes/intern/CMP_nodes/CMP_colorMatte.c
source/blender/nodes/intern/CMP_nodes/CMP_composite.c
source/blender/nodes/intern/CMP_nodes/CMP_diffMatte.c
source/blender/nodes/intern/CMP_nodes/CMP_distanceMatte.c
source/blender/nodes/intern/CMP_nodes/CMP_filter.c
source/blender/nodes/intern/CMP_nodes/CMP_image.c
source/blender/nodes/intern/CMP_nodes/CMP_levels.c
source/blender/nodes/intern/CMP_nodes/CMP_lummaMatte.c
source/blender/nodes/intern/CMP_nodes/CMP_mixrgb.c
source/blender/nodes/intern/CMP_nodes/CMP_outputFile.c
source/blender/nodes/intern/CMP_nodes/CMP_splitViewer.c
source/blender/nodes/intern/CMP_nodes/CMP_texture.c
source/blender/nodes/intern/CMP_nodes/CMP_viewer.c
source/blender/nodes/intern/CMP_util.c
source/blender/nodes/intern/CMP_util.h
source/blender/nodes/intern/TEX_nodes/TEX_output.c
source/blender/nodes/intern/TEX_util.c

index fad866a..1a89de7 100644 (file)
@@ -1246,9 +1246,12 @@ void nodeAddToPreview(bNode *node, float *col, int x, int y)
        if(preview) {
                if(x>=0 && y>=0) {
                        if(x<preview->xsize && y<preview->ysize) {
-                               float *tar= preview->rect+ 4*((preview->xsize*y) + x);
+                               unsigned char *tar= preview->rect+ 4*((preview->xsize*y) + x);
                                //if(tar[0]==0.0f) {
-                               QUATCOPY(tar, col);
+                               tar[0]= FTOCHAR(col[0]);
+                               tar[1]= FTOCHAR(col[1]);
+                               tar[2]= FTOCHAR(col[2]);
+                               tar[3]= FTOCHAR(col[3]);
                                //}
                        }
                        //else printf("prv out bound x y %d %d\n", x, y);
index 305b2a6..667a4ec 100644 (file)
@@ -33,12 +33,13 @@ struct Scene;
 struct Tex;
 struct bContext;
 struct bNode;
+struct ID;
 
 /* drawnode.c */
 void ED_init_node_butfuncs(void);
 
 /* node_draw.c */
-void ED_node_changed_update(struct bContext *C, struct bNode *node);
+void ED_node_changed_update(struct ID *id, struct bNode *node);
 
 /* node_edit.c */
 void ED_node_shader_default(struct Material *ma);
index b8da420..33be0b8 100644 (file)
@@ -89,6 +89,7 @@
 #include "UI_resources.h"
 
 #include "RE_pipeline.h"
+#include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
 
 #include "node_intern.h"
@@ -2106,12 +2107,13 @@ void node_rename_but(char *s)
 
 #endif
 
-void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode)
+void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode, int color_manage)
 {
        
        if((snode->flag & SNODE_BACKDRAW) && snode->treetype==NTREE_COMPOSIT) {
                Image *ima= BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
-               ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
+               void *lock;
+               ImBuf *ibuf= BKE_image_acquire_ibuf(ima, NULL, &lock);
                if(ibuf) {
                        float x, y; 
                        
@@ -2126,13 +2128,21 @@ void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode)
                        x = (ar->winx-ibuf->x)/2 + snode->xof;
                        y = (ar->winy-ibuf->y)/2 + snode->yof;
                        
+                       if(!ibuf->rect) {
+                               if(color_manage)
+                                       ibuf->profile= IB_PROFILE_SRGB;
+                               else
+                                       ibuf->profile = IB_PROFILE_NONE;
+                               IMB_rect_from_float(ibuf);
+                       }
+
                        if(ibuf->rect)
                                glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
-                       else if(ibuf->channels==4)
-                               glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_FLOAT, ibuf->rect_float);
                        
                        wmPopMatrix();
                }
+
+               BKE_image_release_ibuf(ima, lock);
        }
 }
 
index dd2dc0d..2660195 100644 (file)
@@ -95,19 +95,19 @@ extern void ui_dropshadow(rctf *rct, float radius, float aspect, int select);
 extern void gl_round_box(int mode, float minx, float miny, float maxx, float maxy, float rad);
 extern void ui_draw_tria_icon(float x, float y, float aspect, char dir);
 
-void ED_node_changed_update(bContext *C, bNode *node)
+void ED_node_changed_update(ID *id, bNode *node)
 {
-       SpaceNode *snode= CTX_wm_space_node(C);
+       bNodeTree *nodetree, *edittree;
+       int treetype;
 
-       if(!snode)
-               return;
+       node_tree_from_ID(id, &nodetree, &edittree, &treetype);
 
-       if(snode->treetype==NTREE_SHADER) {
-               DAG_id_flush_update(snode->id, 0);
-               WM_event_add_notifier(C, NC_MATERIAL|ND_SHADING, snode->id);
+       if(treetype==NTREE_SHADER) {
+               DAG_id_flush_update(id, 0);
+               WM_main_add_notifier(NC_MATERIAL|ND_SHADING, id);
        }
-       else if(snode->treetype==NTREE_COMPOSIT) {
-               NodeTagChanged(snode->edittree, node);
+       else if(treetype==NTREE_COMPOSIT) {
+               NodeTagChanged(edittree, node);
                /* don't use NodeTagIDChanged, it gives far too many recomposites for image, scene layers, ... */
                        
                /* not the best implementation of the world... but we need it to work now :) */
@@ -122,23 +122,26 @@ void ED_node_changed_update(bContext *C, bNode *node)
                        //addqueue(curarea->win, UI_BUT_EVENT, B_NODE_TREE_EXEC);
                }
                else {
-                       node= node_tree_get_editgroup(snode->nodetree);
+                       node= node_tree_get_editgroup(nodetree);
                        if(node)
-                               NodeTagIDChanged(snode->nodetree, node->id);
+                               NodeTagIDChanged(nodetree, node->id);
                }
-               WM_event_add_notifier(C, NC_SCENE|ND_NODES, CTX_data_scene(C));
+
+               WM_main_add_notifier(NC_SCENE|ND_NODES, id);
        }                       
-       else if(snode->treetype==NTREE_TEXTURE) {
-               DAG_id_flush_update(snode->id, 0);
-               WM_event_add_notifier(C, NC_TEXTURE|ND_NODES, snode->id);
+       else if(treetype==NTREE_TEXTURE) {
+               DAG_id_flush_update(id, 0);
+               WM_main_add_notifier(NC_TEXTURE|ND_NODES, id);
        }
-
 }
 
 static void do_node_internal_buttons(bContext *C, void *node_v, int event)
 {
-       if(event==B_NODE_EXEC)
-               ED_node_changed_update(C, node_v);
+       if(event==B_NODE_EXEC) {
+               SpaceNode *snode= CTX_wm_space_node(C);
+               if(snode && snode->id)
+                       ED_node_changed_update(snode->id, node_v);
+       }
 }
 
 
@@ -648,7 +651,7 @@ static void node_draw_preview(bNodePreview *preview, rctf *prv)
        glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );  /* premul graphics */
        
        glColor4f(1.0, 1.0, 1.0, 1.0);
-       glaDrawPixelsTex(prv->xmin, prv->ymin, preview->xsize, preview->ysize, GL_FLOAT, preview->rect);
+       glaDrawPixelsTex(prv->xmin, prv->ymin, preview->xsize, preview->ysize, GL_UNSIGNED_BYTE, preview->rect);
        
        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
        glDisable(GL_BLEND);
@@ -1075,6 +1078,8 @@ void drawnodespace(const bContext *C, ARegion *ar, View2D *v2d)
        float col[3];
        View2DScrollers *scrollers;
        SpaceNode *snode= CTX_wm_space_node(C);
+       Scene *scene= CTX_data_scene(C);
+       int color_manage = scene->r.color_mgt_flag & R_COLOR_MANAGEMENT;
        
        UI_GetThemeColor3fv(TH_BACK, col);
        glClearColor(col[0], col[1], col[2], 0);
@@ -1094,7 +1099,7 @@ void drawnodespace(const bContext *C, ARegion *ar, View2D *v2d)
 
        UI_view2d_constant_grid_draw(C, v2d);
        /* backdrop */
-       draw_nodespace_back_pix(ar, snode);
+       draw_nodespace_back_pix(ar, snode, color_manage);
        
        /* nodes */
        snode_set_context(snode, CTX_data_scene(C));
index 50a9965..cee90b5 100644 (file)
@@ -62,8 +62,6 @@
 #include "BKE_scene.h"
 #include "BKE_utildefines.h"
 
-#include "ED_render.h"
-
 #include "BIF_gl.h"
 
 #include "BLI_arithb.h"
 
 #include "IMB_imbuf_types.h"
 
-#include "ED_space_api.h"
+#include "ED_node.h"
+#include "ED_render.h"
 #include "ED_screen.h"
+#include "ED_space_api.h"
 #include "ED_transform.h"
 #include "ED_types.h"
 
@@ -581,13 +581,45 @@ void ED_node_texture_default(Tex *tx)
        ntreeSolveOrder(tx->nodetree);  /* needed for pointers */
 }
 
+void node_tree_from_ID(ID *id, bNodeTree **ntree, bNodeTree **edittree, int *treetype)
+{
+       bNode *node;
+       short idtype= GS(id->name);
+
+       if(idtype == ID_MA) {
+               *ntree= ((Material*)id)->nodetree;
+               if(treetype) *treetype= NTREE_SHADER;
+       }
+       else if(idtype == ID_SCE) {
+               *ntree= ((Scene*)id)->nodetree;
+               if(treetype) *treetype= NTREE_COMPOSIT;
+       }
+       else if(idtype == ID_TE) {
+               *ntree= ((Tex*)id)->nodetree;
+               if(treetype) *treetype= NTREE_TEXTURE;
+       }
+
+       /* find editable group */
+       if(edittree) {
+               if(*ntree)
+                       for(node= (*ntree)->nodes.first; node; node= node->next)
+                               if(node->flag & NODE_GROUP_EDIT)
+                                       break;
+               
+               if(node && node->id)
+                       *edittree= (bNodeTree *)node->id;
+               else
+                       *edittree= *ntree;
+       }
+}
+
 /* Here we set the active tree(s), even called for each redraw now, so keep it fast :) */
 void snode_set_context(SpaceNode *snode, Scene *scene)
 {
        Object *ob= OBACT;
-       bNode *node= NULL;
        
        snode->nodetree= NULL;
+       snode->edittree= NULL;
        snode->id= snode->from= NULL;
        
        if(snode->treetype==NTREE_SHADER) {
@@ -597,7 +629,6 @@ void snode_set_context(SpaceNode *snode, Scene *scene)
                        if(ma) {
                                snode->from= &ob->id;
                                snode->id= &ma->id;
-                               snode->nodetree= ma->nodetree;
                        }
                }
        }
@@ -608,8 +639,6 @@ void snode_set_context(SpaceNode *snode, Scene *scene)
                /* bit clumsy but reliable way to see if we draw first time */
                if(snode->nodetree==NULL)
                        ntreeCompositForceHidden(scene->nodetree, scene);
-               
-               snode->nodetree= scene->nodetree;
        }
        else if(snode->treetype==NTREE_TEXTURE) {
                Tex *tx= NULL;
@@ -648,22 +677,11 @@ void snode_set_context(SpaceNode *snode, Scene *scene)
                                tx= mtex->tex;
                }
                
-               if(tx) {
-                       snode->id= &tx->id;
-                       snode->nodetree= tx->nodetree;
-               }
+               snode->id= &tx->id;
        }
-       
-       /* find editable group */
-       if(snode->nodetree)
-               for(node= snode->nodetree->nodes.first; node; node= node->next)
-                       if(node->flag & NODE_GROUP_EDIT)
-                               break;
-       
-       if(node && node->id)
-               snode->edittree= (bNodeTree *)node->id;
-       else
-               snode->edittree= snode->nodetree;
+
+       if(snode->id)
+               node_tree_from_ID(snode->id, &snode->nodetree, &snode->edittree, NULL);
 }
 
 #if 0
@@ -691,15 +709,13 @@ static void node_active_image(Image *ima)
 
 void node_set_active(SpaceNode *snode, bNode *node)
 {
-       
        nodeSetActive(snode->edittree, node);
        
-       #if 0
-       // XXX
        if(node->type!=NODE_GROUP) {
-               
                /* tree specific activate calls */
                if(snode->treetype==NTREE_SHADER) {
+                       // XXX
+#if 0
                        
                        /* when we select a material, active texture is cleared, for buttons */
                        if(node->id && GS(node->id->name)==ID_MA)
@@ -709,8 +725,11 @@ void node_set_active(SpaceNode *snode, bNode *node)
                        
                        // allqueue(REDRAWBUTSSHADING, 1);
                        // allqueue(REDRAWIPO, 0);
+#endif
                }
                else if(snode->treetype==NTREE_COMPOSIT) {
+                       Scene *scene= (Scene*)snode->id;
+
                        /* make active viewer, currently only 1 supported... */
                        if( ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
                                bNode *tnode;
@@ -731,31 +750,37 @@ void node_set_active(SpaceNode *snode, bNode *node)
                                        if(gnode)
                                                NodeTagIDChanged(snode->nodetree, gnode->id);
                                        
-                                       // XXX                  snode_handle_recalc(snode);
+                                       ED_node_changed_update(snode->id, node);
                                }
                                
                                /* addnode() doesnt link this yet... */
                                node->id= (ID *)BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
                        }
                        else if(node->type==CMP_NODE_IMAGE) {
+                               // XXX
+#if 0
                                if(node->id)
                                        node_active_image((Image *)node->id);
+#endif
                        }
                        else if(node->type==CMP_NODE_R_LAYERS) {
-                               if(node->id==NULL || node->id==(ID *)G.scene) {
-                                       G.scene->r.actlay= node->custom1;
+                               if(node->id==NULL || node->id==(ID *)scene) {
+                                       scene->r.actlay= node->custom1;
+                                       // XXX
                                        // allqueue(REDRAWBUTSSCENE, 0);
                                }
                        }
                }
                else if(snode->treetype==NTREE_TEXTURE) {
+                       // XXX
+#if 0
                        if(node->id)
                                ; // XXX BIF_preview_changed(-1);
                        // allqueue(REDRAWBUTSSHADING, 1);
                        // allqueue(REDRAWIPO, 0);
+#endif
                }
        }
-       #endif /* 0 */
 }
 
 /* ***************** Edit Group operator ************* */
index 2a92947..9f28a5e 100644 (file)
@@ -69,9 +69,10 @@ void NODE_OT_select_border(struct wmOperatorType *ot);
 void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link);
 void node_draw_link_bezier(View2D *v2d, SpaceNode *snode, bNodeLink *link, int th_col1, int th_col2, int do_shaded);
 int node_link_bezier_points(View2D *v2d, SpaceNode *snode, bNodeLink *link, float coord_array[][2], int resol);
-void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode);
+void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode, int color_manage);
 
 /* node_edit.c */
+void node_tree_from_ID(ID *id, bNodeTree **ntree, bNodeTree **edittree, int *treetype);
 void snode_handle_recalc(bContext *C, SpaceNode *snode);
 bNode *next_node(bNodeTree *ntree);
 bNode *node_add_node(SpaceNode *snode, Scene *scene, int type, float locx, float locy);
index 5612e60..06d0832 100644 (file)
@@ -1961,6 +1961,8 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar)
                v3d->zbuf= TRUE;
                glEnable(GL_DEPTH_TEST);
        }
+       else
+               v3d->zbuf= FALSE;
        
        // needs to be done always, gridview is adjusted in drawgrid() now
        v3d->gridview= v3d->grid;
index b592021..839c354 100644 (file)
@@ -322,7 +322,7 @@ static void viewRedrawForce(bContext *C, TransInfo *t)
        else if(t->spacetype == SPACE_NODE)
        {
                //ED_area_tag_redraw(t->sa);
-               WM_event_add_notifier(C, NC_SCENE|ND_NODES, NULL);
+               WM_event_add_notifier(C, NC_SPACE|ND_SPACE_NODE, NULL);
        }
        else if(t->spacetype == SPACE_SEQ)
        {
index e70221d..ba1bb66 100644 (file)
@@ -99,7 +99,7 @@ typedef struct bNodeSocket {
 #
 #
 typedef struct bNodePreview {
-       float *rect;
+       unsigned char *rect;
        short xsize, ysize;
 } bNodePreview;
 
index ebd032b..4547362 100644 (file)
 
 #include "rna_internal.h"
 
+#include "DNA_material_types.h"
 #include "DNA_node_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_texture_types.h"
 
+#include "BKE_main.h"
 #include "BKE_node.h"
 #include "BKE_image.h"
 
@@ -140,11 +142,42 @@ static char *rna_Node_path(PointerRNA *ptr)
        return BLI_sprintfN("nodes[%d]", index);
 }
 
+static int has_nodetree(bNodeTree *ntree, bNodeTree *lookup)
+{
+       bNode *node;
+
+       if(ntree == lookup)
+               return 1;
+       
+       for(node=ntree->nodes.first; node; node=node->next)
+               if(node->type == NODE_GROUP && node->id)
+                       if(has_nodetree((bNodeTree*)node->id, lookup))
+                               return 1;
+       
+       return 0;
+}
+
 static void rna_Node_update(bContext *C, PointerRNA *ptr)
 {
+       Main *bmain= CTX_data_main(C);
+       bNodeTree *ntree= (bNodeTree*)ptr->id.data;
        bNode *node= (bNode*)ptr->data;
-
-       ED_node_changed_update(C, node);
+       Material *ma;
+       Tex *tex;
+       Scene *sce;
+
+       /* look through all datablocks, to support groups */
+       for(ma=bmain->mat.first; ma; ma=ma->id.next)
+               if(ma->nodetree && ma->use_nodes && has_nodetree(ma->nodetree, ntree))
+                       ED_node_changed_update(&ma->id, node);
+
+       for(tex=bmain->tex.first; tex; tex=tex->id.next)
+               if(tex->nodetree && tex->use_nodes && has_nodetree(tex->nodetree, ntree))
+                       ED_node_changed_update(&tex->id, node);
+
+       for(sce=bmain->scene.first; sce; sce=sce->id.next)
+               if(sce->nodetree && sce->use_nodes && has_nodetree(sce->nodetree, ntree))
+                       ED_node_changed_update(&sce->id, node);
 }
 
 static void rna_Node_update_name(bContext *C, PointerRNA *ptr)
index a96f348..68ccb04 100644 (file)
@@ -671,7 +671,7 @@ static void node_composit_exec_blur(void *data, bNode *node, bNodeStack **in, bN
                        free_compbuf(img);
        }
 
-       generate_preview(node, out[0]->data);
+       generate_preview(data, node, out[0]->data);
 }
 
 static void node_composit_init_blur(bNode* node)
index b0a2531..ac940d7 100644 (file)
@@ -166,7 +166,7 @@ static void node_composit_exec_channel_matte(void *data, bNode *node, bNodeStack
                break;
        }
 
-       generate_preview(node, outbuf);
+       generate_preview(data, node, outbuf);
        out[0]->data=outbuf;
        if(out[1]->hasoutput)
                out[1]->data=valbuf_from_rgbabuf(outbuf, CHAN_A);
index 28b81fe..c8cbe45 100644 (file)
@@ -154,7 +154,7 @@ static void node_composit_exec_chroma_matte(void *data, bNode *node, bNodeStack
        if(out[1]->hasoutput)
                out[1]->data= valbuf_from_rgbabuf(chromabuf, CHAN_A);
        
-       generate_preview(node, chromabuf);
+       generate_preview(data, node, chromabuf);
 
        if(cbuf!=in[0]->data)
                free_compbuf(cbuf);
index 470d04d..e1fa4d7 100644 (file)
@@ -95,7 +95,7 @@ static void node_composit_exec_color_matte(void *data, bNode *node, bNodeStack *
        if(out[1]->hasoutput)
                out[1]->data= valbuf_from_rgbabuf(colorbuf, CHAN_A);
        
-       generate_preview(node, colorbuf);
+       generate_preview(data, node, colorbuf);
 
        if(cbuf!=in[0]->data)
                free_compbuf(cbuf);
index 800cccc..d117a3c 100644 (file)
@@ -73,7 +73,7 @@ static void node_composit_exec_composite(void *data, bNode *node, bNodeStack **i
                                        zbuf->malloc= 0;
                                        free_compbuf(zbuf);
                                }
-                               generate_preview(node, outbuf);
+                               generate_preview(data, node, outbuf);
                                
                                /* we give outbuf to rr... */
                                rr->rectf= outbuf->rect;
@@ -91,7 +91,7 @@ static void node_composit_exec_composite(void *data, bNode *node, bNodeStack **i
                }
        }
        if(in[0]->data)
-               generate_preview(node, in[0]->data);
+               generate_preview(data, node, in[0]->data);
 }
 
 bNodeType cmp_node_composite= {
index 68a1bcd..d36d586 100644 (file)
@@ -108,7 +108,7 @@ static void node_composit_exec_diff_matte(void *data, bNode *node, bNodeStack **
        out[0]->data=outbuf;
        if(out[1]->hasoutput)
                out[1]->data=valbuf_from_rgbabuf(outbuf, CHAN_A);
-       generate_preview(node, outbuf);
+       generate_preview(data, node, outbuf);
 
        if(imbuf1!=in[0]->data)
                free_compbuf(imbuf1);
index f24aedd..27b1ac1 100644 (file)
@@ -111,7 +111,7 @@ static void node_composit_exec_distance_matte(void *data, bNode *node, bNodeStac
        out[0]->data=workbuf;
        if(out[1]->hasoutput)
                out[1]->data=valbuf_from_rgbabuf(workbuf, CHAN_A);
-       generate_preview(node, workbuf);
+       generate_preview(data, node, workbuf);
 
        if(inbuf!=in[0]->data)
                free_compbuf(inbuf);
index 2c3b78e..8300c79 100644 (file)
@@ -212,7 +212,7 @@ static void node_composit_exec_filter(void *data, bNode *node, bNodeStack **in,
                        
                out[0]->data= stackbuf;
                
-               generate_preview(node, out[0]->data);
+               generate_preview(data, node, out[0]->data);
        }
 }
 
index 00be52a..5e22f5c 100644 (file)
@@ -254,7 +254,7 @@ static void node_composit_exec_image(void *data, bNode *node, bNodeStack **in, b
                        if(out[1]->hasoutput)
                                out[1]->data= valbuf_from_rgbabuf(stackbuf, CHAN_A);
 
-                       generate_preview(node, stackbuf);
+                       generate_preview(data, node, stackbuf);
                }
        }       
 };
@@ -386,7 +386,7 @@ static void node_composit_exec_rlayers(void *data, bNode *node, bNodeStack **in,
 
                node_composit_rlayers_out(rd, rl, out, rr->rectx, rr->recty);
 
-               generate_preview(node, stackbuf);
+               generate_preview(data, node, stackbuf);
             }
          }
       }
index 6056e9a..f0e3147 100644 (file)
@@ -305,7 +305,7 @@ static void node_composit_exec_view_levels(void *data, bNode *node, bNodeStack *
        if(out[1]->hasoutput)
                        out[1]->vec[0]= std_dev;
 
-       generate_preview(node, histogram);
+       generate_preview(data, node, histogram);
 
        if(cbuf!=in[0]->data)
                free_compbuf(cbuf);
index 350def7..3e284cd 100644 (file)
@@ -87,7 +87,7 @@ static void node_composit_exec_luma_matte(void *data, bNode *node, bNodeStack **
        composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_luma_matte, CB_RGBA);
        composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_yuva_to_rgba, CB_RGBA);
        
-       generate_preview(node, outbuf);
+       generate_preview(data, node, outbuf);
        out[0]->data=outbuf;
        if (out[1]->hasoutput)
                out[1]->data=valbuf_from_rgbabuf(outbuf, CHAN_A);
index ca6de02..25bb82b 100644 (file)
@@ -74,7 +74,7 @@ static void node_composit_exec_mix_rgb(void *data, bNode *node, bNodeStack **in,
                
                out[0]->data= stackbuf;
                
-               generate_preview(node, out[0]->data);
+               generate_preview(data, node, out[0]->data);
        }
 }
 
index 8c63c34..e63e580 100644 (file)
@@ -71,7 +71,7 @@ static void node_composit_exec_output_file(void *data, bNode *node, bNodeStack *
                        
                        IMB_freeImBuf(ibuf);    
                        
-                       generate_preview(node, cbuf);
+                       generate_preview(data, node, cbuf);
                        
                        if(in[0]->data != cbuf) 
                                free_compbuf(cbuf);
index 8ce5a7c..04383f4 100644 (file)
@@ -121,7 +121,7 @@ static void node_composit_exec_splitviewer(void *data, bNode *node, bNodeStack *
                
                composit3_pixel_processor(node, cbuf, buf1, in[0]->vec, buf2, in[1]->vec, mask, NULL, do_copy_split_rgba, CB_RGBA, CB_RGBA, CB_VAL);
                
-               generate_preview(node, cbuf);
+               generate_preview(data, node, cbuf);
                free_compbuf(cbuf);
                free_compbuf(mask);
                
index b4d0407..26e7345 100644 (file)
@@ -105,7 +105,7 @@ static void node_composit_exec_texture(void *data, bNode *node, bNodeStack **in,
                VECCOPY(prevbuf->procedural_size, in[1]->vec);
                prevbuf->procedural_type= CB_RGBA;
                composit1_pixel_processor(node, prevbuf, prevbuf, out[0]->vec, do_copy_rgba, CB_RGBA);
-               generate_preview(node, prevbuf);
+               generate_preview(data, node, prevbuf);
                free_compbuf(prevbuf);
                
                if(out[0]->hasoutput) {
index c9e95e7..d0dcc5c 100644 (file)
@@ -106,12 +106,12 @@ static void node_composit_exec_viewer(void *data, bNode *node, bNodeStack **in,
                        free_compbuf(zbuf);
                }
 
-               generate_preview(node, cbuf);
+               generate_preview(data, node, cbuf);
                free_compbuf(cbuf);
 
        }
        else if(in[0]->data) {
-               generate_preview(node, in[0]->data);
+               generate_preview(data, node, in[0]->data);
        }
 }
 
index 075eefb..175a0a5 100644 (file)
@@ -604,9 +604,13 @@ static CompBuf *generate_procedural_preview(CompBuf *cbuf, int newx, int newy)
        return outbuf;
 }
 
-void generate_preview(bNode *node, CompBuf *stackbuf)
+void generate_preview(void *data, bNode *node, CompBuf *stackbuf)
 {
+       RenderData *rd= data;
        bNodePreview *preview= node->preview;
+       int xsize, ysize;
+       int color_manage= rd->color_mgt_flag & R_COLOR_MANAGEMENT;
+       unsigned char *rect;
        
        if(preview && stackbuf) {
                CompBuf *cbuf, *stackbuf_use;
@@ -615,30 +619,41 @@ void generate_preview(bNode *node, CompBuf *stackbuf)
                
                stackbuf_use= typecheck_compbuf(stackbuf, CB_RGBA);
 
-               BLI_lock_thread(LOCK_PREVIEW);
-
                if(stackbuf->x > stackbuf->y) {
-                       preview->xsize= 140;
-                       preview->ysize= (140*stackbuf->y)/stackbuf->x;
+                       xsize= 140;
+                       ysize= (140*stackbuf->y)/stackbuf->x;
                }
                else {
-                       preview->ysize= 140;
-                       preview->xsize= (140*stackbuf->x)/stackbuf->y;
+                       ysize= 140;
+                       xsize= (140*stackbuf->x)/stackbuf->y;
                }
                
                if(stackbuf_use->rect_procedural)
-                       cbuf= generate_procedural_preview(stackbuf_use, preview->xsize, preview->ysize);
+                       cbuf= generate_procedural_preview(stackbuf_use, xsize, ysize);
                else
-                       cbuf= scalefast_compbuf(stackbuf_use, preview->xsize, preview->ysize);
+                       cbuf= scalefast_compbuf(stackbuf_use, xsize, ysize);
 
-               /* this ensures free-compbuf does the right stuff */
-               SWAP(float *, cbuf->rect, node->preview->rect);
+               /* convert to byte for preview */
+               rect= MEM_callocN(sizeof(unsigned char)*4*xsize*ysize, "bNodePreview.rect");
 
-               BLI_unlock_thread(LOCK_PREVIEW);
+               if(color_manage)
+                       floatbuf_to_srgb_byte(cbuf->rect, rect, 0, xsize, 0, ysize, xsize);
+               else
+                       floatbuf_to_byte(cbuf->rect, rect, 0, xsize, 0, ysize, xsize);
                
                free_compbuf(cbuf);
                if(stackbuf_use!=stackbuf)
                        free_compbuf(stackbuf_use);
+
+               BLI_lock_thread(LOCK_PREVIEW);
+
+               if(preview->rect)
+                       MEM_freeN(preview->rect);
+               preview->xsize= xsize;
+               preview->ysize= ysize;
+               preview->rect= rect;
+
+               BLI_unlock_thread(LOCK_PREVIEW);
        }
 }
 
index 2a2dc97..bb08a44 100644 (file)
@@ -141,7 +141,7 @@ void composit4_pixel_processor(bNode *node, CompBuf *out, CompBuf *src1_buf, flo
                                                                          int src1_type, int fac1_type, int src2_type, int fac2_type);
 
 CompBuf *valbuf_from_rgbabuf(CompBuf *cbuf, int channel);
-void generate_preview(bNode *node, CompBuf *stackbuf);
+void generate_preview(void *data, bNode *node, CompBuf *stackbuf);
 
 void do_copy_rgba(bNode *node, float *out, float *in);
 void do_copy_rgb(bNode *node, float *out, float *in);
index 140c31a..580b4cd 100644 (file)
@@ -93,20 +93,23 @@ static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
                        tex_input_rgba(&target->tr, in[0], &params, cdata->thread);
                tex_do_preview(node, params.coord, &target->tr);
        }
-       else if(cdata->which_output == node->custom1) {
-               TexParams params;
-               params_from_cdata(&params, cdata);
+       else {
+               /* 0 means don't care, so just use first */
+               if(cdata->which_output == node->custom1 || (cdata->which_output == 0 && node->custom1 == 1)) {
+                       TexParams params;
+                       params_from_cdata(&params, cdata);
+                       
+                       osa(tex_input_rgba, &target->tr, in[0], &params, cdata->thread);
                
-               osa(tex_input_rgba, &target->tr, in[0], &params, cdata->thread);
-       
-               target->tin = (target->tr + target->tg + target->tb) / 3.0f;
-               target->talpha = 1.0f;
-       
-               if(target->nor) {
-                       if(in[1]->hasinput)
-                               osa(tex_input_vec, target->nor, in[1], &params, cdata->thread);
-                       else
-                               target->nor = 0;
+                       target->tin = (target->tr + target->tg + target->tb) / 3.0f;
+                       target->talpha = 1.0f;
+               
+                       if(target->nor) {
+                               if(in[1]->hasinput)
+                                       osa(tex_input_vec, target->nor, in[1], &params, cdata->thread);
+                               else
+                                       target->nor = 0;
+                       }
                }
        }
 }
index 867bbd8..8b24768 100644 (file)
@@ -176,10 +176,6 @@ void ntreeTexExecTree(
        TexResult dummy_texres;
        TexCallData data;
        
-       /* 0 means don't care, so just use first */
-       if(which_output == 0)
-               which_output = 1;
-       
        if(!texres) texres = &dummy_texres;
        data.coord = coord;
        data.dxt = dxt;