diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-08-20 20:56:11 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-08-20 20:56:11 +0400 |
commit | ff876a473aa030a7308560c69c2b6fd4bb7e77a4 (patch) | |
tree | 35cb24c8b548c8eefb36c821cc6b46680805300b /source/blender/editors/space_clip | |
parent | 5e78327b92f0acacd5e77485daa036b40c9ababa (diff) |
HDR color picker now works in the clip space.
Diffstat (limited to 'source/blender/editors/space_clip')
-rw-r--r-- | source/blender/editors/space_clip/clip_editor.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/source/blender/editors/space_clip/clip_editor.c b/source/blender/editors/space_clip/clip_editor.c index 5e4ef1aa24a..5b4849a425f 100644 --- a/source/blender/editors/space_clip/clip_editor.c +++ b/source/blender/editors/space_clip/clip_editor.c @@ -247,6 +247,54 @@ ImBuf *ED_space_clip_get_stable_buffer(SpaceClip *sc, float loc[2], float *scale return NULL; } +/* returns color in SRGB */ +/* matching ED_space_image_color_sample() */ +int ED_space_clip_color_sample(SpaceClip *sc, ARegion *ar, int mval[2], float r_col[3]) +{ + ImBuf *ibuf; + float fx, fy, co[2]; + int ret = FALSE; + + ibuf = ED_space_clip_get_buffer(sc); + if (!ibuf) { + return FALSE; + } + + /* map the mouse coords to the backdrop image space */ + ED_clip_mouse_pos(sc, ar, mval, co); + + fx = co[0]; + fy = co[1]; + + 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; + } + } + + return ret; +} + void ED_clip_update_frame(const Main *mainp, int cfra) { wmWindowManager *wm; |