diff options
Diffstat (limited to 'source/blender/nodes/composite/nodes/node_composite_tonemap.c')
-rw-r--r-- | source/blender/nodes/composite/nodes/node_composite_tonemap.c | 111 |
1 files changed, 0 insertions, 111 deletions
diff --git a/source/blender/nodes/composite/nodes/node_composite_tonemap.c b/source/blender/nodes/composite/nodes/node_composite_tonemap.c index 00b1a5514dc..94492431c9f 100644 --- a/source/blender/nodes/composite/nodes/node_composite_tonemap.c +++ b/source/blender/nodes/composite/nodes/node_composite_tonemap.c @@ -41,114 +41,6 @@ static bNodeSocketTemplate cmp_node_tonemap_out[] = { { -1, 0, "" } }; -#ifdef WITH_COMPOSITOR_LEGACY - -static float avgLogLum(CompBuf *src, float* auto_key, float* Lav, float* Cav) -{ - float lsum = 0; - int p = src->x*src->y; - fRGB* bc = (fRGB*)src->rect; - float avl, maxl = -1e10f, minl = 1e10f; - const float sc = 1.f/(src->x*src->y); - *Lav = 0.f; - while (p--) { - float L = rgb_to_luma_y(bc[0]); - *Lav += L; - add_v3_v3(Cav, bc[0]); - lsum += (float)log((double)MAX2(L, 0.0) + 1e-5); - maxl = (L > maxl) ? L : maxl; - minl = (L < minl) ? L : minl; - bc++; - } - *Lav *= sc; - mul_v3_fl(Cav, sc); - maxl = log((double)maxl + 1e-5); minl = log((double)minl + 1e-5f); avl = lsum*sc; - *auto_key = (maxl > minl) ? ((maxl - avl) / (maxl - minl)) : 1.f; - return exp((double)avl); -} - - -static void tonemap(NodeTonemap* ntm, CompBuf* dst, CompBuf* src) -{ - int x, y; - float dr, dg, db, al, igm = (ntm->gamma==0.f) ? 1 : (1.f / ntm->gamma); - float auto_key, Lav, Cav[3] = {0, 0, 0}; - - al = avgLogLum(src, &auto_key, &Lav, Cav); - al = (al == 0.f) ? 0.f : (ntm->key / al); - - if (ntm->type == 1) { - // Reinhard/Devlin photoreceptor - const float f = exp((double)-ntm->f); - const float m = (ntm->m > 0.f) ? ntm->m : (0.3f + 0.7f*pow((double)auto_key, 1.4)); - const float ic = 1.f - ntm->c, ia = 1.f - ntm->a; - if (ntm->m == 0.f) printf("tonemap node, M: %g\n", m); - for (y=0; y<src->y; ++y) { - fRGB* sp = (fRGB*)&src->rect[y*src->x*src->type]; - fRGB* dp = (fRGB*)&dst->rect[y*src->x*src->type]; - for (x=0; x<src->x; ++x) { - const float L = rgb_to_luma_y(sp[x]); - float I_l = sp[x][0] + ic*(L - sp[x][0]); - float I_g = Cav[0] + ic*(Lav - Cav[0]); - float I_a = I_l + ia*(I_g - I_l); - dp[x][0] /= (dp[x][0] + pow((double)f*I_a, (double)m)); - I_l = sp[x][1] + ic*(L - sp[x][1]); - I_g = Cav[1] + ic*(Lav - Cav[1]); - I_a = I_l + ia*(I_g - I_l); - dp[x][1] /= (dp[x][1] + pow((double)f*I_a, (double)m)); - I_l = sp[x][2] + ic*(L - sp[x][2]); - I_g = Cav[2] + ic*(Lav - Cav[2]); - I_a = I_l + ia*(I_g - I_l); - dp[x][2] /= (dp[x][2] + pow((double)f*I_a, (double)m)); - } - } - return; - } - - // Reinhard simple photographic tm (simplest, not using whitepoint var) - for (y=0; y<src->y; y++) { - fRGB* sp = (fRGB*)&src->rect[y*src->x*src->type]; - fRGB* dp = (fRGB*)&dst->rect[y*src->x*src->type]; - for (x=0; x<src->x; x++) { - copy_v4_v4(dp[x], sp[x]); - mul_v3_fl(dp[x], al); - dr = dp[x][0] + ntm->offset; - dg = dp[x][1] + ntm->offset; - db = dp[x][2] + ntm->offset; - dp[x][0] /= ((dr == 0.f) ? 1.f : dr); - dp[x][1] /= ((dg == 0.f) ? 1.f : dg); - dp[x][2] /= ((db == 0.f) ? 1.f : db); - if (igm != 0.f) { - dp[x][0] = pow((double)MAX2(dp[x][0], 0.0), igm); - dp[x][1] = pow((double)MAX2(dp[x][1], 0.0), igm); - dp[x][2] = pow((double)MAX2(dp[x][2], 0.0), igm); - } - } - } -} - - -static void node_composit_exec_tonemap(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) -{ - CompBuf *new, *img = in[0]->data; - - if ((img==NULL) || (out[0]->hasoutput==0)) return; - - if (img->type != CB_RGBA) - img = typecheck_compbuf(img, CB_RGBA); - - new = dupalloc_compbuf(img); - - tonemap(node->storage, new, img); - - out[0]->data = new; - - if (img!=in[0]->data) - free_compbuf(img); -} - -#endif /* WITH_COMPOSITOR_LEGACY */ - static void node_composit_init_tonemap(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp)) { NodeTonemap *ntm = MEM_callocN(sizeof(NodeTonemap), "node tonemap data"); @@ -174,9 +66,6 @@ void register_node_type_cmp_tonemap(bNodeTreeType *ttype) node_type_size(&ntype, 150, 120, 200); node_type_init(&ntype, node_composit_init_tonemap); node_type_storage(&ntype, "NodeTonemap", node_free_standard_storage, node_copy_standard_storage); -#ifdef WITH_COMPOSITOR_LEGACY - node_type_exec(&ntype, node_composit_exec_tonemap); -#endif nodeRegisterType(ttype, &ntype); } |