diff options
Diffstat (limited to 'source/blender/editors/space_node/node_view.c')
-rw-r--r-- | source/blender/editors/space_node/node_view.c | 69 |
1 files changed, 60 insertions, 9 deletions
diff --git a/source/blender/editors/space_node/node_view.c b/source/blender/editors/space_node/node_view.c index 4be51a02137..e89e798a6fa 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" @@ -71,8 +72,8 @@ static int space_node_view_flag(bContext *C, SpaceNode *snode, ARegion *ar, cons int tot = 0; int has_frame = FALSE; - oldwidth = ar->v2d.cur.xmax - ar->v2d.cur.xmin; - oldheight = ar->v2d.cur.ymax - ar->v2d.cur.ymin; + oldwidth = BLI_RCT_SIZE_X(&ar->v2d.cur); + oldheight = BLI_RCT_SIZE_Y(&ar->v2d.cur); BLI_rctf_init_minmax(&cur_new); @@ -90,8 +91,8 @@ static int space_node_view_flag(bContext *C, SpaceNode *snode, ARegion *ar, cons } if (tot) { - width = cur_new.xmax - cur_new.xmin; - height = cur_new.ymax - cur_new.ymin; + width = BLI_RCT_SIZE_X(&cur_new); + height = BLI_RCT_SIZE_Y(&cur_new); /* for single non-frame nodes, don't zoom in, just pan view, * but do allow zooming out, this allows for big nodes to be zoomed out */ @@ -103,9 +104,6 @@ static int space_node_view_flag(bContext *C, SpaceNode *snode, ARegion *ar, cons BLI_rctf_resize(&cur_new, oldwidth, oldheight); } else { - width = cur_new.xmax - cur_new.xmin; - height = cur_new.ymax - cur_new.ymin; - if (width > height) { float newheight; newheight = oldheight * width / oldwidth; @@ -350,6 +348,59 @@ 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; + unsigned 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)); + /* IB_PROFILE_NONE is default but infact its linear */ + if (ELEM(ibuf->profile, IB_PROFILE_LINEAR_RGB, IB_PROFILE_NONE)) { + linearrgb_to_srgb_v3_v3(r_col, fp); + } + else { + copy_v3_v3(r_col, fp); + } + ret = TRUE; + } + else if (ibuf->rect) { + cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x); + rgb_uchar_to_float(r_col, cp); + 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); @@ -383,7 +434,7 @@ static void sample_apply(bContext *C, wmOperator *op, wmEvent *event) if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) { float *fp; - char *cp; + unsigned char *cp; int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y); CLAMP(x, 0, ibuf->x - 1); @@ -395,7 +446,7 @@ static void sample_apply(bContext *C, wmOperator *op, wmEvent *event) info->channels = ibuf->channels; if (ibuf->rect) { - cp = (char *)(ibuf->rect + y * ibuf->x + x); + cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x); info->col[0] = cp[0]; info->col[1] = cp[1]; |