2
* ***** BEGIN GPL LICENSE BLOCK *****
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
* The Original Code is Copyright (C) 2012 Blender Foundation.
19
* All rights reserved.
21
* Contributor(s): Blender Foundation,
24
* ***** END GPL LICENSE BLOCK *****
28
/** \file blender/editors/space_sequencer/sequencer_view.c
32
#include "MEM_guardedalloc.h"
34
#include "BLI_utildefines.h"
36
#include "DNA_scene_types.h"
38
#include "BKE_context.h"
40
#include "BKE_sequencer.h"
41
#include "BKE_screen.h"
47
#include "ED_screen.h"
48
#include "ED_space_api.h"
50
#include "IMB_imbuf.h"
51
#include "IMB_imbuf_types.h"
52
#include "IMB_colormanagement.h"
54
#include "UI_view2d.h"
57
#include "sequencer_intern.h"
59
/******************** sample backdrop operator ********************/
61
typedef struct ImageSampleInfo {
77
static void sample_draw(const bContext *C, ARegion *ar, void *arg_info)
79
Scene *scene = CTX_data_scene(C);
80
ImageSampleInfo *info = arg_info;
83
ED_image_draw_info(scene, ar, info->color_manage, FALSE, info->channels,
84
info->x, info->y, info->colp, info->colfp, NULL, NULL);
88
static void sample_apply(bContext *C, wmOperator *op, wmEvent *event)
90
Main *bmain = CTX_data_main(C);
91
Scene *scene = CTX_data_scene(C);
92
SpaceSeq *sseq = (SpaceSeq *) CTX_wm_space_data(C);
93
ARegion *ar = CTX_wm_region(C);
94
ImBuf *ibuf = sequencer_ibuf_get(bmain, scene, sseq, CFRA, 0);
95
ImageSampleInfo *info = op->customdata;
104
UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fx, &fy);
106
fx += (float) ibuf->x / 2.0f;
107
fy += (float) ibuf->y / 2.0f;
109
if (fx >= 0.0f && fy >= 0.0f && fx < ibuf->x && fy < ibuf->y) {
112
int x = (int) fx, y = (int) fy;
117
info->channels = ibuf->channels;
123
cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x);
125
info->col[0] = cp[0];
126
info->col[1] = cp[1];
127
info->col[2] = cp[2];
128
info->col[3] = cp[3];
129
info->colp = info->col;
131
info->colf[0] = (float)cp[0] / 255.0f;
132
info->colf[1] = (float)cp[1] / 255.0f;
133
info->colf[2] = (float)cp[2] / 255.0f;
134
info->colf[3] = (float)cp[3] / 255.0f;
135
info->colfp = info->colf;
137
info->color_manage = FALSE;
139
if (ibuf->rect_float) {
140
fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x));
142
info->colf[0] = fp[0];
143
info->colf[1] = fp[1];
144
info->colf[2] = fp[2];
145
info->colf[3] = fp[3];
146
info->colfp = info->colf;
148
/* sequencer's image buffers are in non-linear space, need to make them linear */
149
BKE_sequencer_pixel_from_sequencer_space_v4(scene, info->colf);
151
info->color_manage = TRUE;
159
ED_area_tag_redraw(CTX_wm_area(C));
162
static void sample_exit(bContext *C, wmOperator *op)
164
ImageSampleInfo *info = op->customdata;
166
ED_region_draw_cb_exit(info->art, info->draw_handle);
167
ED_area_tag_redraw(CTX_wm_area(C));
171
static int sample_invoke(bContext *C, wmOperator *op, wmEvent *event)
173
ARegion *ar = CTX_wm_region(C);
174
SpaceSeq *sseq = CTX_wm_space_seq(C);
175
ImageSampleInfo *info;
177
if (sseq->mainb != SEQ_DRAW_IMG_IMBUF)
178
return OPERATOR_CANCELLED;
180
info = MEM_callocN(sizeof(ImageSampleInfo), "ImageSampleInfo");
181
info->art = ar->type;
182
info->draw_handle = ED_region_draw_cb_activate(ar->type, sample_draw, info, REGION_DRAW_POST_PIXEL);
183
op->customdata = info;
185
sample_apply(C, op, event);
187
WM_event_add_modal_handler(C, op);
189
return OPERATOR_RUNNING_MODAL;
192
static int sample_modal(bContext *C, wmOperator *op, wmEvent *event)
194
switch (event->type) {
196
case RIGHTMOUSE: /* XXX hardcoded */
198
return OPERATOR_CANCELLED;
200
sample_apply(C, op, event);
204
return OPERATOR_RUNNING_MODAL;
207
static int sample_cancel(bContext *C, wmOperator *op)
211
return OPERATOR_CANCELLED;
214
static int sample_poll(bContext *C)
216
return BKE_sequencer_editing_get(CTX_data_scene(C), FALSE) != NULL;
219
void SEQUENCER_OT_sample(wmOperatorType *ot)
222
ot->name = "Sample Color";
223
ot->idname = "SEQUENCER_OT_sample";
224
ot->description = "Use mouse to sample color in current frame";
227
ot->invoke = sample_invoke;
228
ot->modal = sample_modal;
229
ot->cancel = sample_cancel;
230
ot->poll = sample_poll;
233
ot->flag = OPTYPE_BLOCKING;