2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-12-28 21:41:33 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2018-06-01 18:19:39 +02:00
|
|
|
* of the License, or (at your option) any later version.
|
2008-12-28 21:41:33 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-12-28 21:41:33 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2008 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
2018-06-01 18:19:39 +02:00
|
|
|
*
|
2008-12-28 21:41:33 +00:00
|
|
|
* Contributor(s): Blender Foundation, Nathan Letwory
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2012-08-02 21:36:33 +00:00
|
|
|
/** \file blender/editors/space_node/node_view.c
|
2011-02-27 20:29:51 +00:00
|
|
|
* \ingroup spnode
|
|
|
|
*/
|
|
|
|
|
2008-12-28 21:41:33 +00:00
|
|
|
#include "DNA_node_types.h"
|
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_rect.h"
|
|
|
|
#include "BLI_utildefines.h"
|
2012-08-16 14:47:14 +00:00
|
|
|
#include "BLI_math.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
|
2008-12-28 21:41:33 +00:00
|
|
|
#include "BKE_context.h"
|
2012-08-02 21:52:09 +00:00
|
|
|
#include "BKE_image.h"
|
|
|
|
#include "BKE_screen.h"
|
2012-08-07 18:45:24 +00:00
|
|
|
#include "BKE_node.h"
|
2008-12-28 21:41:33 +00:00
|
|
|
|
2012-08-02 21:52:09 +00:00
|
|
|
#include "ED_node.h" /* own include */
|
2008-12-28 21:41:33 +00:00
|
|
|
#include "ED_screen.h"
|
2012-08-02 21:52:09 +00:00
|
|
|
#include "ED_space_api.h"
|
|
|
|
#include "ED_image.h"
|
2008-12-28 21:41:33 +00:00
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
|
|
#include "UI_view2d.h"
|
2012-08-02 21:52:09 +00:00
|
|
|
|
2012-08-05 21:06:56 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2013-03-18 11:34:05 +00:00
|
|
|
#include "IMB_colormanagement.h"
|
2012-08-02 21:52:09 +00:00
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
|
|
|
|
#include "node_intern.h" /* own include */
|
2013-03-18 16:34:57 +00:00
|
|
|
#include "NOD_composite.h"
|
2008-12-28 21:41:33 +00:00
|
|
|
|
2009-01-01 16:27:02 +00:00
|
|
|
|
2009-11-20 21:04:41 +00:00
|
|
|
/* **************** View All Operator ************** */
|
|
|
|
|
2013-09-16 04:04:44 +00:00
|
|
|
int space_node_view_flag(bContext *C, SpaceNode *snode, ARegion *ar,
|
|
|
|
const int node_flag, const int smooth_viewtx)
|
2009-11-20 21:04:41 +00:00
|
|
|
{
|
|
|
|
bNode *node;
|
2012-08-07 16:30:34 +00:00
|
|
|
rctf cur_new;
|
2009-11-20 21:04:41 +00:00
|
|
|
float oldwidth, oldheight, width, height;
|
2013-01-03 16:36:17 +00:00
|
|
|
float oldasp, asp;
|
2012-08-07 18:45:24 +00:00
|
|
|
int tot = 0;
|
2014-01-28 03:52:21 +11:00
|
|
|
bool has_frame = false;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-09-15 11:48:20 +00:00
|
|
|
oldwidth = BLI_rctf_size_x(&ar->v2d.cur);
|
|
|
|
oldheight = BLI_rctf_size_y(&ar->v2d.cur);
|
2012-08-07 16:30:34 +00:00
|
|
|
|
2013-01-03 16:36:17 +00:00
|
|
|
oldasp = oldwidth / oldheight;
|
|
|
|
|
2012-08-07 16:30:34 +00:00
|
|
|
BLI_rctf_init_minmax(&cur_new);
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (snode->edittree) {
|
2012-08-04 12:54:27 +00:00
|
|
|
for (node = snode->edittree->nodes.first; node; node = node->next) {
|
2012-08-07 16:30:34 +00:00
|
|
|
if ((node->flag & node_flag) == node_flag) {
|
|
|
|
BLI_rctf_union(&cur_new, &node->totr);
|
2012-08-07 18:45:24 +00:00
|
|
|
tot++;
|
|
|
|
|
|
|
|
if (node->type == NODE_FRAME) {
|
2014-04-01 11:34:00 +11:00
|
|
|
has_frame = true;
|
2012-08-07 18:45:24 +00:00
|
|
|
}
|
2009-11-20 21:04:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-07 16:30:34 +00:00
|
|
|
|
2012-08-07 18:45:24 +00:00
|
|
|
if (tot) {
|
2012-09-15 11:48:20 +00:00
|
|
|
width = BLI_rctf_size_x(&cur_new);
|
|
|
|
height = BLI_rctf_size_y(&cur_new);
|
2013-01-03 16:36:17 +00:00
|
|
|
asp = width / height;
|
2012-08-07 16:30:34 +00:00
|
|
|
|
2012-08-07 18:45:24 +00:00
|
|
|
/* 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 */
|
|
|
|
if ((tot == 1) &&
|
2014-04-01 11:34:00 +11:00
|
|
|
(has_frame == false) &&
|
2012-08-07 18:45:24 +00:00
|
|
|
((oldwidth * oldheight) > (width * height)))
|
|
|
|
{
|
|
|
|
/* center, don't zoom */
|
|
|
|
BLI_rctf_resize(&cur_new, oldwidth, oldheight);
|
2012-08-07 16:30:34 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-01-03 16:36:17 +00:00
|
|
|
if (oldasp < asp) {
|
|
|
|
const float height_new = width / oldasp;
|
|
|
|
cur_new.ymin = cur_new.ymin - height_new / 2.0f;
|
|
|
|
cur_new.ymax = cur_new.ymax + height_new / 2.0f;
|
2012-08-07 18:45:24 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-01-03 16:36:17 +00:00
|
|
|
const float width_new = height * oldasp;
|
|
|
|
cur_new.xmin = cur_new.xmin - width_new / 2.0f;
|
|
|
|
cur_new.xmax = cur_new.xmax + width_new / 2.0f;
|
2012-08-07 18:45:24 +00:00
|
|
|
}
|
2013-01-11 04:34:15 +00:00
|
|
|
|
|
|
|
/* add some padding */
|
|
|
|
BLI_rctf_scale(&cur_new, 1.1f);
|
2012-08-07 16:30:34 +00:00
|
|
|
}
|
|
|
|
|
2013-09-16 04:04:44 +00:00
|
|
|
UI_view2d_smooth_view(C, ar, &cur_new, smooth_viewtx);
|
2009-11-20 21:04:41 +00:00
|
|
|
}
|
2010-07-19 22:47:15 +00:00
|
|
|
|
2012-08-07 18:45:24 +00:00
|
|
|
return (tot != 0);
|
2009-11-20 21:04:41 +00:00
|
|
|
}
|
|
|
|
|
2013-09-16 04:04:44 +00:00
|
|
|
static int node_view_all_exec(bContext *C, wmOperator *op)
|
2009-01-01 16:27:02 +00:00
|
|
|
{
|
2012-08-04 12:54:27 +00:00
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2013-09-16 04:04:44 +00:00
|
|
|
const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
|
2012-08-07 18:45:24 +00:00
|
|
|
|
|
|
|
/* is this really needed? */
|
|
|
|
snode->xof = 0;
|
|
|
|
snode->yof = 0;
|
|
|
|
|
2013-09-16 04:04:44 +00:00
|
|
|
if (space_node_view_flag(C, snode, ar, 0, smooth_viewtx)) {
|
2012-08-07 16:30:34 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
2009-01-01 16:27:02 +00:00
|
|
|
}
|
|
|
|
|
2009-03-29 02:15:13 +00:00
|
|
|
void NODE_OT_view_all(wmOperatorType *ot)
|
2009-01-01 16:27:02 +00:00
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "View All";
|
|
|
|
ot->idname = "NODE_OT_view_all";
|
|
|
|
ot->description = "Resize view so you can see all nodes";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-01 16:27:02 +00:00
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_view_all_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-31 19:40:40 +00:00
|
|
|
/* flags */
|
2012-08-04 12:54:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-01-16 23:53:11 +00:00
|
|
|
}
|
2012-08-02 21:52:09 +00:00
|
|
|
|
2013-09-16 04:04:44 +00:00
|
|
|
static int node_view_selected_exec(bContext *C, wmOperator *op)
|
2012-08-07 16:30:34 +00:00
|
|
|
{
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2013-09-16 04:04:44 +00:00
|
|
|
const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
|
2012-08-07 16:30:34 +00:00
|
|
|
|
2013-09-16 04:04:44 +00:00
|
|
|
if (space_node_view_flag(C, snode, ar, NODE_SELECT, smooth_viewtx)) {
|
2012-08-07 16:30:34 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_view_selected(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "View Selected";
|
|
|
|
ot->idname = "NODE_OT_view_selected";
|
|
|
|
ot->description = "Resize view so you can see selected nodes";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = node_view_selected_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
}
|
2012-08-02 21:52:09 +00:00
|
|
|
|
|
|
|
/* **************** Backround Image Operators ************** */
|
|
|
|
|
|
|
|
typedef struct NodeViewMove {
|
|
|
|
int mvalo[2];
|
|
|
|
int xmin, ymin, xmax, ymax;
|
|
|
|
} NodeViewMove;
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int snode_bg_viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
2012-08-02 21:52:09 +00:00
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
NodeViewMove *nvm = op->customdata;
|
|
|
|
|
|
|
|
switch (event->type) {
|
|
|
|
case MOUSEMOVE:
|
|
|
|
|
|
|
|
snode->xof -= (nvm->mvalo[0] - event->mval[0]);
|
|
|
|
snode->yof -= (nvm->mvalo[1] - event->mval[1]);
|
|
|
|
nvm->mvalo[0] = event->mval[0];
|
|
|
|
nvm->mvalo[1] = event->mval[1];
|
|
|
|
|
|
|
|
/* prevent dragging image outside of the window and losing it! */
|
|
|
|
CLAMP(snode->xof, nvm->xmin, nvm->xmax);
|
|
|
|
CLAMP(snode->yof, nvm->ymin, nvm->ymax);
|
|
|
|
|
|
|
|
ED_region_tag_redraw(ar);
|
2013-11-05 18:28:43 +00:00
|
|
|
WM_main_add_notifier(NC_NODE | ND_DISPLAY, NULL);
|
2012-08-02 21:52:09 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LEFTMOUSE:
|
|
|
|
case MIDDLEMOUSE:
|
|
|
|
case RIGHTMOUSE:
|
2018-06-08 18:52:00 +02:00
|
|
|
if (event->val == KM_RELEASE) {
|
|
|
|
MEM_freeN(nvm);
|
|
|
|
op->customdata = NULL;
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
break;
|
2012-08-02 21:52:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int snode_bg_viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
2012-08-02 21:52:09 +00:00
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
NodeViewMove *nvm;
|
|
|
|
Image *ima;
|
|
|
|
ImBuf *ibuf;
|
|
|
|
const float pad = 32.0f; /* better be bigger then scrollbars */
|
|
|
|
|
|
|
|
void *lock;
|
|
|
|
|
|
|
|
ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
|
|
|
|
ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
|
|
|
|
|
|
|
|
if (ibuf == NULL) {
|
2012-11-15 15:59:58 +00:00
|
|
|
BKE_image_release_ibuf(ima, ibuf, lock);
|
2012-08-02 21:52:09 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nvm = MEM_callocN(sizeof(NodeViewMove), "NodeViewMove struct");
|
|
|
|
op->customdata = nvm;
|
|
|
|
nvm->mvalo[0] = event->mval[0];
|
|
|
|
nvm->mvalo[1] = event->mval[1];
|
|
|
|
|
|
|
|
nvm->xmin = -(ar->winx / 2) - (ibuf->x * (0.5f * snode->zoom)) + pad;
|
|
|
|
nvm->xmax = (ar->winx / 2) + (ibuf->x * (0.5f * snode->zoom)) - pad;
|
|
|
|
nvm->ymin = -(ar->winy / 2) - (ibuf->y * (0.5f * snode->zoom)) + pad;
|
|
|
|
nvm->ymax = (ar->winy / 2) + (ibuf->y * (0.5f * snode->zoom)) - pad;
|
|
|
|
|
2012-11-15 15:59:58 +00:00
|
|
|
BKE_image_release_ibuf(ima, ibuf, lock);
|
2012-08-02 21:52:09 +00:00
|
|
|
|
|
|
|
/* add modal handler */
|
|
|
|
WM_event_add_modal_handler(C, op);
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
2013-10-30 23:08:53 +00:00
|
|
|
static void snode_bg_viewmove_cancel(bContext *UNUSED(C), wmOperator *op)
|
2012-08-02 21:52:09 +00:00
|
|
|
{
|
|
|
|
MEM_freeN(op->customdata);
|
|
|
|
op->customdata = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_backimage_move(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Background Image Move";
|
|
|
|
ot->description = "Move Node backdrop";
|
|
|
|
ot->idname = "NODE_OT_backimage_move";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->invoke = snode_bg_viewmove_invoke;
|
|
|
|
ot->modal = snode_bg_viewmove_modal;
|
|
|
|
ot->poll = composite_node_active;
|
|
|
|
ot->cancel = snode_bg_viewmove_cancel;
|
|
|
|
|
|
|
|
/* flags */
|
2015-04-27 18:44:27 +10:00
|
|
|
ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR;
|
2012-08-02 21:52:09 +00:00
|
|
|
}
|
|
|
|
|
2013-07-28 17:06:31 +00:00
|
|
|
static int backimage_zoom_exec(bContext *C, wmOperator *op)
|
2012-08-02 21:52:09 +00:00
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
float fac = RNA_float_get(op->ptr, "factor");
|
|
|
|
|
|
|
|
snode->zoom *= fac;
|
|
|
|
ED_region_tag_redraw(ar);
|
2013-11-05 18:28:43 +00:00
|
|
|
WM_main_add_notifier(NC_NODE | ND_DISPLAY, NULL);
|
2012-08-02 21:52:09 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NODE_OT_backimage_zoom(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Background Image Zoom";
|
|
|
|
ot->idname = "NODE_OT_backimage_zoom";
|
|
|
|
ot->description = "Zoom in/out the background image";
|
|
|
|
|
|
|
|
/* api callbacks */
|
2013-07-28 17:06:31 +00:00
|
|
|
ot->exec = backimage_zoom_exec;
|
2012-08-02 21:52:09 +00:00
|
|
|
ot->poll = composite_node_active;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_BLOCKING;
|
|
|
|
|
|
|
|
/* internal */
|
|
|
|
RNA_def_float(ot->srna, "factor", 1.2f, 0.0f, 10.0f, "Factor", "", 0.0f, 10.0f);
|
|
|
|
}
|
|
|
|
|
2013-09-01 15:01:03 +00:00
|
|
|
static int backimage_fit_exec(bContext *C, wmOperator *UNUSED(op))
|
2013-09-01 09:50:56 +00:00
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
|
|
|
|
Image *ima;
|
|
|
|
ImBuf *ibuf;
|
|
|
|
|
|
|
|
const float pad = 32.0f;
|
|
|
|
|
|
|
|
void *lock;
|
|
|
|
|
|
|
|
float facx, facy;
|
|
|
|
|
|
|
|
ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
|
|
|
|
ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
|
|
|
|
|
2017-05-30 02:39:07 +10:00
|
|
|
if ((ibuf == NULL) || (ibuf->x == 0) || (ibuf->y == 0)) {
|
2013-09-01 09:50:56 +00:00
|
|
|
BKE_image_release_ibuf(ima, ibuf, lock);
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
facx = 1.0f * (ar->sizex - pad) / (ibuf->x * snode->zoom);
|
|
|
|
facy = 1.0f * (ar->sizey - pad) / (ibuf->y * snode->zoom);
|
|
|
|
|
|
|
|
BKE_image_release_ibuf(ima, ibuf, lock);
|
|
|
|
|
|
|
|
snode->zoom *= min_ff(facx, facy);
|
|
|
|
|
|
|
|
snode->xof = 0;
|
|
|
|
snode->yof = 0;
|
|
|
|
|
|
|
|
ED_region_tag_redraw(ar);
|
2013-11-05 18:28:43 +00:00
|
|
|
WM_main_add_notifier(NC_NODE | ND_DISPLAY, NULL);
|
2013-09-01 09:50:56 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_backimage_fit(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Background Image Fit";
|
|
|
|
ot->idname = "NODE_OT_backimage_fit";
|
2013-09-30 05:50:41 +00:00
|
|
|
ot->description = "Fit the background image to the view";
|
2013-09-01 09:50:56 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = backimage_fit_exec;
|
|
|
|
ot->poll = composite_node_active;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_BLOCKING;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-08-02 21:52:09 +00:00
|
|
|
/******************** sample backdrop operator ********************/
|
|
|
|
|
|
|
|
typedef struct ImageSampleInfo {
|
|
|
|
ARegionType *art;
|
|
|
|
void *draw_handle;
|
|
|
|
int x, y;
|
|
|
|
int channels;
|
|
|
|
|
|
|
|
unsigned char col[4];
|
|
|
|
float colf[4];
|
2013-03-18 11:34:05 +00:00
|
|
|
float linearcol[4];
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-11-15 13:10:24 +00:00
|
|
|
int z;
|
|
|
|
float zf;
|
|
|
|
|
|
|
|
int *zp;
|
|
|
|
float *zfp;
|
2012-08-02 21:52:09 +00:00
|
|
|
|
|
|
|
int draw;
|
Color Management, Stage 2: Switch color pipeline to use OpenColorIO
Replace old color pipeline which was supporting linear/sRGB color spaces
only with OpenColorIO-based pipeline.
This introduces two configurable color spaces:
- Input color space for images and movie clips. This space is used to convert
images/movies from color space in which file is saved to Blender's linear
space (for float images, byte images are not internally converted, only input
space is stored for such images and used later).
This setting could be found in image/clip data block settings.
- Display color space which defines space in which particular display is working.
This settings could be found in scene's Color Management panel.
When render result is being displayed on the screen, apart from converting image
to display space, some additional conversions could happen.
This conversions are:
- View, which defines tone curve applying before display transformation.
These are different ways to view the image on the same display device.
For example it could be used to emulate film view on sRGB display.
- Exposure affects on image exposure before tone map is applied.
- Gamma is post-display gamma correction, could be used to match particular
display gamma.
- RGB curves are user-defined curves which are applying before display
transformation, could be used for different purposes.
All this settings by default are only applying on render result and does not
affect on other images. If some particular image needs to be affected by this
transformation, "View as Render" setting of image data block should be set to
truth. Movie clips are always affected by all display transformations.
This commit also introduces configurable color space in which sequencer is
working. This setting could be found in scene's Color Management panel and
it should be used if such stuff as grading needs to be done in color space
different from sRGB (i.e. when Film view on sRGB display is use, using VD16
space as sequencer's internal space would make grading working in space
which is close to the space using for display).
Some technical notes:
- Image buffer's float buffer is now always in linear space, even if it was
created from 16bit byte images.
- Space of byte buffer is stored in image buffer's rect_colorspace property.
- Profile of image buffer was removed since it's not longer meaningful.
- OpenGL and GLSL is supposed to always work in sRGB space. It is possible
to support other spaces, but it's quite large project which isn't so
much important.
- Legacy Color Management option disabled is emulated by using None display.
It could have some regressions, but there's no clear way to avoid them.
- If OpenColorIO is disabled on build time, it should make blender behaving
in the same way as previous release with color management enabled.
More details could be found at this page (more details would be added soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Color_Management
--
Thanks to Xavier Thomas, Lukas Toene for initial work on OpenColorIO
integration and to Brecht van Lommel for some further development and code/
usecase review!
2012-09-15 10:05:07 +00:00
|
|
|
int color_manage;
|
2012-08-02 21:52:09 +00:00
|
|
|
} ImageSampleInfo;
|
|
|
|
|
|
|
|
static void sample_draw(const bContext *C, ARegion *ar, void *arg_info)
|
|
|
|
{
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
ImageSampleInfo *info = arg_info;
|
|
|
|
|
|
|
|
if (info->draw) {
|
2014-04-01 11:34:00 +11:00
|
|
|
ED_image_draw_info(scene, ar, info->color_manage, false, info->channels,
|
2013-03-18 11:34:05 +00:00
|
|
|
info->x, info->y, info->col, info->colf, info->linearcol,
|
2012-11-15 13:10:24 +00:00
|
|
|
info->zp, info->zfp);
|
2012-08-02 21:52:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-20 22:41:26 +02:00
|
|
|
/* Returns color in linear space, matching ED_space_image_color_sample().
|
2014-04-14 13:45:09 +06:00
|
|
|
* And here we've got recursion in the comments tips...
|
|
|
|
*/
|
2017-04-20 22:41:26 +02:00
|
|
|
bool ED_space_node_color_sample(SpaceNode *snode, ARegion *ar, int mval[2], float r_col[3])
|
2012-08-16 14:47:14 +00:00
|
|
|
{
|
|
|
|
void *lock;
|
|
|
|
Image *ima;
|
|
|
|
ImBuf *ibuf;
|
|
|
|
float fx, fy, bufx, bufy;
|
2014-04-11 11:25:41 +10:00
|
|
|
bool ret = false;
|
2012-08-16 14:47:14 +00:00
|
|
|
|
2017-04-20 22:32:00 +02:00
|
|
|
if (!ED_node_is_compositor(snode) || (snode->flag & SNODE_BACKDRAW) == 0) {
|
2012-09-20 10:38:12 +00:00
|
|
|
/* use viewer image for color sampling only if we're in compositor tree
|
|
|
|
* with backdrop enabled
|
|
|
|
*/
|
2014-04-01 11:34:00 +11:00
|
|
|
return false;
|
2012-09-20 10:38:12 +00:00
|
|
|
}
|
|
|
|
|
2012-08-16 14:47:14 +00:00
|
|
|
ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
|
|
|
|
ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
|
|
|
|
if (!ibuf) {
|
2014-04-01 11:34:00 +11:00
|
|
|
return false;
|
2012-08-16 14:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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) {
|
2014-04-27 00:22:49 +10:00
|
|
|
const float *fp;
|
2012-08-17 12:32:13 +00:00
|
|
|
unsigned char *cp;
|
2012-08-16 14:47:14 +00:00
|
|
|
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));
|
2012-08-17 13:00:11 +00:00
|
|
|
/* IB_PROFILE_NONE is default but infact its linear */
|
2014-04-14 13:45:09 +06:00
|
|
|
copy_v3_v3(r_col, fp);
|
2014-04-01 11:34:00 +11:00
|
|
|
ret = true;
|
2012-08-16 14:47:14 +00:00
|
|
|
}
|
|
|
|
else if (ibuf->rect) {
|
2012-08-17 12:32:13 +00:00
|
|
|
cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x);
|
2014-04-14 17:56:04 +06:00
|
|
|
rgb_uchar_to_float(r_col, cp);
|
2014-04-14 13:45:09 +06:00
|
|
|
IMB_colormanagement_colorspace_to_scene_linear_v3(r_col, ibuf->rect_colorspace);
|
2014-04-01 11:34:00 +11:00
|
|
|
ret = true;
|
2012-08-16 14:47:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-15 15:59:58 +00:00
|
|
|
BKE_image_release_ibuf(ima, ibuf, lock);
|
2012-08-16 14:47:14 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static void sample_apply(bContext *C, wmOperator *op, const wmEvent *event)
|
2012-08-02 21:52:09 +00:00
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
ImageSampleInfo *info = op->customdata;
|
|
|
|
void *lock;
|
|
|
|
Image *ima;
|
|
|
|
ImBuf *ibuf;
|
|
|
|
float fx, fy, bufx, bufy;
|
|
|
|
|
|
|
|
ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
|
|
|
|
ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
|
|
|
|
if (!ibuf) {
|
|
|
|
info->draw = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ibuf->rect) {
|
|
|
|
IMB_rect_from_float(ibuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* map the mouse coords to the backdrop image space */
|
|
|
|
bufx = ibuf->x * snode->zoom;
|
|
|
|
bufy = ibuf->y * snode->zoom;
|
|
|
|
fx = (bufx > 0.0f ? ((float)event->mval[0] - 0.5f * ar->winx - snode->xof) / bufx + 0.5f : 0.0f);
|
|
|
|
fy = (bufy > 0.0f ? ((float)event->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) {
|
2014-04-27 00:22:49 +10:00
|
|
|
const float *fp;
|
2012-08-17 13:00:11 +00:00
|
|
|
unsigned char *cp;
|
2012-08-02 21:52:09 +00:00
|
|
|
int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y);
|
|
|
|
|
|
|
|
CLAMP(x, 0, ibuf->x - 1);
|
|
|
|
CLAMP(y, 0, ibuf->y - 1);
|
|
|
|
|
|
|
|
info->x = x;
|
|
|
|
info->y = y;
|
|
|
|
info->draw = 1;
|
|
|
|
info->channels = ibuf->channels;
|
|
|
|
|
2012-11-15 13:10:24 +00:00
|
|
|
info->zp = NULL;
|
|
|
|
info->zfp = NULL;
|
|
|
|
|
2012-08-02 21:52:09 +00:00
|
|
|
if (ibuf->rect) {
|
2012-08-17 13:00:11 +00:00
|
|
|
cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x);
|
2012-08-02 21:52:09 +00:00
|
|
|
|
|
|
|
info->col[0] = cp[0];
|
|
|
|
info->col[1] = cp[1];
|
|
|
|
info->col[2] = cp[2];
|
|
|
|
info->col[3] = cp[3];
|
|
|
|
|
|
|
|
info->colf[0] = (float)cp[0] / 255.0f;
|
|
|
|
info->colf[1] = (float)cp[1] / 255.0f;
|
|
|
|
info->colf[2] = (float)cp[2] / 255.0f;
|
|
|
|
info->colf[3] = (float)cp[3] / 255.0f;
|
Color Management, Stage 2: Switch color pipeline to use OpenColorIO
Replace old color pipeline which was supporting linear/sRGB color spaces
only with OpenColorIO-based pipeline.
This introduces two configurable color spaces:
- Input color space for images and movie clips. This space is used to convert
images/movies from color space in which file is saved to Blender's linear
space (for float images, byte images are not internally converted, only input
space is stored for such images and used later).
This setting could be found in image/clip data block settings.
- Display color space which defines space in which particular display is working.
This settings could be found in scene's Color Management panel.
When render result is being displayed on the screen, apart from converting image
to display space, some additional conversions could happen.
This conversions are:
- View, which defines tone curve applying before display transformation.
These are different ways to view the image on the same display device.
For example it could be used to emulate film view on sRGB display.
- Exposure affects on image exposure before tone map is applied.
- Gamma is post-display gamma correction, could be used to match particular
display gamma.
- RGB curves are user-defined curves which are applying before display
transformation, could be used for different purposes.
All this settings by default are only applying on render result and does not
affect on other images. If some particular image needs to be affected by this
transformation, "View as Render" setting of image data block should be set to
truth. Movie clips are always affected by all display transformations.
This commit also introduces configurable color space in which sequencer is
working. This setting could be found in scene's Color Management panel and
it should be used if such stuff as grading needs to be done in color space
different from sRGB (i.e. when Film view on sRGB display is use, using VD16
space as sequencer's internal space would make grading working in space
which is close to the space using for display).
Some technical notes:
- Image buffer's float buffer is now always in linear space, even if it was
created from 16bit byte images.
- Space of byte buffer is stored in image buffer's rect_colorspace property.
- Profile of image buffer was removed since it's not longer meaningful.
- OpenGL and GLSL is supposed to always work in sRGB space. It is possible
to support other spaces, but it's quite large project which isn't so
much important.
- Legacy Color Management option disabled is emulated by using None display.
It could have some regressions, but there's no clear way to avoid them.
- If OpenColorIO is disabled on build time, it should make blender behaving
in the same way as previous release with color management enabled.
More details could be found at this page (more details would be added soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Color_Management
--
Thanks to Xavier Thomas, Lukas Toene for initial work on OpenColorIO
integration and to Brecht van Lommel for some further development and code/
usecase review!
2012-09-15 10:05:07 +00:00
|
|
|
|
2013-03-18 11:34:05 +00:00
|
|
|
copy_v4_v4(info->linearcol, info->colf);
|
|
|
|
IMB_colormanagement_colorspace_to_scene_linear_v4(info->linearcol, false, ibuf->rect_colorspace);
|
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
info->color_manage = true;
|
2012-08-02 21:52:09 +00:00
|
|
|
}
|
|
|
|
if (ibuf->rect_float) {
|
|
|
|
fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x));
|
|
|
|
|
|
|
|
info->colf[0] = fp[0];
|
|
|
|
info->colf[1] = fp[1];
|
|
|
|
info->colf[2] = fp[2];
|
|
|
|
info->colf[3] = fp[3];
|
Color Management, Stage 2: Switch color pipeline to use OpenColorIO
Replace old color pipeline which was supporting linear/sRGB color spaces
only with OpenColorIO-based pipeline.
This introduces two configurable color spaces:
- Input color space for images and movie clips. This space is used to convert
images/movies from color space in which file is saved to Blender's linear
space (for float images, byte images are not internally converted, only input
space is stored for such images and used later).
This setting could be found in image/clip data block settings.
- Display color space which defines space in which particular display is working.
This settings could be found in scene's Color Management panel.
When render result is being displayed on the screen, apart from converting image
to display space, some additional conversions could happen.
This conversions are:
- View, which defines tone curve applying before display transformation.
These are different ways to view the image on the same display device.
For example it could be used to emulate film view on sRGB display.
- Exposure affects on image exposure before tone map is applied.
- Gamma is post-display gamma correction, could be used to match particular
display gamma.
- RGB curves are user-defined curves which are applying before display
transformation, could be used for different purposes.
All this settings by default are only applying on render result and does not
affect on other images. If some particular image needs to be affected by this
transformation, "View as Render" setting of image data block should be set to
truth. Movie clips are always affected by all display transformations.
This commit also introduces configurable color space in which sequencer is
working. This setting could be found in scene's Color Management panel and
it should be used if such stuff as grading needs to be done in color space
different from sRGB (i.e. when Film view on sRGB display is use, using VD16
space as sequencer's internal space would make grading working in space
which is close to the space using for display).
Some technical notes:
- Image buffer's float buffer is now always in linear space, even if it was
created from 16bit byte images.
- Space of byte buffer is stored in image buffer's rect_colorspace property.
- Profile of image buffer was removed since it's not longer meaningful.
- OpenGL and GLSL is supposed to always work in sRGB space. It is possible
to support other spaces, but it's quite large project which isn't so
much important.
- Legacy Color Management option disabled is emulated by using None display.
It could have some regressions, but there's no clear way to avoid them.
- If OpenColorIO is disabled on build time, it should make blender behaving
in the same way as previous release with color management enabled.
More details could be found at this page (more details would be added soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Color_Management
--
Thanks to Xavier Thomas, Lukas Toene for initial work on OpenColorIO
integration and to Brecht van Lommel for some further development and code/
usecase review!
2012-09-15 10:05:07 +00:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
info->color_manage = true;
|
2012-08-02 21:52:09 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-11-15 13:10:24 +00:00
|
|
|
if (ibuf->zbuf) {
|
|
|
|
info->z = ibuf->zbuf[y * ibuf->x + x];
|
|
|
|
info->zp = &info->z;
|
|
|
|
}
|
|
|
|
if (ibuf->zbuf_float) {
|
|
|
|
info->zf = ibuf->zbuf_float[y * ibuf->x + x];
|
|
|
|
info->zfp = &info->zf;
|
|
|
|
}
|
2012-08-02 21:52:09 +00:00
|
|
|
|
|
|
|
ED_node_sample_set(info->colf);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
info->draw = 0;
|
|
|
|
ED_node_sample_set(NULL);
|
|
|
|
}
|
|
|
|
|
2012-11-15 15:59:58 +00:00
|
|
|
BKE_image_release_ibuf(ima, ibuf, lock);
|
2012-08-02 21:52:09 +00:00
|
|
|
|
|
|
|
ED_area_tag_redraw(CTX_wm_area(C));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sample_exit(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
ImageSampleInfo *info = op->customdata;
|
|
|
|
|
|
|
|
ED_node_sample_set(NULL);
|
|
|
|
ED_region_draw_cb_exit(info->art, info->draw_handle);
|
|
|
|
ED_area_tag_redraw(CTX_wm_area(C));
|
|
|
|
MEM_freeN(info);
|
|
|
|
}
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int sample_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
2012-08-02 21:52:09 +00:00
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
ImageSampleInfo *info;
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
if (!ED_node_is_compositor(snode) || !(snode->flag & SNODE_BACKDRAW))
|
2012-08-02 21:52:09 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
info = MEM_callocN(sizeof(ImageSampleInfo), "ImageSampleInfo");
|
|
|
|
info->art = ar->type;
|
|
|
|
info->draw_handle = ED_region_draw_cb_activate(ar->type, sample_draw, info, REGION_DRAW_POST_PIXEL);
|
|
|
|
op->customdata = info;
|
|
|
|
|
|
|
|
sample_apply(C, op, event);
|
|
|
|
|
|
|
|
WM_event_add_modal_handler(C, op);
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int sample_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
2012-08-02 21:52:09 +00:00
|
|
|
{
|
|
|
|
switch (event->type) {
|
|
|
|
case LEFTMOUSE:
|
|
|
|
case RIGHTMOUSE: // XXX hardcoded
|
2015-04-06 23:10:21 +02:00
|
|
|
if (event->val == KM_RELEASE) {
|
|
|
|
sample_exit(C, op);
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
break;
|
2012-08-02 21:52:09 +00:00
|
|
|
case MOUSEMOVE:
|
|
|
|
sample_apply(C, op, event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
2013-10-30 23:08:53 +00:00
|
|
|
static void sample_cancel(bContext *C, wmOperator *op)
|
2012-08-02 21:52:09 +00:00
|
|
|
{
|
|
|
|
sample_exit(C, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_backimage_sample(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Backimage Sample";
|
|
|
|
ot->idname = "NODE_OT_backimage_sample";
|
|
|
|
ot->description = "Use mouse to sample background image";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->invoke = sample_invoke;
|
|
|
|
ot->modal = sample_modal;
|
|
|
|
ot->cancel = sample_cancel;
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_BLOCKING;
|
|
|
|
}
|