From fd212cd4bc1e82ad8b61f54ec75d09747f7a9536 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 13 Jun 2012 22:38:31 +0000 Subject: image sample line now updates with the compositor changes (mango request) --- source/blender/blenkernel/intern/colortools.c | 56 +++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'source/blender/blenkernel/intern/colortools.c') diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c index 12dee600532..6879ec506f0 100644 --- a/source/blender/blenkernel/intern/colortools.c +++ b/source/blender/blenkernel/intern/colortools.c @@ -946,6 +946,62 @@ static void save_sample_line(Scopes *scopes, const int idx, const float fx, cons } } +void BKE_histogram_update_sample_line(Histogram *hist, ImBuf *ibuf, const short use_color_management) +{ + int i, x, y; + float *fp; + float rgb[3]; + unsigned char *cp; + + int x1 = 0.5f + hist->co[0][0] * ibuf->x; + int x2 = 0.5f + hist->co[1][0] * ibuf->x; + int y1 = 0.5f + hist->co[0][1] * ibuf->y; + int y2 = 0.5f + hist->co[1][1] * ibuf->y; + + hist->channels = 3; + hist->x_resolution = 256; + hist->xmax = 1.0f; + hist->ymax = 1.0f; + + if (ibuf->rect == NULL && ibuf->rect_float == NULL) return; + + /* persistent draw */ + hist->flag |= HISTO_FLAG_SAMPLELINE; /* keep drawing the flag after */ + + for (i = 0; i < 256; i++) { + x = (int)(0.5f + x1 + (float)i * (x2 - x1) / 255.0f); + y = (int)(0.5f + y1 + (float)i * (y2 - y1) / 255.0f); + + if (x < 0 || y < 0 || x >= ibuf->x || y >= ibuf->y) { + hist->data_luma[i] = hist->data_r[i] = hist->data_g[i] = hist->data_b[i] = hist->data_a[i] = 0.0f; + } + else { + if (ibuf->rect_float) { + fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x)); + + if (use_color_management) + linearrgb_to_srgb_v3_v3(rgb, fp); + else + copy_v3_v3(rgb, fp); + + hist->data_luma[i] = rgb_to_luma(rgb); + hist->data_r[i] = rgb[0]; + hist->data_g[i] = rgb[1]; + hist->data_b[i] = rgb[2]; + hist->data_a[i] = fp[3]; + } + else if (ibuf->rect) { + cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x); + hist->data_luma[i] = (float)rgb_to_luma_byte(cp) / 255.0f; + hist->data_r[i] = (float)cp[0] / 255.0f; + hist->data_g[i] = (float)cp[1] / 255.0f; + hist->data_b[i] = (float)cp[2] / 255.0f; + hist->data_a[i] = (float)cp[3] / 255.0f; + } + } + } +} + void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management) { int x, y, c; -- cgit v1.2.3