Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / space_sequencer / sequencer_view.c
index af9ef34..88dcc3a 100644 (file)
  */
 
 
-/** \file blender/editors/space_sequencer/sequencer_modifier.c
+/** \file blender/editors/space_sequencer/sequencer_view.c
  *  \ingroup spseq
  */
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_math.h"
 #include "BLI_utildefines.h"
 
 #include "DNA_scene_types.h"
@@ -66,9 +67,10 @@ typedef struct ImageSampleInfo {
 
        unsigned char col[4];
        float colf[4];
+       float linearcol[4];
 
        unsigned char *colp;
-       float *colfp;
+       const float *colfp;
 
        int draw;
 int color_manage;
@@ -80,21 +82,23 @@ static void sample_draw(const bContext *C, ARegion *ar, void *arg_info)
        ImageSampleInfo *info = arg_info;
 
        if (info->draw) {
-               ED_image_draw_info(scene, ar, info->color_manage, info->channels,
-                                  info->x, info->y, info->colp, info->colfp, NULL, NULL);
+               ED_image_draw_info(scene, ar, info->color_manage, false, info->channels,
+                                  info->x, info->y, info->colp, info->colfp,
+                                  info->linearcol, NULL, NULL);
        }
 }
 
-static void sample_apply(bContext *C, wmOperator *op, wmEvent *event)
+static void sample_apply(bContext *C, wmOperator *op, const wmEvent *event)
 {
        Main *bmain = CTX_data_main(C);
+       struct Depsgraph *depsgraph = CTX_data_depsgraph(C);
        Scene *scene = CTX_data_scene(C);
        SpaceSeq *sseq = (SpaceSeq *) CTX_wm_space_data(C);
        ARegion *ar = CTX_wm_region(C);
-       ImBuf *ibuf = sequencer_ibuf_get(bmain, scene, sseq, CFRA, 0);
+       ImBuf *ibuf = sequencer_ibuf_get(bmain, depsgraph, scene, sseq, CFRA, 0, NULL);
        ImageSampleInfo *info = op->customdata;
        float fx, fy;
-       
+
        if (ibuf == NULL) {
                IMB_freeImBuf(ibuf);
                info->draw = 0;
@@ -107,7 +111,7 @@ static void sample_apply(bContext *C, wmOperator *op, wmEvent *event)
        fy += (float) ibuf->y / 2.0f;
 
        if (fx >= 0.0f && fy >= 0.0f && fx < ibuf->x && fy < ibuf->y) {
-               float *fp;
+               const float *fp;
                unsigned char *cp;
                int x = (int) fx, y = (int) fy;
 
@@ -118,7 +122,7 @@ static void sample_apply(bContext *C, wmOperator *op, wmEvent *event)
 
                info->colp = NULL;
                info->colfp = NULL;
-               
+
                if (ibuf->rect) {
                        cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x);
 
@@ -134,7 +138,10 @@ static void sample_apply(bContext *C, wmOperator *op, wmEvent *event)
                        info->colf[3] = (float)cp[3] / 255.0f;
                        info->colfp = info->colf;
 
-                       info->color_manage = FALSE;
+                       copy_v4_v4(info->linearcol, info->colf);
+                       IMB_colormanagement_colorspace_to_scene_linear_v4(info->linearcol, false, ibuf->rect_colorspace);
+
+                       info->color_manage = true;
                }
                if (ibuf->rect_float) {
                        fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x));
@@ -146,9 +153,10 @@ static void sample_apply(bContext *C, wmOperator *op, wmEvent *event)
                        info->colfp = info->colf;
 
                        /* sequencer's image buffers are in non-linear space, need to make them linear */
-                       BKE_sequencer_pixel_from_sequencer_space_v4(scene, info->colf);
+                       copy_v4_v4(info->linearcol, info->colf);
+                       BKE_sequencer_pixel_from_sequencer_space_v4(scene, info->linearcol);
 
-                       info->color_manage = TRUE;
+                       info->color_manage = true;
                }
        }
        else {
@@ -168,7 +176,7 @@ static void sample_exit(bContext *C, wmOperator *op)
        MEM_freeN(info);
 }
 
-static int sample_invoke(bContext *C, wmOperator *op, wmEvent *event)
+static int sample_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
        ARegion *ar = CTX_wm_region(C);
        SpaceSeq *sseq = CTX_wm_space_seq(C);
@@ -189,13 +197,16 @@ static int sample_invoke(bContext *C, wmOperator *op, wmEvent *event)
        return OPERATOR_RUNNING_MODAL;
 }
 
-static int sample_modal(bContext *C, wmOperator *op, wmEvent *event)
+static int sample_modal(bContext *C, wmOperator *op, const wmEvent *event)
 {
        switch (event->type) {
                case LEFTMOUSE:
                case RIGHTMOUSE: /* XXX hardcoded */
-                       sample_exit(C, op);
-                       return OPERATOR_CANCELLED;
+                       if (event->val == KM_RELEASE) {
+                               sample_exit(C, op);
+                               return OPERATOR_CANCELLED;
+                       }
+                       break;
                case MOUSEMOVE:
                        sample_apply(C, op, event);
                        break;
@@ -204,16 +215,15 @@ static int sample_modal(bContext *C, wmOperator *op, wmEvent *event)
        return OPERATOR_RUNNING_MODAL;
 }
 
-static int sample_cancel(bContext *C, wmOperator *op)
+static void sample_cancel(bContext *C, wmOperator *op)
 {
        sample_exit(C, op);
-
-       return OPERATOR_CANCELLED;
 }
 
-int sample_poll(bContext *C)
+static int sample_poll(bContext *C)
 {
-       return BKE_sequencer_editing_get(CTX_data_scene(C), FALSE) != NULL;
+       SpaceSeq *sseq = CTX_wm_space_seq(C);
+       return sseq && BKE_sequencer_editing_get(CTX_data_scene(C), false) != NULL;
 }
 
 void SEQUENCER_OT_sample(wmOperatorType *ot)