HDR color picker now works in the clip space.
authorCampbell Barton <ideasman42@gmail.com>
Mon, 20 Aug 2012 16:56:11 +0000 (16:56 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 20 Aug 2012 16:56:11 +0000 (16:56 +0000)
source/blender/editors/include/ED_clip.h
source/blender/editors/interface/interface_ops.c
source/blender/editors/space_clip/clip_editor.c

index 3a1d63574a6248f068b187814a6b64470ab56f2a..13c3b180230df9ea7a5eb36742f8343a7d2687cf 100644 (file)
@@ -62,6 +62,8 @@ int ED_space_clip_get_clip_frame_number(struct SpaceClip *sc);
 struct ImBuf *ED_space_clip_get_buffer(struct SpaceClip *sc);
 struct ImBuf *ED_space_clip_get_stable_buffer(struct SpaceClip *sc, float loc[2], float *scale, float *angle);
 
+int ED_space_clip_color_sample(struct SpaceClip *sc, struct ARegion *ar, int mval[2], float r_col[3]);
+
 void ED_clip_update_frame(const struct Main *mainp, int cfra);
 int ED_clip_view_selection(const struct bContext *C, struct ARegion *ar, int fit);
 
index 802000567da389444fd21b12e64df7c3d5cb8902..d3b8197447951fb43ea3358eccb96b94f46c9c14 100644 (file)
@@ -27,7 +27,6 @@
  *  \ingroup edinterface
  */
 
-
 #include <stdio.h>
 #include <math.h>
 #include <string.h>
@@ -71,6 +70,7 @@
 
 #include "ED_image.h"  /* for HDR color sampling */
 #include "ED_node.h"   /* for HDR color sampling */
+#include "ED_clip.h"   /* for HDR color sampling */
 
 /* ********************************************************** */
 
@@ -165,6 +165,18 @@ static void eyedropper_color_sample_fl(bContext *C, Eyedropper *UNUSED(eye), int
                                        }
                                }
                        }
+                       else if (sa->spacetype == SPACE_CLIP) {
+                               ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
+                               if (BLI_in_rcti(&ar->winrct, mx, my)) {
+                                       SpaceClip *sc = sa->spacedata.first;
+                                       int mval[2] = {mx - ar->winrct.xmin,
+                                                      my - ar->winrct.ymin};
+
+                                       if (ED_space_clip_color_sample(sc, ar, mval, r_col)) {
+                                               return;
+                                       }
+                               }
+                       }
                }
        }
 
index 5e4ef1aa24a8d2cdcf74f5459936aa5ed1bcbe0a..5b4849a425fa0681e5ab8d7c197378c1a2d722fe 100644 (file)
@@ -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;