diff options
-rw-r--r-- | source/blender/blenkernel/BKE_colortools.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/colortools.c | 60 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/node.c | 33 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/node_composite.c | 2 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_color_types.h | 1 |
5 files changed, 75 insertions, 23 deletions
diff --git a/source/blender/blenkernel/BKE_colortools.h b/source/blender/blenkernel/BKE_colortools.h index a9d38162824..53097b915f0 100644 --- a/source/blender/blenkernel/BKE_colortools.h +++ b/source/blender/blenkernel/BKE_colortools.h @@ -56,5 +56,7 @@ void curvemapping_evaluate_premulRGBF(struct CurveMapping *cumap, float *veco void curvemapping_do_image(struct CurveMapping *cumap, struct Image *ima); void curvemapping_premultiply(struct CurveMapping *cumap, int restore); int curvemapping_RGBA_does_something(struct CurveMapping *cumap); +void curvemapping_initialize(struct CurveMapping *cumap); + #endif diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c index 80f39069650..81a202b796b 100644 --- a/source/blender/blenkernel/intern/colortools.c +++ b/source/blender/blenkernel/intern/colortools.c @@ -405,36 +405,45 @@ static void curvemap_make_table(CurveMap *cuma, rctf *clipr) } /* call when you do images etc, needs restore too. also verifies tables */ +/* it uses a flag to prevent premul or free to happen twice */ void curvemapping_premultiply(CurveMapping *cumap, int restore) { int a; if(restore) { - for(a=0; a<3; a++) { - MEM_freeT(cumap->cm[a].table); - cumap->cm[a].table= cumap->cm[a].premultable; - cumap->cm[a].premultable= NULL; + if(cumap->flag & CUMA_PREMULLED) { + for(a=0; a<3; a++) { + MEM_freeT(cumap->cm[a].table); + cumap->cm[a].table= cumap->cm[a].premultable; + cumap->cm[a].premultable= NULL; + } + + cumap->flag &= ~CUMA_PREMULLED; } } else { - /* verify and copy */ - for(a=0; a<3; a++) { - if(cumap->cm[a].table==NULL) - curvemap_make_table(cumap->cm+a, &cumap->clipr); - cumap->cm[a].premultable= cumap->cm[a].table; - cumap->cm[a].table= MEM_mallocT((CM_TABLE+1)*sizeof(CurveMapPoint), "premul table"); - memcpy(cumap->cm[a].table, cumap->cm[a].premultable, (CM_TABLE+1)*sizeof(CurveMapPoint)); - } + if((cumap->flag & CUMA_PREMULLED)==0) { + /* verify and copy */ + for(a=0; a<3; a++) { + if(cumap->cm[a].table==NULL) + curvemap_make_table(cumap->cm+a, &cumap->clipr); + cumap->cm[a].premultable= cumap->cm[a].table; + cumap->cm[a].table= MEM_mallocT((CM_TABLE+1)*sizeof(CurveMapPoint), "premul table"); + memcpy(cumap->cm[a].table, cumap->cm[a].premultable, (CM_TABLE+1)*sizeof(CurveMapPoint)); + } + + if(cumap->cm[3].table==NULL) + curvemap_make_table(cumap->cm+3, &cumap->clipr); - if(cumap->cm[3].table==NULL) - curvemap_make_table(cumap->cm+3, &cumap->clipr); - - /* premul */ - for(a=0; a<3; a++) { - int b; - for(b=0; b<=CM_TABLE; b++) { - cumap->cm[a].table[b].y= curvemap_evaluateF(cumap->cm+3, cumap->cm[a].table[b].y); + /* premul */ + for(a=0; a<3; a++) { + int b; + for(b=0; b<=CM_TABLE; b++) { + cumap->cm[a].table[b].y= curvemap_evaluateF(cumap->cm+3, cumap->cm[a].table[b].y); + } } + + cumap->flag |= CUMA_PREMULLED; } } } @@ -619,3 +628,14 @@ int curvemapping_RGBA_does_something(CurveMapping *cumap) return 0; } +void curvemapping_initialize(CurveMapping *cumap) +{ + int a; + + if(cumap==NULL) return; + + for(a=0; a<CM_TOT; a++) { + if(cumap->cm[a].table==NULL) + curvemap_make_table(cumap->cm+a, &cumap->clipr); + } +} diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index f02148dbd55..26ce81b7bd0 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -1562,7 +1562,21 @@ static int ntree_begin_exec_tree(bNodeTree *ntree) return index; } -/* copy socket compbufs to stack */ +/* groups have same node storage data... cannot initialize them while using in threads */ +static void composit_begin_exec_groupdata(bNodeTree *ntree) +{ + bNode *node; + + for(node= ntree->nodes.first; node; node= node->next) { + if(ELEM3(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB)) { + curvemapping_initialize(node->storage); + if(node->type==CMP_NODE_CURVE_RGB) + curvemapping_premultiply(node->storage, 0); + } + } +} + +/* copy socket compbufs to stack, initialize group usage of curve nodes */ static void composit_begin_exec(bNodeTree *ntree) { bNode *node; @@ -1577,9 +1591,23 @@ static void composit_begin_exec(bNodeTree *ntree) sock->ns.data= NULL; } } + if(node->type==NODE_GROUP) + composit_begin_exec_groupdata((bNodeTree *)node->id); } } +/* groups have same node storage data... cannot initialize them while using in threads */ +static void composit_end_exec_groupdata(bNodeTree *ntree) +{ + bNode *node; + + for(node= ntree->nodes.first; node; node= node->next) { + if(node->type==CMP_NODE_CURVE_RGB) + curvemapping_premultiply(node->storage, 1); + } +} + + /* copy stack compbufs to sockets */ static void composit_end_exec(bNodeTree *ntree) { @@ -1598,6 +1626,9 @@ static void composit_end_exec(bNodeTree *ntree) ns->data= NULL; } } + if(node->type==NODE_GROUP) + composit_end_exec_groupdata((bNodeTree *)node->id); + node->need_exec= 0; } diff --git a/source/blender/blenkernel/intern/node_composite.c b/source/blender/blenkernel/intern/node_composite.c index 2f3af5a00fd..75f5a5ad663 100644 --- a/source/blender/blenkernel/intern/node_composite.c +++ b/source/blender/blenkernel/intern/node_composite.c @@ -1205,12 +1205,10 @@ static void node_composit_exec_curve_rgb(void *data, bNode *node, bNodeStack **i CompBuf *cbuf= in[1]->data; CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); // allocs - curvemapping_premultiply(node->storage, 0); if(in[0]->data) composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, in[0]->vec, do_curves_fac); else composit1_pixel_processor(node, stackbuf, in[1]->data, NULL, do_curves); - curvemapping_premultiply(node->storage, 1); out[0]->data= stackbuf; } diff --git a/source/blender/makesdna/DNA_color_types.h b/source/blender/makesdna/DNA_color_types.h index b969d11d7ce..9aae71b9cc9 100644 --- a/source/blender/makesdna/DNA_color_types.h +++ b/source/blender/makesdna/DNA_color_types.h @@ -70,6 +70,7 @@ typedef struct CurveMapping { /* cumap->flag */ #define CUMA_DO_CLIP 1 +#define CUMA_PREMULLED 2 #endif |