diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-08-16 18:47:14 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-08-16 18:47:14 +0400 |
commit | 81dd80f1d3da6db3227abafe431ac0e92c4e7197 (patch) | |
tree | 6130beb4db65bb8bf7bc5872ce565d4de9e45e16 /source/blender/editors/space_node/node_view.c | |
parent | 6fb4bbdbd963eb0f9626d6bd784b22c65bd5cd44 (diff) |
support fro HDR color picking (values over 1.0) when color picking in the image editor or node space.
Diffstat (limited to 'source/blender/editors/space_node/node_view.c')
-rw-r--r-- | source/blender/editors/space_node/node_view.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/source/blender/editors/space_node/node_view.c b/source/blender/editors/space_node/node_view.c index 4be51a02137..e0cbbd697d7 100644 --- a/source/blender/editors/space_node/node_view.c +++ b/source/blender/editors/space_node/node_view.c @@ -32,6 +32,7 @@ #include "BLI_rect.h" #include "BLI_utildefines.h" +#include "BLI_math.h" #include "BKE_context.h" #include "BKE_image.h" @@ -350,6 +351,61 @@ static void sample_draw(const bContext *C, ARegion *ar, void *arg_info) } } +/* returns color in SRGB */ +/* matching ED_space_image_color_sample() */ +int ED_space_node_color_sample(SpaceNode *snode, ARegion *ar, int mval[2], float r_col[3]) +{ + void *lock; + Image *ima; + ImBuf *ibuf; + float fx, fy, bufx, bufy; + int ret = FALSE; + + ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node"); + ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); + if (!ibuf) { + return FALSE; + } + + /* map the mouse coords to the backdrop image space */ + bufx = ibuf->x * snode->zoom; + bufy = ibuf->y * snode->zoom; + fx = (bufx > 0.0f ? ((float)mval[0] - 0.5f * ar->winx - snode->xof) / bufx + 0.5f : 0.0f); + fy = (bufy > 0.0f ? ((float)mval[1] - 0.5f * ar->winy - snode->yof) / bufy + 0.5f : 0.0f); + + if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) { + float *fp; + char *cp; + int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y); + + CLAMP(x, 0, ibuf->x - 1); + CLAMP(y, 0, ibuf->y - 1); + + if (ibuf->rect_float) { + fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x)); + + if (ibuf->profile == IB_PROFILE_LINEAR_RGB) { + linearrgb_to_srgb_v3_v3(r_col, fp); + } + else { + copy_v3_v3(r_col, fp); + } + ret = TRUE; + } + else if (ibuf->rect) { + cp = (char *)(ibuf->rect + y * ibuf->x + x); + r_col[0] = cp[0] / 255.0f; + r_col[1] = cp[1] / 255.0f; + r_col[2] = cp[2] / 255.0f; + ret = TRUE; + } + } + + BKE_image_release_ibuf(ima, lock); + + return ret; +} + static void sample_apply(bContext *C, wmOperator *op, wmEvent *event) { SpaceNode *snode = CTX_wm_space_node(C); |