diff options
author | Guillermo S. Romero <gsr.b3d@infernal-iceberg.com> | 2009-04-21 21:40:39 +0400 |
---|---|---|
committer | Guillermo S. Romero <gsr.b3d@infernal-iceberg.com> | 2009-04-21 21:40:39 +0400 |
commit | 41eb029bb9c2ab43c9feba901026ebd640be2c0a (patch) | |
tree | 862b29d1b29aaca8428b3b0577ad12b7f65997d7 | |
parent | c5756a9822f72579ddc1797dbe7612035a9b2bfe (diff) |
Old "divide by zero" bug and remove debug printf.
-rw-r--r-- | source/blender/nodes/intern/CMP_nodes/CMP_normalize.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_normalize.c b/source/blender/nodes/intern/CMP_nodes/CMP_normalize.c index 846aec490c2..15f3148b54c 100644 --- a/source/blender/nodes/intern/CMP_nodes/CMP_normalize.c +++ b/source/blender/nodes/intern/CMP_nodes/CMP_normalize.c @@ -55,6 +55,7 @@ static void do_normalize(bNode *node, float *out, float *src, float *min, float } } +/* The code below assumes all data is inside range +- this, and that input buffer is single channel */ #define BLENDER_ZMAX 10000.0f static void node_composit_exec_normalize(void *data, bNode *node, bNodeStack **in, bNodeStack **out) @@ -63,7 +64,7 @@ static void node_composit_exec_normalize(void *data, bNode *node, bNodeStack **i /* stack order out: valbuf */ if(out[0]->hasoutput==0) return; - /* input no image? then only value operation */ + /* Input has no image buffer? Then pass the value */ if(in[0]->data==NULL) { QUATCOPY(out[0]->vec, in[0]->vec); } @@ -78,18 +79,20 @@ static void node_composit_exec_normalize(void *data, bNode *node, bNodeStack **i CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */ for (val = cbuf->rect; tot; tot--, val++) { - if ((*val > max) && (*val < BLENDER_ZMAX)) { + if ((*val > max) && (*val <= BLENDER_ZMAX)) { max = *val; } - if (*val < min) { + if ((*val < min) && (*val >= -BLENDER_ZMAX)) { min = *val; } } - mult = 1.0f/(max-min); - - printf("min %f max %f\n", min, max); - - composit3_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, NULL, &min, NULL, &mult, do_normalize, CB_VAL, CB_VAL, CB_VAL); + /* In the rare case of flat buffer, which would cause a divide by 0, just pass the input to the output */ + if ((max-min) != 0.0f) { + mult = 1.0f/(max-min); + composit3_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, NULL, &min, NULL, &mult, do_normalize, CB_VAL, CB_VAL, CB_VAL); + } else { + memcpy(stackbuf->rect, cbuf->rect, sizeof(float) * cbuf->x * cbuf->y); + } out[0]->data= stackbuf; } |