Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-04-17 07:17:24 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-17 07:21:24 +0300
commite12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch)
tree8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/editors/space_image
parentb3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff)
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/editors/space_image')
-rw-r--r--source/blender/editors/space_image/CMakeLists.txt62
-rw-r--r--source/blender/editors/space_image/image_buttons.c2287
-rw-r--r--source/blender/editors/space_image/image_draw.c1501
-rw-r--r--source/blender/editors/space_image/image_edit.c555
-rw-r--r--source/blender/editors/space_image/image_intern.h1
-rw-r--r--source/blender/editors/space_image/image_ops.c5789
-rw-r--r--source/blender/editors/space_image/space_image.c1559
7 files changed, 6089 insertions, 5665 deletions
diff --git a/source/blender/editors/space_image/CMakeLists.txt b/source/blender/editors/space_image/CMakeLists.txt
index 2687849f211..70b7387bf6b 100644
--- a/source/blender/editors/space_image/CMakeLists.txt
+++ b/source/blender/editors/space_image/CMakeLists.txt
@@ -16,65 +16,65 @@
# ***** END GPL LICENSE BLOCK *****
set(INC
- ../include
- ../../blenfont
- ../../blenkernel
- ../../blenlib
- ../../blentranslation
- ../../bmesh
- ../../depsgraph
- ../../imbuf
- ../../gpu
- ../../makesdna
- ../../makesrna
- ../../render/extern/include
- ../../windowmanager
- ../../../../intern/guardedalloc
- ../../../../intern/glew-mx
+ ../include
+ ../../blenfont
+ ../../blenkernel
+ ../../blenlib
+ ../../blentranslation
+ ../../bmesh
+ ../../depsgraph
+ ../../imbuf
+ ../../gpu
+ ../../makesdna
+ ../../makesrna
+ ../../render/extern/include
+ ../../windowmanager
+ ../../../../intern/guardedalloc
+ ../../../../intern/glew-mx
)
set(INC_SYS
- ${GLEW_INCLUDE_PATH}
+ ${GLEW_INCLUDE_PATH}
)
set(SRC
- image_buttons.c
- image_draw.c
- image_edit.c
- image_ops.c
- space_image.c
+ image_buttons.c
+ image_draw.c
+ image_edit.c
+ image_ops.c
+ space_image.c
- image_intern.h
+ image_intern.h
)
set(LIB
- bf_blenkernel
- bf_blenlib
- bf_editor_uvedit
+ bf_blenkernel
+ bf_blenlib
+ bf_editor_uvedit
)
if(WITH_INTERNATIONAL)
- add_definitions(-DWITH_INTERNATIONAL)
+ add_definitions(-DWITH_INTERNATIONAL)
endif()
if(WITH_OPENIMAGEIO)
- add_definitions(-DWITH_OPENIMAGEIO)
+ add_definitions(-DWITH_OPENIMAGEIO)
endif()
if(WITH_IMAGE_OPENJPEG)
- add_definitions(-DWITH_OPENJPEG)
+ add_definitions(-DWITH_OPENJPEG)
endif()
if(WITH_IMAGE_OPENEXR)
- add_definitions(-DWITH_OPENEXR)
+ add_definitions(-DWITH_OPENEXR)
endif()
if(WITH_IMAGE_TIFF)
- add_definitions(-DWITH_TIFF)
+ add_definitions(-DWITH_TIFF)
endif()
if(WITH_IMAGE_CINEON)
- add_definitions(-DWITH_CINEON)
+ add_definitions(-DWITH_CINEON)
endif()
add_definitions(${GL_DEFINITIONS})
diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c
index 47b3f9995c5..e217987f212 100644
--- a/source/blender/editors/space_image/image_buttons.c
+++ b/source/blender/editors/space_image/image_buttons.c
@@ -60,97 +60,100 @@
#include "image_intern.h"
#define B_NOP -1
-#define MAX_IMAGE_INFO_LEN 128
+#define MAX_IMAGE_INFO_LEN 128
/* proto */
-static void image_info(Scene *scene, ImageUser *iuser, Image *ima, ImBuf *ibuf, char *str, size_t len)
+static void image_info(
+ Scene *scene, ImageUser *iuser, Image *ima, ImBuf *ibuf, char *str, size_t len)
{
- size_t ofs = 0;
-
- str[0] = 0;
- if (ima == NULL) {
- return;
- }
-
- if (ibuf == NULL) {
- ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Can't Load Image"), len - ofs);
- }
- else {
- if (ima->source == IMA_SRC_MOVIE) {
- ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Movie"), len - ofs);
- if (BKE_image_has_anim(ima)) {
- ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_(" %d frs"),
- IMB_anim_get_duration(((ImageAnim *)ima->anims.first)->anim, IMB_TC_RECORD_RUN));
- }
- }
- else {
- ofs += BLI_strncpy_rlen(str, IFACE_("Image"), len - ofs);
- }
-
- ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_(": size %d x %d,"), ibuf->x, ibuf->y);
-
- if (ibuf->rect_float) {
- if (ibuf->channels != 4) {
- ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_("%d float channel(s)"), ibuf->channels);
- }
- else if (ibuf->planes == R_IMF_PLANES_RGBA) {
- ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" RGBA float"), len - ofs);
- }
- else {
- ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" RGB float"), len - ofs);
- }
- }
- else {
- if (ibuf->planes == R_IMF_PLANES_RGBA) {
- ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" RGBA byte"), len - ofs);
- }
- else {
- ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" RGB byte"), len - ofs);
- }
- }
- if (ibuf->zbuf || ibuf->zbuf_float) {
- ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" + Z"), len - ofs);
- }
-
- if (ima->source == IMA_SRC_SEQUENCE) {
- const char *file = BLI_last_slash(ibuf->name);
- if (file == NULL) {
- file = ibuf->name;
- }
- else {
- file++;
- }
- ofs += BLI_snprintf(str + ofs, len - ofs, ", %s", file);
- }
- }
-
- /* the frame number, even if we cant */
- if (ima->source == IMA_SRC_SEQUENCE) {
- /* don't use iuser->framenr directly because it may not be updated if auto-refresh is off */
- const int framenr = BKE_image_user_frame_get(iuser, CFRA, NULL);
- ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_(", Frame: %d"), framenr);
- }
+ size_t ofs = 0;
+
+ str[0] = 0;
+ if (ima == NULL) {
+ return;
+ }
+
+ if (ibuf == NULL) {
+ ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Can't Load Image"), len - ofs);
+ }
+ else {
+ if (ima->source == IMA_SRC_MOVIE) {
+ ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Movie"), len - ofs);
+ if (BKE_image_has_anim(ima)) {
+ ofs += BLI_snprintf(
+ str + ofs,
+ len - ofs,
+ IFACE_(" %d frs"),
+ IMB_anim_get_duration(((ImageAnim *)ima->anims.first)->anim, IMB_TC_RECORD_RUN));
+ }
+ }
+ else {
+ ofs += BLI_strncpy_rlen(str, IFACE_("Image"), len - ofs);
+ }
+
+ ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_(": size %d x %d,"), ibuf->x, ibuf->y);
+
+ if (ibuf->rect_float) {
+ if (ibuf->channels != 4) {
+ ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_("%d float channel(s)"), ibuf->channels);
+ }
+ else if (ibuf->planes == R_IMF_PLANES_RGBA) {
+ ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" RGBA float"), len - ofs);
+ }
+ else {
+ ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" RGB float"), len - ofs);
+ }
+ }
+ else {
+ if (ibuf->planes == R_IMF_PLANES_RGBA) {
+ ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" RGBA byte"), len - ofs);
+ }
+ else {
+ ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" RGB byte"), len - ofs);
+ }
+ }
+ if (ibuf->zbuf || ibuf->zbuf_float) {
+ ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" + Z"), len - ofs);
+ }
+
+ if (ima->source == IMA_SRC_SEQUENCE) {
+ const char *file = BLI_last_slash(ibuf->name);
+ if (file == NULL) {
+ file = ibuf->name;
+ }
+ else {
+ file++;
+ }
+ ofs += BLI_snprintf(str + ofs, len - ofs, ", %s", file);
+ }
+ }
+
+ /* the frame number, even if we cant */
+ if (ima->source == IMA_SRC_SEQUENCE) {
+ /* don't use iuser->framenr directly because it may not be updated if auto-refresh is off */
+ const int framenr = BKE_image_user_frame_get(iuser, CFRA, NULL);
+ ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_(", Frame: %d"), framenr);
+ }
}
/* gets active viewer user */
struct ImageUser *ntree_get_active_iuser(bNodeTree *ntree)
{
- bNode *node;
-
- if (ntree) {
- for (node = ntree->nodes.first; node; node = node->next) {
- if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
- if (node->flag & NODE_DO_OUTPUT) {
- return node->storage;
- }
- }
- }
- }
- return NULL;
+ bNode *node;
+
+ if (ntree) {
+ for (node = ntree->nodes.first; node; node = node->next) {
+ if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
+ if (node->flag & NODE_DO_OUTPUT) {
+ return node->storage;
+ }
+ }
+ }
+ }
+ return NULL;
}
-
/* ************ panel stuff ************* */
#if 0
@@ -160,1203 +163,1351 @@ struct ImageUser *ntree_get_active_iuser(bNodeTree *ntree)
* XXX if you put this back, also check XXX in image_main_region_draw() */
void image_preview_event(int event)
{
- int exec = 0;
+ int exec = 0;
- if (event == 0) {
- G.scene->r.scemode &= ~R_COMP_CROP;
- exec = 1;
- }
- else {
- if (image_preview_active(curarea, NULL, NULL)) {
- G.scene->r.scemode |= R_COMP_CROP;
- exec = 1;
- }
- else
- G.scene->r.scemode &= ~R_COMP_CROP;
- }
+ if (event == 0) {
+ G.scene->r.scemode &= ~R_COMP_CROP;
+ exec = 1;
+ }
+ else {
+ if (image_preview_active(curarea, NULL, NULL)) {
+ G.scene->r.scemode |= R_COMP_CROP;
+ exec = 1;
+ }
+ else
+ G.scene->r.scemode &= ~R_COMP_CROP;
+ }
- if (exec && G.scene->nodetree) {
- Scene *scene = G.scene;
- /* should work when no node editor in screen..., so we execute right away */
+ if (exec && G.scene->nodetree) {
+ Scene *scene = G.scene;
+ /* should work when no node editor in screen..., so we execute right away */
- ntreeCompositTagGenerators(G.scene->nodetree);
+ ntreeCompositTagGenerators(G.scene->nodetree);
- G.is_break = false;
- G.scene->nodetree->timecursor = set_timecursor;
- G.scene->nodetree->test_break = BKE_blender_test_break;
+ G.is_break = false;
+ G.scene->nodetree->timecursor = set_timecursor;
+ G.scene->nodetree->test_break = BKE_blender_test_break;
- BIF_store_spare();
+ BIF_store_spare();
- /* 1 is do_previews */
- ntreeCompositExecTree(scene->nodetree, &scene->r, 1, &scene->view_settings, &scene->display_settings);
+ /* 1 is do_previews */
+ ntreeCompositExecTree(scene->nodetree, &scene->r, 1, &scene->view_settings, &scene->display_settings);
- G.scene->nodetree->timecursor = NULL;
- G.scene->nodetree->test_break = NULL;
+ G.scene->nodetree->timecursor = NULL;
+ G.scene->nodetree->test_break = NULL;
- scrarea_do_windraw(curarea);
- waitcursor(0);
+ scrarea_do_windraw(curarea);
+ waitcursor(0);
- WM_event_add_notifier(C, NC_IMAGE, ima_v);
- }
+ WM_event_add_notifier(C, NC_IMAGE, ima_v);
+ }
}
/* nothing drawn here, we use it to store values */
static void preview_cb(ScrArea *sa, struct uiBlock *block)
{
- SpaceImage *sima = sa->spacedata.first;
- rctf dispf;
- rcti *disprect = &G.scene->r.disprect;
- int winx = (G.scene->r.size * G.scene->r.xsch) / 100;
- int winy = (G.scene->r.size * G.scene->r.ysch) / 100;
- int mval[2];
-
- if (G.scene->r.mode & R_BORDER) {
- winx *= BLI_rcti_size_x(&G.scene->r.border);
- winy *= BLI_rctf_size_y(&G.scene->r.border);
- }
-
- /* while dragging we need to update the rects, otherwise it doesn't end with correct one */
-
- BLI_rctf_init(&dispf, 15.0f, BLI_rcti_size_x(&block->rect) - 15.0f, 15.0f, (BLI_rctf_size_y(&block->rect)) - 15.0f);
- ui_graphics_to_window_rct(sa->win, &dispf, disprect);
-
- /* correction for gla draw */
- BLI_rcti_translate(disprect, -curarea->winrct.xmin, -curarea->winrct.ymin);
-
- calc_image_view(sima, 'p');
-// printf("winrct %d %d %d %d\n", disprect->xmin, disprect->ymin, disprect->xmax, disprect->ymax);
- /* map to image space coordinates */
- mval[0] = disprect->xmin; mval[1] = disprect->ymin;
- areamouseco_to_ipoco(v2d, mval, &dispf.xmin, &dispf.ymin);
- mval[0] = disprect->xmax; mval[1] = disprect->ymax;
- areamouseco_to_ipoco(v2d, mval, &dispf.xmax, &dispf.ymax);
-
- /* map to render coordinates */
- disprect->xmin = dispf.xmin;
- disprect->xmax = dispf.xmax;
- disprect->ymin = dispf.ymin;
- disprect->ymax = dispf.ymax;
-
- CLAMP(disprect->xmin, 0, winx);
- CLAMP(disprect->xmax, 0, winx);
- CLAMP(disprect->ymin, 0, winy);
- CLAMP(disprect->ymax, 0, winy);
-// printf("drawrct %d %d %d %d\n", disprect->xmin, disprect->ymin, disprect->xmax, disprect->ymax);
+ SpaceImage *sima = sa->spacedata.first;
+ rctf dispf;
+ rcti *disprect = &G.scene->r.disprect;
+ int winx = (G.scene->r.size * G.scene->r.xsch) / 100;
+ int winy = (G.scene->r.size * G.scene->r.ysch) / 100;
+ int mval[2];
+
+ if (G.scene->r.mode & R_BORDER) {
+ winx *= BLI_rcti_size_x(&G.scene->r.border);
+ winy *= BLI_rctf_size_y(&G.scene->r.border);
+ }
+
+ /* while dragging we need to update the rects, otherwise it doesn't end with correct one */
+
+ BLI_rctf_init(&dispf, 15.0f, BLI_rcti_size_x(&block->rect) - 15.0f, 15.0f, (BLI_rctf_size_y(&block->rect)) - 15.0f);
+ ui_graphics_to_window_rct(sa->win, &dispf, disprect);
+
+ /* correction for gla draw */
+ BLI_rcti_translate(disprect, -curarea->winrct.xmin, -curarea->winrct.ymin);
+
+ calc_image_view(sima, 'p');
+// printf("winrct %d %d %d %d\n", disprect->xmin, disprect->ymin, disprect->xmax, disprect->ymax);
+ /* map to image space coordinates */
+ mval[0] = disprect->xmin; mval[1] = disprect->ymin;
+ areamouseco_to_ipoco(v2d, mval, &dispf.xmin, &dispf.ymin);
+ mval[0] = disprect->xmax; mval[1] = disprect->ymax;
+ areamouseco_to_ipoco(v2d, mval, &dispf.xmax, &dispf.ymax);
+
+ /* map to render coordinates */
+ disprect->xmin = dispf.xmin;
+ disprect->xmax = dispf.xmax;
+ disprect->ymin = dispf.ymin;
+ disprect->ymax = dispf.ymax;
+
+ CLAMP(disprect->xmin, 0, winx);
+ CLAMP(disprect->xmax, 0, winx);
+ CLAMP(disprect->ymin, 0, winy);
+ CLAMP(disprect->ymax, 0, winy);
+// printf("drawrct %d %d %d %d\n", disprect->xmin, disprect->ymin, disprect->xmax, disprect->ymax);
}
static bool is_preview_allowed(ScrArea *cur)
{
- SpaceImage *sima = cur->spacedata.first;
- ScrArea *sa;
-
- /* check if another areawindow has preview set */
- for (sa = G.curscreen->areabase.first; sa; sa = sa->next) {
- if (sa != cur && sa->spacetype == SPACE_IMAGE) {
- if (image_preview_active(sa, NULL, NULL))
- return 0;
- }
- }
- /* check image type */
- if (sima->image == NULL || sima->image->type != IMA_TYPE_COMPOSITE)
- return 0;
-
- return 1;
+ SpaceImage *sima = cur->spacedata.first;
+ ScrArea *sa;
+
+ /* check if another areawindow has preview set */
+ for (sa = G.curscreen->areabase.first; sa; sa = sa->next) {
+ if (sa != cur && sa->spacetype == SPACE_IMAGE) {
+ if (image_preview_active(sa, NULL, NULL))
+ return 0;
+ }
+ }
+ /* check image type */
+ if (sima->image == NULL || sima->image->type != IMA_TYPE_COMPOSITE)
+ return 0;
+
+ return 1;
}
static void image_panel_preview(ScrArea *sa, short cntrl) // IMAGE_HANDLER_PREVIEW
{
- uiBlock *block;
- SpaceImage *sima = sa->spacedata.first;
- int ofsx, ofsy;
+ uiBlock *block;
+ SpaceImage *sima = sa->spacedata.first;
+ int ofsx, ofsy;
- if (is_preview_allowed(sa) == 0) {
- rem_blockhandler(sa, IMAGE_HANDLER_PREVIEW);
- G.scene->r.scemode &= ~R_COMP_CROP; /* quite weak */
- return;
- }
+ if (is_preview_allowed(sa) == 0) {
+ rem_blockhandler(sa, IMAGE_HANDLER_PREVIEW);
+ G.scene->r.scemode &= ~R_COMP_CROP; /* quite weak */
+ return;
+ }
- block = UI_block_begin(C, ar, __func__, UI_EMBOSS);
- uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | UI_PNL_SCALE | cntrl);
- uiSetPanelHandler(IMAGE_HANDLER_PREVIEW); // for close and esc
+ block = UI_block_begin(C, ar, __func__, UI_EMBOSS);
+ uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | UI_PNL_SCALE | cntrl);
+ uiSetPanelHandler(IMAGE_HANDLER_PREVIEW); // for close and esc
- ofsx = -150 + (sa->winx / 2) / sima->blockscale;
- ofsy = -100 + (sa->winy / 2) / sima->blockscale;
- if (uiNewPanel(C, ar, block, "Preview", "Image", ofsx, ofsy, 300, 200) == 0) return;
+ ofsx = -150 + (sa->winx / 2) / sima->blockscale;
+ ofsy = -100 + (sa->winy / 2) / sima->blockscale;
+ if (uiNewPanel(C, ar, block, "Preview", "Image", ofsx, ofsy, 300, 200) == 0) return;
- UI_but_func_drawextra_set(block, preview_cb);
+ UI_but_func_drawextra_set(block, preview_cb);
}
#endif
-
/* ********************* callbacks for standard image buttons *************** */
static void ui_imageuser_slot_menu(bContext *UNUSED(C), uiLayout *layout, void *image_p)
{
- uiBlock *block = uiLayoutGetBlock(layout);
- Image *image = image_p;
- int slot_id;
-
- uiDefBut(block, UI_BTYPE_LABEL, 0, IFACE_("Slot"),
- 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
- uiItemS(layout);
-
- slot_id = BLI_listbase_count(&image->renderslots) - 1;
- for (RenderSlot *slot = image->renderslots.last; slot; slot = slot->prev) {
- char str[64];
- if (slot->name[0] != '\0') {
- BLI_strncpy(str, slot->name, sizeof(str));
- }
- else {
- BLI_snprintf(str, sizeof(str), IFACE_("Slot %d"), slot_id + 1);
- }
- uiDefButS(block, UI_BTYPE_BUT_MENU, B_NOP, str, 0, 0,
- UI_UNIT_X * 5, UI_UNIT_X, &image->render_slot, (float) slot_id, 0.0, 0, -1, "");
- slot_id--;
- }
+ uiBlock *block = uiLayoutGetBlock(layout);
+ Image *image = image_p;
+ int slot_id;
+
+ uiDefBut(block,
+ UI_BTYPE_LABEL,
+ 0,
+ IFACE_("Slot"),
+ 0,
+ 0,
+ UI_UNIT_X * 5,
+ UI_UNIT_Y,
+ NULL,
+ 0.0,
+ 0.0,
+ 0,
+ 0,
+ "");
+ uiItemS(layout);
+
+ slot_id = BLI_listbase_count(&image->renderslots) - 1;
+ for (RenderSlot *slot = image->renderslots.last; slot; slot = slot->prev) {
+ char str[64];
+ if (slot->name[0] != '\0') {
+ BLI_strncpy(str, slot->name, sizeof(str));
+ }
+ else {
+ BLI_snprintf(str, sizeof(str), IFACE_("Slot %d"), slot_id + 1);
+ }
+ uiDefButS(block,
+ UI_BTYPE_BUT_MENU,
+ B_NOP,
+ str,
+ 0,
+ 0,
+ UI_UNIT_X * 5,
+ UI_UNIT_X,
+ &image->render_slot,
+ (float)slot_id,
+ 0.0,
+ 0,
+ -1,
+ "");
+ slot_id--;
+ }
}
static bool ui_imageuser_slot_menu_step(bContext *C, int direction, void *image_p)
{
- Image *image = image_p;
-
- if (ED_image_slot_cycle(image, direction)) {
- WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL);
- return true;
- }
- else {
- return true;
- }
+ Image *image = image_p;
+
+ if (ED_image_slot_cycle(image, direction)) {
+ WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL);
+ return true;
+ }
+ else {
+ return true;
+ }
}
static const char *ui_imageuser_layer_fake_name(RenderResult *rr)
{
- RenderView *rv = RE_RenderViewGetById(rr, 0);
- if (rv->rectf) {
- return IFACE_("Composite");
- }
- else if (rv->rect32) {
- return IFACE_("Sequence");
- }
- else {
- return NULL;
- }
+ RenderView *rv = RE_RenderViewGetById(rr, 0);
+ if (rv->rectf) {
+ return IFACE_("Composite");
+ }
+ else if (rv->rect32) {
+ return IFACE_("Sequence");
+ }
+ else {
+ return NULL;
+ }
}
/* workaround for passing many args */
struct ImageUI_Data {
- Image *image;
- ImageUser *iuser;
- int rpass_index;
+ Image *image;
+ ImageUser *iuser;
+ int rpass_index;
};
static struct ImageUI_Data *ui_imageuser_data_copy(const struct ImageUI_Data *rnd_pt_src)
{
- struct ImageUI_Data *rnd_pt_dst = MEM_mallocN(sizeof(*rnd_pt_src), __func__);
- memcpy(rnd_pt_dst, rnd_pt_src, sizeof(*rnd_pt_src));
- return rnd_pt_dst;
+ struct ImageUI_Data *rnd_pt_dst = MEM_mallocN(sizeof(*rnd_pt_src), __func__);
+ memcpy(rnd_pt_dst, rnd_pt_src, sizeof(*rnd_pt_src));
+ return rnd_pt_dst;
}
static void ui_imageuser_layer_menu(bContext *UNUSED(C), uiLayout *layout, void *rnd_pt)
{
- struct ImageUI_Data *rnd_data = rnd_pt;
- uiBlock *block = uiLayoutGetBlock(layout);
- Image *image = rnd_data->image;
- ImageUser *iuser = rnd_data->iuser;
- Scene *scene = iuser->scene;
- RenderResult *rr;
- RenderLayer *rl;
- RenderLayer rl_fake = {NULL};
- const char *fake_name;
- int nr;
-
- /* may have been freed since drawing */
- rr = BKE_image_acquire_renderresult(scene, image);
- if (UNLIKELY(rr == NULL)) {
- return;
- }
-
- UI_block_layout_set_current(block, layout);
- uiLayoutColumn(layout, false);
-
- uiDefBut(block, UI_BTYPE_LABEL, 0, IFACE_("Layer"),
- 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
- uiItemS(layout);
-
- nr = BLI_listbase_count(&rr->layers) - 1;
- fake_name = ui_imageuser_layer_fake_name(rr);
-
- if (fake_name) {
- BLI_strncpy(rl_fake.name, fake_name, sizeof(rl_fake.name));
- nr += 1;
- }
-
- for (rl = rr->layers.last; rl; rl = rl->prev, nr--) {
-final:
- uiDefButS(block, UI_BTYPE_BUT_MENU, B_NOP, rl->name, 0, 0,
- UI_UNIT_X * 5, UI_UNIT_X, &iuser->layer, (float) nr, 0.0, 0, -1, "");
- }
-
- if (fake_name) {
- fake_name = NULL;
- rl = &rl_fake;
- goto final;
- }
-
- BLI_assert(nr == -1);
-
- BKE_image_release_renderresult(scene, image);
+ struct ImageUI_Data *rnd_data = rnd_pt;
+ uiBlock *block = uiLayoutGetBlock(layout);
+ Image *image = rnd_data->image;
+ ImageUser *iuser = rnd_data->iuser;
+ Scene *scene = iuser->scene;
+ RenderResult *rr;
+ RenderLayer *rl;
+ RenderLayer rl_fake = {NULL};
+ const char *fake_name;
+ int nr;
+
+ /* may have been freed since drawing */
+ rr = BKE_image_acquire_renderresult(scene, image);
+ if (UNLIKELY(rr == NULL)) {
+ return;
+ }
+
+ UI_block_layout_set_current(block, layout);
+ uiLayoutColumn(layout, false);
+
+ uiDefBut(block,
+ UI_BTYPE_LABEL,
+ 0,
+ IFACE_("Layer"),
+ 0,
+ 0,
+ UI_UNIT_X * 5,
+ UI_UNIT_Y,
+ NULL,
+ 0.0,
+ 0.0,
+ 0,
+ 0,
+ "");
+ uiItemS(layout);
+
+ nr = BLI_listbase_count(&rr->layers) - 1;
+ fake_name = ui_imageuser_layer_fake_name(rr);
+
+ if (fake_name) {
+ BLI_strncpy(rl_fake.name, fake_name, sizeof(rl_fake.name));
+ nr += 1;
+ }
+
+ for (rl = rr->layers.last; rl; rl = rl->prev, nr--) {
+ final:
+ uiDefButS(block,
+ UI_BTYPE_BUT_MENU,
+ B_NOP,
+ rl->name,
+ 0,
+ 0,
+ UI_UNIT_X * 5,
+ UI_UNIT_X,
+ &iuser->layer,
+ (float)nr,
+ 0.0,
+ 0,
+ -1,
+ "");
+ }
+
+ if (fake_name) {
+ fake_name = NULL;
+ rl = &rl_fake;
+ goto final;
+ }
+
+ BLI_assert(nr == -1);
+
+ BKE_image_release_renderresult(scene, image);
}
static void ui_imageuser_pass_menu(bContext *UNUSED(C), uiLayout *layout, void *rnd_pt)
{
- struct ImageUI_Data *rnd_data = rnd_pt;
- uiBlock *block = uiLayoutGetBlock(layout);
- Image *image = rnd_data->image;
- ImageUser *iuser = rnd_data->iuser;
- /* (rpass_index == -1) means composite result */
- const int rpass_index = rnd_data->rpass_index;
- Scene *scene = iuser->scene;
- RenderResult *rr;
- RenderLayer *rl;
- RenderPass *rpass;
- int nr;
-
- /* may have been freed since drawing */
- rr = BKE_image_acquire_renderresult(scene, image);
- if (UNLIKELY(rr == NULL)) {
- return;
- }
-
- rl = BLI_findlink(&rr->layers, rpass_index);
-
- UI_block_layout_set_current(block, layout);
- uiLayoutColumn(layout, false);
-
- uiDefBut(block, UI_BTYPE_LABEL, 0, IFACE_("Pass"),
- 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
-
- uiItemS(layout);
-
- nr = (rl == NULL) ? 1 : 0;
-
- ListBase added_passes;
- BLI_listbase_clear(&added_passes);
-
- /* rendered results don't have a Combined pass */
- /* multiview: the ordering must be ascending, so the left-most pass is always the one picked */
- for (rpass = rl ? rl->passes.first : NULL; rpass; rpass = rpass->next, nr++) {
- /* just show one pass of each kind */
- if (BLI_findstring_ptr(&added_passes, rpass->name, offsetof(LinkData, data))) {
- continue;
- }
- BLI_addtail(&added_passes, BLI_genericNodeN(rpass->name));
-
- uiDefButS(block, UI_BTYPE_BUT_MENU, B_NOP, IFACE_(rpass->name), 0, 0,
- UI_UNIT_X * 5, UI_UNIT_X, &iuser->pass, (float) nr, 0.0, 0, -1, "");
- }
-
- BLI_freelistN(&added_passes);
-
- BKE_image_release_renderresult(scene, image);
+ struct ImageUI_Data *rnd_data = rnd_pt;
+ uiBlock *block = uiLayoutGetBlock(layout);
+ Image *image = rnd_data->image;
+ ImageUser *iuser = rnd_data->iuser;
+ /* (rpass_index == -1) means composite result */
+ const int rpass_index = rnd_data->rpass_index;
+ Scene *scene = iuser->scene;
+ RenderResult *rr;
+ RenderLayer *rl;
+ RenderPass *rpass;
+ int nr;
+
+ /* may have been freed since drawing */
+ rr = BKE_image_acquire_renderresult(scene, image);
+ if (UNLIKELY(rr == NULL)) {
+ return;
+ }
+
+ rl = BLI_findlink(&rr->layers, rpass_index);
+
+ UI_block_layout_set_current(block, layout);
+ uiLayoutColumn(layout, false);
+
+ uiDefBut(block,
+ UI_BTYPE_LABEL,
+ 0,
+ IFACE_("Pass"),
+ 0,
+ 0,
+ UI_UNIT_X * 5,
+ UI_UNIT_Y,
+ NULL,
+ 0.0,
+ 0.0,
+ 0,
+ 0,
+ "");
+
+ uiItemS(layout);
+
+ nr = (rl == NULL) ? 1 : 0;
+
+ ListBase added_passes;
+ BLI_listbase_clear(&added_passes);
+
+ /* rendered results don't have a Combined pass */
+ /* multiview: the ordering must be ascending, so the left-most pass is always the one picked */
+ for (rpass = rl ? rl->passes.first : NULL; rpass; rpass = rpass->next, nr++) {
+ /* just show one pass of each kind */
+ if (BLI_findstring_ptr(&added_passes, rpass->name, offsetof(LinkData, data))) {
+ continue;
+ }
+ BLI_addtail(&added_passes, BLI_genericNodeN(rpass->name));
+
+ uiDefButS(block,
+ UI_BTYPE_BUT_MENU,
+ B_NOP,
+ IFACE_(rpass->name),
+ 0,
+ 0,
+ UI_UNIT_X * 5,
+ UI_UNIT_X,
+ &iuser->pass,
+ (float)nr,
+ 0.0,
+ 0,
+ -1,
+ "");
+ }
+
+ BLI_freelistN(&added_passes);
+
+ BKE_image_release_renderresult(scene, image);
}
/**************************** view menus *****************************/
static void ui_imageuser_view_menu_rr(bContext *UNUSED(C), uiLayout *layout, void *rnd_pt)
{
- struct ImageUI_Data *rnd_data = rnd_pt;
- uiBlock *block = uiLayoutGetBlock(layout);
- Image *image = rnd_data->image;
- ImageUser *iuser = rnd_data->iuser;
- RenderResult *rr;
- RenderView *rview;
- int nr;
- Scene *scene = iuser->scene;
-
- /* may have been freed since drawing */
- rr = BKE_image_acquire_renderresult(scene, image);
- if (UNLIKELY(rr == NULL)) {
- return;
- }
-
- UI_block_layout_set_current(block, layout);
- uiLayoutColumn(layout, false);
-
- uiDefBut(block, UI_BTYPE_LABEL, 0, IFACE_("View"),
- 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
-
- uiItemS(layout);
-
- nr = (rr ? BLI_listbase_count(&rr->views) : 0) - 1;
- for (rview = rr ? rr->views.last : NULL; rview; rview = rview->prev, nr--) {
- uiDefButS(block, UI_BTYPE_BUT_MENU, B_NOP, IFACE_(rview->name), 0, 0,
- UI_UNIT_X * 5, UI_UNIT_X, &iuser->view, (float) nr, 0.0, 0, -1, "");
- }
-
- BKE_image_release_renderresult(scene, image);
+ struct ImageUI_Data *rnd_data = rnd_pt;
+ uiBlock *block = uiLayoutGetBlock(layout);
+ Image *image = rnd_data->image;
+ ImageUser *iuser = rnd_data->iuser;
+ RenderResult *rr;
+ RenderView *rview;
+ int nr;
+ Scene *scene = iuser->scene;
+
+ /* may have been freed since drawing */
+ rr = BKE_image_acquire_renderresult(scene, image);
+ if (UNLIKELY(rr == NULL)) {
+ return;
+ }
+
+ UI_block_layout_set_current(block, layout);
+ uiLayoutColumn(layout, false);
+
+ uiDefBut(block,
+ UI_BTYPE_LABEL,
+ 0,
+ IFACE_("View"),
+ 0,
+ 0,
+ UI_UNIT_X * 5,
+ UI_UNIT_Y,
+ NULL,
+ 0.0,
+ 0.0,
+ 0,
+ 0,
+ "");
+
+ uiItemS(layout);
+
+ nr = (rr ? BLI_listbase_count(&rr->views) : 0) - 1;
+ for (rview = rr ? rr->views.last : NULL; rview; rview = rview->prev, nr--) {
+ uiDefButS(block,
+ UI_BTYPE_BUT_MENU,
+ B_NOP,
+ IFACE_(rview->name),
+ 0,
+ 0,
+ UI_UNIT_X * 5,
+ UI_UNIT_X,
+ &iuser->view,
+ (float)nr,
+ 0.0,
+ 0,
+ -1,
+ "");
+ }
+
+ BKE_image_release_renderresult(scene, image);
}
static void ui_imageuser_view_menu_multiview(bContext *UNUSED(C), uiLayout *layout, void *rnd_pt)
{
- struct ImageUI_Data *rnd_data = rnd_pt;
- uiBlock *block = uiLayoutGetBlock(layout);
- Image *image = rnd_data->image;
- ImageUser *iuser = rnd_data->iuser;
- int nr;
- ImageView *iv;
-
- UI_block_layout_set_current(block, layout);
- uiLayoutColumn(layout, false);
-
- uiDefBut(block, UI_BTYPE_LABEL, 0, IFACE_("View"),
- 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
-
- uiItemS(layout);
-
- nr = BLI_listbase_count(&image->views) - 1;
- for (iv = image->views.last; iv; iv = iv->prev, nr--) {
- uiDefButS(block, UI_BTYPE_BUT_MENU, B_NOP, IFACE_(iv->name), 0, 0,
- UI_UNIT_X * 5, UI_UNIT_X, &iuser->view, (float) nr, 0.0, 0, -1, "");
- }
+ struct ImageUI_Data *rnd_data = rnd_pt;
+ uiBlock *block = uiLayoutGetBlock(layout);
+ Image *image = rnd_data->image;
+ ImageUser *iuser = rnd_data->iuser;
+ int nr;
+ ImageView *iv;
+
+ UI_block_layout_set_current(block, layout);
+ uiLayoutColumn(layout, false);
+
+ uiDefBut(block,
+ UI_BTYPE_LABEL,
+ 0,
+ IFACE_("View"),
+ 0,
+ 0,
+ UI_UNIT_X * 5,
+ UI_UNIT_Y,
+ NULL,
+ 0.0,
+ 0.0,
+ 0,
+ 0,
+ "");
+
+ uiItemS(layout);
+
+ nr = BLI_listbase_count(&image->views) - 1;
+ for (iv = image->views.last; iv; iv = iv->prev, nr--) {
+ uiDefButS(block,
+ UI_BTYPE_BUT_MENU,
+ B_NOP,
+ IFACE_(iv->name),
+ 0,
+ 0,
+ UI_UNIT_X * 5,
+ UI_UNIT_X,
+ &iuser->view,
+ (float)nr,
+ 0.0,
+ 0,
+ -1,
+ "");
+ }
}
/* 5 layer button callbacks... */
static void image_multi_cb(bContext *C, void *rnd_pt, void *rr_v)
{
- struct ImageUI_Data *rnd_data = rnd_pt;
- ImageUser *iuser = rnd_data->iuser;
+ struct ImageUI_Data *rnd_data = rnd_pt;
+ ImageUser *iuser = rnd_data->iuser;
- BKE_image_multilayer_index(rr_v, iuser);
- WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL);
+ BKE_image_multilayer_index(rr_v, iuser);
+ WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL);
}
static bool ui_imageuser_layer_menu_step(bContext *C, int direction, void *rnd_pt)
{
- Scene *scene = CTX_data_scene(C);
- struct ImageUI_Data *rnd_data = rnd_pt;
- Image *image = rnd_data->image;
- ImageUser *iuser = rnd_data->iuser;
- RenderResult *rr;
- bool changed = false;
-
- rr = BKE_image_acquire_renderresult(scene, image);
- if (UNLIKELY(rr == NULL)) {
- return false;
- }
-
- if (direction == -1) {
- if (iuser->layer > 0) {
- iuser->layer--;
- changed = true;
- }
- }
- else if (direction == 1) {
- int tot = BLI_listbase_count(&rr->layers);
-
- if (RE_HasCombinedLayer(rr)) {
- tot++; /* fake compo/sequencer layer */
- }
-
- if (iuser->layer < tot - 1) {
- iuser->layer++;
- changed = true;
- }
- }
- else {
- BLI_assert(0);
- }
-
- BKE_image_release_renderresult(scene, image);
-
- if (changed) {
- BKE_image_multilayer_index(rr, iuser);
- WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL);
- }
-
- return changed;
+ Scene *scene = CTX_data_scene(C);
+ struct ImageUI_Data *rnd_data = rnd_pt;
+ Image *image = rnd_data->image;
+ ImageUser *iuser = rnd_data->iuser;
+ RenderResult *rr;
+ bool changed = false;
+
+ rr = BKE_image_acquire_renderresult(scene, image);
+ if (UNLIKELY(rr == NULL)) {
+ return false;
+ }
+
+ if (direction == -1) {
+ if (iuser->layer > 0) {
+ iuser->layer--;
+ changed = true;
+ }
+ }
+ else if (direction == 1) {
+ int tot = BLI_listbase_count(&rr->layers);
+
+ if (RE_HasCombinedLayer(rr)) {
+ tot++; /* fake compo/sequencer layer */
+ }
+
+ if (iuser->layer < tot - 1) {
+ iuser->layer++;
+ changed = true;
+ }
+ }
+ else {
+ BLI_assert(0);
+ }
+
+ BKE_image_release_renderresult(scene, image);
+
+ if (changed) {
+ BKE_image_multilayer_index(rr, iuser);
+ WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL);
+ }
+
+ return changed;
}
static bool ui_imageuser_pass_menu_step(bContext *C, int direction, void *rnd_pt)
{
- Scene *scene = CTX_data_scene(C);
- struct ImageUI_Data *rnd_data = rnd_pt;
- Image *image = rnd_data->image;
- ImageUser *iuser = rnd_data->iuser;
- RenderResult *rr;
- bool changed = false;
- int layer = iuser->layer;
- RenderLayer *rl;
- RenderPass *rpass;
-
- rr = BKE_image_acquire_renderresult(scene, image);
- if (UNLIKELY(rr == NULL)) {
- BKE_image_release_renderresult(scene, image);
- return false;
- }
-
- if (RE_HasCombinedLayer(rr)) {
- layer -= 1;
- }
-
- rl = BLI_findlink(&rr->layers, layer);
- if (rl == NULL) {
- BKE_image_release_renderresult(scene, image);
- return false;
- }
-
- rpass = BLI_findlink(&rl->passes, iuser->pass);
- if (rpass == NULL) {
- BKE_image_release_renderresult(scene, image);
- return false;
- }
-
- /* note, this looks reversed, but matches menu direction */
- if (direction == -1) {
- RenderPass *rp;
- int rp_index = iuser->pass + 1;
-
- for (rp = rpass->next; rp; rp = rp->next, rp_index++) {
- if (!STREQ(rp->name, rpass->name)) {
- iuser->pass = rp_index;
- changed = true;
- break;
- }
- }
- }
- else if (direction == 1) {
- RenderPass *rp;
- int rp_index = 0;
-
- if (iuser->pass == 0) {
- BKE_image_release_renderresult(scene, image);
- return false;
- }
-
- for (rp = rl->passes.first; rp; rp = rp->next, rp_index++) {
- if (STREQ(rp->name, rpass->name)) {
- iuser->pass = rp_index - 1;
- changed = true;
- break;
- }
- }
- }
- else {
- BLI_assert(0);
- }
-
- BKE_image_release_renderresult(scene, image);
-
- if (changed) {
- BKE_image_multilayer_index(rr, iuser);
- WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL);
- }
-
- return changed;
+ Scene *scene = CTX_data_scene(C);
+ struct ImageUI_Data *rnd_data = rnd_pt;
+ Image *image = rnd_data->image;
+ ImageUser *iuser = rnd_data->iuser;
+ RenderResult *rr;
+ bool changed = false;
+ int layer = iuser->layer;
+ RenderLayer *rl;
+ RenderPass *rpass;
+
+ rr = BKE_image_acquire_renderresult(scene, image);
+ if (UNLIKELY(rr == NULL)) {
+ BKE_image_release_renderresult(scene, image);
+ return false;
+ }
+
+ if (RE_HasCombinedLayer(rr)) {
+ layer -= 1;
+ }
+
+ rl = BLI_findlink(&rr->layers, layer);
+ if (rl == NULL) {
+ BKE_image_release_renderresult(scene, image);
+ return false;
+ }
+
+ rpass = BLI_findlink(&rl->passes, iuser->pass);
+ if (rpass == NULL) {
+ BKE_image_release_renderresult(scene, image);
+ return false;
+ }
+
+ /* note, this looks reversed, but matches menu direction */
+ if (direction == -1) {
+ RenderPass *rp;
+ int rp_index = iuser->pass + 1;
+
+ for (rp = rpass->next; rp; rp = rp->next, rp_index++) {
+ if (!STREQ(rp->name, rpass->name)) {
+ iuser->pass = rp_index;
+ changed = true;
+ break;
+ }
+ }
+ }
+ else if (direction == 1) {
+ RenderPass *rp;
+ int rp_index = 0;
+
+ if (iuser->pass == 0) {
+ BKE_image_release_renderresult(scene, image);
+ return false;
+ }
+
+ for (rp = rl->passes.first; rp; rp = rp->next, rp_index++) {
+ if (STREQ(rp->name, rpass->name)) {
+ iuser->pass = rp_index - 1;
+ changed = true;
+ break;
+ }
+ }
+ }
+ else {
+ BLI_assert(0);
+ }
+
+ BKE_image_release_renderresult(scene, image);
+
+ if (changed) {
+ BKE_image_multilayer_index(rr, iuser);
+ WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL);
+ }
+
+ return changed;
}
/* 5 view button callbacks... */
static void image_multiview_cb(bContext *C, void *rnd_pt, void *UNUSED(arg_v))
{
- struct ImageUI_Data *rnd_data = rnd_pt;
- Image *ima = rnd_data->image;
- ImageUser *iuser = rnd_data->iuser;
+ struct ImageUI_Data *rnd_data = rnd_pt;
+ Image *ima = rnd_data->image;
+ ImageUser *iuser = rnd_data->iuser;
- BKE_image_multiview_index(ima, iuser);
- WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL);
+ BKE_image_multiview_index(ima, iuser);
+ WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL);
}
#if 0
static void image_freecache_cb(bContext *C, void *ima_v, void *unused)
{
- Scene *scene = CTX_data_scene(C);
- BKE_image_free_anim_ibufs(ima_v, scene->r.cfra);
- WM_event_add_notifier(C, NC_IMAGE, ima_v);
+ Scene *scene = CTX_data_scene(C);
+ BKE_image_free_anim_ibufs(ima_v, scene->r.cfra);
+ WM_event_add_notifier(C, NC_IMAGE, ima_v);
}
#endif
#if 0
static void image_user_change(bContext *C, void *iuser_v, void *unused)
{
- Scene *scene = CTX_data_scene(C);
- BKE_image_user_calc_imanr(iuser_v, scene->r.cfra, 0);
+ Scene *scene = CTX_data_scene(C);
+ BKE_image_user_calc_imanr(iuser_v, scene->r.cfra, 0);
}
#endif
static void uiblock_layer_pass_buttons(
- uiLayout *layout, Image *image, RenderResult *rr, ImageUser *iuser, int w,
- short *render_slot)
+ uiLayout *layout, Image *image, RenderResult *rr, ImageUser *iuser, int w, short *render_slot)
{
- struct ImageUI_Data rnd_pt_local, *rnd_pt = NULL;
- uiBlock *block = uiLayoutGetBlock(layout);
- uiBut *but;
- RenderLayer *rl = NULL;
- int wmenu1, wmenu2, wmenu3, wmenu4;
- const char *fake_name;
- const char *display_name = "";
- const bool show_stereo = (iuser->flag & IMA_SHOW_STEREO) != 0;
-
- if (iuser->scene == NULL) {
- return;
- }
-
- uiLayoutRow(layout, true);
-
- /* layer menu is 1/3 larger than pass */
- wmenu1 = (2 * w) / 5;
- wmenu2 = (3 * w) / 5;
- wmenu3 = (3 * w) / 6;
- wmenu4 = (3 * w) / 6;
-
- rnd_pt_local.image = image;
- rnd_pt_local.iuser = iuser;
- rnd_pt_local.rpass_index = 0;
-
- /* menu buts */
- if (render_slot) {
- char str[64];
- RenderSlot *slot = BKE_image_get_renderslot(image, *render_slot);
- if (slot && slot->name[0] != '\0') {
- BLI_strncpy(str, slot->name, sizeof(str));
- }
- else {
- BLI_snprintf(str, sizeof(str), IFACE_("Slot %d"), *render_slot + 1);
- }
-
- rnd_pt = ui_imageuser_data_copy(&rnd_pt_local);
- but = uiDefMenuBut(block, ui_imageuser_slot_menu, image, str, 0, 0, wmenu1, UI_UNIT_Y, TIP_("Select Slot"));
- UI_but_func_menu_step_set(but, ui_imageuser_slot_menu_step);
- UI_but_funcN_set(but, image_multi_cb, rnd_pt, rr);
- UI_but_type_set_menu_from_pulldown(but);
- rnd_pt = NULL;
- }
-
- if (rr) {
- RenderPass *rpass;
- RenderView *rview;
- int rpass_index;
-
- /* layer */
- fake_name = ui_imageuser_layer_fake_name(rr);
- rpass_index = iuser->layer - (fake_name ? 1 : 0);
- rl = BLI_findlink(&rr->layers, rpass_index);
- rnd_pt_local.rpass_index = rpass_index;
-
- if (RE_layers_have_name(rr)) {
- display_name = rl ? rl->name : (fake_name ? fake_name : "");
- rnd_pt = ui_imageuser_data_copy(&rnd_pt_local);
- but = uiDefMenuBut(
- block, ui_imageuser_layer_menu, rnd_pt, display_name,
- 0, 0, wmenu2, UI_UNIT_Y, TIP_("Select Layer"));
- UI_but_func_menu_step_set(but, ui_imageuser_layer_menu_step);
- UI_but_funcN_set(but, image_multi_cb, rnd_pt, rr);
- UI_but_type_set_menu_from_pulldown(but);
- rnd_pt = NULL;
- }
-
- /* pass */
- rpass = (rl ? BLI_findlink(&rl->passes, iuser->pass) : NULL);
-
- if (rpass && RE_passes_have_name(rl)) {
- display_name = rpass->name;
- rnd_pt = ui_imageuser_data_copy(&rnd_pt_local);
- but = uiDefMenuBut(
- block, ui_imageuser_pass_menu, rnd_pt, IFACE_(display_name),
- 0, 0, wmenu3, UI_UNIT_Y, TIP_("Select Pass"));
- UI_but_func_menu_step_set(but, ui_imageuser_pass_menu_step);
- UI_but_funcN_set(but, image_multi_cb, rnd_pt, rr);
- UI_but_type_set_menu_from_pulldown(but);
- rnd_pt = NULL;
- }
-
- /* view */
- if (BLI_listbase_count_at_most(&rr->views, 2) > 1 &&
- ((!show_stereo) || (!RE_RenderResult_is_stereo(rr))))
- {
- rview = BLI_findlink(&rr->views, iuser->view);
- display_name = rview ? rview->name : "";
-
- rnd_pt = ui_imageuser_data_copy(&rnd_pt_local);
- but = uiDefMenuBut(
- block, ui_imageuser_view_menu_rr, rnd_pt, display_name,
- 0, 0, wmenu4, UI_UNIT_Y, TIP_("Select View"));
- UI_but_funcN_set(but, image_multi_cb, rnd_pt, rr);
- UI_but_type_set_menu_from_pulldown(but);
- rnd_pt = NULL;
- }
- }
-
- /* stereo image */
- else if ((BKE_image_is_stereo(image) && (!show_stereo)) ||
- (BKE_image_is_multiview(image) && !BKE_image_is_stereo(image)))
- {
- ImageView *iv;
- int nr = 0;
-
- for (iv = image->views.first; iv; iv = iv->next) {
- if (nr++ == iuser->view) {
- display_name = iv->name;
- break;
- }
- }
-
- rnd_pt = ui_imageuser_data_copy(&rnd_pt_local);
- but = uiDefMenuBut(
- block, ui_imageuser_view_menu_multiview, rnd_pt, display_name,
- 0, 0, wmenu1, UI_UNIT_Y, TIP_("Select View"));
- UI_but_funcN_set(but, image_multiview_cb, rnd_pt, NULL);
- UI_but_type_set_menu_from_pulldown(but);
- rnd_pt = NULL;
- }
+ struct ImageUI_Data rnd_pt_local, *rnd_pt = NULL;
+ uiBlock *block = uiLayoutGetBlock(layout);
+ uiBut *but;
+ RenderLayer *rl = NULL;
+ int wmenu1, wmenu2, wmenu3, wmenu4;
+ const char *fake_name;
+ const char *display_name = "";
+ const bool show_stereo = (iuser->flag & IMA_SHOW_STEREO) != 0;
+
+ if (iuser->scene == NULL) {
+ return;
+ }
+
+ uiLayoutRow(layout, true);
+
+ /* layer menu is 1/3 larger than pass */
+ wmenu1 = (2 * w) / 5;
+ wmenu2 = (3 * w) / 5;
+ wmenu3 = (3 * w) / 6;
+ wmenu4 = (3 * w) / 6;
+
+ rnd_pt_local.image = image;
+ rnd_pt_local.iuser = iuser;
+ rnd_pt_local.rpass_index = 0;
+
+ /* menu buts */
+ if (render_slot) {
+ char str[64];
+ RenderSlot *slot = BKE_image_get_renderslot(image, *render_slot);
+ if (slot && slot->name[0] != '\0') {
+ BLI_strncpy(str, slot->name, sizeof(str));
+ }
+ else {
+ BLI_snprintf(str, sizeof(str), IFACE_("Slot %d"), *render_slot + 1);
+ }
+
+ rnd_pt = ui_imageuser_data_copy(&rnd_pt_local);
+ but = uiDefMenuBut(
+ block, ui_imageuser_slot_menu, image, str, 0, 0, wmenu1, UI_UNIT_Y, TIP_("Select Slot"));
+ UI_but_func_menu_step_set(but, ui_imageuser_slot_menu_step);
+ UI_but_funcN_set(but, image_multi_cb, rnd_pt, rr);
+ UI_but_type_set_menu_from_pulldown(but);
+ rnd_pt = NULL;
+ }
+
+ if (rr) {
+ RenderPass *rpass;
+ RenderView *rview;
+ int rpass_index;
+
+ /* layer */
+ fake_name = ui_imageuser_layer_fake_name(rr);
+ rpass_index = iuser->layer - (fake_name ? 1 : 0);
+ rl = BLI_findlink(&rr->layers, rpass_index);
+ rnd_pt_local.rpass_index = rpass_index;
+
+ if (RE_layers_have_name(rr)) {
+ display_name = rl ? rl->name : (fake_name ? fake_name : "");
+ rnd_pt = ui_imageuser_data_copy(&rnd_pt_local);
+ but = uiDefMenuBut(block,
+ ui_imageuser_layer_menu,
+ rnd_pt,
+ display_name,
+ 0,
+ 0,
+ wmenu2,
+ UI_UNIT_Y,
+ TIP_("Select Layer"));
+ UI_but_func_menu_step_set(but, ui_imageuser_layer_menu_step);
+ UI_but_funcN_set(but, image_multi_cb, rnd_pt, rr);
+ UI_but_type_set_menu_from_pulldown(but);
+ rnd_pt = NULL;
+ }
+
+ /* pass */
+ rpass = (rl ? BLI_findlink(&rl->passes, iuser->pass) : NULL);
+
+ if (rpass && RE_passes_have_name(rl)) {
+ display_name = rpass->name;
+ rnd_pt = ui_imageuser_data_copy(&rnd_pt_local);
+ but = uiDefMenuBut(block,
+ ui_imageuser_pass_menu,
+ rnd_pt,
+ IFACE_(display_name),
+ 0,
+ 0,
+ wmenu3,
+ UI_UNIT_Y,
+ TIP_("Select Pass"));
+ UI_but_func_menu_step_set(but, ui_imageuser_pass_menu_step);
+ UI_but_funcN_set(but, image_multi_cb, rnd_pt, rr);
+ UI_but_type_set_menu_from_pulldown(but);
+ rnd_pt = NULL;
+ }
+
+ /* view */
+ if (BLI_listbase_count_at_most(&rr->views, 2) > 1 &&
+ ((!show_stereo) || (!RE_RenderResult_is_stereo(rr)))) {
+ rview = BLI_findlink(&rr->views, iuser->view);
+ display_name = rview ? rview->name : "";
+
+ rnd_pt = ui_imageuser_data_copy(&rnd_pt_local);
+ but = uiDefMenuBut(block,
+ ui_imageuser_view_menu_rr,
+ rnd_pt,
+ display_name,
+ 0,
+ 0,
+ wmenu4,
+ UI_UNIT_Y,
+ TIP_("Select View"));
+ UI_but_funcN_set(but, image_multi_cb, rnd_pt, rr);
+ UI_but_type_set_menu_from_pulldown(but);
+ rnd_pt = NULL;
+ }
+ }
+
+ /* stereo image */
+ else if ((BKE_image_is_stereo(image) && (!show_stereo)) ||
+ (BKE_image_is_multiview(image) && !BKE_image_is_stereo(image))) {
+ ImageView *iv;
+ int nr = 0;
+
+ for (iv = image->views.first; iv; iv = iv->next) {
+ if (nr++ == iuser->view) {
+ display_name = iv->name;
+ break;
+ }
+ }
+
+ rnd_pt = ui_imageuser_data_copy(&rnd_pt_local);
+ but = uiDefMenuBut(block,
+ ui_imageuser_view_menu_multiview,
+ rnd_pt,
+ display_name,
+ 0,
+ 0,
+ wmenu1,
+ UI_UNIT_Y,
+ TIP_("Select View"));
+ UI_but_funcN_set(but, image_multiview_cb, rnd_pt, NULL);
+ UI_but_type_set_menu_from_pulldown(but);
+ rnd_pt = NULL;
+ }
}
// XXX HACK!
// static int packdummy=0;
typedef struct RNAUpdateCb {
- PointerRNA ptr;
- PropertyRNA *prop;
- ImageUser *iuser;
+ PointerRNA ptr;
+ PropertyRNA *prop;
+ ImageUser *iuser;
} RNAUpdateCb;
static void rna_update_cb(bContext *C, void *arg_cb, void *UNUSED(arg))
{
- RNAUpdateCb *cb = (RNAUpdateCb *)arg_cb;
+ RNAUpdateCb *cb = (RNAUpdateCb *)arg_cb;
- /* ideally this would be done by RNA itself, but there we have
- * no image user available, so we just update this flag here */
- cb->iuser->ok = 1;
+ /* ideally this would be done by RNA itself, but there we have
+ * no image user available, so we just update this flag here */
+ cb->iuser->ok = 1;
- /* we call update here on the pointer property, this way the
- * owner of the image pointer can still define it's own update
- * and notifier */
- RNA_property_update(C, &cb->ptr, cb->prop);
+ /* we call update here on the pointer property, this way the
+ * owner of the image pointer can still define it's own update
+ * and notifier */
+ RNA_property_update(C, &cb->ptr, cb->prop);
}
-void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, PointerRNA *userptr, bool compact, bool multiview)
+void uiTemplateImage(uiLayout *layout,
+ bContext *C,
+ PointerRNA *ptr,
+ const char *propname,
+ PointerRNA *userptr,
+ bool compact,
+ bool multiview)
{
- PropertyRNA *prop;
- PointerRNA imaptr;
- RNAUpdateCb *cb;
- Image *ima;
- ImageUser *iuser;
- Scene *scene = CTX_data_scene(C);
- uiLayout *row, *split, *col;
- uiBlock *block;
- char str[MAX_IMAGE_INFO_LEN];
-
- void *lock;
-
- if (!ptr->data) {
- return;
- }
-
- prop = RNA_struct_find_property(ptr, propname);
- if (!prop) {
- printf("%s: property not found: %s.%s\n",
- __func__, RNA_struct_identifier(ptr->type), propname);
- return;
- }
-
- if (RNA_property_type(prop) != PROP_POINTER) {
- printf("%s: expected pointer property for %s.%s\n",
- __func__, RNA_struct_identifier(ptr->type), propname);
- return;
- }
-
- block = uiLayoutGetBlock(layout);
-
- imaptr = RNA_property_pointer_get(ptr, prop);
- ima = imaptr.data;
- iuser = userptr->data;
-
- BKE_image_user_frame_calc(iuser, (int)scene->r.cfra);
-
- cb = MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb");
- cb->ptr = *ptr;
- cb->prop = prop;
- cb->iuser = iuser;
-
- uiLayoutSetContextPointer(layout, "edit_image", &imaptr);
- uiLayoutSetContextPointer(layout, "edit_image_user", userptr);
-
- if (!compact) {
- uiTemplateID(
- layout, C, ptr, propname,
- ima ? NULL : "IMAGE_OT_new", "IMAGE_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false);
- }
-
- if (ima) {
- UI_block_funcN_set(block, rna_update_cb, MEM_dupallocN(cb), NULL);
-
- if (ima->source == IMA_SRC_VIEWER) {
- ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, &lock);
- image_info(scene, iuser, ima, ibuf, str, MAX_IMAGE_INFO_LEN);
- BKE_image_release_ibuf(ima, ibuf, lock);
-
- uiItemL(layout, ima->id.name + 2, ICON_NONE);
- uiItemL(layout, str, ICON_NONE);
-
- if (ima->type == IMA_TYPE_COMPOSITE) {
- // XXX not working yet
+ PropertyRNA *prop;
+ PointerRNA imaptr;
+ RNAUpdateCb *cb;
+ Image *ima;
+ ImageUser *iuser;
+ Scene *scene = CTX_data_scene(C);
+ uiLayout *row, *split, *col;
+ uiBlock *block;
+ char str[MAX_IMAGE_INFO_LEN];
+
+ void *lock;
+
+ if (!ptr->data) {
+ return;
+ }
+
+ prop = RNA_struct_find_property(ptr, propname);
+ if (!prop) {
+ printf(
+ "%s: property not found: %s.%s\n", __func__, RNA_struct_identifier(ptr->type), propname);
+ return;
+ }
+
+ if (RNA_property_type(prop) != PROP_POINTER) {
+ printf("%s: expected pointer property for %s.%s\n",
+ __func__,
+ RNA_struct_identifier(ptr->type),
+ propname);
+ return;
+ }
+
+ block = uiLayoutGetBlock(layout);
+
+ imaptr = RNA_property_pointer_get(ptr, prop);
+ ima = imaptr.data;
+ iuser = userptr->data;
+
+ BKE_image_user_frame_calc(iuser, (int)scene->r.cfra);
+
+ cb = MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb");
+ cb->ptr = *ptr;
+ cb->prop = prop;
+ cb->iuser = iuser;
+
+ uiLayoutSetContextPointer(layout, "edit_image", &imaptr);
+ uiLayoutSetContextPointer(layout, "edit_image_user", userptr);
+
+ if (!compact) {
+ uiTemplateID(layout,
+ C,
+ ptr,
+ propname,
+ ima ? NULL : "IMAGE_OT_new",
+ "IMAGE_OT_open",
+ NULL,
+ UI_TEMPLATE_ID_FILTER_ALL,
+ false);
+ }
+
+ if (ima) {
+ UI_block_funcN_set(block, rna_update_cb, MEM_dupallocN(cb), NULL);
+
+ if (ima->source == IMA_SRC_VIEWER) {
+ ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, &lock);
+ image_info(scene, iuser, ima, ibuf, str, MAX_IMAGE_INFO_LEN);
+ BKE_image_release_ibuf(ima, ibuf, lock);
+
+ uiItemL(layout, ima->id.name + 2, ICON_NONE);
+ uiItemL(layout, str, ICON_NONE);
+
+ if (ima->type == IMA_TYPE_COMPOSITE) {
+ // XXX not working yet
#if 0
- iuser = ntree_get_active_iuser(scene->nodetree);
- if (iuser) {
- UI_block_align_begin(block);
- uiDefIconTextBut(block, UI_BTYPE_BUT, B_SIMA_RECORD, ICON_REC, "Record", 10, 120, 100, 20, 0, 0, 0, 0, 0, "");
- uiDefIconTextBut(block, UI_BTYPE_BUT, B_SIMA_PLAY, ICON_PLAY, "Play", 110, 120, 100, 20, 0, 0, 0, 0, 0, "");
- but = uiDefBut(block, UI_BTYPE_BUT, B_NOP, "Free Cache", 210, 120, 100, 20, 0, 0, 0, 0, 0, "");
- UI_but_func_set(but, image_freecache_cb, ima, NULL);
-
- if (iuser->frames)
- BLI_snprintf(str, sizeof(str), "(%d) Frames:", iuser->framenr);
- else strcpy(str, "Frames:");
- UI_block_align_begin(block);
- uiDefButI(block, UI_BTYPE_NUM, imagechanged, str, 10, 90, 150, 20, &iuser->frames, 0.0, MAXFRAMEF, 0, 0, "Number of images of a movie to use");
- uiDefButI(block, UI_BTYPE_NUM, imagechanged, "StartFr:", 160, 90, 150, 20, &iuser->sfra, 1.0, MAXFRAMEF, 0, 0, "Global starting frame of the movie");
- }
+ iuser = ntree_get_active_iuser(scene->nodetree);
+ if (iuser) {
+ UI_block_align_begin(block);
+ uiDefIconTextBut(block, UI_BTYPE_BUT, B_SIMA_RECORD, ICON_REC, "Record", 10, 120, 100, 20, 0, 0, 0, 0, 0, "");
+ uiDefIconTextBut(block, UI_BTYPE_BUT, B_SIMA_PLAY, ICON_PLAY, "Play", 110, 120, 100, 20, 0, 0, 0, 0, 0, "");
+ but = uiDefBut(block, UI_BTYPE_BUT, B_NOP, "Free Cache", 210, 120, 100, 20, 0, 0, 0, 0, 0, "");
+ UI_but_func_set(but, image_freecache_cb, ima, NULL);
+
+ if (iuser->frames)
+ BLI_snprintf(str, sizeof(str), "(%d) Frames:", iuser->framenr);
+ else strcpy(str, "Frames:");
+ UI_block_align_begin(block);
+ uiDefButI(block, UI_BTYPE_NUM, imagechanged, str, 10, 90, 150, 20, &iuser->frames, 0.0, MAXFRAMEF, 0, 0, "Number of images of a movie to use");
+ uiDefButI(block, UI_BTYPE_NUM, imagechanged, "StartFr:", 160, 90, 150, 20, &iuser->sfra, 1.0, MAXFRAMEF, 0, 0, "Global starting frame of the movie");
+ }
#endif
- }
- else if (ima->type == IMA_TYPE_R_RESULT) {
- /* browse layer/passes */
- RenderResult *rr;
- const float dpi_fac = UI_DPI_FAC;
- const int menus_width = 230 * dpi_fac;
-
- /* use BKE_image_acquire_renderresult so we get the correct slot in the menu */
- rr = BKE_image_acquire_renderresult(scene, ima);
- uiblock_layer_pass_buttons(layout, ima, rr, iuser, menus_width, &ima->render_slot);
- BKE_image_release_renderresult(scene, ima);
- }
- }
- else {
- uiItemR(layout, &imaptr, "source", 0, NULL, ICON_NONE);
-
- if (ima->source != IMA_SRC_GENERATED) {
- row = uiLayoutRow(layout, true);
- if (BKE_image_has_packedfile(ima)) {
- uiItemO(row, "", ICON_PACKAGE, "image.unpack");
- }
- else {
- uiItemO(row, "", ICON_UGLYPACKAGE, "image.pack");
- }
-
- row = uiLayoutRow(row, true);
- uiLayoutSetEnabled(row, BKE_image_has_packedfile(ima) == false);
- uiItemR(row, &imaptr, "filepath", 0, "", ICON_NONE);
- uiItemO(row, "", ICON_FILE_REFRESH, "image.reload");
- }
-
- /* multilayer? */
- if (ima->type == IMA_TYPE_MULTILAYER && ima->rr) {
- const float dpi_fac = UI_DPI_FAC;
- uiblock_layer_pass_buttons(layout, ima, ima->rr, iuser, 230 * dpi_fac, NULL);
- }
- else if (ima->source != IMA_SRC_GENERATED) {
- if (compact == 0) {
- uiTemplateImageInfo(layout, C, ima, iuser);
- }
- }
-
- col = uiLayoutColumn(layout, false);
- uiTemplateColorspaceSettings(col, &imaptr, "colorspace_settings");
- uiItemR(col, &imaptr, "use_view_as_render", 0, NULL, ICON_NONE);
-
- if (ima->source != IMA_SRC_GENERATED) {
- if (compact == 0) { /* background image view doesn't need these */
- ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
- bool has_alpha = true;
-
- if (ibuf) {
- int imtype = BKE_image_ftype_to_imtype(ibuf->ftype, &ibuf->foptions);
- char valid_channels = BKE_imtype_valid_channels(imtype, false);
-
- has_alpha = (valid_channels & IMA_CHAN_FLAG_ALPHA) != 0;
-
- BKE_image_release_ibuf(ima, ibuf, NULL);
- }
-
- if (multiview) {
- if ((scene->r.scemode & R_MULTIVIEW) != 0) {
- uiItemR(layout, &imaptr, "use_multiview", 0, NULL, ICON_NONE);
-
- if (RNA_boolean_get(&imaptr, "use_multiview")) {
- uiTemplateImageViews(layout, &imaptr);
- }
- }
- }
-
- if (has_alpha) {
- col = uiLayoutColumn(layout, false);
- uiItemR(col, &imaptr, "use_alpha", 0, NULL, ICON_NONE);
- row = uiLayoutRow(col, false);
- uiLayoutSetActive(row, RNA_boolean_get(&imaptr, "use_alpha"));
- uiItemR(row, &imaptr, "alpha_mode", 0, IFACE_("Alpha"), ICON_NONE);
- }
-
- if (ima->source == IMA_SRC_MOVIE) {
- col = uiLayoutColumn(layout, false);
- uiItemR(col, &imaptr, "use_deinterlace", 0, IFACE_("Deinterlace"), ICON_NONE);
- }
- }
- }
-
- if (BKE_image_is_animated(ima)) {
- uiItemS(layout);
-
- split = uiLayoutSplit(layout, 0.0f, false);
-
- col = uiLayoutColumn(split, false);
-
- BLI_snprintf(str, sizeof(str), IFACE_("(%d) Frames"), iuser->framenr);
- uiItemR(col, userptr, "frame_duration", 0, str, ICON_NONE);
- uiItemR(col, userptr, "frame_start", 0, IFACE_("Start"), ICON_NONE);
- uiItemR(col, userptr, "frame_offset", 0, NULL, ICON_NONE);
-
- col = uiLayoutColumn(split, false);
- uiItemO(col, NULL, ICON_NONE, "IMAGE_OT_match_movie_length");
- uiItemR(col, userptr, "use_auto_refresh", 0, NULL, ICON_NONE);
- uiItemR(col, userptr, "use_cyclic", 0, NULL, ICON_NONE);
- }
- else if (ima->source == IMA_SRC_GENERATED) {
- split = uiLayoutSplit(layout, 0.0f, false);
-
- col = uiLayoutColumn(split, true);
- uiItemR(col, &imaptr, "generated_width", 0, "X", ICON_NONE);
- uiItemR(col, &imaptr, "generated_height", 0, "Y", ICON_NONE);
-
- uiItemR(col, &imaptr, "use_generated_float", 0, NULL, ICON_NONE);
-
- uiItemR(split, &imaptr, "generated_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
-
- if (ima->gen_type == IMA_GENTYPE_BLANK) {
- uiItemR(layout, &imaptr, "generated_color", 0, NULL, ICON_NONE);
- }
- }
-
- }
-
- UI_block_funcN_set(block, NULL, NULL, NULL);
- }
-
- MEM_freeN(cb);
+ }
+ else if (ima->type == IMA_TYPE_R_RESULT) {
+ /* browse layer/passes */
+ RenderResult *rr;
+ const float dpi_fac = UI_DPI_FAC;
+ const int menus_width = 230 * dpi_fac;
+
+ /* use BKE_image_acquire_renderresult so we get the correct slot in the menu */
+ rr = BKE_image_acquire_renderresult(scene, ima);
+ uiblock_layer_pass_buttons(layout, ima, rr, iuser, menus_width, &ima->render_slot);
+ BKE_image_release_renderresult(scene, ima);
+ }
+ }
+ else {
+ uiItemR(layout, &imaptr, "source", 0, NULL, ICON_NONE);
+
+ if (ima->source != IMA_SRC_GENERATED) {
+ row = uiLayoutRow(layout, true);
+ if (BKE_image_has_packedfile(ima)) {
+ uiItemO(row, "", ICON_PACKAGE, "image.unpack");
+ }
+ else {
+ uiItemO(row, "", ICON_UGLYPACKAGE, "image.pack");
+ }
+
+ row = uiLayoutRow(row, true);
+ uiLayoutSetEnabled(row, BKE_image_has_packedfile(ima) == false);
+ uiItemR(row, &imaptr, "filepath", 0, "", ICON_NONE);
+ uiItemO(row, "", ICON_FILE_REFRESH, "image.reload");
+ }
+
+ /* multilayer? */
+ if (ima->type == IMA_TYPE_MULTILAYER && ima->rr) {
+ const float dpi_fac = UI_DPI_FAC;
+ uiblock_layer_pass_buttons(layout, ima, ima->rr, iuser, 230 * dpi_fac, NULL);
+ }
+ else if (ima->source != IMA_SRC_GENERATED) {
+ if (compact == 0) {
+ uiTemplateImageInfo(layout, C, ima, iuser);
+ }
+ }
+
+ col = uiLayoutColumn(layout, false);
+ uiTemplateColorspaceSettings(col, &imaptr, "colorspace_settings");
+ uiItemR(col, &imaptr, "use_view_as_render", 0, NULL, ICON_NONE);
+
+ if (ima->source != IMA_SRC_GENERATED) {
+ if (compact == 0) { /* background image view doesn't need these */
+ ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
+ bool has_alpha = true;
+
+ if (ibuf) {
+ int imtype = BKE_image_ftype_to_imtype(ibuf->ftype, &ibuf->foptions);
+ char valid_channels = BKE_imtype_valid_channels(imtype, false);
+
+ has_alpha = (valid_channels & IMA_CHAN_FLAG_ALPHA) != 0;
+
+ BKE_image_release_ibuf(ima, ibuf, NULL);
+ }
+
+ if (multiview) {
+ if ((scene->r.scemode & R_MULTIVIEW) != 0) {
+ uiItemR(layout, &imaptr, "use_multiview", 0, NULL, ICON_NONE);
+
+ if (RNA_boolean_get(&imaptr, "use_multiview")) {
+ uiTemplateImageViews(layout, &imaptr);
+ }
+ }
+ }
+
+ if (has_alpha) {
+ col = uiLayoutColumn(layout, false);
+ uiItemR(col, &imaptr, "use_alpha", 0, NULL, ICON_NONE);
+ row = uiLayoutRow(col, false);
+ uiLayoutSetActive(row, RNA_boolean_get(&imaptr, "use_alpha"));
+ uiItemR(row, &imaptr, "alpha_mode", 0, IFACE_("Alpha"), ICON_NONE);
+ }
+
+ if (ima->source == IMA_SRC_MOVIE) {
+ col = uiLayoutColumn(layout, false);
+ uiItemR(col, &imaptr, "use_deinterlace", 0, IFACE_("Deinterlace"), ICON_NONE);
+ }
+ }
+ }
+
+ if (BKE_image_is_animated(ima)) {
+ uiItemS(layout);
+
+ split = uiLayoutSplit(layout, 0.0f, false);
+
+ col = uiLayoutColumn(split, false);
+
+ BLI_snprintf(str, sizeof(str), IFACE_("(%d) Frames"), iuser->framenr);
+ uiItemR(col, userptr, "frame_duration", 0, str, ICON_NONE);
+ uiItemR(col, userptr, "frame_start", 0, IFACE_("Start"), ICON_NONE);
+ uiItemR(col, userptr, "frame_offset", 0, NULL, ICON_NONE);
+
+ col = uiLayoutColumn(split, false);
+ uiItemO(col, NULL, ICON_NONE, "IMAGE_OT_match_movie_length");
+ uiItemR(col, userptr, "use_auto_refresh", 0, NULL, ICON_NONE);
+ uiItemR(col, userptr, "use_cyclic", 0, NULL, ICON_NONE);
+ }
+ else if (ima->source == IMA_SRC_GENERATED) {
+ split = uiLayoutSplit(layout, 0.0f, false);
+
+ col = uiLayoutColumn(split, true);
+ uiItemR(col, &imaptr, "generated_width", 0, "X", ICON_NONE);
+ uiItemR(col, &imaptr, "generated_height", 0, "Y", ICON_NONE);
+
+ uiItemR(col, &imaptr, "use_generated_float", 0, NULL, ICON_NONE);
+
+ uiItemR(split, &imaptr, "generated_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
+
+ if (ima->gen_type == IMA_GENTYPE_BLANK) {
+ uiItemR(layout, &imaptr, "generated_color", 0, NULL, ICON_NONE);
+ }
+ }
+ }
+
+ UI_block_funcN_set(block, NULL, NULL, NULL);
+ }
+
+ MEM_freeN(cb);
}
void uiTemplateImageSettings(uiLayout *layout, PointerRNA *imfptr, bool color_management)
{
- ImageFormatData *imf = imfptr->data;
- ID *id = imfptr->id.data;
- PointerRNA display_settings_ptr;
- PropertyRNA *prop;
- const int depth_ok = BKE_imtype_valid_depths(imf->imtype);
- /* some settings depend on this being a scene that's rendered */
- const bool is_render_out = (id && GS(id->name) == ID_SCE);
-
- uiLayout *col;
- bool show_preview = false;
-
- col = uiLayoutColumn(layout, false);
-
- uiLayoutSetPropSep(col, true);
- uiLayoutSetPropDecorate(col, false);
-
- uiItemR(col, imfptr, "file_format", 0, NULL, ICON_NONE);
- uiItemR(uiLayoutRow(col, true), imfptr, "color_mode", UI_ITEM_R_EXPAND, IFACE_("Color"), ICON_NONE);
-
- /* only display depth setting if multiple depths can be used */
- if ((ELEM(depth_ok,
- R_IMF_CHAN_DEPTH_1,
- R_IMF_CHAN_DEPTH_8,
- R_IMF_CHAN_DEPTH_10,
- R_IMF_CHAN_DEPTH_12,
- R_IMF_CHAN_DEPTH_16,
- R_IMF_CHAN_DEPTH_24,
- R_IMF_CHAN_DEPTH_32)) == 0)
- {
- uiItemR(uiLayoutRow(col, true), imfptr, "color_depth", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
- }
-
- if (BKE_imtype_supports_quality(imf->imtype)) {
- uiItemR(col, imfptr, "quality", 0, NULL, ICON_NONE);
- }
-
- if (BKE_imtype_supports_compress(imf->imtype)) {
- uiItemR(col, imfptr, "compression", 0, NULL, ICON_NONE);
- }
-
- if (ELEM(imf->imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER)) {
- uiItemR(col, imfptr, "exr_codec", 0, NULL, ICON_NONE);
- }
-
- if (BKE_imtype_supports_zbuf(imf->imtype)) {
- uiItemR(col, imfptr, "use_zbuffer", 0, NULL, ICON_NONE);
- }
-
- if (is_render_out && ELEM(imf->imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER)) {
- show_preview = true;
- uiItemR(col, imfptr, "use_preview", 0, NULL, ICON_NONE);
- }
-
- if (imf->imtype == R_IMF_IMTYPE_JP2) {
- uiItemR(col, imfptr, "jpeg2k_codec", 0, NULL, ICON_NONE);
-
- uiItemR(col, imfptr, "use_jpeg2k_cinema_preset", 0, NULL, ICON_NONE);
- uiItemR(col, imfptr, "use_jpeg2k_cinema_48", 0, NULL, ICON_NONE);
-
- uiItemR(col, imfptr, "use_jpeg2k_ycc", 0, NULL, ICON_NONE);
- }
-
- if (imf->imtype == R_IMF_IMTYPE_DPX) {
- uiItemR(col, imfptr, "use_cineon_log", 0, NULL, ICON_NONE);
- }
-
- if (imf->imtype == R_IMF_IMTYPE_CINEON) {
+ ImageFormatData *imf = imfptr->data;
+ ID *id = imfptr->id.data;
+ PointerRNA display_settings_ptr;
+ PropertyRNA *prop;
+ const int depth_ok = BKE_imtype_valid_depths(imf->imtype);
+ /* some settings depend on this being a scene that's rendered */
+ const bool is_render_out = (id && GS(id->name) == ID_SCE);
+
+ uiLayout *col;
+ bool show_preview = false;
+
+ col = uiLayoutColumn(layout, false);
+
+ uiLayoutSetPropSep(col, true);
+ uiLayoutSetPropDecorate(col, false);
+
+ uiItemR(col, imfptr, "file_format", 0, NULL, ICON_NONE);
+ uiItemR(
+ uiLayoutRow(col, true), imfptr, "color_mode", UI_ITEM_R_EXPAND, IFACE_("Color"), ICON_NONE);
+
+ /* only display depth setting if multiple depths can be used */
+ if ((ELEM(depth_ok,
+ R_IMF_CHAN_DEPTH_1,
+ R_IMF_CHAN_DEPTH_8,
+ R_IMF_CHAN_DEPTH_10,
+ R_IMF_CHAN_DEPTH_12,
+ R_IMF_CHAN_DEPTH_16,
+ R_IMF_CHAN_DEPTH_24,
+ R_IMF_CHAN_DEPTH_32)) == 0) {
+ uiItemR(uiLayoutRow(col, true), imfptr, "color_depth", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
+ }
+
+ if (BKE_imtype_supports_quality(imf->imtype)) {
+ uiItemR(col, imfptr, "quality", 0, NULL, ICON_NONE);
+ }
+
+ if (BKE_imtype_supports_compress(imf->imtype)) {
+ uiItemR(col, imfptr, "compression", 0, NULL, ICON_NONE);
+ }
+
+ if (ELEM(imf->imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER)) {
+ uiItemR(col, imfptr, "exr_codec", 0, NULL, ICON_NONE);
+ }
+
+ if (BKE_imtype_supports_zbuf(imf->imtype)) {
+ uiItemR(col, imfptr, "use_zbuffer", 0, NULL, ICON_NONE);
+ }
+
+ if (is_render_out && ELEM(imf->imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER)) {
+ show_preview = true;
+ uiItemR(col, imfptr, "use_preview", 0, NULL, ICON_NONE);
+ }
+
+ if (imf->imtype == R_IMF_IMTYPE_JP2) {
+ uiItemR(col, imfptr, "jpeg2k_codec", 0, NULL, ICON_NONE);
+
+ uiItemR(col, imfptr, "use_jpeg2k_cinema_preset", 0, NULL, ICON_NONE);
+ uiItemR(col, imfptr, "use_jpeg2k_cinema_48", 0, NULL, ICON_NONE);
+
+ uiItemR(col, imfptr, "use_jpeg2k_ycc", 0, NULL, ICON_NONE);
+ }
+
+ if (imf->imtype == R_IMF_IMTYPE_DPX) {
+ uiItemR(col, imfptr, "use_cineon_log", 0, NULL, ICON_NONE);
+ }
+
+ if (imf->imtype == R_IMF_IMTYPE_CINEON) {
#if 1
- uiItemL(col, IFACE_("Hard coded Non-Linear, Gamma:1.7"), ICON_NONE);
+ uiItemL(col, IFACE_("Hard coded Non-Linear, Gamma:1.7"), ICON_NONE);
#else
- uiItemR(col, imfptr, "use_cineon_log", 0, NULL, ICON_NONE);
- uiItemR(col, imfptr, "cineon_black", 0, NULL, ICON_NONE);
- uiItemR(col, imfptr, "cineon_white", 0, NULL, ICON_NONE);
- uiItemR(col, imfptr, "cineon_gamma", 0, NULL, ICON_NONE);
+ uiItemR(col, imfptr, "use_cineon_log", 0, NULL, ICON_NONE);
+ uiItemR(col, imfptr, "cineon_black", 0, NULL, ICON_NONE);
+ uiItemR(col, imfptr, "cineon_white", 0, NULL, ICON_NONE);
+ uiItemR(col, imfptr, "cineon_gamma", 0, NULL, ICON_NONE);
#endif
- }
+ }
- if (imf->imtype == R_IMF_IMTYPE_TIFF) {
- uiItemR(col, imfptr, "tiff_codec", 0, NULL, ICON_NONE);
- }
+ if (imf->imtype == R_IMF_IMTYPE_TIFF) {
+ uiItemR(col, imfptr, "tiff_codec", 0, NULL, ICON_NONE);
+ }
- /* color management */
- if (color_management &&
- (!BKE_imtype_requires_linear_float(imf->imtype) ||
- (show_preview && imf->flag & R_IMF_FLAG_PREVIEW_JPG)))
- {
- prop = RNA_struct_find_property(imfptr, "display_settings");
- display_settings_ptr = RNA_property_pointer_get(imfptr, prop);
+ /* color management */
+ if (color_management && (!BKE_imtype_requires_linear_float(imf->imtype) ||
+ (show_preview && imf->flag & R_IMF_FLAG_PREVIEW_JPG))) {
+ prop = RNA_struct_find_property(imfptr, "display_settings");
+ display_settings_ptr = RNA_property_pointer_get(imfptr, prop);
- col = uiLayoutColumn(layout, false);
- uiItemL(col, IFACE_("Color Management"), ICON_NONE);
+ col = uiLayoutColumn(layout, false);
+ uiItemL(col, IFACE_("Color Management"), ICON_NONE);
- uiItemR(col, &display_settings_ptr, "display_device", 0, NULL, ICON_NONE);
+ uiItemR(col, &display_settings_ptr, "display_device", 0, NULL, ICON_NONE);
- uiTemplateColormanagedViewSettings(col, NULL, imfptr, "view_settings");
- }
+ uiTemplateColormanagedViewSettings(col, NULL, imfptr, "view_settings");
+ }
}
void uiTemplateImageStereo3d(uiLayout *layout, PointerRNA *stereo3d_format_ptr)
{
- Stereo3dFormat *stereo3d_format = stereo3d_format_ptr->data;
- uiLayout *col;
-
- col = uiLayoutColumn(layout, false);
- uiItemR(col, stereo3d_format_ptr, "display_mode", 0, NULL, ICON_NONE);
-
- switch (stereo3d_format->display_mode) {
- case S3D_DISPLAY_ANAGLYPH:
- {
- uiItemR(col, stereo3d_format_ptr, "anaglyph_type", 0, NULL, ICON_NONE);
- break;
- }
- case S3D_DISPLAY_INTERLACE:
- {
- uiItemR(col, stereo3d_format_ptr, "interlace_type", 0, NULL, ICON_NONE);
- uiItemR(col, stereo3d_format_ptr, "use_interlace_swap", 0, NULL, ICON_NONE);
- break;
- }
- case S3D_DISPLAY_SIDEBYSIDE:
- {
- uiItemR(col, stereo3d_format_ptr, "use_sidebyside_crosseyed", 0, NULL, ICON_NONE);
- ATTR_FALLTHROUGH;
- }
- case S3D_DISPLAY_TOPBOTTOM:
- {
- uiItemR(col, stereo3d_format_ptr, "use_squeezed_frame", 0, NULL, ICON_NONE);
- break;
- }
- }
+ Stereo3dFormat *stereo3d_format = stereo3d_format_ptr->data;
+ uiLayout *col;
+
+ col = uiLayoutColumn(layout, false);
+ uiItemR(col, stereo3d_format_ptr, "display_mode", 0, NULL, ICON_NONE);
+
+ switch (stereo3d_format->display_mode) {
+ case S3D_DISPLAY_ANAGLYPH: {
+ uiItemR(col, stereo3d_format_ptr, "anaglyph_type", 0, NULL, ICON_NONE);
+ break;
+ }
+ case S3D_DISPLAY_INTERLACE: {
+ uiItemR(col, stereo3d_format_ptr, "interlace_type", 0, NULL, ICON_NONE);
+ uiItemR(col, stereo3d_format_ptr, "use_interlace_swap", 0, NULL, ICON_NONE);
+ break;
+ }
+ case S3D_DISPLAY_SIDEBYSIDE: {
+ uiItemR(col, stereo3d_format_ptr, "use_sidebyside_crosseyed", 0, NULL, ICON_NONE);
+ ATTR_FALLTHROUGH;
+ }
+ case S3D_DISPLAY_TOPBOTTOM: {
+ uiItemR(col, stereo3d_format_ptr, "use_squeezed_frame", 0, NULL, ICON_NONE);
+ break;
+ }
+ }
}
-static void uiTemplateViewsFormat(uiLayout *layout, PointerRNA *ptr, PointerRNA *stereo3d_format_ptr)
+static void uiTemplateViewsFormat(uiLayout *layout,
+ PointerRNA *ptr,
+ PointerRNA *stereo3d_format_ptr)
{
- uiLayout *col;
+ uiLayout *col;
- col = uiLayoutColumn(layout, false);
+ col = uiLayoutColumn(layout, false);
- uiLayoutSetPropSep(col, true);
- uiLayoutSetPropDecorate(col, false);
+ uiLayoutSetPropSep(col, true);
+ uiLayoutSetPropDecorate(col, false);
- uiItemR(col, ptr, "views_format", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
+ uiItemR(col, ptr, "views_format", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
- if (stereo3d_format_ptr &&
- RNA_enum_get(ptr, "views_format") == R_IMF_VIEWS_STEREO_3D)
- {
- uiTemplateImageStereo3d(col, stereo3d_format_ptr);
- }
+ if (stereo3d_format_ptr && RNA_enum_get(ptr, "views_format") == R_IMF_VIEWS_STEREO_3D) {
+ uiTemplateImageStereo3d(col, stereo3d_format_ptr);
+ }
}
void uiTemplateImageViews(uiLayout *layout, PointerRNA *imaptr)
{
- Image *ima = imaptr->data;
+ Image *ima = imaptr->data;
- if (ima->type != IMA_TYPE_MULTILAYER) {
- PropertyRNA *prop;
- PointerRNA stereo3d_format_ptr;
+ if (ima->type != IMA_TYPE_MULTILAYER) {
+ PropertyRNA *prop;
+ PointerRNA stereo3d_format_ptr;
- prop = RNA_struct_find_property(imaptr, "stereo_3d_format");
- stereo3d_format_ptr = RNA_property_pointer_get(imaptr, prop);
+ prop = RNA_struct_find_property(imaptr, "stereo_3d_format");
+ stereo3d_format_ptr = RNA_property_pointer_get(imaptr, prop);
- uiTemplateViewsFormat(layout, imaptr, &stereo3d_format_ptr);
- }
- else {
- uiTemplateViewsFormat(layout, imaptr, NULL);
- }
+ uiTemplateViewsFormat(layout, imaptr, &stereo3d_format_ptr);
+ }
+ else {
+ uiTemplateViewsFormat(layout, imaptr, NULL);
+ }
}
void uiTemplateImageFormatViews(uiLayout *layout, PointerRNA *imfptr, PointerRNA *ptr)
{
- ImageFormatData *imf = imfptr->data;
+ ImageFormatData *imf = imfptr->data;
- if (ptr == NULL) {
- return;
- }
+ if (ptr == NULL) {
+ return;
+ }
- uiItemR(layout, ptr, "use_multiview", 0, NULL, ICON_NONE);
+ uiItemR(layout, ptr, "use_multiview", 0, NULL, ICON_NONE);
- if (RNA_boolean_get(ptr, "use_multiview")) {
- if (imf->imtype != R_IMF_IMTYPE_MULTILAYER) {
- PropertyRNA *prop;
- PointerRNA stereo3d_format_ptr;
+ if (RNA_boolean_get(ptr, "use_multiview")) {
+ if (imf->imtype != R_IMF_IMTYPE_MULTILAYER) {
+ PropertyRNA *prop;
+ PointerRNA stereo3d_format_ptr;
- prop = RNA_struct_find_property(imfptr, "stereo_3d_format");
- stereo3d_format_ptr = RNA_property_pointer_get(imfptr, prop);
+ prop = RNA_struct_find_property(imfptr, "stereo_3d_format");
+ stereo3d_format_ptr = RNA_property_pointer_get(imfptr, prop);
- uiTemplateViewsFormat(layout, imfptr, &stereo3d_format_ptr);
- }
- else {
- uiTemplateViewsFormat(layout, imfptr, NULL);
- }
- }
+ uiTemplateViewsFormat(layout, imfptr, &stereo3d_format_ptr);
+ }
+ else {
+ uiTemplateViewsFormat(layout, imfptr, NULL);
+ }
+ }
}
void uiTemplateImageLayers(uiLayout *layout, bContext *C, Image *ima, ImageUser *iuser)
{
- Scene *scene = CTX_data_scene(C);
-
- /* render layers and passes */
- if (ima && iuser) {
- RenderResult *rr;
- const float dpi_fac = UI_DPI_FAC;
- const int menus_width = 160 * dpi_fac;
- const bool is_render_result = (ima->type == IMA_TYPE_R_RESULT);
-
- /* use BKE_image_acquire_renderresult so we get the correct slot in the menu */
- rr = BKE_image_acquire_renderresult(scene, ima);
- uiblock_layer_pass_buttons(layout, ima, rr, iuser, menus_width,
- is_render_result ? &ima->render_slot : NULL);
- BKE_image_release_renderresult(scene, ima);
- }
+ Scene *scene = CTX_data_scene(C);
+
+ /* render layers and passes */
+ if (ima && iuser) {
+ RenderResult *rr;
+ const float dpi_fac = UI_DPI_FAC;
+ const int menus_width = 160 * dpi_fac;
+ const bool is_render_result = (ima->type == IMA_TYPE_R_RESULT);
+
+ /* use BKE_image_acquire_renderresult so we get the correct slot in the menu */
+ rr = BKE_image_acquire_renderresult(scene, ima);
+ uiblock_layer_pass_buttons(
+ layout, ima, rr, iuser, menus_width, is_render_result ? &ima->render_slot : NULL);
+ BKE_image_release_renderresult(scene, ima);
+ }
}
void uiTemplateImageInfo(uiLayout *layout, bContext *C, Image *ima, ImageUser *iuser)
{
- Scene *scene = CTX_data_scene(C);
- ImBuf *ibuf;
- char str[MAX_IMAGE_INFO_LEN];
- void *lock;
+ Scene *scene = CTX_data_scene(C);
+ ImBuf *ibuf;
+ char str[MAX_IMAGE_INFO_LEN];
+ void *lock;
- if (!ima || !iuser) {
- return;
- }
+ if (!ima || !iuser) {
+ return;
+ }
- ibuf = BKE_image_acquire_ibuf(ima, iuser, &lock);
+ ibuf = BKE_image_acquire_ibuf(ima, iuser, &lock);
- BKE_image_user_frame_calc(iuser, (int)scene->r.cfra);
- image_info(scene, iuser, ima, ibuf, str, MAX_IMAGE_INFO_LEN);
- BKE_image_release_ibuf(ima, ibuf, lock);
- uiItemL(layout, str, ICON_NONE);
+ BKE_image_user_frame_calc(iuser, (int)scene->r.cfra);
+ image_info(scene, iuser, ima, ibuf, str, MAX_IMAGE_INFO_LEN);
+ BKE_image_release_ibuf(ima, ibuf, lock);
+ uiItemL(layout, str, ICON_NONE);
}
#undef MAX_IMAGE_INFO_LEN
static bool metadata_panel_context_poll(const bContext *C, PanelType *UNUSED(pt))
{
- SpaceImage *space_image = CTX_wm_space_image(C);
- return space_image != NULL && space_image->image != NULL;
+ SpaceImage *space_image = CTX_wm_space_image(C);
+ return space_image != NULL && space_image->image != NULL;
}
static void metadata_panel_context_draw(const bContext *C, Panel *panel)
{
- void *lock;
- SpaceImage *space_image = CTX_wm_space_image(C);
- Image *image = space_image->image;
- ImBuf *ibuf = BKE_image_acquire_ibuf(image, &space_image->iuser, &lock);
- if (ibuf != NULL) {
- ED_region_image_metadata_panel_draw(ibuf, panel->layout);
- }
- BKE_image_release_ibuf(image, ibuf, lock);
+ void *lock;
+ SpaceImage *space_image = CTX_wm_space_image(C);
+ Image *image = space_image->image;
+ ImBuf *ibuf = BKE_image_acquire_ibuf(image, &space_image->iuser, &lock);
+ if (ibuf != NULL) {
+ ED_region_image_metadata_panel_draw(ibuf, panel->layout);
+ }
+ BKE_image_release_ibuf(image, ibuf, lock);
}
void image_buttons_register(ARegionType *art)
{
- PanelType *pt;
-
- pt = MEM_callocN(sizeof(PanelType), "spacetype image panel metadata");
- strcpy(pt->idname, "IMAGE_PT_metadata");
- strcpy(pt->label, N_("Metadata"));
- strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
- pt->poll = metadata_panel_context_poll;
- pt->draw = metadata_panel_context_draw;
- pt->flag |= PNL_DEFAULT_CLOSED;
- BLI_addtail(&art->paneltypes, pt);
+ PanelType *pt;
+
+ pt = MEM_callocN(sizeof(PanelType), "spacetype image panel metadata");
+ strcpy(pt->idname, "IMAGE_PT_metadata");
+ strcpy(pt->label, N_("Metadata"));
+ strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
+ pt->poll = metadata_panel_context_poll;
+ pt->draw = metadata_panel_context_draw;
+ pt->flag |= PNL_DEFAULT_CLOSED;
+ BLI_addtail(&art->paneltypes, pt);
}
static int image_properties_toggle_exec(bContext *C, wmOperator *UNUSED(op))
{
- ScrArea *sa = CTX_wm_area(C);
- ARegion *ar = image_has_buttons_region(sa);
+ ScrArea *sa = CTX_wm_area(C);
+ ARegion *ar = image_has_buttons_region(sa);
- if (ar) {
- ED_region_toggle_hidden(C, ar);
- }
+ if (ar) {
+ ED_region_toggle_hidden(C, ar);
+ }
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void IMAGE_OT_properties(wmOperatorType *ot)
{
- ot->name = "Toggle Sidebar";
- ot->idname = "IMAGE_OT_properties";
- ot->description = "Toggle the properties region visibility";
+ ot->name = "Toggle Sidebar";
+ ot->idname = "IMAGE_OT_properties";
+ ot->description = "Toggle the properties region visibility";
- ot->exec = image_properties_toggle_exec;
- ot->poll = ED_operator_image_active;
+ ot->exec = image_properties_toggle_exec;
+ ot->poll = ED_operator_image_active;
- /* flags */
- ot->flag = 0;
+ /* flags */
+ ot->flag = 0;
}
static int image_scopes_toggle_exec(bContext *C, wmOperator *UNUSED(op))
{
- ScrArea *sa = CTX_wm_area(C);
- ARegion *ar = image_has_tools_region(sa);
+ ScrArea *sa = CTX_wm_area(C);
+ ARegion *ar = image_has_tools_region(sa);
- if (ar) {
- ED_region_toggle_hidden(C, ar);
- }
+ if (ar) {
+ ED_region_toggle_hidden(C, ar);
+ }
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void IMAGE_OT_toolshelf(wmOperatorType *ot)
{
- ot->name = "Toggle Toolbar";
- ot->idname = "IMAGE_OT_toolshelf";
- ot->description = "Toggles tool shelf display";
+ ot->name = "Toggle Toolbar";
+ ot->idname = "IMAGE_OT_toolshelf";
+ ot->description = "Toggles tool shelf display";
- ot->exec = image_scopes_toggle_exec;
- ot->poll = ED_operator_image_active;
+ ot->exec = image_scopes_toggle_exec;
+ ot->poll = ED_operator_image_active;
- /* flags */
- ot->flag = 0;
+ /* flags */
+ ot->flag = 0;
}
diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c
index ca0f9bd013f..a87808e1601 100644
--- a/source/blender/editors/space_image/image_draw.c
+++ b/source/blender/editors/space_image/image_draw.c
@@ -21,7 +21,6 @@
* \ingroup spimage
*/
-
#include <math.h>
#include <stdlib.h>
#include <string.h>
@@ -77,523 +76,589 @@
#include "image_intern.h"
-static void draw_render_info(const bContext *C,
- Scene *scene,
- Image *ima,
- ARegion *ar,
- float zoomx,
- float zoomy)
+static void draw_render_info(
+ const bContext *C, Scene *scene, Image *ima, ARegion *ar, float zoomx, float zoomy)
{
- Render *re = RE_GetSceneRender(scene);
- RenderData *rd = RE_engine_get_render_data(re);
- Scene *stats_scene = ED_render_job_get_scene(C);
- if (stats_scene == NULL) {
- stats_scene = CTX_data_scene(C);
- }
-
- RenderResult *rr = BKE_image_acquire_renderresult(stats_scene, ima);
-
- if (rr && rr->text) {
- float fill_color[4] = {0.0f, 0.0f, 0.0f, 0.25f};
- ED_region_info_draw(ar, rr->text, fill_color, true);
- }
-
- BKE_image_release_renderresult(stats_scene, ima);
-
- if (re) {
- int total_tiles;
- bool need_free_tiles;
- rcti *tiles = RE_engine_get_current_tiles(re, &total_tiles, &need_free_tiles);
-
- if (total_tiles) {
- /* find window pixel coordinates of origin */
- int x, y;
- UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y);
-
- GPU_matrix_push();
- GPU_matrix_translate_2f(x, y);
- GPU_matrix_scale_2f(zoomx, zoomy);
-
- if (rd->mode & R_BORDER) {
- /* TODO: round or floor instead of casting to int */
- GPU_matrix_translate_2f((int)(-rd->border.xmin * rd->xsch * rd->size * 0.01f),
- (int)(-rd->border.ymin * rd->ysch * rd->size * 0.01f));
- }
-
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- immUniformThemeColor(TH_FACE_SELECT);
-
- GPU_line_width(1.0f);
-
- rcti *tile = tiles;
- for (int i = 0; i < total_tiles; i++, tile++) {
- immDrawBorderCorners(pos, tile, zoomx, zoomy);
- }
-
- immUnbindProgram();
-
- if (need_free_tiles) {
- MEM_freeN(tiles);
- }
-
- GPU_matrix_pop();
- }
- }
+ Render *re = RE_GetSceneRender(scene);
+ RenderData *rd = RE_engine_get_render_data(re);
+ Scene *stats_scene = ED_render_job_get_scene(C);
+ if (stats_scene == NULL) {
+ stats_scene = CTX_data_scene(C);
+ }
+
+ RenderResult *rr = BKE_image_acquire_renderresult(stats_scene, ima);
+
+ if (rr && rr->text) {
+ float fill_color[4] = {0.0f, 0.0f, 0.0f, 0.25f};
+ ED_region_info_draw(ar, rr->text, fill_color, true);
+ }
+
+ BKE_image_release_renderresult(stats_scene, ima);
+
+ if (re) {
+ int total_tiles;
+ bool need_free_tiles;
+ rcti *tiles = RE_engine_get_current_tiles(re, &total_tiles, &need_free_tiles);
+
+ if (total_tiles) {
+ /* find window pixel coordinates of origin */
+ int x, y;
+ UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y);
+
+ GPU_matrix_push();
+ GPU_matrix_translate_2f(x, y);
+ GPU_matrix_scale_2f(zoomx, zoomy);
+
+ if (rd->mode & R_BORDER) {
+ /* TODO: round or floor instead of casting to int */
+ GPU_matrix_translate_2f((int)(-rd->border.xmin * rd->xsch * rd->size * 0.01f),
+ (int)(-rd->border.ymin * rd->ysch * rd->size * 0.01f));
+ }
+
+ uint pos = GPU_vertformat_attr_add(
+ immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColor(TH_FACE_SELECT);
+
+ GPU_line_width(1.0f);
+
+ rcti *tile = tiles;
+ for (int i = 0; i < total_tiles; i++, tile++) {
+ immDrawBorderCorners(pos, tile, zoomx, zoomy);
+ }
+
+ immUnbindProgram();
+
+ if (need_free_tiles) {
+ MEM_freeN(tiles);
+ }
+
+ GPU_matrix_pop();
+ }
+ }
}
/* used by node view too */
-void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_default_view, int channels, int x, int y,
- const unsigned char cp[4], const float fp[4], const float linearcol[4], int *zp, float *zpf)
+void ED_image_draw_info(Scene *scene,
+ ARegion *ar,
+ bool color_manage,
+ bool use_default_view,
+ int channels,
+ int x,
+ int y,
+ const unsigned char cp[4],
+ const float fp[4],
+ const float linearcol[4],
+ int *zp,
+ float *zpf)
{
- rcti color_rect;
- char str[256];
- int dx = 6;
- /* local coordinate visible rect inside region, to accommodate overlapping ui */
- rcti rect;
- ED_region_visible_rect(ar, &rect);
- const int ymin = rect.ymin;
- const int dy = ymin + 0.3f * UI_UNIT_Y;
-
- /* text colors */
- /* XXX colored text not allowed in Blender UI */
+ rcti color_rect;
+ char str[256];
+ int dx = 6;
+ /* local coordinate visible rect inside region, to accommodate overlapping ui */
+ rcti rect;
+ ED_region_visible_rect(ar, &rect);
+ const int ymin = rect.ymin;
+ const int dy = ymin + 0.3f * UI_UNIT_Y;
+
+ /* text colors */
+ /* XXX colored text not allowed in Blender UI */
#if 0
- unsigned char red[3] = {255, 50, 50};
- unsigned char green[3] = {0, 255, 0};
- unsigned char blue[3] = {100, 100, 255};
+ unsigned char red[3] = {255, 50, 50};
+ unsigned char green[3] = {0, 255, 0};
+ unsigned char blue[3] = {100, 100, 255};
#else
- unsigned char red[3] = {255, 255, 255};
- unsigned char green[3] = {255, 255, 255};
- unsigned char blue[3] = {255, 255, 255};
+ unsigned char red[3] = {255, 255, 255};
+ unsigned char green[3] = {255, 255, 255};
+ unsigned char blue[3] = {255, 255, 255};
#endif
- float hue = 0, sat = 0, val = 0, lum = 0, u = 0, v = 0;
- float col[4], finalcol[4];
-
- GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
- GPU_blend(true);
-
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
-
- /* noisy, high contrast make impossible to read if lower alpha is used. */
- immUniformColor4ub(0, 0, 0, 190);
- immRecti(pos, 0, ymin, BLI_rcti_size_x(&ar->winrct) + 1, ymin + UI_UNIT_Y);
-
- immUnbindProgram();
-
- GPU_blend(false);
-
- BLF_size(blf_mono_font, 11 * U.pixelsize, U.dpi);
-
- BLF_color3ub(blf_mono_font, 255, 255, 255);
- SNPRINTF(str, "X:%-4d Y:%-4d |", x, y);
- BLF_position(blf_mono_font, dx, dy, 0);
- BLF_draw_ascii(blf_mono_font, str, sizeof(str));
- dx += BLF_width(blf_mono_font, str, sizeof(str));
-
- if (zp) {
- BLF_color3ub(blf_mono_font, 255, 255, 255);
- SNPRINTF(str, " Z:%-.4f |", 0.5f + 0.5f * (((float)*zp) / (float)0x7fffffff));
- BLF_position(blf_mono_font, dx, dy, 0);
- BLF_draw_ascii(blf_mono_font, str, sizeof(str));
- dx += BLF_width(blf_mono_font, str, sizeof(str));
- }
- if (zpf) {
- BLF_color3ub(blf_mono_font, 255, 255, 255);
- SNPRINTF(str, " Z:%-.3f |", *zpf);
- BLF_position(blf_mono_font, dx, dy, 0);
- BLF_draw_ascii(blf_mono_font, str, sizeof(str));
- dx += BLF_width(blf_mono_font, str, sizeof(str));
- }
-
- if (channels == 1 && (cp != NULL || fp != NULL)) {
- if (fp != NULL) {
- SNPRINTF(str, " Val:%-.3f |", fp[0]);
- }
- else if (cp != NULL) {
- SNPRINTF(str, " Val:%-.3f |", cp[0] / 255.0f);
- }
- BLF_color3ub(blf_mono_font, 255, 255, 255);
- BLF_position(blf_mono_font, dx, dy, 0);
- BLF_draw_ascii(blf_mono_font, str, sizeof(str));
- dx += BLF_width(blf_mono_font, str, sizeof(str));
- }
-
- if (channels >= 3) {
- BLF_color3ubv(blf_mono_font, red);
- if (fp) {
- SNPRINTF(str, " R:%-.5f", fp[0]);
- }
- else if (cp) {
- SNPRINTF(str, " R:%-3d", cp[0]);
- }
- else {
- STRNCPY(str, " R:-");
- }
- BLF_position(blf_mono_font, dx, dy, 0);
- BLF_draw_ascii(blf_mono_font, str, sizeof(str));
- dx += BLF_width(blf_mono_font, str, sizeof(str));
-
- BLF_color3ubv(blf_mono_font, green);
- if (fp) {
- SNPRINTF(str, " G:%-.5f", fp[1]);
- }
- else if (cp) {
- SNPRINTF(str, " G:%-3d", cp[1]);
- }
- else {
- STRNCPY(str, " G:-");
- }
- BLF_position(blf_mono_font, dx, dy, 0);
- BLF_draw_ascii(blf_mono_font, str, sizeof(str));
- dx += BLF_width(blf_mono_font, str, sizeof(str));
-
- BLF_color3ubv(blf_mono_font, blue);
- if (fp) {
- SNPRINTF(str, " B:%-.5f", fp[2]);
- }
- else if (cp) {
- SNPRINTF(str, " B:%-3d", cp[2]);
- }
- else {
- STRNCPY(str, " B:-");
- }
- BLF_position(blf_mono_font, dx, dy, 0);
- BLF_draw_ascii(blf_mono_font, str, sizeof(str));
- dx += BLF_width(blf_mono_font, str, sizeof(str));
-
- if (channels == 4) {
- BLF_color3ub(blf_mono_font, 255, 255, 255);
- if (fp) {
- SNPRINTF(str, " A:%-.4f", fp[3]);
- }
- else if (cp) {
- SNPRINTF(str, " A:%-3d", cp[3]);
- }
- else {
- STRNCPY(str, "- ");
- }
- BLF_position(blf_mono_font, dx, dy, 0);
- BLF_draw_ascii(blf_mono_font, str, sizeof(str));
- dx += BLF_width(blf_mono_font, str, sizeof(str));
- }
-
- if (color_manage) {
- float rgba[4];
-
- copy_v3_v3(rgba, linearcol);
- if (channels == 3) {
- rgba[3] = 1.0f;
- }
- else {
- rgba[3] = linearcol[3];
- }
-
- if (use_default_view) {
- IMB_colormanagement_pixel_to_display_space_v4(rgba, rgba, NULL, &scene->display_settings);
- }
- else {
- IMB_colormanagement_pixel_to_display_space_v4(rgba, rgba, &scene->view_settings, &scene->display_settings);
- }
-
- SNPRINTF(str, " | CM R:%-.4f G:%-.4f B:%-.4f", rgba[0], rgba[1], rgba[2]);
- BLF_position(blf_mono_font, dx, dy, 0);
- BLF_draw_ascii(blf_mono_font, str, sizeof(str));
- dx += BLF_width(blf_mono_font, str, sizeof(str));
- }
- }
-
- /* color rectangle */
- if (channels == 1) {
- if (fp) {
- col[0] = col[1] = col[2] = fp[0];
- }
- else if (cp) {
- col[0] = col[1] = col[2] = (float)cp[0] / 255.0f;
- }
- else {
- col[0] = col[1] = col[2] = 0.0f;
- }
- col[3] = 1.0f;
- }
- else if (channels == 3) {
- copy_v3_v3(col, linearcol);
- col[3] = 1.0f;
- }
- else if (channels == 4) {
- copy_v4_v4(col, linearcol);
- }
- else {
- BLI_assert(0);
- zero_v4(col);
- }
-
- if (color_manage) {
- if (use_default_view) {
- IMB_colormanagement_pixel_to_display_space_v4(finalcol, col, NULL, &scene->display_settings);
- }
- else {
- IMB_colormanagement_pixel_to_display_space_v4(finalcol, col, &scene->view_settings, &scene->display_settings);
- }
- }
- else {
- copy_v4_v4(finalcol, col);
- }
-
- GPU_blend(false);
- dx += 0.25f * UI_UNIT_X;
-
- BLI_rcti_init(&color_rect, dx, dx + (1.5f * UI_UNIT_X), ymin + 0.15f * UI_UNIT_Y, ymin + 0.85f * UI_UNIT_Y);
-
- /* BLF uses immediate mode too, so we must reset our vertex format */
- pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
-
- if (channels == 4) {
- rcti color_rect_half;
- int color_quater_x, color_quater_y;
-
- color_rect_half = color_rect;
- color_rect_half.xmax = BLI_rcti_cent_x(&color_rect);
- /* what color ??? */
- immRecti(pos, color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax);
-
- color_rect_half = color_rect;
- color_rect_half.xmin = BLI_rcti_cent_x(&color_rect);
-
- color_quater_x = BLI_rcti_cent_x(&color_rect_half);
- color_quater_y = BLI_rcti_cent_y(&color_rect_half);
-
- immUniformColor3ub(UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK);
- immRecti(pos, color_rect_half.xmin, color_rect_half.ymin, color_rect_half.xmax, color_rect_half.ymax);
-
- immUniformColor3ub(UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT);
- immRecti(pos, color_quater_x, color_quater_y, color_rect_half.xmax, color_rect_half.ymax);
- immRecti(pos, color_rect_half.xmin, color_rect_half.ymin, color_quater_x, color_quater_y);
-
- GPU_blend(true);
- immUniformColor3fvAlpha(finalcol, fp ? fp[3] : (cp[3] / 255.0f));
- immRecti(pos, color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax);
- GPU_blend(false);
- }
- else {
- immUniformColor3fv(finalcol);
- immRecti(pos, color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax);
- }
- immUnbindProgram();
-
- /* draw outline */
- pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- immUniformColor3ub(128, 128, 128);
- imm_draw_box_wire_2d(pos, color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax);
- immUnbindProgram();
-
- dx += 1.75f * UI_UNIT_X;
-
- BLF_color3ub(blf_mono_font, 255, 255, 255);
- if (channels == 1) {
- if (fp) {
- rgb_to_hsv(fp[0], fp[0], fp[0], &hue, &sat, &val);
- rgb_to_yuv(fp[0], fp[0], fp[0], &lum, &u, &v, BLI_YUV_ITU_BT709);
- }
- else if (cp) {
- rgb_to_hsv((float)cp[0] / 255.0f, (float)cp[0] / 255.0f, (float)cp[0] / 255.0f, &hue, &sat, &val);
- rgb_to_yuv((float)cp[0] / 255.0f, (float)cp[0] / 255.0f, (float)cp[0] / 255.0f, &lum, &u, &v, BLI_YUV_ITU_BT709);
- }
-
- SNPRINTF(str, "V:%-.4f", val);
- BLF_position(blf_mono_font, dx, dy, 0);
- BLF_draw_ascii(blf_mono_font, str, sizeof(str));
- dx += BLF_width(blf_mono_font, str, sizeof(str));
-
- SNPRINTF(str, " L:%-.4f", lum);
- BLF_position(blf_mono_font, dx, dy, 0);
- BLF_draw_ascii(blf_mono_font, str, sizeof(str));
- }
- else if (channels >= 3) {
- rgb_to_hsv(finalcol[0], finalcol[1], finalcol[2], &hue, &sat, &val);
- rgb_to_yuv(finalcol[0], finalcol[1], finalcol[2], &lum, &u, &v, BLI_YUV_ITU_BT709);
-
- SNPRINTF(str, "H:%-.4f", hue);
- BLF_position(blf_mono_font, dx, dy, 0);
- BLF_draw_ascii(blf_mono_font, str, sizeof(str));
- dx += BLF_width(blf_mono_font, str, sizeof(str));
-
- SNPRINTF(str, " S:%-.4f", sat);
- BLF_position(blf_mono_font, dx, dy, 0);
- BLF_draw_ascii(blf_mono_font, str, sizeof(str));
- dx += BLF_width(blf_mono_font, str, sizeof(str));
-
- SNPRINTF(str, " V:%-.4f", val);
- BLF_position(blf_mono_font, dx, dy, 0);
- BLF_draw_ascii(blf_mono_font, str, sizeof(str));
- dx += BLF_width(blf_mono_font, str, sizeof(str));
-
- SNPRINTF(str, " L:%-.4f", lum);
- BLF_position(blf_mono_font, dx, dy, 0);
- BLF_draw_ascii(blf_mono_font, str, sizeof(str));
- }
+ float hue = 0, sat = 0, val = 0, lum = 0, u = 0, v = 0;
+ float col[4], finalcol[4];
+
+ GPU_blend_set_func_separate(
+ GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
+ GPU_blend(true);
+
+ uint pos = GPU_vertformat_attr_add(
+ immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ /* noisy, high contrast make impossible to read if lower alpha is used. */
+ immUniformColor4ub(0, 0, 0, 190);
+ immRecti(pos, 0, ymin, BLI_rcti_size_x(&ar->winrct) + 1, ymin + UI_UNIT_Y);
+
+ immUnbindProgram();
+
+ GPU_blend(false);
+
+ BLF_size(blf_mono_font, 11 * U.pixelsize, U.dpi);
+
+ BLF_color3ub(blf_mono_font, 255, 255, 255);
+ SNPRINTF(str, "X:%-4d Y:%-4d |", x, y);
+ BLF_position(blf_mono_font, dx, dy, 0);
+ BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+ dx += BLF_width(blf_mono_font, str, sizeof(str));
+
+ if (zp) {
+ BLF_color3ub(blf_mono_font, 255, 255, 255);
+ SNPRINTF(str, " Z:%-.4f |", 0.5f + 0.5f * (((float)*zp) / (float)0x7fffffff));
+ BLF_position(blf_mono_font, dx, dy, 0);
+ BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+ dx += BLF_width(blf_mono_font, str, sizeof(str));
+ }
+ if (zpf) {
+ BLF_color3ub(blf_mono_font, 255, 255, 255);
+ SNPRINTF(str, " Z:%-.3f |", *zpf);
+ BLF_position(blf_mono_font, dx, dy, 0);
+ BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+ dx += BLF_width(blf_mono_font, str, sizeof(str));
+ }
+
+ if (channels == 1 && (cp != NULL || fp != NULL)) {
+ if (fp != NULL) {
+ SNPRINTF(str, " Val:%-.3f |", fp[0]);
+ }
+ else if (cp != NULL) {
+ SNPRINTF(str, " Val:%-.3f |", cp[0] / 255.0f);
+ }
+ BLF_color3ub(blf_mono_font, 255, 255, 255);
+ BLF_position(blf_mono_font, dx, dy, 0);
+ BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+ dx += BLF_width(blf_mono_font, str, sizeof(str));
+ }
+
+ if (channels >= 3) {
+ BLF_color3ubv(blf_mono_font, red);
+ if (fp) {
+ SNPRINTF(str, " R:%-.5f", fp[0]);
+ }
+ else if (cp) {
+ SNPRINTF(str, " R:%-3d", cp[0]);
+ }
+ else {
+ STRNCPY(str, " R:-");
+ }
+ BLF_position(blf_mono_font, dx, dy, 0);
+ BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+ dx += BLF_width(blf_mono_font, str, sizeof(str));
+
+ BLF_color3ubv(blf_mono_font, green);
+ if (fp) {
+ SNPRINTF(str, " G:%-.5f", fp[1]);
+ }
+ else if (cp) {
+ SNPRINTF(str, " G:%-3d", cp[1]);
+ }
+ else {
+ STRNCPY(str, " G:-");
+ }
+ BLF_position(blf_mono_font, dx, dy, 0);
+ BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+ dx += BLF_width(blf_mono_font, str, sizeof(str));
+
+ BLF_color3ubv(blf_mono_font, blue);
+ if (fp) {
+ SNPRINTF(str, " B:%-.5f", fp[2]);
+ }
+ else if (cp) {
+ SNPRINTF(str, " B:%-3d", cp[2]);
+ }
+ else {
+ STRNCPY(str, " B:-");
+ }
+ BLF_position(blf_mono_font, dx, dy, 0);
+ BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+ dx += BLF_width(blf_mono_font, str, sizeof(str));
+
+ if (channels == 4) {
+ BLF_color3ub(blf_mono_font, 255, 255, 255);
+ if (fp) {
+ SNPRINTF(str, " A:%-.4f", fp[3]);
+ }
+ else if (cp) {
+ SNPRINTF(str, " A:%-3d", cp[3]);
+ }
+ else {
+ STRNCPY(str, "- ");
+ }
+ BLF_position(blf_mono_font, dx, dy, 0);
+ BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+ dx += BLF_width(blf_mono_font, str, sizeof(str));
+ }
+
+ if (color_manage) {
+ float rgba[4];
+
+ copy_v3_v3(rgba, linearcol);
+ if (channels == 3) {
+ rgba[3] = 1.0f;
+ }
+ else {
+ rgba[3] = linearcol[3];
+ }
+
+ if (use_default_view) {
+ IMB_colormanagement_pixel_to_display_space_v4(rgba, rgba, NULL, &scene->display_settings);
+ }
+ else {
+ IMB_colormanagement_pixel_to_display_space_v4(
+ rgba, rgba, &scene->view_settings, &scene->display_settings);
+ }
+
+ SNPRINTF(str, " | CM R:%-.4f G:%-.4f B:%-.4f", rgba[0], rgba[1], rgba[2]);
+ BLF_position(blf_mono_font, dx, dy, 0);
+ BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+ dx += BLF_width(blf_mono_font, str, sizeof(str));
+ }
+ }
+
+ /* color rectangle */
+ if (channels == 1) {
+ if (fp) {
+ col[0] = col[1] = col[2] = fp[0];
+ }
+ else if (cp) {
+ col[0] = col[1] = col[2] = (float)cp[0] / 255.0f;
+ }
+ else {
+ col[0] = col[1] = col[2] = 0.0f;
+ }
+ col[3] = 1.0f;
+ }
+ else if (channels == 3) {
+ copy_v3_v3(col, linearcol);
+ col[3] = 1.0f;
+ }
+ else if (channels == 4) {
+ copy_v4_v4(col, linearcol);
+ }
+ else {
+ BLI_assert(0);
+ zero_v4(col);
+ }
+
+ if (color_manage) {
+ if (use_default_view) {
+ IMB_colormanagement_pixel_to_display_space_v4(finalcol, col, NULL, &scene->display_settings);
+ }
+ else {
+ IMB_colormanagement_pixel_to_display_space_v4(
+ finalcol, col, &scene->view_settings, &scene->display_settings);
+ }
+ }
+ else {
+ copy_v4_v4(finalcol, col);
+ }
+
+ GPU_blend(false);
+ dx += 0.25f * UI_UNIT_X;
+
+ BLI_rcti_init(&color_rect,
+ dx,
+ dx + (1.5f * UI_UNIT_X),
+ ymin + 0.15f * UI_UNIT_Y,
+ ymin + 0.85f * UI_UNIT_Y);
+
+ /* BLF uses immediate mode too, so we must reset our vertex format */
+ pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ if (channels == 4) {
+ rcti color_rect_half;
+ int color_quater_x, color_quater_y;
+
+ color_rect_half = color_rect;
+ color_rect_half.xmax = BLI_rcti_cent_x(&color_rect);
+ /* what color ??? */
+ immRecti(pos, color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax);
+
+ color_rect_half = color_rect;
+ color_rect_half.xmin = BLI_rcti_cent_x(&color_rect);
+
+ color_quater_x = BLI_rcti_cent_x(&color_rect_half);
+ color_quater_y = BLI_rcti_cent_y(&color_rect_half);
+
+ immUniformColor3ub(UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK);
+ immRecti(pos,
+ color_rect_half.xmin,
+ color_rect_half.ymin,
+ color_rect_half.xmax,
+ color_rect_half.ymax);
+
+ immUniformColor3ub(UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT);
+ immRecti(pos, color_quater_x, color_quater_y, color_rect_half.xmax, color_rect_half.ymax);
+ immRecti(pos, color_rect_half.xmin, color_rect_half.ymin, color_quater_x, color_quater_y);
+
+ GPU_blend(true);
+ immUniformColor3fvAlpha(finalcol, fp ? fp[3] : (cp[3] / 255.0f));
+ immRecti(pos, color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax);
+ GPU_blend(false);
+ }
+ else {
+ immUniformColor3fv(finalcol);
+ immRecti(pos, color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax);
+ }
+ immUnbindProgram();
+
+ /* draw outline */
+ pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor3ub(128, 128, 128);
+ imm_draw_box_wire_2d(pos, color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax);
+ immUnbindProgram();
+
+ dx += 1.75f * UI_UNIT_X;
+
+ BLF_color3ub(blf_mono_font, 255, 255, 255);
+ if (channels == 1) {
+ if (fp) {
+ rgb_to_hsv(fp[0], fp[0], fp[0], &hue, &sat, &val);
+ rgb_to_yuv(fp[0], fp[0], fp[0], &lum, &u, &v, BLI_YUV_ITU_BT709);
+ }
+ else if (cp) {
+ rgb_to_hsv(
+ (float)cp[0] / 255.0f, (float)cp[0] / 255.0f, (float)cp[0] / 255.0f, &hue, &sat, &val);
+ rgb_to_yuv((float)cp[0] / 255.0f,
+ (float)cp[0] / 255.0f,
+ (float)cp[0] / 255.0f,
+ &lum,
+ &u,
+ &v,
+ BLI_YUV_ITU_BT709);
+ }
+
+ SNPRINTF(str, "V:%-.4f", val);
+ BLF_position(blf_mono_font, dx, dy, 0);
+ BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+ dx += BLF_width(blf_mono_font, str, sizeof(str));
+
+ SNPRINTF(str, " L:%-.4f", lum);
+ BLF_position(blf_mono_font, dx, dy, 0);
+ BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+ }
+ else if (channels >= 3) {
+ rgb_to_hsv(finalcol[0], finalcol[1], finalcol[2], &hue, &sat, &val);
+ rgb_to_yuv(finalcol[0], finalcol[1], finalcol[2], &lum, &u, &v, BLI_YUV_ITU_BT709);
+
+ SNPRINTF(str, "H:%-.4f", hue);
+ BLF_position(blf_mono_font, dx, dy, 0);
+ BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+ dx += BLF_width(blf_mono_font, str, sizeof(str));
+
+ SNPRINTF(str, " S:%-.4f", sat);
+ BLF_position(blf_mono_font, dx, dy, 0);
+ BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+ dx += BLF_width(blf_mono_font, str, sizeof(str));
+
+ SNPRINTF(str, " V:%-.4f", val);
+ BLF_position(blf_mono_font, dx, dy, 0);
+ BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+ dx += BLF_width(blf_mono_font, str, sizeof(str));
+
+ SNPRINTF(str, " L:%-.4f", lum);
+ BLF_position(blf_mono_font, dx, dy, 0);
+ BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+ }
}
/* image drawing */
-static void sima_draw_zbuf_pixels(float x1, float y1, int rectx, int recty, int *rect,
- float zoomx, float zoomy)
+static void sima_draw_zbuf_pixels(
+ float x1, float y1, int rectx, int recty, int *rect, float zoomx, float zoomy)
{
- float red[4] = {1.0f, 0.0f, 0.0f, 0.0f};
+ float red[4] = {1.0f, 0.0f, 0.0f, 0.0f};
- /* Slowwww */
- int *recti = MEM_mallocN(rectx * recty * sizeof(int), "temp");
- for (int a = rectx * recty - 1; a >= 0; a--) {
- /* zbuffer values are signed, so we need to shift color range */
- recti[a] = rect[a] * 0.5f + 0.5f;
- }
+ /* Slowwww */
+ int *recti = MEM_mallocN(rectx * recty * sizeof(int), "temp");
+ for (int a = rectx * recty - 1; a >= 0; a--) {
+ /* zbuffer values are signed, so we need to shift color range */
+ recti[a] = rect[a] * 0.5f + 0.5f;
+ }
- IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
- GPU_shader_uniform_vector(state.shader, GPU_shader_get_uniform_ensure(state.shader, "shuffle"), 4, 1, red);
+ IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
+ GPU_shader_uniform_vector(
+ state.shader, GPU_shader_get_uniform_ensure(state.shader, "shuffle"), 4, 1, red);
- immDrawPixelsTex(&state, x1, y1, rectx, recty, GL_RED, GL_INT, GL_NEAREST, recti, zoomx, zoomy, NULL);
+ immDrawPixelsTex(
+ &state, x1, y1, rectx, recty, GL_RED, GL_INT, GL_NEAREST, recti, zoomx, zoomy, NULL);
- MEM_freeN(recti);
+ MEM_freeN(recti);
}
-static void sima_draw_zbuffloat_pixels(Scene *scene, float x1, float y1, int rectx, int recty,
- float *rect_float, float zoomx, float zoomy)
+static void sima_draw_zbuffloat_pixels(Scene *scene,
+ float x1,
+ float y1,
+ int rectx,
+ int recty,
+ float *rect_float,
+ float zoomx,
+ float zoomy)
{
- float bias, scale, *rectf, clip_end;
- int a;
- float red[4] = {1.0f, 0.0f, 0.0f, 0.0f};
-
- if (scene->camera && scene->camera->type == OB_CAMERA) {
- bias = ((Camera *)scene->camera->data)->clip_start;
- clip_end = ((Camera *)scene->camera->data)->clip_end;
- scale = 1.0f / (clip_end - bias);
- }
- else {
- bias = 0.1f;
- scale = 0.01f;
- clip_end = 100.0f;
- }
-
- rectf = MEM_mallocN(rectx * recty * sizeof(float), "temp");
- for (a = rectx * recty - 1; a >= 0; a--) {
- if (rect_float[a] > clip_end) {
- rectf[a] = 0.0f;
- }
- else if (rect_float[a] < bias) {
- rectf[a] = 1.0f;
- }
- else {
- rectf[a] = 1.0f - (rect_float[a] - bias) * scale;
- rectf[a] *= rectf[a];
- }
- }
-
- IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
- GPU_shader_uniform_vector(state.shader, GPU_shader_get_uniform_ensure(state.shader, "shuffle"), 4, 1, red);
-
- immDrawPixelsTex(&state, x1, y1, rectx, recty, GL_RED, GL_FLOAT, GL_NEAREST, rectf, zoomx, zoomy, NULL);
-
- MEM_freeN(rectf);
+ float bias, scale, *rectf, clip_end;
+ int a;
+ float red[4] = {1.0f, 0.0f, 0.0f, 0.0f};
+
+ if (scene->camera && scene->camera->type == OB_CAMERA) {
+ bias = ((Camera *)scene->camera->data)->clip_start;
+ clip_end = ((Camera *)scene->camera->data)->clip_end;
+ scale = 1.0f / (clip_end - bias);
+ }
+ else {
+ bias = 0.1f;
+ scale = 0.01f;
+ clip_end = 100.0f;
+ }
+
+ rectf = MEM_mallocN(rectx * recty * sizeof(float), "temp");
+ for (a = rectx * recty - 1; a >= 0; a--) {
+ if (rect_float[a] > clip_end) {
+ rectf[a] = 0.0f;
+ }
+ else if (rect_float[a] < bias) {
+ rectf[a] = 1.0f;
+ }
+ else {
+ rectf[a] = 1.0f - (rect_float[a] - bias) * scale;
+ rectf[a] *= rectf[a];
+ }
+ }
+
+ IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
+ GPU_shader_uniform_vector(
+ state.shader, GPU_shader_get_uniform_ensure(state.shader, "shuffle"), 4, 1, red);
+
+ immDrawPixelsTex(
+ &state, x1, y1, rectx, recty, GL_RED, GL_FLOAT, GL_NEAREST, rectf, zoomx, zoomy, NULL);
+
+ MEM_freeN(rectf);
}
-static void draw_image_buffer(const bContext *C, SpaceImage *sima, ARegion *ar, Scene *scene, ImBuf *ibuf, float fx, float fy, float zoomx, float zoomy)
+static void draw_image_buffer(const bContext *C,
+ SpaceImage *sima,
+ ARegion *ar,
+ Scene *scene,
+ ImBuf *ibuf,
+ float fx,
+ float fy,
+ float zoomx,
+ float zoomy)
{
- int x, y;
-
- /* find window pixel coordinates of origin */
- UI_view2d_view_to_region(&ar->v2d, fx, fy, &x, &y);
-
- /* this part is generic image display */
- if (sima->flag & SI_SHOW_ZBUF && (ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels == 1))) {
- if (ibuf->zbuf) {
- sima_draw_zbuf_pixels(x, y, ibuf->x, ibuf->y, ibuf->zbuf, zoomx, zoomy);
- }
- else if (ibuf->zbuf_float) {
- sima_draw_zbuffloat_pixels(scene, x, y, ibuf->x, ibuf->y, ibuf->zbuf_float, zoomx, zoomy);
- }
- else if (ibuf->channels == 1) {
- sima_draw_zbuffloat_pixels(scene, x, y, ibuf->x, ibuf->y, ibuf->rect_float, zoomx, zoomy);
- }
- }
- else {
- int clip_max_x, clip_max_y;
- UI_view2d_view_to_region(&ar->v2d,
- ar->v2d.cur.xmax, ar->v2d.cur.ymax,
- &clip_max_x, &clip_max_y);
-
- if (sima->flag & SI_USE_ALPHA) {
- imm_draw_box_checker_2d(x, y, x + ibuf->x * zoomx, y + ibuf->y * zoomy);
-
- GPU_blend(true);
- GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
- }
-
- /* If RGBA display with color management */
- if ((sima->flag & (SI_SHOW_R | SI_SHOW_G | SI_SHOW_B | SI_SHOW_ALPHA)) == 0) {
-
- glaDrawImBuf_glsl_ctx_clipping(C, ibuf, x, y, GL_NEAREST,
- 0, 0, clip_max_x, clip_max_y, zoomx, zoomy);
- }
- else {
- float shuffle[4] = {0.0f, 0.0f, 0.0f, 0.0f};
- unsigned char *display_buffer;
- void *cache_handle;
- ColorManagedViewSettings *view_settings;
- ColorManagedDisplaySettings *display_settings;
-
- if (sima->flag & SI_SHOW_R) {
- shuffle[0] = 1.0f;
- }
- else if (sima->flag & SI_SHOW_G) {
- shuffle[1] = 1.0f;
- }
- else if (sima->flag & SI_SHOW_B) {
- shuffle[2] = 1.0f;
- }
- else if (sima->flag & SI_SHOW_ALPHA) {
- shuffle[3] = 1.0f;
- }
-
- IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
- GPU_shader_uniform_vector(state.shader, GPU_shader_get_uniform_ensure(state.shader, "shuffle"), 4, 1, shuffle);
-
- IMB_colormanagement_display_settings_from_ctx(C, &view_settings, &display_settings);
- display_buffer = IMB_display_buffer_acquire(ibuf, view_settings, display_settings, &cache_handle);
-
- if (display_buffer) {
- immDrawPixelsTex_clipping(&state, x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, display_buffer,
- 0, 0, clip_max_x, clip_max_y, zoomx, zoomy, NULL);
- }
-
- IMB_display_buffer_release(cache_handle);
- }
-
- if (sima->flag & SI_USE_ALPHA) {
- GPU_blend(false);
- }
- }
+ int x, y;
+
+ /* find window pixel coordinates of origin */
+ UI_view2d_view_to_region(&ar->v2d, fx, fy, &x, &y);
+
+ /* this part is generic image display */
+ if (sima->flag & SI_SHOW_ZBUF && (ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels == 1))) {
+ if (ibuf->zbuf) {
+ sima_draw_zbuf_pixels(x, y, ibuf->x, ibuf->y, ibuf->zbuf, zoomx, zoomy);
+ }
+ else if (ibuf->zbuf_float) {
+ sima_draw_zbuffloat_pixels(scene, x, y, ibuf->x, ibuf->y, ibuf->zbuf_float, zoomx, zoomy);
+ }
+ else if (ibuf->channels == 1) {
+ sima_draw_zbuffloat_pixels(scene, x, y, ibuf->x, ibuf->y, ibuf->rect_float, zoomx, zoomy);
+ }
+ }
+ else {
+ int clip_max_x, clip_max_y;
+ UI_view2d_view_to_region(
+ &ar->v2d, ar->v2d.cur.xmax, ar->v2d.cur.ymax, &clip_max_x, &clip_max_y);
+
+ if (sima->flag & SI_USE_ALPHA) {
+ imm_draw_box_checker_2d(x, y, x + ibuf->x * zoomx, y + ibuf->y * zoomy);
+
+ GPU_blend(true);
+ GPU_blend_set_func_separate(
+ GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
+ }
+
+ /* If RGBA display with color management */
+ if ((sima->flag & (SI_SHOW_R | SI_SHOW_G | SI_SHOW_B | SI_SHOW_ALPHA)) == 0) {
+
+ glaDrawImBuf_glsl_ctx_clipping(
+ C, ibuf, x, y, GL_NEAREST, 0, 0, clip_max_x, clip_max_y, zoomx, zoomy);
+ }
+ else {
+ float shuffle[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+ unsigned char *display_buffer;
+ void *cache_handle;
+ ColorManagedViewSettings *view_settings;
+ ColorManagedDisplaySettings *display_settings;
+
+ if (sima->flag & SI_SHOW_R) {
+ shuffle[0] = 1.0f;
+ }
+ else if (sima->flag & SI_SHOW_G) {
+ shuffle[1] = 1.0f;
+ }
+ else if (sima->flag & SI_SHOW_B) {
+ shuffle[2] = 1.0f;
+ }
+ else if (sima->flag & SI_SHOW_ALPHA) {
+ shuffle[3] = 1.0f;
+ }
+
+ IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
+ GPU_shader_uniform_vector(
+ state.shader, GPU_shader_get_uniform_ensure(state.shader, "shuffle"), 4, 1, shuffle);
+
+ IMB_colormanagement_display_settings_from_ctx(C, &view_settings, &display_settings);
+ display_buffer = IMB_display_buffer_acquire(
+ ibuf, view_settings, display_settings, &cache_handle);
+
+ if (display_buffer) {
+ immDrawPixelsTex_clipping(&state,
+ x,
+ y,
+ ibuf->x,
+ ibuf->y,
+ GL_RGBA,
+ GL_UNSIGNED_BYTE,
+ GL_NEAREST,
+ display_buffer,
+ 0,
+ 0,
+ clip_max_x,
+ clip_max_y,
+ zoomx,
+ zoomy,
+ NULL);
+ }
+
+ IMB_display_buffer_release(cache_handle);
+ }
+
+ if (sima->flag & SI_USE_ALPHA) {
+ GPU_blend(false);
+ }
+ }
}
-static void draw_image_buffer_repeated(const bContext *C, SpaceImage *sima, ARegion *ar, Scene *scene, ImBuf *ibuf, float zoomx, float zoomy)
+static void draw_image_buffer_repeated(const bContext *C,
+ SpaceImage *sima,
+ ARegion *ar,
+ Scene *scene,
+ ImBuf *ibuf,
+ float zoomx,
+ float zoomy)
{
- const double time_current = PIL_check_seconds_timer();
-
- const int xmax = ceil(ar->v2d.cur.xmax);
- const int ymax = ceil(ar->v2d.cur.ymax);
- const int xmin = floor(ar->v2d.cur.xmin);
- const int ymin = floor(ar->v2d.cur.ymin);
-
- for (int x = xmin; x < xmax; x++) {
- for (int y = ymin; y < ymax; y++) {
- draw_image_buffer(C, sima, ar, scene, ibuf, x, y, zoomx, zoomy);
-
- /* only draw until running out of time */
- if ((PIL_check_seconds_timer() - time_current) > 0.25) {
- return;
- }
- }
- }
+ const double time_current = PIL_check_seconds_timer();
+
+ const int xmax = ceil(ar->v2d.cur.xmax);
+ const int ymax = ceil(ar->v2d.cur.ymax);
+ const int xmin = floor(ar->v2d.cur.xmin);
+ const int ymin = floor(ar->v2d.cur.ymin);
+
+ for (int x = xmin; x < xmax; x++) {
+ for (int y = ymin; y < ymax; y++) {
+ draw_image_buffer(C, sima, ar, scene, ibuf, x, y, zoomx, zoomy);
+
+ /* only draw until running out of time */
+ if ((PIL_check_seconds_timer() - time_current) > 0.25) {
+ return;
+ }
+ }
+ }
}
/* draw uv edit */
@@ -601,249 +666,269 @@ static void draw_image_buffer_repeated(const bContext *C, SpaceImage *sima, AReg
/* draw grease pencil */
void draw_image_grease_pencil(bContext *C, bool onlyv2d)
{
- /* draw in View2D space? */
- if (onlyv2d) {
- /* draw grease-pencil ('image' strokes) */
- ED_annotation_draw_2dimage(C);
- }
- else {
- /* assume that UI_view2d_restore(C) has been called... */
- //SpaceImage *sima = (SpaceImage *)CTX_wm_space_data(C);
-
- /* draw grease-pencil ('screen' strokes) */
- ED_annotation_draw_view2d(C, 0);
- }
+ /* draw in View2D space? */
+ if (onlyv2d) {
+ /* draw grease-pencil ('image' strokes) */
+ ED_annotation_draw_2dimage(C);
+ }
+ else {
+ /* assume that UI_view2d_restore(C) has been called... */
+ //SpaceImage *sima = (SpaceImage *)CTX_wm_space_data(C);
+
+ /* draw grease-pencil ('screen' strokes) */
+ ED_annotation_draw_view2d(C, 0);
+ }
}
void draw_image_sample_line(SpaceImage *sima)
{
- if (sima->sample_line_hist.flag & HISTO_FLAG_SAMPLELINE) {
- Histogram *hist = &sima->sample_line_hist;
+ if (sima->sample_line_hist.flag & HISTO_FLAG_SAMPLELINE) {
+ Histogram *hist = &sima->sample_line_hist;
- GPUVertFormat *format = immVertexFormat();
- uint shdr_dashed_pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ GPUVertFormat *format = immVertexFormat();
+ uint shdr_dashed_pos = GPU_vertformat_attr_add(
+ format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
- float viewport_size[4];
- GPU_viewport_size_get_f(viewport_size);
- immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
+ float viewport_size[4];
+ GPU_viewport_size_get_f(viewport_size);
+ immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
- immUniform1i("colors_len", 2); /* Advanced dashes. */
- immUniformArray4fv("colors", (float *)(float[][4]){{1.0f, 1.0f, 1.0f, 1.0f}, {0.0f, 0.0f, 0.0f, 1.0f}}, 2);
- immUniform1f("dash_width", 2.0f);
+ immUniform1i("colors_len", 2); /* Advanced dashes. */
+ immUniformArray4fv(
+ "colors", (float *)(float[][4]){{1.0f, 1.0f, 1.0f, 1.0f}, {0.0f, 0.0f, 0.0f, 1.0f}}, 2);
+ immUniform1f("dash_width", 2.0f);
- immBegin(GPU_PRIM_LINES, 2);
- immVertex2fv(shdr_dashed_pos, hist->co[0]);
- immVertex2fv(shdr_dashed_pos, hist->co[1]);
- immEnd();
+ immBegin(GPU_PRIM_LINES, 2);
+ immVertex2fv(shdr_dashed_pos, hist->co[0]);
+ immVertex2fv(shdr_dashed_pos, hist->co[1]);
+ immEnd();
- immUnbindProgram();
- }
+ immUnbindProgram();
+ }
}
-static void draw_image_paint_helpers(const bContext *C, ARegion *ar, Scene *scene, float zoomx, float zoomy)
+static void draw_image_paint_helpers(
+ const bContext *C, ARegion *ar, Scene *scene, float zoomx, float zoomy)
{
- Brush *brush;
- int x, y;
- ImBuf *ibuf;
-
- brush = BKE_paint_brush(&scene->toolsettings->imapaint.paint);
-
- if (brush && (brush->imagepaint_tool == PAINT_TOOL_CLONE) && brush->clone.image) {
- ibuf = BKE_image_acquire_ibuf(brush->clone.image, NULL, NULL);
-
- if (ibuf) {
- void *cache_handle = NULL;
- float col[4] = {1.0f, 1.0f, 1.0f, brush->clone.alpha};
- UI_view2d_view_to_region(&ar->v2d, brush->clone.offset[0], brush->clone.offset[1], &x, &y);
-
- unsigned char *display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle);
-
- if (!display_buffer) {
- BKE_image_release_ibuf(brush->clone.image, ibuf, NULL);
- IMB_display_buffer_release(cache_handle);
- return;
- }
-
- GPU_blend(true);
- GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
-
- IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
- immDrawPixelsTex(&state, x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, display_buffer, zoomx, zoomy, col);
-
- GPU_blend(false);
-
- BKE_image_release_ibuf(brush->clone.image, ibuf, NULL);
- IMB_display_buffer_release(cache_handle);
- }
- }
+ Brush *brush;
+ int x, y;
+ ImBuf *ibuf;
+
+ brush = BKE_paint_brush(&scene->toolsettings->imapaint.paint);
+
+ if (brush && (brush->imagepaint_tool == PAINT_TOOL_CLONE) && brush->clone.image) {
+ ibuf = BKE_image_acquire_ibuf(brush->clone.image, NULL, NULL);
+
+ if (ibuf) {
+ void *cache_handle = NULL;
+ float col[4] = {1.0f, 1.0f, 1.0f, brush->clone.alpha};
+ UI_view2d_view_to_region(&ar->v2d, brush->clone.offset[0], brush->clone.offset[1], &x, &y);
+
+ unsigned char *display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle);
+
+ if (!display_buffer) {
+ BKE_image_release_ibuf(brush->clone.image, ibuf, NULL);
+ IMB_display_buffer_release(cache_handle);
+ return;
+ }
+
+ GPU_blend(true);
+ GPU_blend_set_func_separate(
+ GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
+
+ IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+ immDrawPixelsTex(&state,
+ x,
+ y,
+ ibuf->x,
+ ibuf->y,
+ GL_RGBA,
+ GL_UNSIGNED_BYTE,
+ GL_NEAREST,
+ display_buffer,
+ zoomx,
+ zoomy,
+ col);
+
+ GPU_blend(false);
+
+ BKE_image_release_ibuf(brush->clone.image, ibuf, NULL);
+ IMB_display_buffer_release(cache_handle);
+ }
+ }
}
/* draw main image region */
void draw_image_main(const bContext *C, ARegion *ar)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- Scene *scene = CTX_data_scene(C);
- Image *ima;
- ImBuf *ibuf;
- float zoomx, zoomy;
- bool show_viewer, show_render, show_paint, show_stereo3d, show_multilayer;
- void *lock;
-
- /* XXX can we do this in refresh? */
+ SpaceImage *sima = CTX_wm_space_image(C);
+ Scene *scene = CTX_data_scene(C);
+ Image *ima;
+ ImBuf *ibuf;
+ float zoomx, zoomy;
+ bool show_viewer, show_render, show_paint, show_stereo3d, show_multilayer;
+ void *lock;
+
+ /* XXX can we do this in refresh? */
#if 0
- what_image(sima);
-
- if (sima->image) {
- ED_image_get_aspect(sima->image, &xuser_asp, &yuser_asp);
-
- /* UGLY hack? until now iusers worked fine... but for flipbook viewer we need this */
- if (sima->image->type == IMA_TYPE_COMPOSITE) {
- ImageUser *iuser = ntree_get_active_iuser(scene->nodetree);
- if (iuser) {
- BKE_image_user_calc_imanr(iuser, scene->r.cfra, 0);
- sima->iuser = *iuser;
- }
- }
- /* and we check for spare */
- ibuf = ED_space_image_buffer(sima);
- }
+ what_image(sima);
+
+ if (sima->image) {
+ ED_image_get_aspect(sima->image, &xuser_asp, &yuser_asp);
+
+ /* UGLY hack? until now iusers worked fine... but for flipbook viewer we need this */
+ if (sima->image->type == IMA_TYPE_COMPOSITE) {
+ ImageUser *iuser = ntree_get_active_iuser(scene->nodetree);
+ if (iuser) {
+ BKE_image_user_calc_imanr(iuser, scene->r.cfra, 0);
+ sima->iuser = *iuser;
+ }
+ }
+ /* and we check for spare */
+ ibuf = ED_space_image_buffer(sima);
+ }
#endif
- /* retrieve the image and information about it */
- ima = ED_space_image(sima);
- ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy);
-
- show_viewer = (ima && ima->source == IMA_SRC_VIEWER) != 0;
- show_render = (show_viewer && ima->type == IMA_TYPE_R_RESULT) != 0;
- show_paint = (ima && (sima->mode == SI_MODE_PAINT) && (show_viewer == false) && (show_render == false));
- show_stereo3d = (ima && BKE_image_is_stereo(ima) && (sima->iuser.flag & IMA_SHOW_STEREO));
- show_multilayer = ima && BKE_image_is_multilayer(ima);
-
- if (show_viewer) {
- /* use locked draw for drawing viewer image buffer since the compositor
- * is running in separated thread and compositor could free this buffers.
- * other images are not modifying in such a way so they does not require
- * lock (sergey)
- */
- BLI_thread_lock(LOCK_DRAW_IMAGE);
- }
-
- if (show_stereo3d) {
- if (show_multilayer) {
- /* update multiindex and pass for the current eye */
- BKE_image_multilayer_index(ima->rr, &sima->iuser);
- }
- else {
- BKE_image_multiview_index(ima, &sima->iuser);
- }
- }
-
- ibuf = ED_space_image_acquire_buffer(sima, &lock);
-
- /* draw the image or grid */
- if (ibuf == NULL) {
- ED_region_grid_draw(ar, zoomx, zoomy);
- }
- else {
- if (sima->flag & SI_DRAW_TILE) {
- draw_image_buffer_repeated(C, sima, ar, scene, ibuf, zoomx, zoomy);
- }
- else {
- draw_image_buffer(C, sima, ar, scene, ibuf, 0.0f, 0.0f, zoomx, zoomy);
- }
-
- if (sima->flag & SI_DRAW_METADATA) {
- int x, y;
- rctf frame;
-
- BLI_rctf_init(&frame, 0.0f, ibuf->x, 0.0f, ibuf->y);
- UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y);
-
- ED_region_image_metadata_draw(x, y, ibuf, &frame, zoomx, zoomy);
- }
- }
-
- ED_space_image_release_buffer(sima, ibuf, lock);
-
- /* paint helpers */
- if (show_paint) {
- draw_image_paint_helpers(C, ar, scene, zoomx, zoomy);
- }
-
- if (show_viewer) {
- BLI_thread_unlock(LOCK_DRAW_IMAGE);
- }
-
- /* render info */
- if (ima && show_render) {
- draw_render_info(C, sima->iuser.scene, ima, ar, zoomx, zoomy);
- }
+ /* retrieve the image and information about it */
+ ima = ED_space_image(sima);
+ ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy);
+
+ show_viewer = (ima && ima->source == IMA_SRC_VIEWER) != 0;
+ show_render = (show_viewer && ima->type == IMA_TYPE_R_RESULT) != 0;
+ show_paint = (ima && (sima->mode == SI_MODE_PAINT) && (show_viewer == false) &&
+ (show_render == false));
+ show_stereo3d = (ima && BKE_image_is_stereo(ima) && (sima->iuser.flag & IMA_SHOW_STEREO));
+ show_multilayer = ima && BKE_image_is_multilayer(ima);
+
+ if (show_viewer) {
+ /* use locked draw for drawing viewer image buffer since the compositor
+ * is running in separated thread and compositor could free this buffers.
+ * other images are not modifying in such a way so they does not require
+ * lock (sergey)
+ */
+ BLI_thread_lock(LOCK_DRAW_IMAGE);
+ }
+
+ if (show_stereo3d) {
+ if (show_multilayer) {
+ /* update multiindex and pass for the current eye */
+ BKE_image_multilayer_index(ima->rr, &sima->iuser);
+ }
+ else {
+ BKE_image_multiview_index(ima, &sima->iuser);
+ }
+ }
+
+ ibuf = ED_space_image_acquire_buffer(sima, &lock);
+
+ /* draw the image or grid */
+ if (ibuf == NULL) {
+ ED_region_grid_draw(ar, zoomx, zoomy);
+ }
+ else {
+ if (sima->flag & SI_DRAW_TILE) {
+ draw_image_buffer_repeated(C, sima, ar, scene, ibuf, zoomx, zoomy);
+ }
+ else {
+ draw_image_buffer(C, sima, ar, scene, ibuf, 0.0f, 0.0f, zoomx, zoomy);
+ }
+
+ if (sima->flag & SI_DRAW_METADATA) {
+ int x, y;
+ rctf frame;
+
+ BLI_rctf_init(&frame, 0.0f, ibuf->x, 0.0f, ibuf->y);
+ UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y);
+
+ ED_region_image_metadata_draw(x, y, ibuf, &frame, zoomx, zoomy);
+ }
+ }
+
+ ED_space_image_release_buffer(sima, ibuf, lock);
+
+ /* paint helpers */
+ if (show_paint) {
+ draw_image_paint_helpers(C, ar, scene, zoomx, zoomy);
+ }
+
+ if (show_viewer) {
+ BLI_thread_unlock(LOCK_DRAW_IMAGE);
+ }
+
+ /* render info */
+ if (ima && show_render) {
+ draw_render_info(C, sima->iuser.scene, ima, ar, zoomx, zoomy);
+ }
}
bool ED_space_image_show_cache(SpaceImage *sima)
{
- Image *image = ED_space_image(sima);
- Mask *mask = NULL;
- if (sima->mode == SI_MODE_MASK) {
- mask = ED_space_image_get_mask(sima);
- }
- if (image == NULL && mask == NULL) {
- return false;
- }
- if (mask == NULL) {
- return ELEM(image->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE);
- }
- return true;
+ Image *image = ED_space_image(sima);
+ Mask *mask = NULL;
+ if (sima->mode == SI_MODE_MASK) {
+ mask = ED_space_image_get_mask(sima);
+ }
+ if (image == NULL && mask == NULL) {
+ return false;
+ }
+ if (mask == NULL) {
+ return ELEM(image->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE);
+ }
+ return true;
}
void draw_image_cache(const bContext *C, ARegion *ar)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- Scene *scene = CTX_data_scene(C);
- Image *image = ED_space_image(sima);
- float x, cfra = CFRA, sfra = SFRA, efra = EFRA, framelen = ar->winx / (efra - sfra + 1);
- Mask *mask = NULL;
-
- if (!ED_space_image_show_cache(sima)) {
- return;
- }
-
- if (sima->mode == SI_MODE_MASK) {
- mask = ED_space_image_get_mask(sima);
- }
-
- GPU_blend(true);
- GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
-
- /* Draw cache background. */
- ED_region_cache_draw_background(ar);
-
- /* Draw cached segments. */
- if (image != NULL && image->cache != NULL && ELEM(image->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) {
- int num_segments = 0;
- int *points = NULL;
-
- IMB_moviecache_get_cache_segments(image->cache, IMB_PROXY_NONE, 0, &num_segments, &points);
- ED_region_cache_draw_cached_segments(ar, num_segments, points, sfra + sima->iuser.offset, efra + sima->iuser.offset);
- }
-
- GPU_blend(false);
-
- /* Draw current frame. */
- x = (cfra - sfra) / (efra - sfra + 1) * ar->winx;
-
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- immUniformThemeColor(TH_CFRAME);
- immRecti(pos, x, 0, x + ceilf(framelen), 8 * UI_DPI_FAC);
- immUnbindProgram();
-
- ED_region_cache_draw_curfra_label(cfra, x, 8.0f * UI_DPI_FAC);
-
- if (mask != NULL) {
- ED_mask_draw_frames(mask, ar, cfra, sfra, efra);
- }
+ SpaceImage *sima = CTX_wm_space_image(C);
+ Scene *scene = CTX_data_scene(C);
+ Image *image = ED_space_image(sima);
+ float x, cfra = CFRA, sfra = SFRA, efra = EFRA, framelen = ar->winx / (efra - sfra + 1);
+ Mask *mask = NULL;
+
+ if (!ED_space_image_show_cache(sima)) {
+ return;
+ }
+
+ if (sima->mode == SI_MODE_MASK) {
+ mask = ED_space_image_get_mask(sima);
+ }
+
+ GPU_blend(true);
+ GPU_blend_set_func_separate(
+ GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
+
+ /* Draw cache background. */
+ ED_region_cache_draw_background(ar);
+
+ /* Draw cached segments. */
+ if (image != NULL && image->cache != NULL &&
+ ELEM(image->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) {
+ int num_segments = 0;
+ int *points = NULL;
+
+ IMB_moviecache_get_cache_segments(image->cache, IMB_PROXY_NONE, 0, &num_segments, &points);
+ ED_region_cache_draw_cached_segments(
+ ar, num_segments, points, sfra + sima->iuser.offset, efra + sima->iuser.offset);
+ }
+
+ GPU_blend(false);
+
+ /* Draw current frame. */
+ x = (cfra - sfra) / (efra - sfra + 1) * ar->winx;
+
+ uint pos = GPU_vertformat_attr_add(
+ immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColor(TH_CFRAME);
+ immRecti(pos, x, 0, x + ceilf(framelen), 8 * UI_DPI_FAC);
+ immUnbindProgram();
+
+ ED_region_cache_draw_curfra_label(cfra, x, 8.0f * UI_DPI_FAC);
+
+ if (mask != NULL) {
+ ED_mask_draw_frames(mask, ar, cfra, sfra, efra);
+ }
}
diff --git a/source/blender/editors/space_image/image_edit.c b/source/blender/editors/space_image/image_edit.c
index c838c6a87fe..fc6546f0079 100644
--- a/source/blender/editors/space_image/image_edit.c
+++ b/source/blender/editors/space_image/image_edit.c
@@ -41,7 +41,7 @@
#include "DEG_depsgraph.h"
-#include "ED_image.h" /* own include */
+#include "ED_image.h" /* own include */
#include "ED_mesh.h"
#include "ED_screen.h"
#include "ED_uvedit.h"
@@ -54,276 +54,276 @@
/* note; image_panel_properties() uses pointer to sima->image directly */
Image *ED_space_image(SpaceImage *sima)
{
- return sima->image;
+ return sima->image;
}
void ED_space_image_set(Main *bmain, SpaceImage *sima, Object *obedit, Image *ima, bool automatic)
{
- /* Automatically pin image when manually assigned, otherwise it follows object. */
- if (!automatic && sima->image != ima && sima->mode == SI_MODE_UV) {
- sima->pin = true;
- }
+ /* Automatically pin image when manually assigned, otherwise it follows object. */
+ if (!automatic && sima->image != ima && sima->mode == SI_MODE_UV) {
+ sima->pin = true;
+ }
- /* change the space ima after because uvedit_face_visible_test uses the space ima
- * to check if the face is displayed in UV-localview */
- sima->image = ima;
+ /* change the space ima after because uvedit_face_visible_test uses the space ima
+ * to check if the face is displayed in UV-localview */
+ sima->image = ima;
- if (ima == NULL || ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE) {
- if (sima->mode == SI_MODE_PAINT) {
- sima->mode = SI_MODE_VIEW;
- }
- }
+ if (ima == NULL || ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE) {
+ if (sima->mode == SI_MODE_PAINT) {
+ sima->mode = SI_MODE_VIEW;
+ }
+ }
- if (sima->image) {
- BKE_image_signal(bmain, sima->image, &sima->iuser, IMA_SIGNAL_USER_NEW_IMAGE);
- }
+ if (sima->image) {
+ BKE_image_signal(bmain, sima->image, &sima->iuser, IMA_SIGNAL_USER_NEW_IMAGE);
+ }
- id_us_ensure_real((ID *)sima->image);
+ id_us_ensure_real((ID *)sima->image);
- if (obedit) {
- WM_main_add_notifier(NC_GEOM | ND_DATA, obedit->data);
- }
+ if (obedit) {
+ WM_main_add_notifier(NC_GEOM | ND_DATA, obedit->data);
+ }
- WM_main_add_notifier(NC_SPACE | ND_SPACE_IMAGE, NULL);
+ WM_main_add_notifier(NC_SPACE | ND_SPACE_IMAGE, NULL);
}
void ED_space_image_auto_set(const bContext *C, SpaceImage *sima)
{
- if (sima->mode != SI_MODE_UV || sima->pin) {
- return;
- }
-
- /* Track image assigned to active face in edit mode. */
- Object *ob = CTX_data_active_object(C);
- if (!(ob && (ob->mode & OB_MODE_EDIT) && ED_space_image_show_uvedit(sima, ob))) {
- return;
- }
-
- BMEditMesh *em = BKE_editmesh_from_object(ob);
- BMesh *bm = em->bm;
- BMFace *efa = BM_mesh_active_face_get(bm, true, false);
- if (efa == NULL) {
- return;
- }
-
- Image *ima = NULL;
- ED_object_get_active_image(ob, efa->mat_nr + 1, &ima, NULL, NULL, NULL);
-
- if (ima != sima->image) {
- sima->image = ima;
-
- if (sima->image) {
- Main *bmain = CTX_data_main(C);
- BKE_image_signal(bmain, sima->image, &sima->iuser, IMA_SIGNAL_USER_NEW_IMAGE);
- }
- }
+ if (sima->mode != SI_MODE_UV || sima->pin) {
+ return;
+ }
+
+ /* Track image assigned to active face in edit mode. */
+ Object *ob = CTX_data_active_object(C);
+ if (!(ob && (ob->mode & OB_MODE_EDIT) && ED_space_image_show_uvedit(sima, ob))) {
+ return;
+ }
+
+ BMEditMesh *em = BKE_editmesh_from_object(ob);
+ BMesh *bm = em->bm;
+ BMFace *efa = BM_mesh_active_face_get(bm, true, false);
+ if (efa == NULL) {
+ return;
+ }
+
+ Image *ima = NULL;
+ ED_object_get_active_image(ob, efa->mat_nr + 1, &ima, NULL, NULL, NULL);
+
+ if (ima != sima->image) {
+ sima->image = ima;
+
+ if (sima->image) {
+ Main *bmain = CTX_data_main(C);
+ BKE_image_signal(bmain, sima->image, &sima->iuser, IMA_SIGNAL_USER_NEW_IMAGE);
+ }
+ }
}
Mask *ED_space_image_get_mask(SpaceImage *sima)
{
- return sima->mask_info.mask;
+ return sima->mask_info.mask;
}
void ED_space_image_set_mask(bContext *C, SpaceImage *sima, Mask *mask)
{
- sima->mask_info.mask = mask;
+ sima->mask_info.mask = mask;
- /* weak, but same as image/space */
- id_us_ensure_real((ID *)sima->mask_info.mask);
+ /* weak, but same as image/space */
+ id_us_ensure_real((ID *)sima->mask_info.mask);
- if (C) {
- WM_event_add_notifier(C, NC_MASK | NA_SELECTED, mask);
- }
+ if (C) {
+ WM_event_add_notifier(C, NC_MASK | NA_SELECTED, mask);
+ }
}
ImBuf *ED_space_image_acquire_buffer(SpaceImage *sima, void **r_lock)
{
- ImBuf *ibuf;
+ ImBuf *ibuf;
- if (sima && sima->image) {
+ if (sima && sima->image) {
#if 0
- if (sima->image->type == IMA_TYPE_R_RESULT && BIF_show_render_spare())
- return BIF_render_spare_imbuf();
- else
+ if (sima->image->type == IMA_TYPE_R_RESULT && BIF_show_render_spare())
+ return BIF_render_spare_imbuf();
+ else
#endif
- ibuf = BKE_image_acquire_ibuf(sima->image, &sima->iuser, r_lock);
-
- if (ibuf) {
- if (ibuf->rect || ibuf->rect_float) {
- return ibuf;
- }
- BKE_image_release_ibuf(sima->image, ibuf, *r_lock);
- *r_lock = NULL;
- }
- }
- else {
- *r_lock = NULL;
- }
-
- return NULL;
+ ibuf = BKE_image_acquire_ibuf(sima->image, &sima->iuser, r_lock);
+
+ if (ibuf) {
+ if (ibuf->rect || ibuf->rect_float) {
+ return ibuf;
+ }
+ BKE_image_release_ibuf(sima->image, ibuf, *r_lock);
+ *r_lock = NULL;
+ }
+ }
+ else {
+ *r_lock = NULL;
+ }
+
+ return NULL;
}
void ED_space_image_release_buffer(SpaceImage *sima, ImBuf *ibuf, void *lock)
{
- if (sima && sima->image) {
- BKE_image_release_ibuf(sima->image, ibuf, lock);
- }
+ if (sima && sima->image) {
+ BKE_image_release_ibuf(sima->image, ibuf, lock);
+ }
}
bool ED_space_image_has_buffer(SpaceImage *sima)
{
- ImBuf *ibuf;
- void *lock;
- bool has_buffer;
+ ImBuf *ibuf;
+ void *lock;
+ bool has_buffer;
- ibuf = ED_space_image_acquire_buffer(sima, &lock);
- has_buffer = (ibuf != NULL);
- ED_space_image_release_buffer(sima, ibuf, lock);
+ ibuf = ED_space_image_acquire_buffer(sima, &lock);
+ has_buffer = (ibuf != NULL);
+ ED_space_image_release_buffer(sima, ibuf, lock);
- return has_buffer;
+ return has_buffer;
}
void ED_space_image_get_size(SpaceImage *sima, int *width, int *height)
{
- Scene *scene = sima->iuser.scene;
- ImBuf *ibuf;
- void *lock;
-
- ibuf = ED_space_image_acquire_buffer(sima, &lock);
-
- if (ibuf && ibuf->x > 0 && ibuf->y > 0) {
- *width = ibuf->x;
- *height = ibuf->y;
- }
- else if (sima->image && sima->image->type == IMA_TYPE_R_RESULT && scene) {
- /* not very important, just nice */
- *width = (scene->r.xsch * scene->r.size) / 100;
- *height = (scene->r.ysch * scene->r.size) / 100;
-
- if ((scene->r.mode & R_BORDER) && (scene->r.mode & R_CROP)) {
- *width *= BLI_rctf_size_x(&scene->r.border);
- *height *= BLI_rctf_size_y(&scene->r.border);
- }
-
- }
- /* I know a bit weak... but preview uses not actual image size */
- // XXX else if (image_preview_active(sima, width, height));
- else {
- *width = IMG_SIZE_FALLBACK;
- *height = IMG_SIZE_FALLBACK;
- }
-
- ED_space_image_release_buffer(sima, ibuf, lock);
+ Scene *scene = sima->iuser.scene;
+ ImBuf *ibuf;
+ void *lock;
+
+ ibuf = ED_space_image_acquire_buffer(sima, &lock);
+
+ if (ibuf && ibuf->x > 0 && ibuf->y > 0) {
+ *width = ibuf->x;
+ *height = ibuf->y;
+ }
+ else if (sima->image && sima->image->type == IMA_TYPE_R_RESULT && scene) {
+ /* not very important, just nice */
+ *width = (scene->r.xsch * scene->r.size) / 100;
+ *height = (scene->r.ysch * scene->r.size) / 100;
+
+ if ((scene->r.mode & R_BORDER) && (scene->r.mode & R_CROP)) {
+ *width *= BLI_rctf_size_x(&scene->r.border);
+ *height *= BLI_rctf_size_y(&scene->r.border);
+ }
+ }
+ /* I know a bit weak... but preview uses not actual image size */
+ // XXX else if (image_preview_active(sima, width, height));
+ else {
+ *width = IMG_SIZE_FALLBACK;
+ *height = IMG_SIZE_FALLBACK;
+ }
+
+ ED_space_image_release_buffer(sima, ibuf, lock);
}
void ED_space_image_get_size_fl(SpaceImage *sima, float size[2])
{
- int size_i[2];
- ED_space_image_get_size(sima, &size_i[0], &size_i[1]);
- size[0] = size_i[0];
- size[1] = size_i[1];
+ int size_i[2];
+ ED_space_image_get_size(sima, &size_i[0], &size_i[1]);
+ size[0] = size_i[0];
+ size[1] = size_i[1];
}
-
void ED_space_image_get_aspect(SpaceImage *sima, float *aspx, float *aspy)
{
- Image *ima = sima->image;
- if ((ima == NULL) || (ima->aspx == 0.0f || ima->aspy == 0.0f)) {
- *aspx = *aspy = 1.0;
- }
- else {
- BKE_image_get_aspect(ima, aspx, aspy);
- }
+ Image *ima = sima->image;
+ if ((ima == NULL) || (ima->aspx == 0.0f || ima->aspy == 0.0f)) {
+ *aspx = *aspy = 1.0;
+ }
+ else {
+ BKE_image_get_aspect(ima, aspx, aspy);
+ }
}
void ED_space_image_get_zoom(SpaceImage *sima, ARegion *ar, float *zoomx, float *zoomy)
{
- int width, height;
+ int width, height;
- ED_space_image_get_size(sima, &width, &height);
+ ED_space_image_get_size(sima, &width, &height);
- *zoomx = (float)(BLI_rcti_size_x(&ar->winrct) + 1) / (float)(BLI_rctf_size_x(&ar->v2d.cur) * width);
- *zoomy = (float)(BLI_rcti_size_y(&ar->winrct) + 1) / (float)(BLI_rctf_size_y(&ar->v2d.cur) * height);
+ *zoomx = (float)(BLI_rcti_size_x(&ar->winrct) + 1) /
+ (float)(BLI_rctf_size_x(&ar->v2d.cur) * width);
+ *zoomy = (float)(BLI_rcti_size_y(&ar->winrct) + 1) /
+ (float)(BLI_rctf_size_y(&ar->v2d.cur) * height);
}
void ED_space_image_get_uv_aspect(SpaceImage *sima, float *aspx, float *aspy)
{
- int w, h;
-
- ED_space_image_get_aspect(sima, aspx, aspy);
- ED_space_image_get_size(sima, &w, &h);
-
- *aspx *= (float)w;
- *aspy *= (float)h;
-
- if (*aspx < *aspy) {
- *aspy = *aspy / *aspx;
- *aspx = 1.0f;
- }
- else {
- *aspx = *aspx / *aspy;
- *aspy = 1.0f;
- }
+ int w, h;
+
+ ED_space_image_get_aspect(sima, aspx, aspy);
+ ED_space_image_get_size(sima, &w, &h);
+
+ *aspx *= (float)w;
+ *aspy *= (float)h;
+
+ if (*aspx < *aspy) {
+ *aspy = *aspy / *aspx;
+ *aspx = 1.0f;
+ }
+ else {
+ *aspx = *aspx / *aspy;
+ *aspy = 1.0f;
+ }
}
void ED_image_get_uv_aspect(Image *ima, ImageUser *iuser, float *aspx, float *aspy)
{
- if (ima) {
- int w, h;
-
- BKE_image_get_aspect(ima, aspx, aspy);
- BKE_image_get_size(ima, iuser, &w, &h);
-
- *aspx *= (float)w;
- *aspy *= (float)h;
- }
- else {
- *aspx = 1.0f;
- *aspy = 1.0f;
- }
+ if (ima) {
+ int w, h;
+
+ BKE_image_get_aspect(ima, aspx, aspy);
+ BKE_image_get_size(ima, iuser, &w, &h);
+
+ *aspx *= (float)w;
+ *aspy *= (float)h;
+ }
+ else {
+ *aspx = 1.0f;
+ *aspy = 1.0f;
+ }
}
/* takes event->mval */
void ED_image_mouse_pos(SpaceImage *sima, ARegion *ar, const int mval[2], float co[2])
{
- int sx, sy, width, height;
- float zoomx, zoomy;
+ int sx, sy, width, height;
+ float zoomx, zoomy;
- ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy);
- ED_space_image_get_size(sima, &width, &height);
+ ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy);
+ ED_space_image_get_size(sima, &width, &height);
- UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &sx, &sy);
+ UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &sx, &sy);
- co[0] = ((mval[0] - sx) / zoomx) / width;
- co[1] = ((mval[1] - sy) / zoomy) / height;
+ co[0] = ((mval[0] - sx) / zoomx) / width;
+ co[1] = ((mval[1] - sy) / zoomy) / height;
}
void ED_image_point_pos(SpaceImage *sima, ARegion *ar, float x, float y, float *xr, float *yr)
{
- int sx, sy, width, height;
- float zoomx, zoomy;
+ int sx, sy, width, height;
+ float zoomx, zoomy;
- ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy);
- ED_space_image_get_size(sima, &width, &height);
+ ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy);
+ ED_space_image_get_size(sima, &width, &height);
- UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &sx, &sy);
+ UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &sx, &sy);
- *xr = ((x - sx) / zoomx) / width;
- *yr = ((y - sy) / zoomy) / height;
+ *xr = ((x - sx) / zoomx) / width;
+ *yr = ((y - sy) / zoomy) / height;
}
void ED_image_point_pos__reverse(SpaceImage *sima, ARegion *ar, const float co[2], float r_co[2])
{
- float zoomx, zoomy;
- int width, height;
- int sx, sy;
+ float zoomx, zoomy;
+ int width, height;
+ int sx, sy;
- UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &sx, &sy);
- ED_space_image_get_size(sima, &width, &height);
- ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy);
+ UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &sx, &sy);
+ ED_space_image_get_size(sima, &width, &height);
+ ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy);
- r_co[0] = (co[0] * width * zoomx) + (float)sx;
- r_co[1] = (co[1] * height * zoomy) + (float)sy;
+ r_co[0] = (co[0] * width * zoomx) + (float)sx;
+ r_co[1] = (co[1] * height * zoomy) + (float)sy;
}
/**
@@ -332,141 +332,144 @@ void ED_image_point_pos__reverse(SpaceImage *sima, ARegion *ar, const float co[2
*/
bool ED_image_slot_cycle(struct Image *image, int direction)
{
- const int cur = image->render_slot;
- int i, slot;
-
- BLI_assert(ELEM(direction, -1, 1));
-
- int num_slots = BLI_listbase_count(&image->renderslots);
- for (i = 1; i < num_slots; i++) {
- slot = (cur + ((direction == -1) ? -i : i)) % num_slots;
- if (slot < 0) {
- slot += num_slots;
- }
-
- RenderSlot *render_slot = BKE_image_get_renderslot(image, slot);
- if ((render_slot && render_slot->render) || slot == image->last_render_slot) {
- image->render_slot = slot;
- break;
- }
- }
-
- if (i == num_slots) {
- image->render_slot = ((cur == 1) ? 0 : 1);
- }
-
- return (cur != image->render_slot);
+ const int cur = image->render_slot;
+ int i, slot;
+
+ BLI_assert(ELEM(direction, -1, 1));
+
+ int num_slots = BLI_listbase_count(&image->renderslots);
+ for (i = 1; i < num_slots; i++) {
+ slot = (cur + ((direction == -1) ? -i : i)) % num_slots;
+ if (slot < 0) {
+ slot += num_slots;
+ }
+
+ RenderSlot *render_slot = BKE_image_get_renderslot(image, slot);
+ if ((render_slot && render_slot->render) || slot == image->last_render_slot) {
+ image->render_slot = slot;
+ break;
+ }
+ }
+
+ if (i == num_slots) {
+ image->render_slot = ((cur == 1) ? 0 : 1);
+ }
+
+ return (cur != image->render_slot);
}
-void ED_space_image_scopes_update(const struct bContext *C, struct SpaceImage *sima, struct ImBuf *ibuf, bool use_view_settings)
+void ED_space_image_scopes_update(const struct bContext *C,
+ struct SpaceImage *sima,
+ struct ImBuf *ibuf,
+ bool use_view_settings)
{
- Scene *scene = CTX_data_scene(C);
- Object *ob = CTX_data_active_object(C);
-
- /* scope update can be expensive, don't update during paint modes */
- if (sima->mode == SI_MODE_PAINT) {
- return;
- }
- if (ob && ((ob->mode & (OB_MODE_TEXTURE_PAINT | OB_MODE_EDIT)) != 0)) {
- return;
- }
-
- /* We also don't update scopes of render result during render. */
- if (G.is_rendering) {
- const Image *image = sima->image;
- if (image != NULL &&
- (image->type == IMA_TYPE_R_RESULT || image->type == IMA_TYPE_COMPOSITE))
- {
- return;
- }
- }
-
- scopes_update(&sima->scopes, ibuf, use_view_settings ? &scene->view_settings : NULL, &scene->display_settings);
+ Scene *scene = CTX_data_scene(C);
+ Object *ob = CTX_data_active_object(C);
+
+ /* scope update can be expensive, don't update during paint modes */
+ if (sima->mode == SI_MODE_PAINT) {
+ return;
+ }
+ if (ob && ((ob->mode & (OB_MODE_TEXTURE_PAINT | OB_MODE_EDIT)) != 0)) {
+ return;
+ }
+
+ /* We also don't update scopes of render result during render. */
+ if (G.is_rendering) {
+ const Image *image = sima->image;
+ if (image != NULL && (image->type == IMA_TYPE_R_RESULT || image->type == IMA_TYPE_COMPOSITE)) {
+ return;
+ }
+ }
+
+ scopes_update(&sima->scopes,
+ ibuf,
+ use_view_settings ? &scene->view_settings : NULL,
+ &scene->display_settings);
}
bool ED_space_image_show_render(SpaceImage *sima)
{
- return (sima->image && ELEM(sima->image->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE));
+ return (sima->image && ELEM(sima->image->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE));
}
bool ED_space_image_show_paint(SpaceImage *sima)
{
- if (ED_space_image_show_render(sima)) {
- return false;
- }
+ if (ED_space_image_show_render(sima)) {
+ return false;
+ }
- return (sima->mode == SI_MODE_PAINT);
+ return (sima->mode == SI_MODE_PAINT);
}
bool ED_space_image_show_uvedit(SpaceImage *sima, Object *obedit)
{
- if (sima) {
- if (ED_space_image_show_render(sima)) {
- return false;
- }
- if (sima->mode != SI_MODE_UV) {
- return false;
- }
- }
+ if (sima) {
+ if (ED_space_image_show_render(sima)) {
+ return false;
+ }
+ if (sima->mode != SI_MODE_UV) {
+ return false;
+ }
+ }
- if (obedit && obedit->type == OB_MESH) {
- struct BMEditMesh *em = BKE_editmesh_from_object(obedit);
- bool ret;
+ if (obedit && obedit->type == OB_MESH) {
+ struct BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ bool ret;
- ret = EDBM_uv_check(em);
+ ret = EDBM_uv_check(em);
- return ret;
- }
+ return ret;
+ }
- return false;
+ return false;
}
/* matches clip function */
bool ED_space_image_check_show_maskedit(SpaceImage *sima, ViewLayer *view_layer)
{
- /* check editmode - this is reserved for UV editing */
- Object *ob = OBACT(view_layer);
- if (ob && ob->mode & OB_MODE_EDIT && ED_space_image_show_uvedit(sima, ob)) {
- return false;
- }
+ /* check editmode - this is reserved for UV editing */
+ Object *ob = OBACT(view_layer);
+ if (ob && ob->mode & OB_MODE_EDIT && ED_space_image_show_uvedit(sima, ob)) {
+ return false;
+ }
- return (sima->mode == SI_MODE_MASK);
+ return (sima->mode == SI_MODE_MASK);
}
bool ED_space_image_maskedit_poll(bContext *C)
{
- SpaceImage *sima = CTX_wm_space_image(C);
+ SpaceImage *sima = CTX_wm_space_image(C);
- if (sima) {
- ViewLayer *view_layer = CTX_data_view_layer(C);
- return ED_space_image_check_show_maskedit(sima, view_layer);
- }
+ if (sima) {
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ return ED_space_image_check_show_maskedit(sima, view_layer);
+ }
- return false;
+ return false;
}
bool ED_space_image_paint_curve(const bContext *C)
{
- SpaceImage *sima = CTX_wm_space_image(C);
+ SpaceImage *sima = CTX_wm_space_image(C);
- if (sima && sima->mode == SI_MODE_PAINT) {
- Brush *br = CTX_data_tool_settings(C)->imapaint.paint.brush;
+ if (sima && sima->mode == SI_MODE_PAINT) {
+ Brush *br = CTX_data_tool_settings(C)->imapaint.paint.brush;
- if (br && (br->flag & BRUSH_CURVE)) {
- return true;
- }
- }
+ if (br && (br->flag & BRUSH_CURVE)) {
+ return true;
+ }
+ }
- return false;
+ return false;
}
-
bool ED_space_image_maskedit_mask_poll(bContext *C)
{
- if (ED_space_image_maskedit_poll(C)) {
- SpaceImage *sima = CTX_wm_space_image(C);
- return sima->mask_info.mask != NULL;
- }
+ if (ED_space_image_maskedit_poll(C)) {
+ SpaceImage *sima = CTX_wm_space_image(C);
+ return sima->mask_info.mask != NULL;
+ }
- return false;
+ return false;
}
diff --git a/source/blender/editors/space_image/image_intern.h b/source/blender/editors/space_image/image_intern.h
index 55ae664decd..db56f1051c5 100644
--- a/source/blender/editors/space_image/image_intern.h
+++ b/source/blender/editors/space_image/image_intern.h
@@ -21,7 +21,6 @@
* \ingroup spimage
*/
-
#ifndef __IMAGE_INTERN_H__
#define __IMAGE_INTERN_H__
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 85c7d2d8fa9..06bacabe6fa 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -21,7 +21,6 @@
* \ingroup spimage
*/
-
#include <stddef.h>
#include <string.h>
#include <fcntl.h>
@@ -105,46 +104,49 @@
static void sima_zoom_set(SpaceImage *sima, ARegion *ar, float zoom, const float location[2])
{
- float oldzoom = sima->zoom;
- int width, height;
+ float oldzoom = sima->zoom;
+ int width, height;
- sima->zoom = zoom;
+ sima->zoom = zoom;
- if (sima->zoom < 0.1f || sima->zoom > 4.0f) {
- /* check zoom limits */
- ED_space_image_get_size(sima, &width, &height);
+ if (sima->zoom < 0.1f || sima->zoom > 4.0f) {
+ /* check zoom limits */
+ ED_space_image_get_size(sima, &width, &height);
- width *= sima->zoom;
- height *= sima->zoom;
+ width *= sima->zoom;
+ height *= sima->zoom;
- if ((width < 4) && (height < 4) && sima->zoom < oldzoom) {
- sima->zoom = oldzoom;
- }
- else if (BLI_rcti_size_x(&ar->winrct) <= sima->zoom) {
- sima->zoom = oldzoom;
- }
- else if (BLI_rcti_size_y(&ar->winrct) <= sima->zoom) {
- sima->zoom = oldzoom;
- }
- }
+ if ((width < 4) && (height < 4) && sima->zoom < oldzoom) {
+ sima->zoom = oldzoom;
+ }
+ else if (BLI_rcti_size_x(&ar->winrct) <= sima->zoom) {
+ sima->zoom = oldzoom;
+ }
+ else if (BLI_rcti_size_y(&ar->winrct) <= sima->zoom) {
+ sima->zoom = oldzoom;
+ }
+ }
- if ((U.uiflag & USER_ZOOM_TO_MOUSEPOS) && location) {
- float aspx, aspy, w, h;
+ if ((U.uiflag & USER_ZOOM_TO_MOUSEPOS) && location) {
+ float aspx, aspy, w, h;
- ED_space_image_get_size(sima, &width, &height);
- ED_space_image_get_aspect(sima, &aspx, &aspy);
+ ED_space_image_get_size(sima, &width, &height);
+ ED_space_image_get_aspect(sima, &aspx, &aspy);
- w = width * aspx;
- h = height * aspy;
+ w = width * aspx;
+ h = height * aspy;
- sima->xof += ((location[0] - 0.5f) * w - sima->xof) * (sima->zoom - oldzoom) / sima->zoom;
- sima->yof += ((location[1] - 0.5f) * h - sima->yof) * (sima->zoom - oldzoom) / sima->zoom;
- }
+ sima->xof += ((location[0] - 0.5f) * w - sima->xof) * (sima->zoom - oldzoom) / sima->zoom;
+ sima->yof += ((location[1] - 0.5f) * h - sima->yof) * (sima->zoom - oldzoom) / sima->zoom;
+ }
}
-static void sima_zoom_set_factor(SpaceImage *sima, ARegion *ar, float zoomfac, const float location[2])
+static void sima_zoom_set_factor(SpaceImage *sima,
+ ARegion *ar,
+ float zoomfac,
+ const float location[2])
{
- sima_zoom_set(sima, ar, sima->zoom * zoomfac, location);
+ sima_zoom_set(sima, ar, sima->zoom * zoomfac, location);
}
/**
@@ -152,509 +154,530 @@ static void sima_zoom_set_factor(SpaceImage *sima, ARegion *ar, float zoomfac, c
*/
static void sima_zoom_set_from_bounds(SpaceImage *sima, ARegion *ar, const rctf *bounds)
{
- int image_size[2];
- float aspx, aspy;
+ int image_size[2];
+ float aspx, aspy;
- ED_space_image_get_size(sima, &image_size[0], &image_size[1]);
- ED_space_image_get_aspect(sima, &aspx, &aspy);
+ ED_space_image_get_size(sima, &image_size[0], &image_size[1]);
+ ED_space_image_get_aspect(sima, &aspx, &aspy);
- image_size[0] = image_size[0] * aspx;
- image_size[1] = image_size[1] * aspy;
+ image_size[0] = image_size[0] * aspx;
+ image_size[1] = image_size[1] * aspy;
- /* adjust offset and zoom */
- sima->xof = roundf((BLI_rctf_cent_x(bounds) - 0.5f) * image_size[0]);
- sima->yof = roundf((BLI_rctf_cent_y(bounds) - 0.5f) * image_size[1]);
+ /* adjust offset and zoom */
+ sima->xof = roundf((BLI_rctf_cent_x(bounds) - 0.5f) * image_size[0]);
+ sima->yof = roundf((BLI_rctf_cent_y(bounds) - 0.5f) * image_size[1]);
- float size_xy[2], size;
- size_xy[0] = BLI_rcti_size_x(&ar->winrct) / (BLI_rctf_size_x(bounds) * image_size[0]);
- size_xy[1] = BLI_rcti_size_y(&ar->winrct) / (BLI_rctf_size_y(bounds) * image_size[1]);
+ float size_xy[2], size;
+ size_xy[0] = BLI_rcti_size_x(&ar->winrct) / (BLI_rctf_size_x(bounds) * image_size[0]);
+ size_xy[1] = BLI_rcti_size_y(&ar->winrct) / (BLI_rctf_size_y(bounds) * image_size[1]);
- size = min_ff(size_xy[0], size_xy[1]);
- CLAMP_MAX(size, 100.0f);
+ size = min_ff(size_xy[0], size_xy[1]);
+ CLAMP_MAX(size, 100.0f);
- sima_zoom_set(sima, ar, size, NULL);
+ sima_zoom_set(sima, ar, size, NULL);
}
-#if 0 // currently unused
+#if 0 // currently unused
static bool image_poll(bContext *C)
{
- return (CTX_data_edit_image(C) != NULL);
+ return (CTX_data_edit_image(C) != NULL);
}
#endif
static bool space_image_buffer_exists_poll(bContext *C)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- if (sima && ED_space_image_has_buffer(sima)) {
- return true;
- }
- return false;
+ SpaceImage *sima = CTX_wm_space_image(C);
+ if (sima && ED_space_image_has_buffer(sima)) {
+ return true;
+ }
+ return false;
}
static bool image_not_packed_poll(bContext *C)
{
- SpaceImage *sima = CTX_wm_space_image(C);
+ SpaceImage *sima = CTX_wm_space_image(C);
- /* Do not run 'replace' on packed images, it does not give user expected results at all. */
- if (sima && sima->image && BLI_listbase_is_empty(&sima->image->packedfiles)) {
- return true;
- }
- return false;
+ /* Do not run 'replace' on packed images, it does not give user expected results at all. */
+ if (sima && sima->image && BLI_listbase_is_empty(&sima->image->packedfiles)) {
+ return true;
+ }
+ return false;
}
static bool imbuf_format_writeable(const ImBuf *ibuf)
{
- ImageFormatData im_format;
- ImbFormatOptions options_dummy;
- BKE_imbuf_to_image_format(&im_format, ibuf);
- return (BKE_image_imtype_to_ftype(im_format.imtype, &options_dummy) == ibuf->ftype);
+ ImageFormatData im_format;
+ ImbFormatOptions options_dummy;
+ BKE_imbuf_to_image_format(&im_format, ibuf);
+ return (BKE_image_imtype_to_ftype(im_format.imtype, &options_dummy) == ibuf->ftype);
}
static bool space_image_file_exists_poll(bContext *C)
{
- if (space_image_buffer_exists_poll(C)) {
- Main *bmain = CTX_data_main(C);
- SpaceImage *sima = CTX_wm_space_image(C);
- ImBuf *ibuf;
- void *lock;
- bool ret = false;
- char name[FILE_MAX];
-
- ibuf = ED_space_image_acquire_buffer(sima, &lock);
- if (ibuf) {
- BLI_strncpy(name, ibuf->name, FILE_MAX);
- BLI_path_abs(name, BKE_main_blendfile_path(bmain));
-
- if (BLI_exists(name) == false) {
- CTX_wm_operator_poll_msg_set(C, "image file not found");
- }
- else if (!BLI_file_is_writable(name)) {
- CTX_wm_operator_poll_msg_set(C, "image path can't be written to");
- }
- else if (!imbuf_format_writeable(ibuf)) {
- CTX_wm_operator_poll_msg_set(C, "image format is read-only");
- }
- else {
- ret = true;
- }
- }
- ED_space_image_release_buffer(sima, ibuf, lock);
-
- return ret;
- }
- return false;
-}
-
-#if 0 /* UNUSED */
+ if (space_image_buffer_exists_poll(C)) {
+ Main *bmain = CTX_data_main(C);
+ SpaceImage *sima = CTX_wm_space_image(C);
+ ImBuf *ibuf;
+ void *lock;
+ bool ret = false;
+ char name[FILE_MAX];
+
+ ibuf = ED_space_image_acquire_buffer(sima, &lock);
+ if (ibuf) {
+ BLI_strncpy(name, ibuf->name, FILE_MAX);
+ BLI_path_abs(name, BKE_main_blendfile_path(bmain));
+
+ if (BLI_exists(name) == false) {
+ CTX_wm_operator_poll_msg_set(C, "image file not found");
+ }
+ else if (!BLI_file_is_writable(name)) {
+ CTX_wm_operator_poll_msg_set(C, "image path can't be written to");
+ }
+ else if (!imbuf_format_writeable(ibuf)) {
+ CTX_wm_operator_poll_msg_set(C, "image format is read-only");
+ }
+ else {
+ ret = true;
+ }
+ }
+ ED_space_image_release_buffer(sima, ibuf, lock);
+
+ return ret;
+ }
+ return false;
+}
+
+#if 0 /* UNUSED */
static bool space_image_poll(bContext *C)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- if (sima && sima->image) {
- return true;
- }
- return false;
+ SpaceImage *sima = CTX_wm_space_image(C);
+ if (sima && sima->image) {
+ return true;
+ }
+ return false;
}
#endif
bool space_image_main_region_poll(bContext *C)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- /* XXX ARegion *ar = CTX_wm_region(C); */
+ SpaceImage *sima = CTX_wm_space_image(C);
+ /* XXX ARegion *ar = CTX_wm_region(C); */
- if (sima) {
- return true; /* XXX (ar && ar->type->regionid == RGN_TYPE_WINDOW); */
- }
- return false;
+ if (sima) {
+ return true; /* XXX (ar && ar->type->regionid == RGN_TYPE_WINDOW); */
+ }
+ return false;
}
/* For IMAGE_OT_curves_point_set to avoid sampling when in uv smooth mode or editmode */
static bool space_image_main_area_not_uv_brush_poll(bContext *C)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- Scene *scene = CTX_data_scene(C);
- ToolSettings *toolsettings = scene->toolsettings;
+ SpaceImage *sima = CTX_wm_space_image(C);
+ Scene *scene = CTX_data_scene(C);
+ ToolSettings *toolsettings = scene->toolsettings;
- if (sima && !toolsettings->uvsculpt && (CTX_data_edit_object(C) == NULL)) {
- return 1;
- }
+ if (sima && !toolsettings->uvsculpt && (CTX_data_edit_object(C) == NULL)) {
+ return 1;
+ }
- return 0;
+ return 0;
}
static bool image_sample_poll(bContext *C)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- if (sima) {
- Object *obedit = CTX_data_edit_object(C);
- if (obedit) {
- /* Disable when UV editing so it doesn't swallow all click events (use for setting cursor). */
- if (ED_space_image_show_uvedit(sima, obedit)) {
- return false;
- }
- }
- else if (sima->mode != SI_MODE_VIEW) {
- return false;
- }
-
- return space_image_main_region_poll(C);
- }
- else {
- return false;
- }
+ SpaceImage *sima = CTX_wm_space_image(C);
+ if (sima) {
+ Object *obedit = CTX_data_edit_object(C);
+ if (obedit) {
+ /* Disable when UV editing so it doesn't swallow all click events (use for setting cursor). */
+ if (ED_space_image_show_uvedit(sima, obedit)) {
+ return false;
+ }
+ }
+ else if (sima->mode != SI_MODE_VIEW) {
+ return false;
+ }
+
+ return space_image_main_region_poll(C);
+ }
+ else {
+ return false;
+ }
}
/********************** view pan operator *********************/
typedef struct ViewPanData {
- float x, y;
- float xof, yof;
- int event_type;
+ float x, y;
+ float xof, yof;
+ int event_type;
} ViewPanData;
static void image_view_pan_init(bContext *C, wmOperator *op, const wmEvent *event)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- ViewPanData *vpd;
+ SpaceImage *sima = CTX_wm_space_image(C);
+ ViewPanData *vpd;
- op->customdata = vpd = MEM_callocN(sizeof(ViewPanData), "ImageViewPanData");
- WM_cursor_modal_set(CTX_wm_window(C), BC_NSEW_SCROLLCURSOR);
+ op->customdata = vpd = MEM_callocN(sizeof(ViewPanData), "ImageViewPanData");
+ WM_cursor_modal_set(CTX_wm_window(C), BC_NSEW_SCROLLCURSOR);
- vpd->x = event->x;
- vpd->y = event->y;
- vpd->xof = sima->xof;
- vpd->yof = sima->yof;
- vpd->event_type = event->type;
+ vpd->x = event->x;
+ vpd->y = event->y;
+ vpd->xof = sima->xof;
+ vpd->yof = sima->yof;
+ vpd->event_type = event->type;
- WM_event_add_modal_handler(C, op);
+ WM_event_add_modal_handler(C, op);
}
static void image_view_pan_exit(bContext *C, wmOperator *op, bool cancel)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- ViewPanData *vpd = op->customdata;
+ SpaceImage *sima = CTX_wm_space_image(C);
+ ViewPanData *vpd = op->customdata;
- if (cancel) {
- sima->xof = vpd->xof;
- sima->yof = vpd->yof;
- ED_region_tag_redraw(CTX_wm_region(C));
- }
+ if (cancel) {
+ sima->xof = vpd->xof;
+ sima->yof = vpd->yof;
+ ED_region_tag_redraw(CTX_wm_region(C));
+ }
- WM_cursor_modal_restore(CTX_wm_window(C));
- MEM_freeN(op->customdata);
+ WM_cursor_modal_restore(CTX_wm_window(C));
+ MEM_freeN(op->customdata);
}
static int image_view_pan_exec(bContext *C, wmOperator *op)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- float offset[2];
+ SpaceImage *sima = CTX_wm_space_image(C);
+ float offset[2];
- RNA_float_get_array(op->ptr, "offset", offset);
- sima->xof += offset[0];
- sima->yof += offset[1];
+ RNA_float_get_array(op->ptr, "offset", offset);
+ sima->xof += offset[0];
+ sima->yof += offset[1];
- ED_region_tag_redraw(CTX_wm_region(C));
+ ED_region_tag_redraw(CTX_wm_region(C));
- /* XXX notifier? */
+ /* XXX notifier? */
#if 0
- if (image_preview_active(curarea, NULL, NULL)) {
- /* recalculates new preview rect */
- scrarea_do_windraw(curarea);
- image_preview_event(2);
- }
+ if (image_preview_active(curarea, NULL, NULL)) {
+ /* recalculates new preview rect */
+ scrarea_do_windraw(curarea);
+ image_preview_event(2);
+ }
#endif
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
static int image_view_pan_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- if (event->type == MOUSEPAN) {
- SpaceImage *sima = CTX_wm_space_image(C);
- float offset[2];
+ if (event->type == MOUSEPAN) {
+ SpaceImage *sima = CTX_wm_space_image(C);
+ float offset[2];
- offset[0] = (event->prevx - event->x) / sima->zoom;
- offset[1] = (event->prevy - event->y) / sima->zoom;
- RNA_float_set_array(op->ptr, "offset", offset);
+ offset[0] = (event->prevx - event->x) / sima->zoom;
+ offset[1] = (event->prevy - event->y) / sima->zoom;
+ RNA_float_set_array(op->ptr, "offset", offset);
- image_view_pan_exec(C, op);
- return OPERATOR_FINISHED;
- }
- else {
- image_view_pan_init(C, op, event);
- return OPERATOR_RUNNING_MODAL;
- }
+ image_view_pan_exec(C, op);
+ return OPERATOR_FINISHED;
+ }
+ else {
+ image_view_pan_init(C, op, event);
+ return OPERATOR_RUNNING_MODAL;
+ }
}
static int image_view_pan_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- ViewPanData *vpd = op->customdata;
- float offset[2];
-
- switch (event->type) {
- case MOUSEMOVE:
- sima->xof = vpd->xof;
- sima->yof = vpd->yof;
- offset[0] = (vpd->x - event->x) / sima->zoom;
- offset[1] = (vpd->y - event->y) / sima->zoom;
- RNA_float_set_array(op->ptr, "offset", offset);
- image_view_pan_exec(C, op);
- break;
- default:
- if (event->type == vpd->event_type && event->val == KM_RELEASE) {
- image_view_pan_exit(C, op, false);
- return OPERATOR_FINISHED;
- }
- break;
- }
-
- return OPERATOR_RUNNING_MODAL;
+ SpaceImage *sima = CTX_wm_space_image(C);
+ ViewPanData *vpd = op->customdata;
+ float offset[2];
+
+ switch (event->type) {
+ case MOUSEMOVE:
+ sima->xof = vpd->xof;
+ sima->yof = vpd->yof;
+ offset[0] = (vpd->x - event->x) / sima->zoom;
+ offset[1] = (vpd->y - event->y) / sima->zoom;
+ RNA_float_set_array(op->ptr, "offset", offset);
+ image_view_pan_exec(C, op);
+ break;
+ default:
+ if (event->type == vpd->event_type && event->val == KM_RELEASE) {
+ image_view_pan_exit(C, op, false);
+ return OPERATOR_FINISHED;
+ }
+ break;
+ }
+
+ return OPERATOR_RUNNING_MODAL;
}
static void image_view_pan_cancel(bContext *C, wmOperator *op)
{
- image_view_pan_exit(C, op, true);
+ image_view_pan_exit(C, op, true);
}
void IMAGE_OT_view_pan(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Pan View";
- ot->idname = "IMAGE_OT_view_pan";
- ot->description = "Pan the view";
-
- /* api callbacks */
- ot->exec = image_view_pan_exec;
- ot->invoke = image_view_pan_invoke;
- ot->modal = image_view_pan_modal;
- ot->cancel = image_view_pan_cancel;
- ot->poll = space_image_main_region_poll;
-
- /* flags */
- ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR | OPTYPE_LOCK_BYPASS;
-
- /* properties */
- RNA_def_float_vector(ot->srna, "offset", 2, NULL, -FLT_MAX, FLT_MAX,
- "Offset", "Offset in floating point units, 1.0 is the width and height of the image", -FLT_MAX, FLT_MAX);
+ /* identifiers */
+ ot->name = "Pan View";
+ ot->idname = "IMAGE_OT_view_pan";
+ ot->description = "Pan the view";
+
+ /* api callbacks */
+ ot->exec = image_view_pan_exec;
+ ot->invoke = image_view_pan_invoke;
+ ot->modal = image_view_pan_modal;
+ ot->cancel = image_view_pan_cancel;
+ ot->poll = space_image_main_region_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR | OPTYPE_LOCK_BYPASS;
+
+ /* properties */
+ RNA_def_float_vector(ot->srna,
+ "offset",
+ 2,
+ NULL,
+ -FLT_MAX,
+ FLT_MAX,
+ "Offset",
+ "Offset in floating point units, 1.0 is the width and height of the image",
+ -FLT_MAX,
+ FLT_MAX);
}
/********************** view zoom operator *********************/
typedef struct ViewZoomData {
- float origx, origy;
- float zoom;
- int event_type;
- float location[2];
-
- /* needed for continuous zoom */
- wmTimer *timer;
- double timer_lastdraw;
-
- /* */
- SpaceImage *sima;
- ARegion *ar;
+ float origx, origy;
+ float zoom;
+ int event_type;
+ float location[2];
+
+ /* needed for continuous zoom */
+ wmTimer *timer;
+ double timer_lastdraw;
+
+ /* */
+ SpaceImage *sima;
+ ARegion *ar;
} ViewZoomData;
static void image_view_zoom_init(bContext *C, wmOperator *op, const wmEvent *event)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- ARegion *ar = CTX_wm_region(C);
- ViewZoomData *vpd;
+ SpaceImage *sima = CTX_wm_space_image(C);
+ ARegion *ar = CTX_wm_region(C);
+ ViewZoomData *vpd;
- op->customdata = vpd = MEM_callocN(sizeof(ViewZoomData), "ImageViewZoomData");
- WM_cursor_modal_set(CTX_wm_window(C), BC_NSEW_SCROLLCURSOR);
+ op->customdata = vpd = MEM_callocN(sizeof(ViewZoomData), "ImageViewZoomData");
+ WM_cursor_modal_set(CTX_wm_window(C), BC_NSEW_SCROLLCURSOR);
- vpd->origx = event->x;
- vpd->origy = event->y;
- vpd->zoom = sima->zoom;
- vpd->event_type = event->type;
+ vpd->origx = event->x;
+ vpd->origy = event->y;
+ vpd->zoom = sima->zoom;
+ vpd->event_type = event->type;
- UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &vpd->location[0], &vpd->location[1]);
+ UI_view2d_region_to_view(
+ &ar->v2d, event->mval[0], event->mval[1], &vpd->location[0], &vpd->location[1]);
- if (U.viewzoom == USER_ZOOM_CONT) {
- /* needs a timer to continue redrawing */
- vpd->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f);
- vpd->timer_lastdraw = PIL_check_seconds_timer();
- }
+ if (U.viewzoom == USER_ZOOM_CONT) {
+ /* needs a timer to continue redrawing */
+ vpd->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f);
+ vpd->timer_lastdraw = PIL_check_seconds_timer();
+ }
- vpd->sima = sima;
- vpd->ar = ar;
+ vpd->sima = sima;
+ vpd->ar = ar;
- WM_event_add_modal_handler(C, op);
+ WM_event_add_modal_handler(C, op);
}
static void image_view_zoom_exit(bContext *C, wmOperator *op, bool cancel)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- ViewZoomData *vpd = op->customdata;
+ SpaceImage *sima = CTX_wm_space_image(C);
+ ViewZoomData *vpd = op->customdata;
- if (cancel) {
- sima->zoom = vpd->zoom;
- ED_region_tag_redraw(CTX_wm_region(C));
- }
+ if (cancel) {
+ sima->zoom = vpd->zoom;
+ ED_region_tag_redraw(CTX_wm_region(C));
+ }
- if (vpd->timer) {
- WM_event_remove_timer(CTX_wm_manager(C), vpd->timer->win, vpd->timer);
- }
+ if (vpd->timer) {
+ WM_event_remove_timer(CTX_wm_manager(C), vpd->timer->win, vpd->timer);
+ }
- WM_cursor_modal_restore(CTX_wm_window(C));
- MEM_freeN(op->customdata);
+ WM_cursor_modal_restore(CTX_wm_window(C));
+ MEM_freeN(op->customdata);
}
static int image_view_zoom_exec(bContext *C, wmOperator *op)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- ARegion *ar = CTX_wm_region(C);
+ SpaceImage *sima = CTX_wm_space_image(C);
+ ARegion *ar = CTX_wm_region(C);
- sima_zoom_set_factor(sima, ar, RNA_float_get(op->ptr, "factor"), NULL);
+ sima_zoom_set_factor(sima, ar, RNA_float_get(op->ptr, "factor"), NULL);
- ED_region_tag_redraw(ar);
+ ED_region_tag_redraw(ar);
- /* XXX notifier? */
+ /* XXX notifier? */
#if 0
- if (image_preview_active(curarea, NULL, NULL)) {
- /* recalculates new preview rect */
- scrarea_do_windraw(curarea);
- image_preview_event(2);
- }
+ if (image_preview_active(curarea, NULL, NULL)) {
+ /* recalculates new preview rect */
+ scrarea_do_windraw(curarea);
+ image_preview_event(2);
+ }
#endif
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
enum {
- VIEW_PASS = 0,
- VIEW_APPLY,
- VIEW_CONFIRM,
+ VIEW_PASS = 0,
+ VIEW_APPLY,
+ VIEW_CONFIRM,
};
static int image_view_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- if (event->type == MOUSEZOOM || event->type == MOUSEPAN) {
- SpaceImage *sima = CTX_wm_space_image(C);
- ARegion *ar = CTX_wm_region(C);
- float delta, factor, location[2];
-
- UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &location[0], &location[1]);
-
- delta = event->prevx - event->x + event->prevy - event->y;
-
- if (U.uiflag & USER_ZOOM_INVERT) {
- delta *= -1;
- }
-
- factor = 1.0f + delta / 300.0f;
- RNA_float_set(op->ptr, "factor", factor);
- sima_zoom_set(sima, ar, sima->zoom * factor, location);
- ED_region_tag_redraw(ar);
-
- return OPERATOR_FINISHED;
- }
- else {
- image_view_zoom_init(C, op, event);
- return OPERATOR_RUNNING_MODAL;
- }
-}
-
-static void image_zoom_apply(ViewZoomData *vpd, wmOperator *op, const int x, const int y, const short viewzoom, const short zoom_invert)
-{
- float factor;
-
- if (viewzoom == USER_ZOOM_CONT) {
- double time = PIL_check_seconds_timer();
- float time_step = (float)(time - vpd->timer_lastdraw);
- float fac;
- float zfac;
-
- if (U.uiflag & USER_ZOOM_HORIZ) {
- fac = (float)(x - vpd->origx);
- }
- else {
- fac = (float)(y - vpd->origy);
- }
-
- if (zoom_invert) {
- fac = -fac;
- }
-
- /* oldstyle zoom */
- zfac = 1.0f + ((fac / 20.0f) * time_step);
- vpd->timer_lastdraw = time;
- /* this is the final zoom, but instead make it into a factor */
- //zoom = vpd->sima->zoom * zfac;
- factor = (vpd->sima->zoom * zfac) / vpd->zoom;
- }
- else {
- /* for now do the same things for scale and dolly */
- float delta = x - vpd->origx + y - vpd->origy;
-
- if (zoom_invert) {
- delta *= -1.0f;
- }
-
- factor = 1.0f + delta / 300.0f;
- }
-
- RNA_float_set(op->ptr, "factor", factor);
- sima_zoom_set(vpd->sima, vpd->ar, vpd->zoom * factor, vpd->location);
- ED_region_tag_redraw(vpd->ar);
+ if (event->type == MOUSEZOOM || event->type == MOUSEPAN) {
+ SpaceImage *sima = CTX_wm_space_image(C);
+ ARegion *ar = CTX_wm_region(C);
+ float delta, factor, location[2];
+
+ UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &location[0], &location[1]);
+
+ delta = event->prevx - event->x + event->prevy - event->y;
+
+ if (U.uiflag & USER_ZOOM_INVERT) {
+ delta *= -1;
+ }
+
+ factor = 1.0f + delta / 300.0f;
+ RNA_float_set(op->ptr, "factor", factor);
+ sima_zoom_set(sima, ar, sima->zoom * factor, location);
+ ED_region_tag_redraw(ar);
+
+ return OPERATOR_FINISHED;
+ }
+ else {
+ image_view_zoom_init(C, op, event);
+ return OPERATOR_RUNNING_MODAL;
+ }
+}
+
+static void image_zoom_apply(ViewZoomData *vpd,
+ wmOperator *op,
+ const int x,
+ const int y,
+ const short viewzoom,
+ const short zoom_invert)
+{
+ float factor;
+
+ if (viewzoom == USER_ZOOM_CONT) {
+ double time = PIL_check_seconds_timer();
+ float time_step = (float)(time - vpd->timer_lastdraw);
+ float fac;
+ float zfac;
+
+ if (U.uiflag & USER_ZOOM_HORIZ) {
+ fac = (float)(x - vpd->origx);
+ }
+ else {
+ fac = (float)(y - vpd->origy);
+ }
+
+ if (zoom_invert) {
+ fac = -fac;
+ }
+
+ /* oldstyle zoom */
+ zfac = 1.0f + ((fac / 20.0f) * time_step);
+ vpd->timer_lastdraw = time;
+ /* this is the final zoom, but instead make it into a factor */
+ //zoom = vpd->sima->zoom * zfac;
+ factor = (vpd->sima->zoom * zfac) / vpd->zoom;
+ }
+ else {
+ /* for now do the same things for scale and dolly */
+ float delta = x - vpd->origx + y - vpd->origy;
+
+ if (zoom_invert) {
+ delta *= -1.0f;
+ }
+
+ factor = 1.0f + delta / 300.0f;
+ }
+
+ RNA_float_set(op->ptr, "factor", factor);
+ sima_zoom_set(vpd->sima, vpd->ar, vpd->zoom * factor, vpd->location);
+ ED_region_tag_redraw(vpd->ar);
}
static int image_view_zoom_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
- ViewZoomData *vpd = op->customdata;
- short event_code = VIEW_PASS;
+ ViewZoomData *vpd = op->customdata;
+ short event_code = VIEW_PASS;
- /* execute the events */
- if (event->type == TIMER && event->customdata == vpd->timer) {
- /* continuous zoom */
- event_code = VIEW_APPLY;
- }
- else if (event->type == MOUSEMOVE) {
- event_code = VIEW_APPLY;
- }
- else if (event->type == vpd->event_type && event->val == KM_RELEASE) {
- event_code = VIEW_CONFIRM;
- }
+ /* execute the events */
+ if (event->type == TIMER && event->customdata == vpd->timer) {
+ /* continuous zoom */
+ event_code = VIEW_APPLY;
+ }
+ else if (event->type == MOUSEMOVE) {
+ event_code = VIEW_APPLY;
+ }
+ else if (event->type == vpd->event_type && event->val == KM_RELEASE) {
+ event_code = VIEW_CONFIRM;
+ }
- if (event_code == VIEW_APPLY) {
- image_zoom_apply(vpd, op, event->x, event->y, U.viewzoom, (U.uiflag & USER_ZOOM_INVERT) != 0);
- }
- else if (event_code == VIEW_CONFIRM) {
- image_view_zoom_exit(C, op, false);
- return OPERATOR_FINISHED;
- }
+ if (event_code == VIEW_APPLY) {
+ image_zoom_apply(vpd, op, event->x, event->y, U.viewzoom, (U.uiflag & USER_ZOOM_INVERT) != 0);
+ }
+ else if (event_code == VIEW_CONFIRM) {
+ image_view_zoom_exit(C, op, false);
+ return OPERATOR_FINISHED;
+ }
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
static void image_view_zoom_cancel(bContext *C, wmOperator *op)
{
- image_view_zoom_exit(C, op, true);
+ image_view_zoom_exit(C, op, true);
}
void IMAGE_OT_view_zoom(wmOperatorType *ot)
{
- PropertyRNA *prop;
+ PropertyRNA *prop;
- /* identifiers */
- ot->name = "Zoom View";
- ot->idname = "IMAGE_OT_view_zoom";
- ot->description = "Zoom in/out the image";
+ /* identifiers */
+ ot->name = "Zoom View";
+ ot->idname = "IMAGE_OT_view_zoom";
+ ot->description = "Zoom in/out the image";
- /* api callbacks */
- ot->exec = image_view_zoom_exec;
- ot->invoke = image_view_zoom_invoke;
- ot->modal = image_view_zoom_modal;
- ot->cancel = image_view_zoom_cancel;
- ot->poll = space_image_main_region_poll;
+ /* api callbacks */
+ ot->exec = image_view_zoom_exec;
+ ot->invoke = image_view_zoom_invoke;
+ ot->modal = image_view_zoom_modal;
+ ot->cancel = image_view_zoom_cancel;
+ ot->poll = space_image_main_region_poll;
- /* flags */
- ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR | OPTYPE_LOCK_BYPASS;
+ /* flags */
+ ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR | OPTYPE_LOCK_BYPASS;
- /* properties */
- prop = RNA_def_float(ot->srna, "factor", 0.0f, -FLT_MAX, FLT_MAX, "Factor",
- "Zoom factor, values higher than 1.0 zoom in, lower values zoom out", -FLT_MAX, FLT_MAX);
- RNA_def_property_flag(prop, PROP_HIDDEN);
+ /* properties */
+ prop = RNA_def_float(ot->srna,
+ "factor",
+ 0.0f,
+ -FLT_MAX,
+ FLT_MAX,
+ "Factor",
+ "Zoom factor, values higher than 1.0 zoom in, lower values zoom out",
+ -FLT_MAX,
+ FLT_MAX);
+ RNA_def_property_flag(prop, PROP_HIDDEN);
}
#ifdef WITH_INPUT_NDOF
@@ -668,45 +691,45 @@ void IMAGE_OT_view_zoom(wmOperatorType *ot)
static int image_view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
{
- if (event->type != NDOF_MOTION) {
- return OPERATOR_CANCELLED;
- }
- else {
- SpaceImage *sima = CTX_wm_space_image(C);
- ARegion *ar = CTX_wm_region(C);
- float pan_vec[3];
+ if (event->type != NDOF_MOTION) {
+ return OPERATOR_CANCELLED;
+ }
+ else {
+ SpaceImage *sima = CTX_wm_space_image(C);
+ ARegion *ar = CTX_wm_region(C);
+ float pan_vec[3];
- const wmNDOFMotionData *ndof = event->customdata;
- const float speed = NDOF_PIXELS_PER_SECOND;
+ const wmNDOFMotionData *ndof = event->customdata;
+ const float speed = NDOF_PIXELS_PER_SECOND;
- WM_event_ndof_pan_get(ndof, pan_vec, true);
+ WM_event_ndof_pan_get(ndof, pan_vec, true);
- mul_v2_fl(pan_vec, (speed * ndof->dt) / sima->zoom);
- pan_vec[2] *= -ndof->dt;
+ mul_v2_fl(pan_vec, (speed * ndof->dt) / sima->zoom);
+ pan_vec[2] *= -ndof->dt;
- sima_zoom_set_factor(sima, ar, 1.0f + pan_vec[2], NULL);
- sima->xof += pan_vec[0];
- sima->yof += pan_vec[1];
+ sima_zoom_set_factor(sima, ar, 1.0f + pan_vec[2], NULL);
+ sima->xof += pan_vec[0];
+ sima->yof += pan_vec[1];
- ED_region_tag_redraw(ar);
+ ED_region_tag_redraw(ar);
- return OPERATOR_FINISHED;
- }
+ return OPERATOR_FINISHED;
+ }
}
void IMAGE_OT_view_ndof(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "NDOF Pan/Zoom";
- ot->idname = "IMAGE_OT_view_ndof";
- ot->description = "Use a 3D mouse device to pan/zoom the view";
+ /* identifiers */
+ ot->name = "NDOF Pan/Zoom";
+ ot->idname = "IMAGE_OT_view_ndof";
+ ot->description = "Use a 3D mouse device to pan/zoom the view";
- /* api callbacks */
- ot->invoke = image_view_ndof_invoke;
- ot->poll = space_image_main_region_poll;
+ /* api callbacks */
+ ot->invoke = image_view_ndof_invoke;
+ ot->poll = space_image_main_region_poll;
- /* flags */
- ot->flag = OPTYPE_LOCK_BYPASS;
+ /* flags */
+ ot->flag = OPTYPE_LOCK_BYPASS;
}
#endif /* WITH_INPUT_NDOF */
@@ -718,380 +741,405 @@ void IMAGE_OT_view_ndof(wmOperatorType *ot)
static int image_view_all_exec(bContext *C, wmOperator *op)
{
- SpaceImage *sima;
- ARegion *ar;
- float aspx, aspy, zoomx, zoomy, w, h;
- int width, height;
- const bool fit_view = RNA_boolean_get(op->ptr, "fit_view");
+ SpaceImage *sima;
+ ARegion *ar;
+ float aspx, aspy, zoomx, zoomy, w, h;
+ int width, height;
+ const bool fit_view = RNA_boolean_get(op->ptr, "fit_view");
- /* retrieve state */
- sima = CTX_wm_space_image(C);
- ar = CTX_wm_region(C);
+ /* retrieve state */
+ sima = CTX_wm_space_image(C);
+ ar = CTX_wm_region(C);
- ED_space_image_get_size(sima, &width, &height);
- ED_space_image_get_aspect(sima, &aspx, &aspy);
+ ED_space_image_get_size(sima, &width, &height);
+ ED_space_image_get_aspect(sima, &aspx, &aspy);
- w = width * aspx;
- h = height * aspy;
+ w = width * aspx;
+ h = height * aspy;
- /* check if the image will fit in the image with (zoom == 1) */
- width = BLI_rcti_size_x(&ar->winrct) + 1;
- height = BLI_rcti_size_y(&ar->winrct) + 1;
+ /* check if the image will fit in the image with (zoom == 1) */
+ width = BLI_rcti_size_x(&ar->winrct) + 1;
+ height = BLI_rcti_size_y(&ar->winrct) + 1;
- if (fit_view) {
- const int margin = 5; /* margin from border */
+ if (fit_view) {
+ const int margin = 5; /* margin from border */
- zoomx = (float) width / (w + 2 * margin);
- zoomy = (float) height / (h + 2 * margin);
+ zoomx = (float)width / (w + 2 * margin);
+ zoomy = (float)height / (h + 2 * margin);
- sima_zoom_set(sima, ar, min_ff(zoomx, zoomy), NULL);
- }
- else {
- if ((w >= width || h >= height) && (width > 0 && height > 0)) {
- zoomx = (float) width / w;
- zoomy = (float) height / h;
+ sima_zoom_set(sima, ar, min_ff(zoomx, zoomy), NULL);
+ }
+ else {
+ if ((w >= width || h >= height) && (width > 0 && height > 0)) {
+ zoomx = (float)width / w;
+ zoomy = (float)height / h;
- /* find the zoom value that will fit the image in the image space */
- sima_zoom_set(sima, ar, 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)), NULL);
- }
- else {
- sima_zoom_set(sima, ar, 1.0f, NULL);
- }
- }
+ /* find the zoom value that will fit the image in the image space */
+ sima_zoom_set(sima, ar, 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)), NULL);
+ }
+ else {
+ sima_zoom_set(sima, ar, 1.0f, NULL);
+ }
+ }
- sima->xof = sima->yof = 0.0f;
+ sima->xof = sima->yof = 0.0f;
- ED_region_tag_redraw(ar);
+ ED_region_tag_redraw(ar);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void IMAGE_OT_view_all(wmOperatorType *ot)
{
- PropertyRNA *prop;
+ PropertyRNA *prop;
- /* identifiers */
- ot->name = "View All";
- ot->idname = "IMAGE_OT_view_all";
- ot->description = "View the entire image";
+ /* identifiers */
+ ot->name = "View All";
+ ot->idname = "IMAGE_OT_view_all";
+ ot->description = "View the entire image";
- /* api callbacks */
- ot->exec = image_view_all_exec;
- ot->poll = space_image_main_region_poll;
+ /* api callbacks */
+ ot->exec = image_view_all_exec;
+ ot->poll = space_image_main_region_poll;
- /* flags */
- ot->flag = OPTYPE_LOCK_BYPASS;
+ /* flags */
+ ot->flag = OPTYPE_LOCK_BYPASS;
- /* properties */
- prop = RNA_def_boolean(ot->srna, "fit_view", 0, "Fit View", "Fit frame to the viewport");
- RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ /* properties */
+ prop = RNA_def_boolean(ot->srna, "fit_view", 0, "Fit View", "Fit frame to the viewport");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
/********************** view selected operator *********************/
static int image_view_selected_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceImage *sima;
- ARegion *ar;
- Scene *scene;
- ViewLayer *view_layer;
- Object *obedit;
- Image *ima;
-
- /* retrieve state */
- sima = CTX_wm_space_image(C);
- ar = CTX_wm_region(C);
- scene = CTX_data_scene(C);
- view_layer = CTX_data_view_layer(C);
- obedit = CTX_data_edit_object(C);
-
- ima = ED_space_image(sima);
-
- /* get bounds */
- float min[2], max[2];
- if (ED_space_image_show_uvedit(sima, obedit)) {
- if (!ED_uvedit_minmax(scene, ima, obedit, min, max)) {
- return OPERATOR_CANCELLED;
- }
- }
- else if (ED_space_image_check_show_maskedit(sima, view_layer)) {
- if (!ED_mask_selected_minmax(C, min, max)) {
- return OPERATOR_CANCELLED;
- }
- }
- rctf bounds = {
- .xmin = min[0], .ymin = min[1],
- .xmax = max[0], .ymax = max[1],
- };
-
- /* add some margin */
- BLI_rctf_scale(&bounds, 1.4f);
-
- sima_zoom_set_from_bounds(sima, ar, &bounds);
-
- ED_region_tag_redraw(ar);
-
- return OPERATOR_FINISHED;
+ SpaceImage *sima;
+ ARegion *ar;
+ Scene *scene;
+ ViewLayer *view_layer;
+ Object *obedit;
+ Image *ima;
+
+ /* retrieve state */
+ sima = CTX_wm_space_image(C);
+ ar = CTX_wm_region(C);
+ scene = CTX_data_scene(C);
+ view_layer = CTX_data_view_layer(C);
+ obedit = CTX_data_edit_object(C);
+
+ ima = ED_space_image(sima);
+
+ /* get bounds */
+ float min[2], max[2];
+ if (ED_space_image_show_uvedit(sima, obedit)) {
+ if (!ED_uvedit_minmax(scene, ima, obedit, min, max)) {
+ return OPERATOR_CANCELLED;
+ }
+ }
+ else if (ED_space_image_check_show_maskedit(sima, view_layer)) {
+ if (!ED_mask_selected_minmax(C, min, max)) {
+ return OPERATOR_CANCELLED;
+ }
+ }
+ rctf bounds = {
+ .xmin = min[0],
+ .ymin = min[1],
+ .xmax = max[0],
+ .ymax = max[1],
+ };
+
+ /* add some margin */
+ BLI_rctf_scale(&bounds, 1.4f);
+
+ sima_zoom_set_from_bounds(sima, ar, &bounds);
+
+ ED_region_tag_redraw(ar);
+
+ return OPERATOR_FINISHED;
}
static bool image_view_selected_poll(bContext *C)
{
- return (space_image_main_region_poll(C) && (ED_operator_uvedit(C) || ED_operator_mask(C)));
+ return (space_image_main_region_poll(C) && (ED_operator_uvedit(C) || ED_operator_mask(C)));
}
void IMAGE_OT_view_selected(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "View Center";
- ot->idname = "IMAGE_OT_view_selected";
- ot->description = "View all selected UVs";
+ /* identifiers */
+ ot->name = "View Center";
+ ot->idname = "IMAGE_OT_view_selected";
+ ot->description = "View all selected UVs";
- /* api callbacks */
- ot->exec = image_view_selected_exec;
- ot->poll = image_view_selected_poll;
+ /* api callbacks */
+ ot->exec = image_view_selected_exec;
+ ot->poll = image_view_selected_poll;
}
/********************** view zoom in/out operator *********************/
static int image_view_zoom_in_exec(bContext *C, wmOperator *op)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- ARegion *ar = CTX_wm_region(C);
- float location[2];
+ SpaceImage *sima = CTX_wm_space_image(C);
+ ARegion *ar = CTX_wm_region(C);
+ float location[2];
- RNA_float_get_array(op->ptr, "location", location);
+ RNA_float_get_array(op->ptr, "location", location);
- sima_zoom_set_factor(sima, ar, powf(2.0f, 1.0f / 3.0f), location);
+ sima_zoom_set_factor(sima, ar, powf(2.0f, 1.0f / 3.0f), location);
- ED_region_tag_redraw(ar);
+ ED_region_tag_redraw(ar);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
static int image_view_zoom_in_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- ARegion *ar = CTX_wm_region(C);
- float location[2];
+ ARegion *ar = CTX_wm_region(C);
+ float location[2];
- UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &location[0], &location[1]);
- RNA_float_set_array(op->ptr, "location", location);
+ UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &location[0], &location[1]);
+ RNA_float_set_array(op->ptr, "location", location);
- return image_view_zoom_in_exec(C, op);
+ return image_view_zoom_in_exec(C, op);
}
void IMAGE_OT_view_zoom_in(wmOperatorType *ot)
{
- PropertyRNA *prop;
+ PropertyRNA *prop;
- /* identifiers */
- ot->name = "View Zoom In";
- ot->idname = "IMAGE_OT_view_zoom_in";
- ot->description = "Zoom in the image (centered around 2D cursor)";
+ /* identifiers */
+ ot->name = "View Zoom In";
+ ot->idname = "IMAGE_OT_view_zoom_in";
+ ot->description = "Zoom in the image (centered around 2D cursor)";
- /* api callbacks */
- ot->invoke = image_view_zoom_in_invoke;
- ot->exec = image_view_zoom_in_exec;
- ot->poll = space_image_main_region_poll;
+ /* api callbacks */
+ ot->invoke = image_view_zoom_in_invoke;
+ ot->exec = image_view_zoom_in_exec;
+ ot->poll = space_image_main_region_poll;
- /* flags */
- ot->flag = OPTYPE_LOCK_BYPASS;
+ /* flags */
+ ot->flag = OPTYPE_LOCK_BYPASS;
- /* properties */
- prop = RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX,
- "Location", "Cursor location in screen coordinates", -10.0f, 10.0f);
- RNA_def_property_flag(prop, PROP_HIDDEN);
+ /* properties */
+ prop = RNA_def_float_vector(ot->srna,
+ "location",
+ 2,
+ NULL,
+ -FLT_MAX,
+ FLT_MAX,
+ "Location",
+ "Cursor location in screen coordinates",
+ -10.0f,
+ 10.0f);
+ RNA_def_property_flag(prop, PROP_HIDDEN);
}
static int image_view_zoom_out_exec(bContext *C, wmOperator *op)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- ARegion *ar = CTX_wm_region(C);
- float location[2];
+ SpaceImage *sima = CTX_wm_space_image(C);
+ ARegion *ar = CTX_wm_region(C);
+ float location[2];
- RNA_float_get_array(op->ptr, "location", location);
+ RNA_float_get_array(op->ptr, "location", location);
- sima_zoom_set_factor(sima, ar, powf(0.5f, 1.0f / 3.0f), location);
+ sima_zoom_set_factor(sima, ar, powf(0.5f, 1.0f / 3.0f), location);
- ED_region_tag_redraw(ar);
+ ED_region_tag_redraw(ar);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
static int image_view_zoom_out_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- ARegion *ar = CTX_wm_region(C);
- float location[2];
+ ARegion *ar = CTX_wm_region(C);
+ float location[2];
- UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &location[0], &location[1]);
- RNA_float_set_array(op->ptr, "location", location);
+ UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &location[0], &location[1]);
+ RNA_float_set_array(op->ptr, "location", location);
- return image_view_zoom_out_exec(C, op);
+ return image_view_zoom_out_exec(C, op);
}
void IMAGE_OT_view_zoom_out(wmOperatorType *ot)
{
- PropertyRNA *prop;
+ PropertyRNA *prop;
- /* identifiers */
- ot->name = "View Zoom Out";
- ot->idname = "IMAGE_OT_view_zoom_out";
- ot->description = "Zoom out the image (centered around 2D cursor)";
+ /* identifiers */
+ ot->name = "View Zoom Out";
+ ot->idname = "IMAGE_OT_view_zoom_out";
+ ot->description = "Zoom out the image (centered around 2D cursor)";
- /* api callbacks */
- ot->invoke = image_view_zoom_out_invoke;
- ot->exec = image_view_zoom_out_exec;
- ot->poll = space_image_main_region_poll;
+ /* api callbacks */
+ ot->invoke = image_view_zoom_out_invoke;
+ ot->exec = image_view_zoom_out_exec;
+ ot->poll = space_image_main_region_poll;
- /* flags */
- ot->flag = OPTYPE_LOCK_BYPASS;
+ /* flags */
+ ot->flag = OPTYPE_LOCK_BYPASS;
- /* properties */
- prop = RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX,
- "Location", "Cursor location in screen coordinates", -10.0f, 10.0f);
- RNA_def_property_flag(prop, PROP_HIDDEN);
+ /* properties */
+ prop = RNA_def_float_vector(ot->srna,
+ "location",
+ 2,
+ NULL,
+ -FLT_MAX,
+ FLT_MAX,
+ "Location",
+ "Cursor location in screen coordinates",
+ -10.0f,
+ 10.0f);
+ RNA_def_property_flag(prop, PROP_HIDDEN);
}
/********************** view zoom ratio operator *********************/
static int image_view_zoom_ratio_exec(bContext *C, wmOperator *op)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- ARegion *ar = CTX_wm_region(C);
+ SpaceImage *sima = CTX_wm_space_image(C);
+ ARegion *ar = CTX_wm_region(C);
- sima_zoom_set(sima, ar, RNA_float_get(op->ptr, "ratio"), NULL);
+ sima_zoom_set(sima, ar, RNA_float_get(op->ptr, "ratio"), NULL);
- /* ensure pixel exact locations for draw */
- sima->xof = (int)sima->xof;
- sima->yof = (int)sima->yof;
+ /* ensure pixel exact locations for draw */
+ sima->xof = (int)sima->xof;
+ sima->yof = (int)sima->yof;
- /* XXX notifier? */
+ /* XXX notifier? */
#if 0
- if (image_preview_active(curarea, NULL, NULL)) {
- /* recalculates new preview rect */
- scrarea_do_windraw(curarea);
- image_preview_event(2);
- }
+ if (image_preview_active(curarea, NULL, NULL)) {
+ /* recalculates new preview rect */
+ scrarea_do_windraw(curarea);
+ image_preview_event(2);
+ }
#endif
- ED_region_tag_redraw(ar);
+ ED_region_tag_redraw(ar);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void IMAGE_OT_view_zoom_ratio(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "View Zoom Ratio";
- ot->idname = "IMAGE_OT_view_zoom_ratio";
- ot->description = "Set zoom ratio of the view";
+ /* identifiers */
+ ot->name = "View Zoom Ratio";
+ ot->idname = "IMAGE_OT_view_zoom_ratio";
+ ot->description = "Set zoom ratio of the view";
- /* api callbacks */
- ot->exec = image_view_zoom_ratio_exec;
- ot->poll = space_image_main_region_poll;
+ /* api callbacks */
+ ot->exec = image_view_zoom_ratio_exec;
+ ot->poll = space_image_main_region_poll;
- /* flags */
- ot->flag = OPTYPE_LOCK_BYPASS;
+ /* flags */
+ ot->flag = OPTYPE_LOCK_BYPASS;
- /* properties */
- RNA_def_float(ot->srna, "ratio", 0.0f, -FLT_MAX, FLT_MAX,
- "Ratio", "Zoom ratio, 1.0 is 1:1, higher is zoomed in, lower is zoomed out", -FLT_MAX, FLT_MAX);
+ /* properties */
+ RNA_def_float(ot->srna,
+ "ratio",
+ 0.0f,
+ -FLT_MAX,
+ FLT_MAX,
+ "Ratio",
+ "Zoom ratio, 1.0 is 1:1, higher is zoomed in, lower is zoomed out",
+ -FLT_MAX,
+ FLT_MAX);
}
/********************** view border-zoom operator *********************/
static int image_view_zoom_border_exec(bContext *C, wmOperator *op)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- ARegion *ar = CTX_wm_region(C);
- rctf bounds;
- const bool zoom_in = !RNA_boolean_get(op->ptr, "zoom_out");
+ SpaceImage *sima = CTX_wm_space_image(C);
+ ARegion *ar = CTX_wm_region(C);
+ rctf bounds;
+ const bool zoom_in = !RNA_boolean_get(op->ptr, "zoom_out");
- WM_operator_properties_border_to_rctf(op, &bounds);
+ WM_operator_properties_border_to_rctf(op, &bounds);
- UI_view2d_region_to_view_rctf(&ar->v2d, &bounds, &bounds);
+ UI_view2d_region_to_view_rctf(&ar->v2d, &bounds, &bounds);
- const struct {
- float xof;
- float yof;
- float zoom;
- } sima_view_prev = {
- .xof = sima->xof,
- .yof = sima->yof,
- .zoom = sima->zoom,
- };
+ const struct {
+ float xof;
+ float yof;
+ float zoom;
+ } sima_view_prev = {
+ .xof = sima->xof,
+ .yof = sima->yof,
+ .zoom = sima->zoom,
+ };
- sima_zoom_set_from_bounds(sima, ar, &bounds);
+ sima_zoom_set_from_bounds(sima, ar, &bounds);
- /* zoom out */
- if (!zoom_in) {
- sima->xof = sima_view_prev.xof + (sima->xof - sima_view_prev.xof);
- sima->yof = sima_view_prev.yof + (sima->yof - sima_view_prev.yof);
- sima->zoom = sima_view_prev.zoom * (sima_view_prev.zoom / sima->zoom);
- }
+ /* zoom out */
+ if (!zoom_in) {
+ sima->xof = sima_view_prev.xof + (sima->xof - sima_view_prev.xof);
+ sima->yof = sima_view_prev.yof + (sima->yof - sima_view_prev.yof);
+ sima->zoom = sima_view_prev.zoom * (sima_view_prev.zoom / sima->zoom);
+ }
- ED_region_tag_redraw(ar);
+ ED_region_tag_redraw(ar);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void IMAGE_OT_view_zoom_border(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Zoom to Border";
- ot->description = "Zoom in the view to the nearest item contained in the border";
- ot->idname = "IMAGE_OT_view_zoom_border";
+ /* identifiers */
+ ot->name = "Zoom to Border";
+ ot->description = "Zoom in the view to the nearest item contained in the border";
+ ot->idname = "IMAGE_OT_view_zoom_border";
- /* api callbacks */
- ot->invoke = WM_gesture_box_invoke;
- ot->exec = image_view_zoom_border_exec;
- ot->modal = WM_gesture_box_modal;
- ot->cancel = WM_gesture_box_cancel;
+ /* api callbacks */
+ ot->invoke = WM_gesture_box_invoke;
+ ot->exec = image_view_zoom_border_exec;
+ ot->modal = WM_gesture_box_modal;
+ ot->cancel = WM_gesture_box_cancel;
- ot->poll = space_image_main_region_poll;
+ ot->poll = space_image_main_region_poll;
- /* rna */
- WM_operator_properties_gesture_box_zoom(ot);
+ /* rna */
+ WM_operator_properties_gesture_box_zoom(ot);
}
/**************** load/replace/save callbacks ******************/
static void image_filesel(bContext *C, wmOperator *op, const char *path)
{
- RNA_string_set(op->ptr, "filepath", path);
- WM_event_add_fileselect(C, op);
+ RNA_string_set(op->ptr, "filepath", path);
+ WM_event_add_fileselect(C, op);
}
/******************** open image operator ********************/
typedef struct ImageOpenData {
- PropertyPointerRNA pprop;
- ImageUser *iuser;
- ImageFormatData im_format;
+ PropertyPointerRNA pprop;
+ ImageUser *iuser;
+ ImageFormatData im_format;
} ImageOpenData;
typedef struct ImageFrameRange {
- struct ImageFrameRange *next, *prev;
- ListBase frames;
- /** The full path of the first file in the list of image files */
- char filepath[FILE_MAX];
+ struct ImageFrameRange *next, *prev;
+ ListBase frames;
+ /** The full path of the first file in the list of image files */
+ char filepath[FILE_MAX];
} ImageFrameRange;
typedef struct ImageFrame {
- struct ImageFrame *next, *prev;
- int framenr;
+ struct ImageFrame *next, *prev;
+ int framenr;
} ImageFrame;
static void image_open_init(bContext *C, wmOperator *op)
{
- ImageOpenData *iod;
- op->customdata = iod = MEM_callocN(sizeof(ImageOpenData), __func__);
- iod->iuser = CTX_data_pointer_get_type(C, "image_user", &RNA_ImageUser).data;
- UI_context_active_but_prop_get_templateID(C, &iod->pprop.ptr, &iod->pprop.prop);
+ ImageOpenData *iod;
+ op->customdata = iod = MEM_callocN(sizeof(ImageOpenData), __func__);
+ iod->iuser = CTX_data_pointer_get_type(C, "image_user", &RNA_ImageUser).data;
+ UI_context_active_but_prop_get_templateID(C, &iod->pprop.ptr, &iod->pprop.prop);
}
static void image_open_cancel(bContext *UNUSED(C), wmOperator *op)
{
- MEM_freeN(op->customdata);
- op->customdata = NULL;
+ MEM_freeN(op->customdata);
+ op->customdata = NULL;
}
/**
@@ -1101,58 +1149,54 @@ static void image_open_cancel(bContext *UNUSED(C), wmOperator *op)
*/
static void image_sequence_get_frame_ranges(PointerRNA *ptr, ListBase *frames_all)
{
- char dir[FILE_MAXDIR];
- const bool do_frame_range = RNA_boolean_get(ptr, "use_sequence_detection");
- ImageFrameRange *frame_range = NULL;
-
- RNA_string_get(ptr, "directory", dir);
- RNA_BEGIN (ptr, itemptr, "files")
- {
- char base_head[FILE_MAX], base_tail[FILE_MAX];
- char head[FILE_MAX], tail[FILE_MAX];
- unsigned short digits;
- char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0);
- ImageFrame *frame = MEM_callocN(sizeof(ImageFrame), "image_frame");
-
- /* use the first file in the list as base filename */
- frame->framenr = BLI_stringdec(filename, head, tail, &digits);
-
- /* still in the same sequence */
- if (do_frame_range &&
- (frame_range != NULL) &&
- (STREQLEN(base_head, head, FILE_MAX)) &&
- (STREQLEN(base_tail, tail, FILE_MAX)))
- {
- /* pass */
- }
- else {
- /* start a new frame range */
- frame_range = MEM_callocN(sizeof(*frame_range), __func__);
- BLI_join_dirfile(frame_range->filepath, sizeof(frame_range->filepath), dir, filename);
- BLI_addtail(frames_all, frame_range);
-
- BLI_strncpy(base_head, head, sizeof(base_head));
- BLI_strncpy(base_tail, tail, sizeof(base_tail));
- }
-
- BLI_addtail(&frame_range->frames, frame);
- MEM_freeN(filename);
- }
- RNA_END;
+ char dir[FILE_MAXDIR];
+ const bool do_frame_range = RNA_boolean_get(ptr, "use_sequence_detection");
+ ImageFrameRange *frame_range = NULL;
+
+ RNA_string_get(ptr, "directory", dir);
+ RNA_BEGIN (ptr, itemptr, "files") {
+ char base_head[FILE_MAX], base_tail[FILE_MAX];
+ char head[FILE_MAX], tail[FILE_MAX];
+ unsigned short digits;
+ char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0);
+ ImageFrame *frame = MEM_callocN(sizeof(ImageFrame), "image_frame");
+
+ /* use the first file in the list as base filename */
+ frame->framenr = BLI_stringdec(filename, head, tail, &digits);
+
+ /* still in the same sequence */
+ if (do_frame_range && (frame_range != NULL) && (STREQLEN(base_head, head, FILE_MAX)) &&
+ (STREQLEN(base_tail, tail, FILE_MAX))) {
+ /* pass */
+ }
+ else {
+ /* start a new frame range */
+ frame_range = MEM_callocN(sizeof(*frame_range), __func__);
+ BLI_join_dirfile(frame_range->filepath, sizeof(frame_range->filepath), dir, filename);
+ BLI_addtail(frames_all, frame_range);
+
+ BLI_strncpy(base_head, head, sizeof(base_head));
+ BLI_strncpy(base_tail, tail, sizeof(base_tail));
+ }
+
+ BLI_addtail(&frame_range->frames, frame);
+ MEM_freeN(filename);
+ }
+ RNA_END;
}
static int image_cmp_frame(const void *a, const void *b)
{
- const ImageFrame *frame_a = a;
- const ImageFrame *frame_b = b;
+ const ImageFrame *frame_a = a;
+ const ImageFrame *frame_b = b;
- if (frame_a->framenr < frame_b->framenr) {
- return -1;
- }
- if (frame_a->framenr > frame_b->framenr) {
- return 1;
- }
- return 0;
+ if (frame_a->framenr < frame_b->framenr) {
+ return -1;
+ }
+ if (frame_a->framenr > frame_b->framenr) {
+ return 1;
+ }
+ return 0;
}
/**
@@ -1164,673 +1208,724 @@ static int image_cmp_frame(const void *a, const void *b)
*/
static int image_sequence_get_len(ListBase *frames, int *ofs)
{
- ImageFrame *frame;
-
- BLI_listbase_sort(frames, image_cmp_frame);
-
- frame = frames->first;
- if (frame) {
- int frame_curr = frame->framenr;
- (*ofs) = frame_curr;
- while (frame && (frame->framenr == frame_curr)) {
- frame_curr++;
- frame = frame->next;
- }
- return frame_curr - (*ofs);
- }
- *ofs = 0;
- return 0;
-}
-
-static Image *image_open_single(
- Main *bmain, wmOperator *op, const char *filepath, const char *relbase,
- bool is_relative_path, bool use_multiview, int frame_seq_len)
-{
- bool exists = false;
- Image *ima = NULL;
-
- errno = 0;
- ima = BKE_image_load_exists_ex(bmain, filepath, &exists);
-
- if (!ima) {
- if (op->customdata) {
- MEM_freeN(op->customdata);
- }
- BKE_reportf(op->reports, RPT_ERROR, "Cannot read '%s': %s",
- filepath, errno ? strerror(errno) : TIP_("unsupported image format"));
- return NULL;
- }
-
- if (!exists) {
- /* only image path after save, never ibuf */
- if (is_relative_path) {
- BLI_path_rel(ima->name, relbase);
- }
-
- /* handle multiview images */
- if (use_multiview) {
- ImageOpenData *iod = op->customdata;
- ImageFormatData *imf = &iod->im_format;
-
- ima->flag |= IMA_USE_VIEWS;
- ima->views_format = imf->views_format;
- *ima->stereo3d_format = imf->stereo3d_format;
- }
- else {
- ima->flag &= ~IMA_USE_VIEWS;
- BKE_image_free_views(ima);
- }
-
- if ((frame_seq_len > 1) && (ima->source == IMA_SRC_FILE)) {
- ima->source = IMA_SRC_SEQUENCE;
- }
- }
-
- return ima;
+ ImageFrame *frame;
+
+ BLI_listbase_sort(frames, image_cmp_frame);
+
+ frame = frames->first;
+ if (frame) {
+ int frame_curr = frame->framenr;
+ (*ofs) = frame_curr;
+ while (frame && (frame->framenr == frame_curr)) {
+ frame_curr++;
+ frame = frame->next;
+ }
+ return frame_curr - (*ofs);
+ }
+ *ofs = 0;
+ return 0;
+}
+
+static Image *image_open_single(Main *bmain,
+ wmOperator *op,
+ const char *filepath,
+ const char *relbase,
+ bool is_relative_path,
+ bool use_multiview,
+ int frame_seq_len)
+{
+ bool exists = false;
+ Image *ima = NULL;
+
+ errno = 0;
+ ima = BKE_image_load_exists_ex(bmain, filepath, &exists);
+
+ if (!ima) {
+ if (op->customdata) {
+ MEM_freeN(op->customdata);
+ }
+ BKE_reportf(op->reports,
+ RPT_ERROR,
+ "Cannot read '%s': %s",
+ filepath,
+ errno ? strerror(errno) : TIP_("unsupported image format"));
+ return NULL;
+ }
+
+ if (!exists) {
+ /* only image path after save, never ibuf */
+ if (is_relative_path) {
+ BLI_path_rel(ima->name, relbase);
+ }
+
+ /* handle multiview images */
+ if (use_multiview) {
+ ImageOpenData *iod = op->customdata;
+ ImageFormatData *imf = &iod->im_format;
+
+ ima->flag |= IMA_USE_VIEWS;
+ ima->views_format = imf->views_format;
+ *ima->stereo3d_format = imf->stereo3d_format;
+ }
+ else {
+ ima->flag &= ~IMA_USE_VIEWS;
+ BKE_image_free_views(ima);
+ }
+
+ if ((frame_seq_len > 1) && (ima->source == IMA_SRC_FILE)) {
+ ima->source = IMA_SRC_SEQUENCE;
+ }
+ }
+
+ return ima;
}
-
static int image_open_exec(bContext *C, wmOperator *op)
{
- Main *bmain = CTX_data_main(C);
- ScrArea *sa = CTX_wm_area(C);
- Scene *scene = CTX_data_scene(C);
- Object *obedit = CTX_data_edit_object(C);
- ImageUser *iuser = NULL;
- ImageOpenData *iod = op->customdata;
- Image *ima = NULL;
- char filepath[FILE_MAX];
- int frame_seq_len = 0;
- int frame_ofs = 1;
-
- const bool is_relative_path = RNA_boolean_get(op->ptr, "relative_path");
- const bool use_multiview = RNA_boolean_get(op->ptr, "use_multiview");
-
- if (!op->customdata) {
- image_open_init(C, op);
- }
-
- RNA_string_get(op->ptr, "filepath", filepath);
-
- if (RNA_struct_property_is_set(op->ptr, "directory") &&
- RNA_struct_property_is_set(op->ptr, "files"))
- {
- bool was_relative = BLI_path_is_rel(filepath);
- ListBase frame_ranges_all;
-
- BLI_listbase_clear(&frame_ranges_all);
- image_sequence_get_frame_ranges(op->ptr, &frame_ranges_all);
- for (ImageFrameRange *frame_range = frame_ranges_all.first; frame_range; frame_range = frame_range->next) {
- int frame_range_ofs;
- int frame_range_seq_len = image_sequence_get_len(&frame_range->frames, &frame_range_ofs);
- BLI_freelistN(&frame_range->frames);
-
- char filepath_range[FILE_MAX];
- BLI_strncpy(filepath_range, frame_range->filepath, sizeof(filepath_range));
-
- if (was_relative) {
- BLI_path_rel(filepath_range, BKE_main_blendfile_path(bmain));
- }
-
- Image *ima_range = image_open_single(
- bmain, op, filepath_range, BKE_main_blendfile_path(bmain),
- is_relative_path, use_multiview, frame_range_seq_len);
-
- /* take the first image */
- if ((ima == NULL) && ima_range) {
- ima = ima_range;
- frame_seq_len = frame_range_seq_len;
- frame_ofs = frame_range_ofs;
- }
- }
- BLI_freelistN(&frame_ranges_all);
- }
- else {
- /* for drag & drop etc. */
- ima = image_open_single(
- bmain, op, filepath, BKE_main_blendfile_path(bmain),
- is_relative_path, use_multiview, 1);
- }
-
- if (ima == NULL) {
- return OPERATOR_CANCELLED;
- }
-
- /* hook into UI */
- iod = op->customdata;
-
- if (iod->pprop.prop) {
- /* when creating new ID blocks, use is already 1, but RNA
- * pointer use also increases user, so this compensates it */
- id_us_min(&ima->id);
-
- PointerRNA imaptr;
- RNA_id_pointer_create(&ima->id, &imaptr);
- RNA_property_pointer_set(&iod->pprop.ptr, iod->pprop.prop, imaptr);
- RNA_property_update(C, &iod->pprop.ptr, iod->pprop.prop);
- }
-
- if (iod->iuser) {
- iuser = iod->iuser;
- }
- else if (sa && sa->spacetype == SPACE_IMAGE) {
- SpaceImage *sima = sa->spacedata.first;
- ED_space_image_set(bmain, sima, obedit, ima, false);
- iuser = &sima->iuser;
- }
- else {
- Tex *tex = CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
- if (tex && tex->type == TEX_IMAGE) {
- iuser = &tex->iuser;
- }
-
- if (iuser == NULL) {
- Camera *cam = CTX_data_pointer_get_type(C, "camera", &RNA_Camera).data;
- if (cam) {
- for (CameraBGImage *bgpic = cam->bg_images.first; bgpic; bgpic = bgpic->next) {
- if (bgpic->ima == ima) {
- iuser = &bgpic->iuser;
- break;
- }
- }
- }
- }
- }
-
- /* initialize because of new image */
- if (iuser) {
- iuser->frames = frame_seq_len;
- iuser->sfra = 1;
- iuser->framenr = 1;
- if (ima->source == IMA_SRC_MOVIE) {
- iuser->offset = 0;
- }
- else {
- iuser->offset = frame_ofs - 1;
- }
- iuser->scene = scene;
- BKE_image_init_imageuser(ima, iuser);
- }
-
- /* XXX unpackImage frees image buffers */
- ED_preview_kill_jobs(CTX_wm_manager(C), bmain);
-
- BKE_image_signal(bmain, ima, iuser, IMA_SIGNAL_RELOAD);
- WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
-
- MEM_freeN(op->customdata);
-
- return OPERATOR_FINISHED;
+ Main *bmain = CTX_data_main(C);
+ ScrArea *sa = CTX_wm_area(C);
+ Scene *scene = CTX_data_scene(C);
+ Object *obedit = CTX_data_edit_object(C);
+ ImageUser *iuser = NULL;
+ ImageOpenData *iod = op->customdata;
+ Image *ima = NULL;
+ char filepath[FILE_MAX];
+ int frame_seq_len = 0;
+ int frame_ofs = 1;
+
+ const bool is_relative_path = RNA_boolean_get(op->ptr, "relative_path");
+ const bool use_multiview = RNA_boolean_get(op->ptr, "use_multiview");
+
+ if (!op->customdata) {
+ image_open_init(C, op);
+ }
+
+ RNA_string_get(op->ptr, "filepath", filepath);
+
+ if (RNA_struct_property_is_set(op->ptr, "directory") &&
+ RNA_struct_property_is_set(op->ptr, "files")) {
+ bool was_relative = BLI_path_is_rel(filepath);
+ ListBase frame_ranges_all;
+
+ BLI_listbase_clear(&frame_ranges_all);
+ image_sequence_get_frame_ranges(op->ptr, &frame_ranges_all);
+ for (ImageFrameRange *frame_range = frame_ranges_all.first; frame_range;
+ frame_range = frame_range->next) {
+ int frame_range_ofs;
+ int frame_range_seq_len = image_sequence_get_len(&frame_range->frames, &frame_range_ofs);
+ BLI_freelistN(&frame_range->frames);
+
+ char filepath_range[FILE_MAX];
+ BLI_strncpy(filepath_range, frame_range->filepath, sizeof(filepath_range));
+
+ if (was_relative) {
+ BLI_path_rel(filepath_range, BKE_main_blendfile_path(bmain));
+ }
+
+ Image *ima_range = image_open_single(bmain,
+ op,
+ filepath_range,
+ BKE_main_blendfile_path(bmain),
+ is_relative_path,
+ use_multiview,
+ frame_range_seq_len);
+
+ /* take the first image */
+ if ((ima == NULL) && ima_range) {
+ ima = ima_range;
+ frame_seq_len = frame_range_seq_len;
+ frame_ofs = frame_range_ofs;
+ }
+ }
+ BLI_freelistN(&frame_ranges_all);
+ }
+ else {
+ /* for drag & drop etc. */
+ ima = image_open_single(
+ bmain, op, filepath, BKE_main_blendfile_path(bmain), is_relative_path, use_multiview, 1);
+ }
+
+ if (ima == NULL) {
+ return OPERATOR_CANCELLED;
+ }
+
+ /* hook into UI */
+ iod = op->customdata;
+
+ if (iod->pprop.prop) {
+ /* when creating new ID blocks, use is already 1, but RNA
+ * pointer use also increases user, so this compensates it */
+ id_us_min(&ima->id);
+
+ PointerRNA imaptr;
+ RNA_id_pointer_create(&ima->id, &imaptr);
+ RNA_property_pointer_set(&iod->pprop.ptr, iod->pprop.prop, imaptr);
+ RNA_property_update(C, &iod->pprop.ptr, iod->pprop.prop);
+ }
+
+ if (iod->iuser) {
+ iuser = iod->iuser;
+ }
+ else if (sa && sa->spacetype == SPACE_IMAGE) {
+ SpaceImage *sima = sa->spacedata.first;
+ ED_space_image_set(bmain, sima, obedit, ima, false);
+ iuser = &sima->iuser;
+ }
+ else {
+ Tex *tex = CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
+ if (tex && tex->type == TEX_IMAGE) {
+ iuser = &tex->iuser;
+ }
+
+ if (iuser == NULL) {
+ Camera *cam = CTX_data_pointer_get_type(C, "camera", &RNA_Camera).data;
+ if (cam) {
+ for (CameraBGImage *bgpic = cam->bg_images.first; bgpic; bgpic = bgpic->next) {
+ if (bgpic->ima == ima) {
+ iuser = &bgpic->iuser;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ /* initialize because of new image */
+ if (iuser) {
+ iuser->frames = frame_seq_len;
+ iuser->sfra = 1;
+ iuser->framenr = 1;
+ if (ima->source == IMA_SRC_MOVIE) {
+ iuser->offset = 0;
+ }
+ else {
+ iuser->offset = frame_ofs - 1;
+ }
+ iuser->scene = scene;
+ BKE_image_init_imageuser(ima, iuser);
+ }
+
+ /* XXX unpackImage frees image buffers */
+ ED_preview_kill_jobs(CTX_wm_manager(C), bmain);
+
+ BKE_image_signal(bmain, ima, iuser, IMA_SIGNAL_RELOAD);
+ WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
+
+ MEM_freeN(op->customdata);
+
+ return OPERATOR_FINISHED;
}
static int image_open_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- SpaceImage *sima = CTX_wm_space_image(C); /* XXX other space types can call */
- const char *path = U.textudir;
- Image *ima = NULL;
- Scene *scene = CTX_data_scene(C);
+ SpaceImage *sima = CTX_wm_space_image(C); /* XXX other space types can call */
+ const char *path = U.textudir;
+ Image *ima = NULL;
+ Scene *scene = CTX_data_scene(C);
- if (sima) {
- ima = sima->image;
- }
+ if (sima) {
+ ima = sima->image;
+ }
- if (ima == NULL) {
- Tex *tex = CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
- if (tex && tex->type == TEX_IMAGE) {
- ima = tex->ima;
- }
- }
+ if (ima == NULL) {
+ Tex *tex = CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
+ if (tex && tex->type == TEX_IMAGE) {
+ ima = tex->ima;
+ }
+ }
- if (ima == NULL) {
- PointerRNA ptr;
- PropertyRNA *prop;
+ if (ima == NULL) {
+ PointerRNA ptr;
+ PropertyRNA *prop;
- /* hook into UI */
- UI_context_active_but_prop_get_templateID(C, &ptr, &prop);
+ /* hook into UI */
+ UI_context_active_but_prop_get_templateID(C, &ptr, &prop);
- if (prop) {
- PointerRNA oldptr;
- Image *oldima;
+ if (prop) {
+ PointerRNA oldptr;
+ Image *oldima;
- oldptr = RNA_property_pointer_get(&ptr, prop);
- oldima = (Image *)oldptr.id.data;
- /* unlikely to fail but better avoid strange crash */
- if (oldima && GS(oldima->id.name) == ID_IM) {
- ima = oldima;
- }
- }
- }
+ oldptr = RNA_property_pointer_get(&ptr, prop);
+ oldima = (Image *)oldptr.id.data;
+ /* unlikely to fail but better avoid strange crash */
+ if (oldima && GS(oldima->id.name) == ID_IM) {
+ ima = oldima;
+ }
+ }
+ }
- if (ima) {
- path = ima->name;
- }
+ if (ima) {
+ path = ima->name;
+ }
- if (RNA_struct_property_is_set(op->ptr, "filepath")) {
- return image_open_exec(C, op);
- }
+ if (RNA_struct_property_is_set(op->ptr, "filepath")) {
+ return image_open_exec(C, op);
+ }
- image_open_init(C, op);
+ image_open_init(C, op);
- /* show multiview save options only if scene has multiviews */
- PropertyRNA *prop;
- prop = RNA_struct_find_property(op->ptr, "show_multiview");
- RNA_property_boolean_set(op->ptr, prop, (scene->r.scemode & R_MULTIVIEW) != 0);
+ /* show multiview save options only if scene has multiviews */
+ PropertyRNA *prop;
+ prop = RNA_struct_find_property(op->ptr, "show_multiview");
+ RNA_property_boolean_set(op->ptr, prop, (scene->r.scemode & R_MULTIVIEW) != 0);
- image_filesel(C, op, path);
+ image_filesel(C, op, path);
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
-static bool image_open_draw_check_prop(PointerRNA *UNUSED(ptr), PropertyRNA *prop, void *UNUSED(user_data))
+static bool image_open_draw_check_prop(PointerRNA *UNUSED(ptr),
+ PropertyRNA *prop,
+ void *UNUSED(user_data))
{
- const char *prop_id = RNA_property_identifier(prop);
+ const char *prop_id = RNA_property_identifier(prop);
- return !(STREQ(prop_id, "filepath") ||
- STREQ(prop_id, "directory") ||
- STREQ(prop_id, "filename")
- );
+ return !(STREQ(prop_id, "filepath") || STREQ(prop_id, "directory") ||
+ STREQ(prop_id, "filename"));
}
static void image_open_draw(bContext *UNUSED(C), wmOperator *op)
{
- uiLayout *layout = op->layout;
- ImageOpenData *iod = op->customdata;
- ImageFormatData *imf = &iod->im_format;
- PointerRNA imf_ptr, ptr;
+ uiLayout *layout = op->layout;
+ ImageOpenData *iod = op->customdata;
+ ImageFormatData *imf = &iod->im_format;
+ PointerRNA imf_ptr, ptr;
- /* main draw call */
- RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
- uiDefAutoButsRNA(layout, &ptr, image_open_draw_check_prop, NULL, NULL, UI_BUT_LABEL_ALIGN_NONE, false);
+ /* main draw call */
+ RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
+ uiDefAutoButsRNA(
+ layout, &ptr, image_open_draw_check_prop, NULL, NULL, UI_BUT_LABEL_ALIGN_NONE, false);
- /* image template */
- RNA_pointer_create(NULL, &RNA_ImageFormatSettings, imf, &imf_ptr);
+ /* image template */
+ RNA_pointer_create(NULL, &RNA_ImageFormatSettings, imf, &imf_ptr);
- /* multiview template */
- if (RNA_boolean_get(op->ptr, "show_multiview")) {
- uiTemplateImageFormatViews(layout, &imf_ptr, op->ptr);
- }
+ /* multiview template */
+ if (RNA_boolean_get(op->ptr, "show_multiview")) {
+ uiTemplateImageFormatViews(layout, &imf_ptr, op->ptr);
+ }
}
/* called by other space types too */
void IMAGE_OT_open(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Open Image";
- ot->description = "Open image";
- ot->idname = "IMAGE_OT_open";
-
- /* api callbacks */
- ot->exec = image_open_exec;
- ot->invoke = image_open_invoke;
- ot->cancel = image_open_cancel;
- ot->ui = image_open_draw;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- WM_operator_properties_filesel(
- ot, FILE_TYPE_FOLDER | FILE_TYPE_IMAGE | FILE_TYPE_MOVIE, FILE_SPECIAL, FILE_OPENFILE,
- WM_FILESEL_FILEPATH | WM_FILESEL_DIRECTORY | WM_FILESEL_FILES | WM_FILESEL_RELPATH,
- FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA);
-
- RNA_def_boolean(ot->srna, "use_sequence_detection", true, "Detect Sequences",
- "Automatically detect animated sequences in selected images (based on file names)");
+ /* identifiers */
+ ot->name = "Open Image";
+ ot->description = "Open image";
+ ot->idname = "IMAGE_OT_open";
+
+ /* api callbacks */
+ ot->exec = image_open_exec;
+ ot->invoke = image_open_invoke;
+ ot->cancel = image_open_cancel;
+ ot->ui = image_open_draw;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ WM_operator_properties_filesel(ot,
+ FILE_TYPE_FOLDER | FILE_TYPE_IMAGE | FILE_TYPE_MOVIE,
+ FILE_SPECIAL,
+ FILE_OPENFILE,
+ WM_FILESEL_FILEPATH | WM_FILESEL_DIRECTORY | WM_FILESEL_FILES |
+ WM_FILESEL_RELPATH,
+ FILE_DEFAULTDISPLAY,
+ FILE_SORT_ALPHA);
+
+ RNA_def_boolean(
+ ot->srna,
+ "use_sequence_detection",
+ true,
+ "Detect Sequences",
+ "Automatically detect animated sequences in selected images (based on file names)");
}
/******************** Match movie length operator ********************/
static int image_match_len_exec(bContext *C, wmOperator *UNUSED(op))
{
- Scene *scene = CTX_data_scene(C);
- Image *ima = CTX_data_pointer_get_type(C, "edit_image", &RNA_Image).data;
- ImageUser *iuser = CTX_data_pointer_get_type(C, "edit_image_user", &RNA_ImageUser).data;
-
- if (!ima || !iuser) {
- /* Try to get a Texture, or a SpaceImage from context... */
- SpaceImage *sima = CTX_wm_space_image(C);
- Tex *tex = CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
- if (tex && tex->type == TEX_IMAGE) {
- ima = tex->ima;
- iuser = &tex->iuser;
- }
- else if (sima) {
- ima = sima->image;
- iuser = &sima->iuser;
- }
-
- }
-
- if (!ima || !iuser || !BKE_image_has_anim(ima)) {
- return OPERATOR_CANCELLED;
- }
-
- struct anim *anim = ((ImageAnim *)ima->anims.first)->anim;
- if (!anim) {
- return OPERATOR_CANCELLED;
- }
- iuser->frames = IMB_anim_get_duration(anim, IMB_TC_RECORD_RUN);
- BKE_image_user_frame_calc(iuser, scene->r.cfra);
-
- return OPERATOR_FINISHED;
+ Scene *scene = CTX_data_scene(C);
+ Image *ima = CTX_data_pointer_get_type(C, "edit_image", &RNA_Image).data;
+ ImageUser *iuser = CTX_data_pointer_get_type(C, "edit_image_user", &RNA_ImageUser).data;
+
+ if (!ima || !iuser) {
+ /* Try to get a Texture, or a SpaceImage from context... */
+ SpaceImage *sima = CTX_wm_space_image(C);
+ Tex *tex = CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
+ if (tex && tex->type == TEX_IMAGE) {
+ ima = tex->ima;
+ iuser = &tex->iuser;
+ }
+ else if (sima) {
+ ima = sima->image;
+ iuser = &sima->iuser;
+ }
+ }
+
+ if (!ima || !iuser || !BKE_image_has_anim(ima)) {
+ return OPERATOR_CANCELLED;
+ }
+
+ struct anim *anim = ((ImageAnim *)ima->anims.first)->anim;
+ if (!anim) {
+ return OPERATOR_CANCELLED;
+ }
+ iuser->frames = IMB_anim_get_duration(anim, IMB_TC_RECORD_RUN);
+ BKE_image_user_frame_calc(iuser, scene->r.cfra);
+
+ return OPERATOR_FINISHED;
}
/* called by other space types too */
void IMAGE_OT_match_movie_length(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Match Movie Length";
- ot->description = "Set image's user's length to the one of this video";
- ot->idname = "IMAGE_OT_match_movie_length";
+ /* identifiers */
+ ot->name = "Match Movie Length";
+ ot->description = "Set image's user's length to the one of this video";
+ ot->idname = "IMAGE_OT_match_movie_length";
- /* api callbacks */
- ot->exec = image_match_len_exec;
+ /* api callbacks */
+ ot->exec = image_match_len_exec;
- /* flags */
- /* Don't think we need undo for that. */
- ot->flag = OPTYPE_REGISTER | OPTYPE_INTERNAL/* | OPTYPE_UNDO */;
+ /* flags */
+ /* Don't think we need undo for that. */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_INTERNAL /* | OPTYPE_UNDO */;
}
/******************** replace image operator ********************/
static int image_replace_exec(bContext *C, wmOperator *op)
{
- Main *bmain = CTX_data_main(C);
- SpaceImage *sima = CTX_wm_space_image(C);
- char str[FILE_MAX];
+ Main *bmain = CTX_data_main(C);
+ SpaceImage *sima = CTX_wm_space_image(C);
+ char str[FILE_MAX];
- if (!sima->image) {
- return OPERATOR_CANCELLED;
- }
+ if (!sima->image) {
+ return OPERATOR_CANCELLED;
+ }
- RNA_string_get(op->ptr, "filepath", str);
+ RNA_string_get(op->ptr, "filepath", str);
- /* we cant do much if the str is longer then FILE_MAX :/ */
- BLI_strncpy(sima->image->name, str, sizeof(sima->image->name));
+ /* we cant do much if the str is longer then FILE_MAX :/ */
+ BLI_strncpy(sima->image->name, str, sizeof(sima->image->name));
- if (sima->image->source == IMA_SRC_GENERATED) {
- sima->image->source = IMA_SRC_FILE;
- BKE_image_signal(bmain, sima->image, &sima->iuser, IMA_SIGNAL_SRC_CHANGE);
- }
+ if (sima->image->source == IMA_SRC_GENERATED) {
+ sima->image->source = IMA_SRC_FILE;
+ BKE_image_signal(bmain, sima->image, &sima->iuser, IMA_SIGNAL_SRC_CHANGE);
+ }
- if (BLI_path_extension_check_array(str, imb_ext_movie)) {
- sima->image->source = IMA_SRC_MOVIE;
- }
- else {
- sima->image->source = IMA_SRC_FILE;
- }
+ if (BLI_path_extension_check_array(str, imb_ext_movie)) {
+ sima->image->source = IMA_SRC_MOVIE;
+ }
+ else {
+ sima->image->source = IMA_SRC_FILE;
+ }
- /* XXX unpackImage frees image buffers */
- ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
+ /* XXX unpackImage frees image buffers */
+ ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
- BKE_icon_changed(BKE_icon_id_ensure(&sima->image->id));
- BKE_image_signal(bmain, sima->image, &sima->iuser, IMA_SIGNAL_RELOAD);
- WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, sima->image);
+ BKE_icon_changed(BKE_icon_id_ensure(&sima->image->id));
+ BKE_image_signal(bmain, sima->image, &sima->iuser, IMA_SIGNAL_RELOAD);
+ WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, sima->image);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
static int image_replace_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- SpaceImage *sima = CTX_wm_space_image(C);
+ SpaceImage *sima = CTX_wm_space_image(C);
- if (!sima->image) {
- return OPERATOR_CANCELLED;
- }
+ if (!sima->image) {
+ return OPERATOR_CANCELLED;
+ }
- if (RNA_struct_property_is_set(op->ptr, "filepath")) {
- return image_replace_exec(C, op);
- }
+ if (RNA_struct_property_is_set(op->ptr, "filepath")) {
+ return image_replace_exec(C, op);
+ }
- if (!RNA_struct_property_is_set(op->ptr, "relative_path")) {
- RNA_boolean_set(op->ptr, "relative_path", BLI_path_is_rel(sima->image->name));
- }
+ if (!RNA_struct_property_is_set(op->ptr, "relative_path")) {
+ RNA_boolean_set(op->ptr, "relative_path", BLI_path_is_rel(sima->image->name));
+ }
- image_filesel(C, op, sima->image->name);
+ image_filesel(C, op, sima->image->name);
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
void IMAGE_OT_replace(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Replace Image";
- ot->idname = "IMAGE_OT_replace";
- ot->description = "Replace current image by another one from disk";
+ /* identifiers */
+ ot->name = "Replace Image";
+ ot->idname = "IMAGE_OT_replace";
+ ot->description = "Replace current image by another one from disk";
- /* api callbacks */
- ot->exec = image_replace_exec;
- ot->invoke = image_replace_invoke;
- ot->poll = image_not_packed_poll;
+ /* api callbacks */
+ ot->exec = image_replace_exec;
+ ot->invoke = image_replace_invoke;
+ ot->poll = image_not_packed_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
- /* properties */
- WM_operator_properties_filesel(
- ot, FILE_TYPE_FOLDER | FILE_TYPE_IMAGE | FILE_TYPE_MOVIE, FILE_SPECIAL, FILE_OPENFILE,
- WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA);
+ /* properties */
+ WM_operator_properties_filesel(ot,
+ FILE_TYPE_FOLDER | FILE_TYPE_IMAGE | FILE_TYPE_MOVIE,
+ FILE_SPECIAL,
+ FILE_OPENFILE,
+ WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH,
+ FILE_DEFAULTDISPLAY,
+ FILE_SORT_ALPHA);
}
/******************** save image as operator ********************/
typedef struct {
- /* matching scene->r settings */
- //short planes, imtype, subimtype, quality;
- ImageFormatData im_format;
- char filepath[FILE_MAX]; /* keep absolute */
+ /* matching scene->r settings */
+ //short planes, imtype, subimtype, quality;
+ ImageFormatData im_format;
+ char filepath[FILE_MAX]; /* keep absolute */
} SaveImageOptions;
static void save_image_options_defaults(SaveImageOptions *simopts)
{
- BKE_imformat_defaults(&simopts->im_format);
- simopts->filepath[0] = '\0';
+ BKE_imformat_defaults(&simopts->im_format);
+ simopts->filepath[0] = '\0';
}
static char imtype_best_depth(ImBuf *ibuf, const char imtype)
{
- const char depth_ok = BKE_imtype_valid_depths(imtype);
-
- if (ibuf->rect_float) {
- if (depth_ok & R_IMF_CHAN_DEPTH_32) { return R_IMF_CHAN_DEPTH_32; }
- if (depth_ok & R_IMF_CHAN_DEPTH_24) { return R_IMF_CHAN_DEPTH_24; }
- if (depth_ok & R_IMF_CHAN_DEPTH_16) { return R_IMF_CHAN_DEPTH_16; }
- if (depth_ok & R_IMF_CHAN_DEPTH_12) { return R_IMF_CHAN_DEPTH_12; }
- return R_IMF_CHAN_DEPTH_8;
- }
- else {
- if (depth_ok & R_IMF_CHAN_DEPTH_8) { return R_IMF_CHAN_DEPTH_8; }
- if (depth_ok & R_IMF_CHAN_DEPTH_12) { return R_IMF_CHAN_DEPTH_12; }
- if (depth_ok & R_IMF_CHAN_DEPTH_16) { return R_IMF_CHAN_DEPTH_16; }
- if (depth_ok & R_IMF_CHAN_DEPTH_24) { return R_IMF_CHAN_DEPTH_24; }
- if (depth_ok & R_IMF_CHAN_DEPTH_32) { return R_IMF_CHAN_DEPTH_32; }
- return R_IMF_CHAN_DEPTH_8; /* fallback, should not get here */
- }
-}
-
-static int save_image_options_init(Main *bmain, SaveImageOptions *simopts, SpaceImage *sima, Scene *scene,
- const bool guess_path, const bool save_as_render)
-{
- void *lock;
- ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
-
- if (ibuf) {
- Image *ima = sima->image;
- bool is_depth_set = false;
-
- if (ELEM(ima->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE)) {
- /* imtype */
- simopts->im_format = scene->r.im_format;
- is_depth_set = true;
- if (!BKE_image_is_multiview(ima)) {
- /* In case multiview is disabled,
- * render settings would be invalid for render result in this area. */
- simopts->im_format.stereo3d_format = *ima->stereo3d_format;
- simopts->im_format.views_format = ima->views_format;
- }
- }
- else {
- if (ima->source == IMA_SRC_GENERATED) {
- simopts->im_format.imtype = R_IMF_IMTYPE_PNG;
- simopts->im_format.compress = ibuf->foptions.quality;
- simopts->im_format.planes = ibuf->planes;
- }
- else {
- BKE_imbuf_to_image_format(&simopts->im_format, ibuf);
- }
-
- /* use the multiview image settings as the default */
- simopts->im_format.stereo3d_format = *ima->stereo3d_format;
- simopts->im_format.views_format = ima->views_format;
- }
-
- ///* XXX - this is lame, we need to make these available too! */
- //simopts->subimtype = scene->r.subimtype;
-
- BLI_strncpy(simopts->filepath, ibuf->name, sizeof(simopts->filepath));
-
- /* sanitize all settings */
-
- /* unlikely but just in case */
- if (ELEM(simopts->im_format.planes, R_IMF_PLANES_BW, R_IMF_PLANES_RGB, R_IMF_PLANES_RGBA) == 0) {
- simopts->im_format.planes = R_IMF_PLANES_RGBA;
- }
-
- /* depth, account for float buffer and format support */
- if (is_depth_set == false) {
- simopts->im_format.depth = imtype_best_depth(ibuf, simopts->im_format.imtype);
- }
-
- /* some formats don't use quality so fallback to scenes quality */
- if (simopts->im_format.quality == 0) {
- simopts->im_format.quality = scene->r.im_format.quality;
- }
-
- /* check for empty path */
- if (guess_path && simopts->filepath[0] == 0) {
- const bool is_prev_save = !STREQ(G.ima, "//");
- if (save_as_render) {
- if (is_prev_save) {
- BLI_strncpy(simopts->filepath, G.ima, sizeof(simopts->filepath));
- }
- else {
- BLI_strncpy(simopts->filepath, "//untitled", sizeof(simopts->filepath));
- BLI_path_abs(simopts->filepath, BKE_main_blendfile_path(bmain));
- }
- }
- else {
- BLI_snprintf(simopts->filepath, sizeof(simopts->filepath), "//%s", ima->id.name + 2);
- BLI_path_abs(simopts->filepath, is_prev_save ? G.ima : BKE_main_blendfile_path(bmain));
- }
- }
-
- /* color management */
- BKE_color_managed_display_settings_copy(&simopts->im_format.display_settings, &scene->display_settings);
- BKE_color_managed_view_settings_copy(&simopts->im_format.view_settings, &scene->view_settings);
- }
-
- ED_space_image_release_buffer(sima, ibuf, lock);
-
- return (ibuf != NULL);
+ const char depth_ok = BKE_imtype_valid_depths(imtype);
+
+ if (ibuf->rect_float) {
+ if (depth_ok & R_IMF_CHAN_DEPTH_32) {
+ return R_IMF_CHAN_DEPTH_32;
+ }
+ if (depth_ok & R_IMF_CHAN_DEPTH_24) {
+ return R_IMF_CHAN_DEPTH_24;
+ }
+ if (depth_ok & R_IMF_CHAN_DEPTH_16) {
+ return R_IMF_CHAN_DEPTH_16;
+ }
+ if (depth_ok & R_IMF_CHAN_DEPTH_12) {
+ return R_IMF_CHAN_DEPTH_12;
+ }
+ return R_IMF_CHAN_DEPTH_8;
+ }
+ else {
+ if (depth_ok & R_IMF_CHAN_DEPTH_8) {
+ return R_IMF_CHAN_DEPTH_8;
+ }
+ if (depth_ok & R_IMF_CHAN_DEPTH_12) {
+ return R_IMF_CHAN_DEPTH_12;
+ }
+ if (depth_ok & R_IMF_CHAN_DEPTH_16) {
+ return R_IMF_CHAN_DEPTH_16;
+ }
+ if (depth_ok & R_IMF_CHAN_DEPTH_24) {
+ return R_IMF_CHAN_DEPTH_24;
+ }
+ if (depth_ok & R_IMF_CHAN_DEPTH_32) {
+ return R_IMF_CHAN_DEPTH_32;
+ }
+ return R_IMF_CHAN_DEPTH_8; /* fallback, should not get here */
+ }
+}
+
+static int save_image_options_init(Main *bmain,
+ SaveImageOptions *simopts,
+ SpaceImage *sima,
+ Scene *scene,
+ const bool guess_path,
+ const bool save_as_render)
+{
+ void *lock;
+ ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
+
+ if (ibuf) {
+ Image *ima = sima->image;
+ bool is_depth_set = false;
+
+ if (ELEM(ima->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE)) {
+ /* imtype */
+ simopts->im_format = scene->r.im_format;
+ is_depth_set = true;
+ if (!BKE_image_is_multiview(ima)) {
+ /* In case multiview is disabled,
+ * render settings would be invalid for render result in this area. */
+ simopts->im_format.stereo3d_format = *ima->stereo3d_format;
+ simopts->im_format.views_format = ima->views_format;
+ }
+ }
+ else {
+ if (ima->source == IMA_SRC_GENERATED) {
+ simopts->im_format.imtype = R_IMF_IMTYPE_PNG;
+ simopts->im_format.compress = ibuf->foptions.quality;
+ simopts->im_format.planes = ibuf->planes;
+ }
+ else {
+ BKE_imbuf_to_image_format(&simopts->im_format, ibuf);
+ }
+
+ /* use the multiview image settings as the default */
+ simopts->im_format.stereo3d_format = *ima->stereo3d_format;
+ simopts->im_format.views_format = ima->views_format;
+ }
+
+ ///* XXX - this is lame, we need to make these available too! */
+ //simopts->subimtype = scene->r.subimtype;
+
+ BLI_strncpy(simopts->filepath, ibuf->name, sizeof(simopts->filepath));
+
+ /* sanitize all settings */
+
+ /* unlikely but just in case */
+ if (ELEM(simopts->im_format.planes, R_IMF_PLANES_BW, R_IMF_PLANES_RGB, R_IMF_PLANES_RGBA) ==
+ 0) {
+ simopts->im_format.planes = R_IMF_PLANES_RGBA;
+ }
+
+ /* depth, account for float buffer and format support */
+ if (is_depth_set == false) {
+ simopts->im_format.depth = imtype_best_depth(ibuf, simopts->im_format.imtype);
+ }
+
+ /* some formats don't use quality so fallback to scenes quality */
+ if (simopts->im_format.quality == 0) {
+ simopts->im_format.quality = scene->r.im_format.quality;
+ }
+
+ /* check for empty path */
+ if (guess_path && simopts->filepath[0] == 0) {
+ const bool is_prev_save = !STREQ(G.ima, "//");
+ if (save_as_render) {
+ if (is_prev_save) {
+ BLI_strncpy(simopts->filepath, G.ima, sizeof(simopts->filepath));
+ }
+ else {
+ BLI_strncpy(simopts->filepath, "//untitled", sizeof(simopts->filepath));
+ BLI_path_abs(simopts->filepath, BKE_main_blendfile_path(bmain));
+ }
+ }
+ else {
+ BLI_snprintf(simopts->filepath, sizeof(simopts->filepath), "//%s", ima->id.name + 2);
+ BLI_path_abs(simopts->filepath, is_prev_save ? G.ima : BKE_main_blendfile_path(bmain));
+ }
+ }
+
+ /* color management */
+ BKE_color_managed_display_settings_copy(&simopts->im_format.display_settings,
+ &scene->display_settings);
+ BKE_color_managed_view_settings_copy(&simopts->im_format.view_settings, &scene->view_settings);
+ }
+
+ ED_space_image_release_buffer(sima, ibuf, lock);
+
+ return (ibuf != NULL);
}
static void save_image_options_from_op(Main *bmain, SaveImageOptions *simopts, wmOperator *op)
{
- if (op->customdata) {
- BKE_color_managed_view_settings_free(&simopts->im_format.view_settings);
+ if (op->customdata) {
+ BKE_color_managed_view_settings_free(&simopts->im_format.view_settings);
- simopts->im_format = *(ImageFormatData *)op->customdata;
- }
+ simopts->im_format = *(ImageFormatData *)op->customdata;
+ }
- if (RNA_struct_property_is_set(op->ptr, "filepath")) {
- RNA_string_get(op->ptr, "filepath", simopts->filepath);
- BLI_path_abs(simopts->filepath, BKE_main_blendfile_path(bmain));
- }
+ if (RNA_struct_property_is_set(op->ptr, "filepath")) {
+ RNA_string_get(op->ptr, "filepath", simopts->filepath);
+ BLI_path_abs(simopts->filepath, BKE_main_blendfile_path(bmain));
+ }
}
static void save_image_options_to_op(SaveImageOptions *simopts, wmOperator *op)
{
- if (op->customdata) {
- BKE_color_managed_view_settings_free(&((ImageFormatData *)op->customdata)->view_settings);
-
- *(ImageFormatData *)op->customdata = simopts->im_format;
- }
-
- RNA_string_set(op->ptr, "filepath", simopts->filepath);
-}
-
-static void save_image_post(
- Main *bmain, wmOperator *op, ImBuf *ibuf, Image *ima, int ok, int save_copy,
- const char *relbase, int relative, int do_newpath, const char *filepath)
-{
- if (ok) {
- if (!save_copy) {
- ColorManagedColorspaceSettings old_colorspace_settings;
-
- if (do_newpath) {
- BLI_strncpy(ibuf->name, filepath, sizeof(ibuf->name));
- BLI_strncpy(ima->name, filepath, sizeof(ima->name));
- }
-
- ibuf->userflags &= ~IB_BITMAPDIRTY;
-
- /* change type? */
- if (ima->type == IMA_TYPE_R_RESULT) {
- ima->type = IMA_TYPE_IMAGE;
-
- /* workaround to ensure the render result buffer is no longer used
- * by this image, otherwise can crash when a new render result is
- * created. */
- if (ibuf->rect && !(ibuf->mall & IB_rect)) {
- imb_freerectImBuf(ibuf);
- }
- if (ibuf->rect_float && !(ibuf->mall & IB_rectfloat)) {
- imb_freerectfloatImBuf(ibuf);
- }
- if (ibuf->zbuf && !(ibuf->mall & IB_zbuf)) {
- IMB_freezbufImBuf(ibuf);
- }
- if (ibuf->zbuf_float && !(ibuf->mall & IB_zbuffloat)) {
- IMB_freezbuffloatImBuf(ibuf);
- }
- }
- if (ELEM(ima->source, IMA_SRC_GENERATED, IMA_SRC_VIEWER)) {
- ima->source = IMA_SRC_FILE;
- ima->type = IMA_TYPE_IMAGE;
- }
-
- /* only image path, never ibuf */
- if (relative) {
- BLI_path_rel(ima->name, relbase); /* only after saving */
- }
-
- BKE_color_managed_colorspace_settings_copy(&old_colorspace_settings,
- &ima->colorspace_settings);
- IMB_colormanagement_colorspace_from_ibuf_ftype(&ima->colorspace_settings, ibuf);
- if (!BKE_color_managed_colorspace_settings_equals(&old_colorspace_settings,
- &ima->colorspace_settings))
- {
- BKE_image_signal(bmain, ima, NULL, IMA_SIGNAL_COLORMANAGE);
- }
- }
- }
- else {
- BKE_reportf(op->reports, RPT_ERROR, "Could not write image: %s", strerror(errno));
- }
+ if (op->customdata) {
+ BKE_color_managed_view_settings_free(&((ImageFormatData *)op->customdata)->view_settings);
+
+ *(ImageFormatData *)op->customdata = simopts->im_format;
+ }
+
+ RNA_string_set(op->ptr, "filepath", simopts->filepath);
+}
+
+static void save_image_post(Main *bmain,
+ wmOperator *op,
+ ImBuf *ibuf,
+ Image *ima,
+ int ok,
+ int save_copy,
+ const char *relbase,
+ int relative,
+ int do_newpath,
+ const char *filepath)
+{
+ if (ok) {
+ if (!save_copy) {
+ ColorManagedColorspaceSettings old_colorspace_settings;
+
+ if (do_newpath) {
+ BLI_strncpy(ibuf->name, filepath, sizeof(ibuf->name));
+ BLI_strncpy(ima->name, filepath, sizeof(ima->name));
+ }
+
+ ibuf->userflags &= ~IB_BITMAPDIRTY;
+
+ /* change type? */
+ if (ima->type == IMA_TYPE_R_RESULT) {
+ ima->type = IMA_TYPE_IMAGE;
+
+ /* workaround to ensure the render result buffer is no longer used
+ * by this image, otherwise can crash when a new render result is
+ * created. */
+ if (ibuf->rect && !(ibuf->mall & IB_rect)) {
+ imb_freerectImBuf(ibuf);
+ }
+ if (ibuf->rect_float && !(ibuf->mall & IB_rectfloat)) {
+ imb_freerectfloatImBuf(ibuf);
+ }
+ if (ibuf->zbuf && !(ibuf->mall & IB_zbuf)) {
+ IMB_freezbufImBuf(ibuf);
+ }
+ if (ibuf->zbuf_float && !(ibuf->mall & IB_zbuffloat)) {
+ IMB_freezbuffloatImBuf(ibuf);
+ }
+ }
+ if (ELEM(ima->source, IMA_SRC_GENERATED, IMA_SRC_VIEWER)) {
+ ima->source = IMA_SRC_FILE;
+ ima->type = IMA_TYPE_IMAGE;
+ }
+
+ /* only image path, never ibuf */
+ if (relative) {
+ BLI_path_rel(ima->name, relbase); /* only after saving */
+ }
+
+ BKE_color_managed_colorspace_settings_copy(&old_colorspace_settings,
+ &ima->colorspace_settings);
+ IMB_colormanagement_colorspace_from_ibuf_ftype(&ima->colorspace_settings, ibuf);
+ if (!BKE_color_managed_colorspace_settings_equals(&old_colorspace_settings,
+ &ima->colorspace_settings)) {
+ BKE_image_signal(bmain, ima, NULL, IMA_SIGNAL_COLORMANAGE);
+ }
+ }
+ }
+ else {
+ BKE_reportf(op->reports, RPT_ERROR, "Could not write image: %s", strerror(errno));
+ }
}
static void save_imbuf_post(ImBuf *ibuf, ImBuf *colormanaged_ibuf)
{
- if (colormanaged_ibuf != ibuf) {
- /* This guys might be modified by image buffer write functions,
- * need to copy them back from color managed image buffer to an
- * original one, so file type of image is being properly updated.
- */
- ibuf->ftype = colormanaged_ibuf->ftype;
- ibuf->foptions = colormanaged_ibuf->foptions;
- ibuf->planes = colormanaged_ibuf->planes;
+ if (colormanaged_ibuf != ibuf) {
+ /* This guys might be modified by image buffer write functions,
+ * need to copy them back from color managed image buffer to an
+ * original one, so file type of image is being properly updated.
+ */
+ ibuf->ftype = colormanaged_ibuf->ftype;
+ ibuf->foptions = colormanaged_ibuf->foptions;
+ ibuf->planes = colormanaged_ibuf->planes;
- IMB_freeImBuf(colormanaged_ibuf);
- }
+ IMB_freeImBuf(colormanaged_ibuf);
+ }
}
/**
@@ -1838,780 +1933,830 @@ static void save_imbuf_post(ImBuf *ibuf, ImBuf *colormanaged_ibuf)
* \note ``ima->name`` and ``ibuf->name`` should end up the same.
* \note for multiview the first ``ibuf`` is important to get the settings.
*/
-static bool save_image_doit(bContext *C, SpaceImage *sima, wmOperator *op, SaveImageOptions *simopts, bool do_newpath)
-{
- Main *bmain = CTX_data_main(C);
- Image *ima = ED_space_image(sima);
- void *lock;
- ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
- Scene *scene;
- RenderResult *rr = NULL;
- bool ok = false;
-
- WM_cursor_wait(1);
-
- if (ibuf) {
- ImBuf *colormanaged_ibuf = NULL;
- const char *relbase = ID_BLEND_PATH(CTX_data_main(C), &ima->id);
- const bool relative = (RNA_struct_find_property(op->ptr, "relative_path") && RNA_boolean_get(op->ptr, "relative_path"));
- const bool save_copy = (RNA_struct_find_property(op->ptr, "copy") && RNA_boolean_get(op->ptr, "copy"));
- const bool save_as_render = (RNA_struct_find_property(op->ptr, "save_as_render") && RNA_boolean_get(op->ptr, "save_as_render"));
- ImageFormatData *imf = &simopts->im_format;
-
- /* old global to ensure a 2nd save goes to same dir */
- BLI_strncpy(G.ima, simopts->filepath, sizeof(G.ima));
-
- if (ima->type == IMA_TYPE_R_RESULT) {
- /* enforce user setting for RGB or RGBA, but skip BW */
- if (simopts->im_format.planes == R_IMF_PLANES_RGBA) {
- ibuf->planes = R_IMF_PLANES_RGBA;
- }
- else if (simopts->im_format.planes == R_IMF_PLANES_RGB) {
- ibuf->planes = R_IMF_PLANES_RGB;
- }
- }
- else {
- /* TODO, better solution, if a 24bit image is painted onto it may contain alpha */
- if ((simopts->im_format.planes == R_IMF_PLANES_RGBA) &&
- /* it has been painted onto */
- (ibuf->userflags & IB_BITMAPDIRTY))
- {
- /* checks each pixel, not ideal */
- ibuf->planes = BKE_imbuf_alpha_test(ibuf) ? R_IMF_PLANES_RGBA : R_IMF_PLANES_RGB;
- }
- }
-
- /* we need renderresult for exr and rendered multiview */
- scene = CTX_data_scene(C);
- rr = BKE_image_acquire_renderresult(scene, ima);
- bool is_mono = rr ? BLI_listbase_count_at_most(&rr->views, 2) < 2 : BLI_listbase_count_at_most(&ima->views, 2) < 2;
- bool is_exr_rr = rr && ELEM(imf->imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER) && RE_HasFloatPixels(rr);
- bool is_multilayer = is_exr_rr && (imf->imtype == R_IMF_IMTYPE_MULTILAYER);
- int layer = (is_multilayer) ? -1 : sima->iuser.layer;
-
- /* error handling */
- if (!rr) {
- if (imf->imtype == R_IMF_IMTYPE_MULTILAYER) {
- BKE_report(op->reports, RPT_ERROR, "Did not write, no Multilayer Image");
- goto cleanup;
- }
- }
- else {
- if (imf->views_format == R_IMF_VIEWS_STEREO_3D) {
- if (!BKE_image_is_stereo(ima)) {
- BKE_reportf(op->reports, RPT_ERROR, "Did not write, the image doesn't have a \"%s\" and \"%s\" views",
- STEREO_LEFT_NAME, STEREO_RIGHT_NAME);
- goto cleanup;
- }
-
- /* it shouldn't ever happen*/
- if ((BLI_findstring(&rr->views, STEREO_LEFT_NAME, offsetof(RenderView, name)) == NULL) ||
- (BLI_findstring(&rr->views, STEREO_RIGHT_NAME, offsetof(RenderView, name)) == NULL))
- {
- BKE_reportf(op->reports, RPT_ERROR, "Did not write, the image doesn't have a \"%s\" and \"%s\" views",
- STEREO_LEFT_NAME, STEREO_RIGHT_NAME);
- goto cleanup;
- }
- }
- BKE_imbuf_stamp_info(rr, ibuf);
- }
-
- /* fancy multiview OpenEXR */
- if (imf->views_format == R_IMF_VIEWS_MULTIVIEW && is_exr_rr) {
- /* save render result */
- ok = RE_WriteRenderResult(op->reports, rr, simopts->filepath, imf, NULL, layer);
- save_image_post(bmain, op, ibuf, ima, ok, true, relbase, relative, do_newpath, simopts->filepath);
- ED_space_image_release_buffer(sima, ibuf, lock);
- }
- /* regular mono pipeline */
- else if (is_mono) {
- if (is_exr_rr) {
- ok = RE_WriteRenderResult(op->reports, rr, simopts->filepath, imf, NULL, layer);
- }
- else {
- colormanaged_ibuf = IMB_colormanagement_imbuf_for_write(ibuf, save_as_render, true, &imf->view_settings, &imf->display_settings, imf);
- ok = BKE_imbuf_write_as(colormanaged_ibuf, simopts->filepath, imf, save_copy);
- save_imbuf_post(ibuf, colormanaged_ibuf);
- }
- save_image_post(bmain, op, ibuf, ima, ok, (is_exr_rr ? true : save_copy), relbase, relative, do_newpath, simopts->filepath);
- ED_space_image_release_buffer(sima, ibuf, lock);
- }
- /* individual multiview images */
- else if (imf->views_format == R_IMF_VIEWS_INDIVIDUAL) {
- int i;
- unsigned char planes = ibuf->planes;
- const int totviews = (rr ? BLI_listbase_count(&rr->views) : BLI_listbase_count(&ima->views));
-
- if (!is_exr_rr) {
- ED_space_image_release_buffer(sima, ibuf, lock);
- }
-
- for (i = 0; i < totviews; i++) {
- char filepath[FILE_MAX];
- bool ok_view = false;
- const char *view = rr ? ((RenderView *) BLI_findlink(&rr->views, i))->name :
- ((ImageView *) BLI_findlink(&ima->views, i))->name;
-
- if (is_exr_rr) {
- BKE_scene_multiview_view_filepath_get(&scene->r, simopts->filepath, view, filepath);
- ok_view = RE_WriteRenderResult(op->reports, rr, filepath, imf, view, layer);
- save_image_post(bmain, op, ibuf, ima, ok_view, true, relbase, relative, do_newpath, filepath);
- }
- else {
- /* copy iuser to get the correct ibuf for this view */
- ImageUser iuser = sima->iuser;
- iuser.view = i;
- iuser.flag &= ~IMA_SHOW_STEREO;
-
- if (rr) {
- BKE_image_multilayer_index(rr, &iuser);
- }
- else {
- BKE_image_multiview_index(ima, &iuser);
- }
-
- ibuf = BKE_image_acquire_ibuf(sima->image, &iuser, &lock);
- ibuf->planes = planes;
-
- BKE_scene_multiview_view_filepath_get(&scene->r, simopts->filepath, view, filepath);
-
- colormanaged_ibuf = IMB_colormanagement_imbuf_for_write(ibuf, save_as_render, true, &imf->view_settings, &imf->display_settings, imf);
- ok_view = BKE_imbuf_write_as(colormanaged_ibuf, filepath, &simopts->im_format, save_copy);
- save_imbuf_post(ibuf, colormanaged_ibuf);
- save_image_post(bmain, op, ibuf, ima, ok_view, true, relbase, relative, do_newpath, filepath);
- BKE_image_release_ibuf(sima->image, ibuf, lock);
- }
- ok &= ok_view;
- }
-
- if (is_exr_rr) {
- ED_space_image_release_buffer(sima, ibuf, lock);
- }
- }
- /* stereo (multiview) images */
- else if (simopts->im_format.views_format == R_IMF_VIEWS_STEREO_3D) {
- if (imf->imtype == R_IMF_IMTYPE_MULTILAYER) {
- ok = RE_WriteRenderResult(op->reports, rr, simopts->filepath, imf, NULL, layer);
- save_image_post(bmain, op, ibuf, ima, ok, true, relbase, relative, do_newpath, simopts->filepath);
- ED_space_image_release_buffer(sima, ibuf, lock);
- }
- else {
- ImBuf *ibuf_stereo[2] = {NULL};
-
- unsigned char planes = ibuf->planes;
- const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME};
- int i;
-
- /* we need to get the specific per-view buffers */
- ED_space_image_release_buffer(sima, ibuf, lock);
-
- for (i = 0; i < 2; i ++) {
- ImageUser iuser = sima->iuser;
- iuser.flag &= ~IMA_SHOW_STEREO;
-
- if (rr) {
- int id = BLI_findstringindex(&rr->views, names[i], offsetof(RenderView, name));
- iuser.view = id;
- BKE_image_multilayer_index(rr, &iuser);
- }
- else {
- iuser.view = i;
- BKE_image_multiview_index(ima, &iuser);
- }
-
- ibuf = BKE_image_acquire_ibuf(sima->image, &iuser, &lock);
-
- if (ibuf == NULL) {
- BKE_report(op->reports, RPT_ERROR, "Did not write, unexpected error when saving stereo image");
- goto cleanup;
- }
-
- ibuf->planes = planes;
-
- /* color manage the ImBuf leaving it ready for saving */
- colormanaged_ibuf = IMB_colormanagement_imbuf_for_write(ibuf, save_as_render, true,
- &imf->view_settings, &imf->display_settings, imf);
-
- BKE_imbuf_write_prepare(colormanaged_ibuf, imf);
- IMB_prepare_write_ImBuf(IMB_isfloat(colormanaged_ibuf), colormanaged_ibuf);
-
- /* duplicate buffer to prevent locker issue when using render result */
- ibuf_stereo[i] = IMB_dupImBuf(colormanaged_ibuf);
-
- save_imbuf_post(ibuf, colormanaged_ibuf);
- BKE_image_release_ibuf(sima->image, ibuf, lock);
- }
-
- ibuf = IMB_stereo3d_ImBuf(imf, ibuf_stereo[0], ibuf_stereo[1]);
-
- /* save via traditional path */
- ok = BKE_imbuf_write_as(ibuf, simopts->filepath, imf, save_copy);
-
- IMB_freeImBuf(ibuf);
-
- for (i = 0; i < 2; i ++) {
- IMB_freeImBuf(ibuf_stereo[i]);
- }
- }
- }
-
- WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, sima->image);
-
- }
- else {
-cleanup:
- ED_space_image_release_buffer(sima, ibuf, lock);
- }
-
- if (rr) {
- BKE_image_release_renderresult(scene, ima);
- }
-
- WM_cursor_wait(0);
-
- return ok;
+static bool save_image_doit(
+ bContext *C, SpaceImage *sima, wmOperator *op, SaveImageOptions *simopts, bool do_newpath)
+{
+ Main *bmain = CTX_data_main(C);
+ Image *ima = ED_space_image(sima);
+ void *lock;
+ ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
+ Scene *scene;
+ RenderResult *rr = NULL;
+ bool ok = false;
+
+ WM_cursor_wait(1);
+
+ if (ibuf) {
+ ImBuf *colormanaged_ibuf = NULL;
+ const char *relbase = ID_BLEND_PATH(CTX_data_main(C), &ima->id);
+ const bool relative = (RNA_struct_find_property(op->ptr, "relative_path") &&
+ RNA_boolean_get(op->ptr, "relative_path"));
+ const bool save_copy = (RNA_struct_find_property(op->ptr, "copy") &&
+ RNA_boolean_get(op->ptr, "copy"));
+ const bool save_as_render = (RNA_struct_find_property(op->ptr, "save_as_render") &&
+ RNA_boolean_get(op->ptr, "save_as_render"));
+ ImageFormatData *imf = &simopts->im_format;
+
+ /* old global to ensure a 2nd save goes to same dir */
+ BLI_strncpy(G.ima, simopts->filepath, sizeof(G.ima));
+
+ if (ima->type == IMA_TYPE_R_RESULT) {
+ /* enforce user setting for RGB or RGBA, but skip BW */
+ if (simopts->im_format.planes == R_IMF_PLANES_RGBA) {
+ ibuf->planes = R_IMF_PLANES_RGBA;
+ }
+ else if (simopts->im_format.planes == R_IMF_PLANES_RGB) {
+ ibuf->planes = R_IMF_PLANES_RGB;
+ }
+ }
+ else {
+ /* TODO, better solution, if a 24bit image is painted onto it may contain alpha */
+ if ((simopts->im_format.planes == R_IMF_PLANES_RGBA) &&
+ /* it has been painted onto */
+ (ibuf->userflags & IB_BITMAPDIRTY)) {
+ /* checks each pixel, not ideal */
+ ibuf->planes = BKE_imbuf_alpha_test(ibuf) ? R_IMF_PLANES_RGBA : R_IMF_PLANES_RGB;
+ }
+ }
+
+ /* we need renderresult for exr and rendered multiview */
+ scene = CTX_data_scene(C);
+ rr = BKE_image_acquire_renderresult(scene, ima);
+ bool is_mono = rr ? BLI_listbase_count_at_most(&rr->views, 2) < 2 :
+ BLI_listbase_count_at_most(&ima->views, 2) < 2;
+ bool is_exr_rr = rr && ELEM(imf->imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER) &&
+ RE_HasFloatPixels(rr);
+ bool is_multilayer = is_exr_rr && (imf->imtype == R_IMF_IMTYPE_MULTILAYER);
+ int layer = (is_multilayer) ? -1 : sima->iuser.layer;
+
+ /* error handling */
+ if (!rr) {
+ if (imf->imtype == R_IMF_IMTYPE_MULTILAYER) {
+ BKE_report(op->reports, RPT_ERROR, "Did not write, no Multilayer Image");
+ goto cleanup;
+ }
+ }
+ else {
+ if (imf->views_format == R_IMF_VIEWS_STEREO_3D) {
+ if (!BKE_image_is_stereo(ima)) {
+ BKE_reportf(op->reports,
+ RPT_ERROR,
+ "Did not write, the image doesn't have a \"%s\" and \"%s\" views",
+ STEREO_LEFT_NAME,
+ STEREO_RIGHT_NAME);
+ goto cleanup;
+ }
+
+ /* it shouldn't ever happen*/
+ if ((BLI_findstring(&rr->views, STEREO_LEFT_NAME, offsetof(RenderView, name)) == NULL) ||
+ (BLI_findstring(&rr->views, STEREO_RIGHT_NAME, offsetof(RenderView, name)) == NULL)) {
+ BKE_reportf(op->reports,
+ RPT_ERROR,
+ "Did not write, the image doesn't have a \"%s\" and \"%s\" views",
+ STEREO_LEFT_NAME,
+ STEREO_RIGHT_NAME);
+ goto cleanup;
+ }
+ }
+ BKE_imbuf_stamp_info(rr, ibuf);
+ }
+
+ /* fancy multiview OpenEXR */
+ if (imf->views_format == R_IMF_VIEWS_MULTIVIEW && is_exr_rr) {
+ /* save render result */
+ ok = RE_WriteRenderResult(op->reports, rr, simopts->filepath, imf, NULL, layer);
+ save_image_post(
+ bmain, op, ibuf, ima, ok, true, relbase, relative, do_newpath, simopts->filepath);
+ ED_space_image_release_buffer(sima, ibuf, lock);
+ }
+ /* regular mono pipeline */
+ else if (is_mono) {
+ if (is_exr_rr) {
+ ok = RE_WriteRenderResult(op->reports, rr, simopts->filepath, imf, NULL, layer);
+ }
+ else {
+ colormanaged_ibuf = IMB_colormanagement_imbuf_for_write(
+ ibuf, save_as_render, true, &imf->view_settings, &imf->display_settings, imf);
+ ok = BKE_imbuf_write_as(colormanaged_ibuf, simopts->filepath, imf, save_copy);
+ save_imbuf_post(ibuf, colormanaged_ibuf);
+ }
+ save_image_post(bmain,
+ op,
+ ibuf,
+ ima,
+ ok,
+ (is_exr_rr ? true : save_copy),
+ relbase,
+ relative,
+ do_newpath,
+ simopts->filepath);
+ ED_space_image_release_buffer(sima, ibuf, lock);
+ }
+ /* individual multiview images */
+ else if (imf->views_format == R_IMF_VIEWS_INDIVIDUAL) {
+ int i;
+ unsigned char planes = ibuf->planes;
+ const int totviews = (rr ? BLI_listbase_count(&rr->views) : BLI_listbase_count(&ima->views));
+
+ if (!is_exr_rr) {
+ ED_space_image_release_buffer(sima, ibuf, lock);
+ }
+
+ for (i = 0; i < totviews; i++) {
+ char filepath[FILE_MAX];
+ bool ok_view = false;
+ const char *view = rr ? ((RenderView *)BLI_findlink(&rr->views, i))->name :
+ ((ImageView *)BLI_findlink(&ima->views, i))->name;
+
+ if (is_exr_rr) {
+ BKE_scene_multiview_view_filepath_get(&scene->r, simopts->filepath, view, filepath);
+ ok_view = RE_WriteRenderResult(op->reports, rr, filepath, imf, view, layer);
+ save_image_post(
+ bmain, op, ibuf, ima, ok_view, true, relbase, relative, do_newpath, filepath);
+ }
+ else {
+ /* copy iuser to get the correct ibuf for this view */
+ ImageUser iuser = sima->iuser;
+ iuser.view = i;
+ iuser.flag &= ~IMA_SHOW_STEREO;
+
+ if (rr) {
+ BKE_image_multilayer_index(rr, &iuser);
+ }
+ else {
+ BKE_image_multiview_index(ima, &iuser);
+ }
+
+ ibuf = BKE_image_acquire_ibuf(sima->image, &iuser, &lock);
+ ibuf->planes = planes;
+
+ BKE_scene_multiview_view_filepath_get(&scene->r, simopts->filepath, view, filepath);
+
+ colormanaged_ibuf = IMB_colormanagement_imbuf_for_write(
+ ibuf, save_as_render, true, &imf->view_settings, &imf->display_settings, imf);
+ ok_view = BKE_imbuf_write_as(
+ colormanaged_ibuf, filepath, &simopts->im_format, save_copy);
+ save_imbuf_post(ibuf, colormanaged_ibuf);
+ save_image_post(
+ bmain, op, ibuf, ima, ok_view, true, relbase, relative, do_newpath, filepath);
+ BKE_image_release_ibuf(sima->image, ibuf, lock);
+ }
+ ok &= ok_view;
+ }
+
+ if (is_exr_rr) {
+ ED_space_image_release_buffer(sima, ibuf, lock);
+ }
+ }
+ /* stereo (multiview) images */
+ else if (simopts->im_format.views_format == R_IMF_VIEWS_STEREO_3D) {
+ if (imf->imtype == R_IMF_IMTYPE_MULTILAYER) {
+ ok = RE_WriteRenderResult(op->reports, rr, simopts->filepath, imf, NULL, layer);
+ save_image_post(
+ bmain, op, ibuf, ima, ok, true, relbase, relative, do_newpath, simopts->filepath);
+ ED_space_image_release_buffer(sima, ibuf, lock);
+ }
+ else {
+ ImBuf *ibuf_stereo[2] = {NULL};
+
+ unsigned char planes = ibuf->planes;
+ const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME};
+ int i;
+
+ /* we need to get the specific per-view buffers */
+ ED_space_image_release_buffer(sima, ibuf, lock);
+
+ for (i = 0; i < 2; i++) {
+ ImageUser iuser = sima->iuser;
+ iuser.flag &= ~IMA_SHOW_STEREO;
+
+ if (rr) {
+ int id = BLI_findstringindex(&rr->views, names[i], offsetof(RenderView, name));
+ iuser.view = id;
+ BKE_image_multilayer_index(rr, &iuser);
+ }
+ else {
+ iuser.view = i;
+ BKE_image_multiview_index(ima, &iuser);
+ }
+
+ ibuf = BKE_image_acquire_ibuf(sima->image, &iuser, &lock);
+
+ if (ibuf == NULL) {
+ BKE_report(op->reports,
+ RPT_ERROR,
+ "Did not write, unexpected error when saving stereo image");
+ goto cleanup;
+ }
+
+ ibuf->planes = planes;
+
+ /* color manage the ImBuf leaving it ready for saving */
+ colormanaged_ibuf = IMB_colormanagement_imbuf_for_write(
+ ibuf, save_as_render, true, &imf->view_settings, &imf->display_settings, imf);
+
+ BKE_imbuf_write_prepare(colormanaged_ibuf, imf);
+ IMB_prepare_write_ImBuf(IMB_isfloat(colormanaged_ibuf), colormanaged_ibuf);
+
+ /* duplicate buffer to prevent locker issue when using render result */
+ ibuf_stereo[i] = IMB_dupImBuf(colormanaged_ibuf);
+
+ save_imbuf_post(ibuf, colormanaged_ibuf);
+ BKE_image_release_ibuf(sima->image, ibuf, lock);
+ }
+
+ ibuf = IMB_stereo3d_ImBuf(imf, ibuf_stereo[0], ibuf_stereo[1]);
+
+ /* save via traditional path */
+ ok = BKE_imbuf_write_as(ibuf, simopts->filepath, imf, save_copy);
+
+ IMB_freeImBuf(ibuf);
+
+ for (i = 0; i < 2; i++) {
+ IMB_freeImBuf(ibuf_stereo[i]);
+ }
+ }
+ }
+
+ WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, sima->image);
+ }
+ else {
+ cleanup:
+ ED_space_image_release_buffer(sima, ibuf, lock);
+ }
+
+ if (rr) {
+ BKE_image_release_renderresult(scene, ima);
+ }
+
+ WM_cursor_wait(0);
+
+ return ok;
}
static void image_save_as_free(wmOperator *op)
{
- if (op->customdata) {
- ImageFormatData *im_format = (ImageFormatData *)op->customdata;
- BKE_color_managed_view_settings_free(&im_format->view_settings);
+ if (op->customdata) {
+ ImageFormatData *im_format = (ImageFormatData *)op->customdata;
+ BKE_color_managed_view_settings_free(&im_format->view_settings);
- MEM_freeN(op->customdata);
- op->customdata = NULL;
- }
+ MEM_freeN(op->customdata);
+ op->customdata = NULL;
+ }
}
static int image_save_as_exec(bContext *C, wmOperator *op)
{
- Main *bmain = CTX_data_main(C);
- SpaceImage *sima = CTX_wm_space_image(C);
- SaveImageOptions simopts;
+ Main *bmain = CTX_data_main(C);
+ SpaceImage *sima = CTX_wm_space_image(C);
+ SaveImageOptions simopts;
- save_image_options_defaults(&simopts);
+ save_image_options_defaults(&simopts);
- /* just in case to initialize values,
- * these should be set on invoke or by the caller. */
- save_image_options_init(bmain, &simopts, sima, CTX_data_scene(C), false, false);
+ /* just in case to initialize values,
+ * these should be set on invoke or by the caller. */
+ save_image_options_init(bmain, &simopts, sima, CTX_data_scene(C), false, false);
- save_image_options_from_op(bmain, &simopts, op);
+ save_image_options_from_op(bmain, &simopts, op);
- save_image_doit(C, sima, op, &simopts, true);
+ save_image_doit(C, sima, op, &simopts, true);
- image_save_as_free(op);
- return OPERATOR_FINISHED;
+ image_save_as_free(op);
+ return OPERATOR_FINISHED;
}
-
static bool image_save_as_check(bContext *UNUSED(C), wmOperator *op)
{
- ImageFormatData *imf = op->customdata;
- return WM_operator_filesel_ensure_ext_imtype(op, imf);
+ ImageFormatData *imf = op->customdata;
+ return WM_operator_filesel_ensure_ext_imtype(op, imf);
}
static int image_save_as_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- Main *bmain = CTX_data_main(C);
- SpaceImage *sima = CTX_wm_space_image(C);
- Image *ima = ED_space_image(sima);
- Scene *scene = CTX_data_scene(C);
- SaveImageOptions simopts;
- PropertyRNA *prop;
- const bool save_as_render = ((ima->source == IMA_SRC_VIEWER) || (ima->flag & IMA_VIEW_AS_RENDER));
+ Main *bmain = CTX_data_main(C);
+ SpaceImage *sima = CTX_wm_space_image(C);
+ Image *ima = ED_space_image(sima);
+ Scene *scene = CTX_data_scene(C);
+ SaveImageOptions simopts;
+ PropertyRNA *prop;
+ const bool save_as_render = ((ima->source == IMA_SRC_VIEWER) ||
+ (ima->flag & IMA_VIEW_AS_RENDER));
- if (RNA_struct_property_is_set(op->ptr, "filepath")) {
- return image_save_as_exec(C, op);
- }
+ if (RNA_struct_property_is_set(op->ptr, "filepath")) {
+ return image_save_as_exec(C, op);
+ }
- save_image_options_defaults(&simopts);
+ save_image_options_defaults(&simopts);
- if (save_image_options_init(bmain, &simopts, sima, scene, true, save_as_render) == 0) {
- return OPERATOR_CANCELLED;
- }
- save_image_options_to_op(&simopts, op);
+ if (save_image_options_init(bmain, &simopts, sima, scene, true, save_as_render) == 0) {
+ return OPERATOR_CANCELLED;
+ }
+ save_image_options_to_op(&simopts, op);
- /* enable save_copy by default for render results */
- if (ELEM(ima->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE) && !RNA_struct_property_is_set(op->ptr, "copy")) {
- RNA_boolean_set(op->ptr, "copy", true);
- }
+ /* enable save_copy by default for render results */
+ if (ELEM(ima->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE) &&
+ !RNA_struct_property_is_set(op->ptr, "copy")) {
+ RNA_boolean_set(op->ptr, "copy", true);
+ }
- RNA_boolean_set(op->ptr, "save_as_render", save_as_render);
+ RNA_boolean_set(op->ptr, "save_as_render", save_as_render);
- op->customdata = MEM_mallocN(sizeof(simopts.im_format), __func__);
- memcpy(op->customdata, &simopts.im_format, sizeof(simopts.im_format));
+ op->customdata = MEM_mallocN(sizeof(simopts.im_format), __func__);
+ memcpy(op->customdata, &simopts.im_format, sizeof(simopts.im_format));
- /* show multiview save options only if image has multiviews */
- prop = RNA_struct_find_property(op->ptr, "show_multiview");
- RNA_property_boolean_set(op->ptr, prop, BKE_image_is_multiview(ima));
- prop = RNA_struct_find_property(op->ptr, "use_multiview");
- RNA_property_boolean_set(op->ptr, prop, BKE_image_is_multiview(ima));
+ /* show multiview save options only if image has multiviews */
+ prop = RNA_struct_find_property(op->ptr, "show_multiview");
+ RNA_property_boolean_set(op->ptr, prop, BKE_image_is_multiview(ima));
+ prop = RNA_struct_find_property(op->ptr, "use_multiview");
+ RNA_property_boolean_set(op->ptr, prop, BKE_image_is_multiview(ima));
- image_filesel(C, op, simopts.filepath);
+ image_filesel(C, op, simopts.filepath);
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
static void image_save_as_cancel(bContext *UNUSED(C), wmOperator *op)
{
- image_save_as_free(op);
+ image_save_as_free(op);
}
-static bool image_save_as_draw_check_prop(PointerRNA *ptr, PropertyRNA *prop, void *UNUSED(user_data))
+static bool image_save_as_draw_check_prop(PointerRNA *ptr,
+ PropertyRNA *prop,
+ void *UNUSED(user_data))
{
- const char *prop_id = RNA_property_identifier(prop);
+ const char *prop_id = RNA_property_identifier(prop);
- return !(STREQ(prop_id, "filepath") ||
- STREQ(prop_id, "directory") ||
- STREQ(prop_id, "filename") ||
- /* when saving a copy, relative path has no effect */
- ((STREQ(prop_id, "relative_path")) && RNA_boolean_get(ptr, "copy"))
- );
+ return !(STREQ(prop_id, "filepath") || STREQ(prop_id, "directory") ||
+ STREQ(prop_id, "filename") ||
+ /* when saving a copy, relative path has no effect */
+ ((STREQ(prop_id, "relative_path")) && RNA_boolean_get(ptr, "copy")));
}
static void image_save_as_draw(bContext *UNUSED(C), wmOperator *op)
{
- uiLayout *layout = op->layout;
- ImageFormatData *imf = op->customdata;
- PointerRNA imf_ptr, ptr;
- const bool is_multiview = RNA_boolean_get(op->ptr, "show_multiview");
+ uiLayout *layout = op->layout;
+ ImageFormatData *imf = op->customdata;
+ PointerRNA imf_ptr, ptr;
+ const bool is_multiview = RNA_boolean_get(op->ptr, "show_multiview");
- /* image template */
- RNA_pointer_create(NULL, &RNA_ImageFormatSettings, imf, &imf_ptr);
- uiTemplateImageSettings(layout, &imf_ptr, false);
+ /* image template */
+ RNA_pointer_create(NULL, &RNA_ImageFormatSettings, imf, &imf_ptr);
+ uiTemplateImageSettings(layout, &imf_ptr, false);
- /* main draw call */
- RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
- uiDefAutoButsRNA(layout, &ptr, image_save_as_draw_check_prop, NULL, NULL, UI_BUT_LABEL_ALIGN_NONE, false);
+ /* main draw call */
+ RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
+ uiDefAutoButsRNA(
+ layout, &ptr, image_save_as_draw_check_prop, NULL, NULL, UI_BUT_LABEL_ALIGN_NONE, false);
- /* multiview template */
- if (is_multiview) {
- uiTemplateImageFormatViews(layout, &imf_ptr, op->ptr);
- }
+ /* multiview template */
+ if (is_multiview) {
+ uiTemplateImageFormatViews(layout, &imf_ptr, op->ptr);
+ }
}
static bool image_save_as_poll(bContext *C)
{
- if (space_image_buffer_exists_poll(C)) {
- if (G.is_rendering) {
- /* no need to NULL check here */
- SpaceImage *sima = CTX_wm_space_image(C);
- Image *ima = ED_space_image(sima);
+ if (space_image_buffer_exists_poll(C)) {
+ if (G.is_rendering) {
+ /* no need to NULL check here */
+ SpaceImage *sima = CTX_wm_space_image(C);
+ Image *ima = ED_space_image(sima);
- if (ima->source == IMA_SRC_VIEWER) {
- CTX_wm_operator_poll_msg_set(C, "can't save image while rendering");
- return false;
- }
- }
- return true;
- }
- return false;
+ if (ima->source == IMA_SRC_VIEWER) {
+ CTX_wm_operator_poll_msg_set(C, "can't save image while rendering");
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
}
void IMAGE_OT_save_as(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Save As Image";
- ot->idname = "IMAGE_OT_save_as";
- ot->description = "Save the image with another name and/or settings";
-
- /* api callbacks */
- ot->exec = image_save_as_exec;
- ot->check = image_save_as_check;
- ot->invoke = image_save_as_invoke;
- ot->cancel = image_save_as_cancel;
- ot->ui = image_save_as_draw;
- ot->poll = image_save_as_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- RNA_def_boolean(ot->srna, "save_as_render", 0, "Save As Render", "Apply render part of display transform when saving byte image");
- RNA_def_boolean(ot->srna, "copy", 0, "Copy", "Create a new image file without modifying the current image in blender");
-
- WM_operator_properties_filesel(
- ot, FILE_TYPE_FOLDER | FILE_TYPE_IMAGE | FILE_TYPE_MOVIE, FILE_SPECIAL, FILE_SAVE,
- WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA);
+ /* identifiers */
+ ot->name = "Save As Image";
+ ot->idname = "IMAGE_OT_save_as";
+ ot->description = "Save the image with another name and/or settings";
+
+ /* api callbacks */
+ ot->exec = image_save_as_exec;
+ ot->check = image_save_as_check;
+ ot->invoke = image_save_as_invoke;
+ ot->cancel = image_save_as_cancel;
+ ot->ui = image_save_as_draw;
+ ot->poll = image_save_as_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_boolean(ot->srna,
+ "save_as_render",
+ 0,
+ "Save As Render",
+ "Apply render part of display transform when saving byte image");
+ RNA_def_boolean(ot->srna,
+ "copy",
+ 0,
+ "Copy",
+ "Create a new image file without modifying the current image in blender");
+
+ WM_operator_properties_filesel(ot,
+ FILE_TYPE_FOLDER | FILE_TYPE_IMAGE | FILE_TYPE_MOVIE,
+ FILE_SPECIAL,
+ FILE_SAVE,
+ WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH,
+ FILE_DEFAULTDISPLAY,
+ FILE_SORT_ALPHA);
}
/******************** save image operator ********************/
static int image_save_exec(bContext *C, wmOperator *op)
{
- Main *bmain = CTX_data_main(C);
- SpaceImage *sima = CTX_wm_space_image(C);
- Scene *scene = CTX_data_scene(C);
- SaveImageOptions simopts;
+ Main *bmain = CTX_data_main(C);
+ SpaceImage *sima = CTX_wm_space_image(C);
+ Scene *scene = CTX_data_scene(C);
+ SaveImageOptions simopts;
- save_image_options_defaults(&simopts);
- if (save_image_options_init(bmain, &simopts, sima, scene, false, false) == 0) {
- return OPERATOR_CANCELLED;
- }
- save_image_options_from_op(bmain, &simopts, op);
+ save_image_options_defaults(&simopts);
+ if (save_image_options_init(bmain, &simopts, sima, scene, false, false) == 0) {
+ return OPERATOR_CANCELLED;
+ }
+ save_image_options_from_op(bmain, &simopts, op);
- if (BLI_exists(simopts.filepath) && BLI_file_is_writable(simopts.filepath)) {
- if (save_image_doit(C, sima, op, &simopts, false)) {
- /* report since this can be called from key-shortcuts */
- BKE_reportf(op->reports, RPT_INFO, "Saved Image '%s'", simopts.filepath);
- }
- }
- else {
- BKE_reportf(op->reports, RPT_ERROR, "Cannot save image, path '%s' is not writable", simopts.filepath);
- return OPERATOR_CANCELLED;
- }
+ if (BLI_exists(simopts.filepath) && BLI_file_is_writable(simopts.filepath)) {
+ if (save_image_doit(C, sima, op, &simopts, false)) {
+ /* report since this can be called from key-shortcuts */
+ BKE_reportf(op->reports, RPT_INFO, "Saved Image '%s'", simopts.filepath);
+ }
+ }
+ else {
+ BKE_reportf(
+ op->reports, RPT_ERROR, "Cannot save image, path '%s' is not writable", simopts.filepath);
+ return OPERATOR_CANCELLED;
+ }
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void IMAGE_OT_save(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Save Image";
- ot->idname = "IMAGE_OT_save";
- ot->description = "Save the image with current name and settings";
+ /* identifiers */
+ ot->name = "Save Image";
+ ot->idname = "IMAGE_OT_save";
+ ot->description = "Save the image with current name and settings";
- /* api callbacks */
- ot->exec = image_save_exec;
- ot->poll = space_image_file_exists_poll;
+ /* api callbacks */
+ ot->exec = image_save_exec;
+ ot->poll = space_image_file_exists_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/******************* save sequence operator ********************/
static int image_save_sequence_exec(bContext *C, wmOperator *op)
{
- Main *bmain = CTX_data_main(C);
- SpaceImage *sima = CTX_wm_space_image(C);
- ImBuf *ibuf, *first_ibuf = NULL;
- int tot = 0;
- char di[FILE_MAX];
- struct MovieCacheIter *iter;
-
- if (sima->image == NULL) {
- return OPERATOR_CANCELLED;
- }
-
- if (sima->image->source != IMA_SRC_SEQUENCE) {
- BKE_report(op->reports, RPT_ERROR, "Can only save sequence on image sequences");
- return OPERATOR_CANCELLED;
- }
-
- if (sima->image->type == IMA_TYPE_MULTILAYER) {
- BKE_report(op->reports, RPT_ERROR, "Cannot save multilayer sequences");
- return OPERATOR_CANCELLED;
- }
-
- /* get total dirty buffers and first dirty buffer which is used for menu */
- ibuf = NULL;
- if (sima->image->cache != NULL) {
- iter = IMB_moviecacheIter_new(sima->image->cache);
- while (!IMB_moviecacheIter_done(iter)) {
- ibuf = IMB_moviecacheIter_getImBuf(iter);
- if (ibuf->userflags & IB_BITMAPDIRTY) {
- if (first_ibuf == NULL) {
- first_ibuf = ibuf;
- }
- tot++;
- }
- IMB_moviecacheIter_step(iter);
- }
- IMB_moviecacheIter_free(iter);
- }
-
- if (tot == 0) {
- BKE_report(op->reports, RPT_WARNING, "No images have been changed");
- return OPERATOR_CANCELLED;
- }
-
- /* get a filename for menu */
- BLI_split_dir_part(first_ibuf->name, di, sizeof(di));
- BKE_reportf(op->reports, RPT_INFO, "%d image(s) will be saved in %s", tot, di);
-
- iter = IMB_moviecacheIter_new(sima->image->cache);
- while (!IMB_moviecacheIter_done(iter)) {
- ibuf = IMB_moviecacheIter_getImBuf(iter);
-
- if (ibuf->userflags & IB_BITMAPDIRTY) {
- char name[FILE_MAX];
- BLI_strncpy(name, ibuf->name, sizeof(name));
-
- BLI_path_abs(name, BKE_main_blendfile_path(bmain));
-
- if (0 == IMB_saveiff(ibuf, name, IB_rect | IB_zbuf | IB_zbuffloat)) {
- BKE_reportf(op->reports, RPT_ERROR, "Could not write image: %s", strerror(errno));
- break;
- }
-
- BKE_reportf(op->reports, RPT_INFO, "Saved %s", ibuf->name);
- ibuf->userflags &= ~IB_BITMAPDIRTY;
- }
-
- IMB_moviecacheIter_step(iter);
- }
- IMB_moviecacheIter_free(iter);
-
- return OPERATOR_FINISHED;
+ Main *bmain = CTX_data_main(C);
+ SpaceImage *sima = CTX_wm_space_image(C);
+ ImBuf *ibuf, *first_ibuf = NULL;
+ int tot = 0;
+ char di[FILE_MAX];
+ struct MovieCacheIter *iter;
+
+ if (sima->image == NULL) {
+ return OPERATOR_CANCELLED;
+ }
+
+ if (sima->image->source != IMA_SRC_SEQUENCE) {
+ BKE_report(op->reports, RPT_ERROR, "Can only save sequence on image sequences");
+ return OPERATOR_CANCELLED;
+ }
+
+ if (sima->image->type == IMA_TYPE_MULTILAYER) {
+ BKE_report(op->reports, RPT_ERROR, "Cannot save multilayer sequences");
+ return OPERATOR_CANCELLED;
+ }
+
+ /* get total dirty buffers and first dirty buffer which is used for menu */
+ ibuf = NULL;
+ if (sima->image->cache != NULL) {
+ iter = IMB_moviecacheIter_new(sima->image->cache);
+ while (!IMB_moviecacheIter_done(iter)) {
+ ibuf = IMB_moviecacheIter_getImBuf(iter);
+ if (ibuf->userflags & IB_BITMAPDIRTY) {
+ if (first_ibuf == NULL) {
+ first_ibuf = ibuf;
+ }
+ tot++;
+ }
+ IMB_moviecacheIter_step(iter);
+ }
+ IMB_moviecacheIter_free(iter);
+ }
+
+ if (tot == 0) {
+ BKE_report(op->reports, RPT_WARNING, "No images have been changed");
+ return OPERATOR_CANCELLED;
+ }
+
+ /* get a filename for menu */
+ BLI_split_dir_part(first_ibuf->name, di, sizeof(di));
+ BKE_reportf(op->reports, RPT_INFO, "%d image(s) will be saved in %s", tot, di);
+
+ iter = IMB_moviecacheIter_new(sima->image->cache);
+ while (!IMB_moviecacheIter_done(iter)) {
+ ibuf = IMB_moviecacheIter_getImBuf(iter);
+
+ if (ibuf->userflags & IB_BITMAPDIRTY) {
+ char name[FILE_MAX];
+ BLI_strncpy(name, ibuf->name, sizeof(name));
+
+ BLI_path_abs(name, BKE_main_blendfile_path(bmain));
+
+ if (0 == IMB_saveiff(ibuf, name, IB_rect | IB_zbuf | IB_zbuffloat)) {
+ BKE_reportf(op->reports, RPT_ERROR, "Could not write image: %s", strerror(errno));
+ break;
+ }
+
+ BKE_reportf(op->reports, RPT_INFO, "Saved %s", ibuf->name);
+ ibuf->userflags &= ~IB_BITMAPDIRTY;
+ }
+
+ IMB_moviecacheIter_step(iter);
+ }
+ IMB_moviecacheIter_free(iter);
+
+ return OPERATOR_FINISHED;
}
void IMAGE_OT_save_sequence(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Save Sequence";
- ot->idname = "IMAGE_OT_save_sequence";
- ot->description = "Save a sequence of images";
+ /* identifiers */
+ ot->name = "Save Sequence";
+ ot->idname = "IMAGE_OT_save_sequence";
+ ot->description = "Save a sequence of images";
- /* api callbacks */
- ot->exec = image_save_sequence_exec;
- ot->poll = space_image_buffer_exists_poll;
+ /* api callbacks */
+ ot->exec = image_save_sequence_exec;
+ ot->poll = space_image_buffer_exists_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/******************** reload image operator ********************/
static int image_reload_exec(bContext *C, wmOperator *UNUSED(op))
{
- Main *bmain = CTX_data_main(C);
- Image *ima = CTX_data_edit_image(C);
- SpaceImage *sima = CTX_wm_space_image(C);
+ Main *bmain = CTX_data_main(C);
+ Image *ima = CTX_data_edit_image(C);
+ SpaceImage *sima = CTX_wm_space_image(C);
- if (!ima) {
- return OPERATOR_CANCELLED;
- }
+ if (!ima) {
+ return OPERATOR_CANCELLED;
+ }
- /* XXX unpackImage frees image buffers */
- ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
+ /* XXX unpackImage frees image buffers */
+ ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
- BKE_image_signal(bmain, ima, (sima) ? &sima->iuser : NULL, IMA_SIGNAL_RELOAD);
- DEG_id_tag_update(&ima->id, 0);
+ BKE_image_signal(bmain, ima, (sima) ? &sima->iuser : NULL, IMA_SIGNAL_RELOAD);
+ DEG_id_tag_update(&ima->id, 0);
- WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
+ WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void IMAGE_OT_reload(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Reload Image";
- ot->idname = "IMAGE_OT_reload";
- ot->description = "Reload current image from disk";
+ /* identifiers */
+ ot->name = "Reload Image";
+ ot->idname = "IMAGE_OT_reload";
+ ot->description = "Reload current image from disk";
- /* api callbacks */
- ot->exec = image_reload_exec;
+ /* api callbacks */
+ ot->exec = image_reload_exec;
- /* flags */
- ot->flag = OPTYPE_REGISTER; /* no undo, image buffer is not handled by undo */
+ /* flags */
+ ot->flag = OPTYPE_REGISTER; /* no undo, image buffer is not handled by undo */
}
/********************** new image operator *********************/
#define IMA_DEF_NAME N_("Untitled")
enum {
- GEN_CONTEXT_NONE = 0,
- GEN_CONTEXT_PAINT_CANVAS = 1,
- GEN_CONTEXT_PAINT_STENCIL = 2,
+ GEN_CONTEXT_NONE = 0,
+ GEN_CONTEXT_PAINT_CANVAS = 1,
+ GEN_CONTEXT_PAINT_STENCIL = 2,
};
typedef struct ImageNewData {
- PropertyPointerRNA pprop;
+ PropertyPointerRNA pprop;
} ImageNewData;
static ImageNewData *image_new_init(bContext *C, wmOperator *op)
{
- if (op->customdata) {
- return op->customdata;
- }
+ if (op->customdata) {
+ return op->customdata;
+ }
- ImageNewData *data = MEM_callocN(sizeof(ImageNewData), __func__);
- UI_context_active_but_prop_get_templateID(C, &data->pprop.ptr, &data->pprop.prop);
- op->customdata = data;
- return data;
+ ImageNewData *data = MEM_callocN(sizeof(ImageNewData), __func__);
+ UI_context_active_but_prop_get_templateID(C, &data->pprop.ptr, &data->pprop.prop);
+ op->customdata = data;
+ return data;
}
static void image_new_free(wmOperator *op)
{
- if (op->customdata) {
- MEM_freeN(op->customdata);
- op->customdata = NULL;
- }
+ if (op->customdata) {
+ MEM_freeN(op->customdata);
+ op->customdata = NULL;
+ }
}
static int image_new_exec(bContext *C, wmOperator *op)
{
- SpaceImage *sima;
- Object *obedit;
- Image *ima;
- Main *bmain;
- PropertyRNA *prop;
- char name_buffer[MAX_ID_NAME - 2];
- const char *name;
- float color[4];
- int width, height, floatbuf, gen_type, alpha;
- int stereo3d;
-
- /* retrieve state */
- sima = CTX_wm_space_image(C);
- obedit = CTX_data_edit_object(C);
- bmain = CTX_data_main(C);
-
- prop = RNA_struct_find_property(op->ptr, "name");
- RNA_property_string_get(op->ptr, prop, name_buffer);
- if (!RNA_property_is_set(op->ptr, prop)) {
- /* Default value, we can translate! */
- name = DATA_(name_buffer);
- }
- else {
- name = name_buffer;
- }
- width = RNA_int_get(op->ptr, "width");
- height = RNA_int_get(op->ptr, "height");
- floatbuf = RNA_boolean_get(op->ptr, "float");
- gen_type = RNA_enum_get(op->ptr, "generated_type");
- RNA_float_get_array(op->ptr, "color", color);
- alpha = RNA_boolean_get(op->ptr, "alpha");
- stereo3d = RNA_boolean_get(op->ptr, "use_stereo_3d");
-
- if (!alpha) {
- color[3] = 1.0f;
- }
-
- ima = BKE_image_add_generated(bmain, width, height, name, alpha ? 32 : 24, floatbuf, gen_type, color, stereo3d);
-
- if (!ima) {
- image_new_free(op);
- return OPERATOR_CANCELLED;
- }
-
- /* hook into UI */
- ImageNewData *data = image_new_init(C, op);
-
- if (data->pprop.prop) {
- /* when creating new ID blocks, use is already 1, but RNA
- * pointer use also increases user, so this compensates it */
- id_us_min(&ima->id);
-
- PointerRNA imaptr;
- RNA_id_pointer_create(&ima->id, &imaptr);
- RNA_property_pointer_set(&data->pprop.ptr, data->pprop.prop, imaptr);
- RNA_property_update(C, &data->pprop.ptr, data->pprop.prop);
- }
- else if (sima) {
- ED_space_image_set(bmain, sima, obedit, ima, false);
- }
-
- BKE_image_signal(bmain, ima, (sima) ? &sima->iuser : NULL, IMA_SIGNAL_USER_NEW_IMAGE);
-
- WM_event_add_notifier(C, NC_IMAGE | NA_ADDED, ima);
-
- image_new_free(op);
-
- return OPERATOR_FINISHED;
+ SpaceImage *sima;
+ Object *obedit;
+ Image *ima;
+ Main *bmain;
+ PropertyRNA *prop;
+ char name_buffer[MAX_ID_NAME - 2];
+ const char *name;
+ float color[4];
+ int width, height, floatbuf, gen_type, alpha;
+ int stereo3d;
+
+ /* retrieve state */
+ sima = CTX_wm_space_image(C);
+ obedit = CTX_data_edit_object(C);
+ bmain = CTX_data_main(C);
+
+ prop = RNA_struct_find_property(op->ptr, "name");
+ RNA_property_string_get(op->ptr, prop, name_buffer);
+ if (!RNA_property_is_set(op->ptr, prop)) {
+ /* Default value, we can translate! */
+ name = DATA_(name_buffer);
+ }
+ else {
+ name = name_buffer;
+ }
+ width = RNA_int_get(op->ptr, "width");
+ height = RNA_int_get(op->ptr, "height");
+ floatbuf = RNA_boolean_get(op->ptr, "float");
+ gen_type = RNA_enum_get(op->ptr, "generated_type");
+ RNA_float_get_array(op->ptr, "color", color);
+ alpha = RNA_boolean_get(op->ptr, "alpha");
+ stereo3d = RNA_boolean_get(op->ptr, "use_stereo_3d");
+
+ if (!alpha) {
+ color[3] = 1.0f;
+ }
+
+ ima = BKE_image_add_generated(
+ bmain, width, height, name, alpha ? 32 : 24, floatbuf, gen_type, color, stereo3d);
+
+ if (!ima) {
+ image_new_free(op);
+ return OPERATOR_CANCELLED;
+ }
+
+ /* hook into UI */
+ ImageNewData *data = image_new_init(C, op);
+
+ if (data->pprop.prop) {
+ /* when creating new ID blocks, use is already 1, but RNA
+ * pointer use also increases user, so this compensates it */
+ id_us_min(&ima->id);
+
+ PointerRNA imaptr;
+ RNA_id_pointer_create(&ima->id, &imaptr);
+ RNA_property_pointer_set(&data->pprop.ptr, data->pprop.prop, imaptr);
+ RNA_property_update(C, &data->pprop.ptr, data->pprop.prop);
+ }
+ else if (sima) {
+ ED_space_image_set(bmain, sima, obedit, ima, false);
+ }
+
+ BKE_image_signal(bmain, ima, (sima) ? &sima->iuser : NULL, IMA_SIGNAL_USER_NEW_IMAGE);
+
+ WM_event_add_notifier(C, NC_IMAGE | NA_ADDED, ima);
+
+ image_new_free(op);
+
+ return OPERATOR_FINISHED;
}
static int image_new_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- /* Get property in advance, it doesn't work after WM_operator_props_dialog_popup. */
- ImageNewData *data;
- op->customdata = data = MEM_callocN(sizeof(ImageNewData), __func__);
- UI_context_active_but_prop_get_templateID(C, &data->pprop.ptr, &data->pprop.prop);
+ /* Get property in advance, it doesn't work after WM_operator_props_dialog_popup. */
+ ImageNewData *data;
+ op->customdata = data = MEM_callocN(sizeof(ImageNewData), __func__);
+ UI_context_active_but_prop_get_templateID(C, &data->pprop.ptr, &data->pprop.prop);
- /* Better for user feedback. */
- RNA_string_set(op->ptr, "name", DATA_(IMA_DEF_NAME));
- return WM_operator_props_dialog_popup(C, op, 300, 100);
+ /* Better for user feedback. */
+ RNA_string_set(op->ptr, "name", DATA_(IMA_DEF_NAME));
+ return WM_operator_props_dialog_popup(C, op, 300, 100);
}
static void image_new_draw(bContext *UNUSED(C), wmOperator *op)
{
- uiLayout *split, *col[2];
- uiLayout *layout = op->layout;
- PointerRNA ptr;
+ uiLayout *split, *col[2];
+ uiLayout *layout = op->layout;
+ PointerRNA ptr;
#if 0
- Scene *scene = CTX_data_scene(C);
- const bool is_multiview = (scene->r.scemode & R_MULTIVIEW) != 0;
+ Scene *scene = CTX_data_scene(C);
+ const bool is_multiview = (scene->r.scemode & R_MULTIVIEW) != 0;
#endif
- RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
+ RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
- /* copy of WM_operator_props_dialog_popup() layout */
+ /* copy of WM_operator_props_dialog_popup() layout */
- split = uiLayoutSplit(layout, 0.5f, false);
- col[0] = uiLayoutColumn(split, false);
- col[1] = uiLayoutColumn(split, false);
+ split = uiLayoutSplit(layout, 0.5f, false);
+ col[0] = uiLayoutColumn(split, false);
+ col[1] = uiLayoutColumn(split, false);
- uiItemL(col[0], IFACE_("Name"), ICON_NONE);
- uiItemR(col[1], &ptr, "name", 0, "", ICON_NONE);
+ uiItemL(col[0], IFACE_("Name"), ICON_NONE);
+ uiItemR(col[1], &ptr, "name", 0, "", ICON_NONE);
- uiItemL(col[0], IFACE_("Width"), ICON_NONE);
- uiItemR(col[1], &ptr, "width", 0, "", ICON_NONE);
+ uiItemL(col[0], IFACE_("Width"), ICON_NONE);
+ uiItemR(col[1], &ptr, "width", 0, "", ICON_NONE);
- uiItemL(col[0], IFACE_("Height"), ICON_NONE);
- uiItemR(col[1], &ptr, "height", 0, "", ICON_NONE);
+ uiItemL(col[0], IFACE_("Height"), ICON_NONE);
+ uiItemR(col[1], &ptr, "height", 0, "", ICON_NONE);
- uiItemL(col[0], IFACE_("Color"), ICON_NONE);
- uiItemR(col[1], &ptr, "color", 0, "", ICON_NONE);
+ uiItemL(col[0], IFACE_("Color"), ICON_NONE);
+ uiItemR(col[1], &ptr, "color", 0, "", ICON_NONE);
- uiItemL(col[0], "", ICON_NONE);
- uiItemR(col[1], &ptr, "alpha", 0, NULL, ICON_NONE);
+ uiItemL(col[0], "", ICON_NONE);
+ uiItemR(col[1], &ptr, "alpha", 0, NULL, ICON_NONE);
- uiItemL(col[0], IFACE_("Generated Type"), ICON_NONE);
- uiItemR(col[1], &ptr, "generated_type", 0, "", ICON_NONE);
+ uiItemL(col[0], IFACE_("Generated Type"), ICON_NONE);
+ uiItemR(col[1], &ptr, "generated_type", 0, "", ICON_NONE);
- uiItemL(col[0], "", ICON_NONE);
- uiItemR(col[1], &ptr, "float", 0, NULL, ICON_NONE);
+ uiItemL(col[0], "", ICON_NONE);
+ uiItemR(col[1], &ptr, "float", 0, NULL, ICON_NONE);
#if 0
- if (is_multiview) {
- uiItemL(col[0], "", ICON_NONE);
- uiItemR(col[1], &ptr, "use_stereo_3d", 0, NULL, ICON_NONE);
- }
+ if (is_multiview) {
+ uiItemL(col[0], "", ICON_NONE);
+ uiItemR(col[1], &ptr, "use_stereo_3d", 0, NULL, ICON_NONE);
+ }
#endif
}
static void image_new_cancel(bContext *UNUSED(C), wmOperator *op)
{
- image_new_free(op);
+ image_new_free(op);
}
void IMAGE_OT_new(wmOperatorType *ot)
{
- PropertyRNA *prop;
- static float default_color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
-
- /* identifiers */
- ot->name = "New Image";
- ot->description = "Create a new image";
- ot->idname = "IMAGE_OT_new";
-
- /* api callbacks */
- ot->exec = image_new_exec;
- ot->invoke = image_new_invoke;
- ot->ui = image_new_draw;
- ot->cancel = image_new_cancel;
-
- /* flags */
- ot->flag = OPTYPE_UNDO;
-
- /* properties */
- RNA_def_string(ot->srna, "name", IMA_DEF_NAME, MAX_ID_NAME - 2, "Name", "Image data-block name");
- prop = RNA_def_int(ot->srna, "width", 1024, 1, INT_MAX, "Width", "Image width", 1, 16384);
- RNA_def_property_subtype(prop, PROP_PIXEL);
- prop = RNA_def_int(ot->srna, "height", 1024, 1, INT_MAX, "Height", "Image height", 1, 16384);
- RNA_def_property_subtype(prop, PROP_PIXEL);
- prop = RNA_def_float_color(ot->srna, "color", 4, NULL, 0.0f, FLT_MAX, "Color", "Default fill color", 0.0f, 1.0f);
- RNA_def_property_subtype(prop, PROP_COLOR_GAMMA);
- RNA_def_property_float_array_default(prop, default_color);
- RNA_def_boolean(ot->srna, "alpha", 1, "Alpha", "Create an image with an alpha channel");
- RNA_def_enum(ot->srna, "generated_type", rna_enum_image_generated_type_items, IMA_GENTYPE_BLANK,
- "Generated Type", "Fill the image with a grid for UV map testing");
- RNA_def_boolean(ot->srna, "float", 0, "32 bit Float", "Create image with 32 bit floating point bit depth");
- RNA_def_property_flag(prop, PROP_HIDDEN);
- prop = RNA_def_boolean(ot->srna, "use_stereo_3d", 0, "Stereo 3D", "Create an image with left and right views");
- RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN);
+ PropertyRNA *prop;
+ static float default_color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
+
+ /* identifiers */
+ ot->name = "New Image";
+ ot->description = "Create a new image";
+ ot->idname = "IMAGE_OT_new";
+
+ /* api callbacks */
+ ot->exec = image_new_exec;
+ ot->invoke = image_new_invoke;
+ ot->ui = image_new_draw;
+ ot->cancel = image_new_cancel;
+
+ /* flags */
+ ot->flag = OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_string(ot->srna, "name", IMA_DEF_NAME, MAX_ID_NAME - 2, "Name", "Image data-block name");
+ prop = RNA_def_int(ot->srna, "width", 1024, 1, INT_MAX, "Width", "Image width", 1, 16384);
+ RNA_def_property_subtype(prop, PROP_PIXEL);
+ prop = RNA_def_int(ot->srna, "height", 1024, 1, INT_MAX, "Height", "Image height", 1, 16384);
+ RNA_def_property_subtype(prop, PROP_PIXEL);
+ prop = RNA_def_float_color(
+ ot->srna, "color", 4, NULL, 0.0f, FLT_MAX, "Color", "Default fill color", 0.0f, 1.0f);
+ RNA_def_property_subtype(prop, PROP_COLOR_GAMMA);
+ RNA_def_property_float_array_default(prop, default_color);
+ RNA_def_boolean(ot->srna, "alpha", 1, "Alpha", "Create an image with an alpha channel");
+ RNA_def_enum(ot->srna,
+ "generated_type",
+ rna_enum_image_generated_type_items,
+ IMA_GENTYPE_BLANK,
+ "Generated Type",
+ "Fill the image with a grid for UV map testing");
+ RNA_def_boolean(
+ ot->srna, "float", 0, "32 bit Float", "Create image with 32 bit floating point bit depth");
+ RNA_def_property_flag(prop, PROP_HIDDEN);
+ prop = RNA_def_boolean(
+ ot->srna, "use_stereo_3d", 0, "Stereo 3D", "Create an image with left and right views");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN);
}
#undef IMA_DEF_NAME
@@ -2620,437 +2765,475 @@ void IMAGE_OT_new(wmOperatorType *ot)
static bool image_invert_poll(bContext *C)
{
- Image *ima = CTX_data_edit_image(C);
+ Image *ima = CTX_data_edit_image(C);
- return BKE_image_has_ibuf(ima, NULL);
+ return BKE_image_has_ibuf(ima, NULL);
}
static int image_invert_exec(bContext *C, wmOperator *op)
{
- Image *ima = CTX_data_edit_image(C);
- ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
- SpaceImage *sima = CTX_wm_space_image(C);
- /* undo is supported only on image paint mode currently */
- bool support_undo = ((sima != NULL) && (sima->mode == SI_MODE_PAINT));
-
- /* flags indicate if this channel should be inverted */
- const bool r = RNA_boolean_get(op->ptr, "invert_r");
- const bool g = RNA_boolean_get(op->ptr, "invert_g");
- const bool b = RNA_boolean_get(op->ptr, "invert_b");
- const bool a = RNA_boolean_get(op->ptr, "invert_a");
-
- size_t i;
-
- if (ibuf == NULL) {
- /* TODO: this should actually never happen, but does for render-results -> cleanup */
- return OPERATOR_CANCELLED;
- }
-
- if (support_undo) {
- ED_image_undo_push_begin(op->type->name, PAINT_MODE_TEXTURE_2D);
- /* not strictly needed, because we only imapaint_dirty_region to invalidate all tiles
- * but better do this right in case someone copies this for a tool that uses partial
- * redraw better */
- ED_imapaint_clear_partial_redraw();
- ED_imapaint_dirty_region(ima, ibuf, 0, 0, ibuf->x, ibuf->y, false);
- }
- /* TODO: make this into an IMB_invert_channels(ibuf,r,g,b,a) method!? */
- if (ibuf->rect_float) {
-
- float *fp = (float *) ibuf->rect_float;
- for (i = ((size_t)ibuf->x) * ibuf->y; i > 0; i--, fp += 4) {
- if (r) { fp[0] = 1.0f - fp[0]; }
- if (g) { fp[1] = 1.0f - fp[1]; }
- if (b) { fp[2] = 1.0f - fp[2]; }
- if (a) { fp[3] = 1.0f - fp[3]; }
- }
-
- if (ibuf->rect) {
- IMB_rect_from_float(ibuf);
- }
- }
- else if (ibuf->rect) {
-
- char *cp = (char *) ibuf->rect;
- for (i = ((size_t)ibuf->x) * ibuf->y; i > 0; i--, cp += 4) {
- if (r) { cp[0] = 255 - cp[0]; }
- if (g) { cp[1] = 255 - cp[1]; }
- if (b) { cp[2] = 255 - cp[2]; }
- if (a) { cp[3] = 255 - cp[3]; }
- }
- }
- else {
- BKE_image_release_ibuf(ima, ibuf, NULL);
- return OPERATOR_CANCELLED;
- }
-
- ibuf->userflags |= IB_BITMAPDIRTY | IB_DISPLAY_BUFFER_INVALID;
-
- if (ibuf->mipmap[0]) {
- ibuf->userflags |= IB_MIPMAP_INVALID;
- }
-
- if (support_undo) {
- ED_image_undo_push_end();
- }
-
- /* force GPU reupload, all image is invalid */
- GPU_free_image(ima);
-
- WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
-
- BKE_image_release_ibuf(ima, ibuf, NULL);
-
- return OPERATOR_FINISHED;
+ Image *ima = CTX_data_edit_image(C);
+ ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
+ SpaceImage *sima = CTX_wm_space_image(C);
+ /* undo is supported only on image paint mode currently */
+ bool support_undo = ((sima != NULL) && (sima->mode == SI_MODE_PAINT));
+
+ /* flags indicate if this channel should be inverted */
+ const bool r = RNA_boolean_get(op->ptr, "invert_r");
+ const bool g = RNA_boolean_get(op->ptr, "invert_g");
+ const bool b = RNA_boolean_get(op->ptr, "invert_b");
+ const bool a = RNA_boolean_get(op->ptr, "invert_a");
+
+ size_t i;
+
+ if (ibuf == NULL) {
+ /* TODO: this should actually never happen, but does for render-results -> cleanup */
+ return OPERATOR_CANCELLED;
+ }
+
+ if (support_undo) {
+ ED_image_undo_push_begin(op->type->name, PAINT_MODE_TEXTURE_2D);
+ /* not strictly needed, because we only imapaint_dirty_region to invalidate all tiles
+ * but better do this right in case someone copies this for a tool that uses partial
+ * redraw better */
+ ED_imapaint_clear_partial_redraw();
+ ED_imapaint_dirty_region(ima, ibuf, 0, 0, ibuf->x, ibuf->y, false);
+ }
+ /* TODO: make this into an IMB_invert_channels(ibuf,r,g,b,a) method!? */
+ if (ibuf->rect_float) {
+
+ float *fp = (float *)ibuf->rect_float;
+ for (i = ((size_t)ibuf->x) * ibuf->y; i > 0; i--, fp += 4) {
+ if (r) {
+ fp[0] = 1.0f - fp[0];
+ }
+ if (g) {
+ fp[1] = 1.0f - fp[1];
+ }
+ if (b) {
+ fp[2] = 1.0f - fp[2];
+ }
+ if (a) {
+ fp[3] = 1.0f - fp[3];
+ }
+ }
+
+ if (ibuf->rect) {
+ IMB_rect_from_float(ibuf);
+ }
+ }
+ else if (ibuf->rect) {
+
+ char *cp = (char *)ibuf->rect;
+ for (i = ((size_t)ibuf->x) * ibuf->y; i > 0; i--, cp += 4) {
+ if (r) {
+ cp[0] = 255 - cp[0];
+ }
+ if (g) {
+ cp[1] = 255 - cp[1];
+ }
+ if (b) {
+ cp[2] = 255 - cp[2];
+ }
+ if (a) {
+ cp[3] = 255 - cp[3];
+ }
+ }
+ }
+ else {
+ BKE_image_release_ibuf(ima, ibuf, NULL);
+ return OPERATOR_CANCELLED;
+ }
+
+ ibuf->userflags |= IB_BITMAPDIRTY | IB_DISPLAY_BUFFER_INVALID;
+
+ if (ibuf->mipmap[0]) {
+ ibuf->userflags |= IB_MIPMAP_INVALID;
+ }
+
+ if (support_undo) {
+ ED_image_undo_push_end();
+ }
+
+ /* force GPU reupload, all image is invalid */
+ GPU_free_image(ima);
+
+ WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
+
+ BKE_image_release_ibuf(ima, ibuf, NULL);
+
+ return OPERATOR_FINISHED;
}
void IMAGE_OT_invert(wmOperatorType *ot)
{
- PropertyRNA *prop;
+ PropertyRNA *prop;
- /* identifiers */
- ot->name = "Invert Channels";
- ot->idname = "IMAGE_OT_invert";
- ot->description = "Invert image's channels";
+ /* identifiers */
+ ot->name = "Invert Channels";
+ ot->idname = "IMAGE_OT_invert";
+ ot->description = "Invert image's channels";
- /* api callbacks */
- ot->exec = image_invert_exec;
- ot->poll = image_invert_poll;
+ /* api callbacks */
+ ot->exec = image_invert_exec;
+ ot->poll = image_invert_poll;
- /* properties */
- prop = RNA_def_boolean(ot->srna, "invert_r", 0, "Red", "Invert Red Channel");
- RNA_def_property_flag(prop, PROP_SKIP_SAVE);
- prop = RNA_def_boolean(ot->srna, "invert_g", 0, "Green", "Invert Green Channel");
- RNA_def_property_flag(prop, PROP_SKIP_SAVE);
- prop = RNA_def_boolean(ot->srna, "invert_b", 0, "Blue", "Invert Blue Channel");
- RNA_def_property_flag(prop, PROP_SKIP_SAVE);
- prop = RNA_def_boolean(ot->srna, "invert_a", 0, "Alpha", "Invert Alpha Channel");
- RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ /* properties */
+ prop = RNA_def_boolean(ot->srna, "invert_r", 0, "Red", "Invert Red Channel");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ prop = RNA_def_boolean(ot->srna, "invert_g", 0, "Green", "Invert Green Channel");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ prop = RNA_def_boolean(ot->srna, "invert_b", 0, "Blue", "Invert Blue Channel");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ prop = RNA_def_boolean(ot->srna, "invert_a", 0, "Alpha", "Invert Alpha Channel");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/********************* pack operator *********************/
static bool image_pack_test(bContext *C, wmOperator *op)
{
- Image *ima = CTX_data_edit_image(C);
- const bool as_png = RNA_boolean_get(op->ptr, "as_png");
+ Image *ima = CTX_data_edit_image(C);
+ const bool as_png = RNA_boolean_get(op->ptr, "as_png");
- if (!ima) {
- return 0;
- }
- if (!as_png && BKE_image_has_packedfile(ima)) {
- return 0;
- }
+ if (!ima) {
+ return 0;
+ }
+ if (!as_png && BKE_image_has_packedfile(ima)) {
+ return 0;
+ }
- if (ima->source == IMA_SRC_SEQUENCE || ima->source == IMA_SRC_MOVIE) {
- BKE_report(op->reports, RPT_ERROR, "Packing movies or image sequences not supported");
- return 0;
- }
+ if (ima->source == IMA_SRC_SEQUENCE || ima->source == IMA_SRC_MOVIE) {
+ BKE_report(op->reports, RPT_ERROR, "Packing movies or image sequences not supported");
+ return 0;
+ }
- return 1;
+ return 1;
}
static int image_pack_exec(bContext *C, wmOperator *op)
{
- struct Main *bmain = CTX_data_main(C);
- Image *ima = CTX_data_edit_image(C);
- ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
- const bool as_png = RNA_boolean_get(op->ptr, "as_png");
+ struct Main *bmain = CTX_data_main(C);
+ Image *ima = CTX_data_edit_image(C);
+ ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
+ const bool as_png = RNA_boolean_get(op->ptr, "as_png");
- if (!image_pack_test(C, op)) {
- return OPERATOR_CANCELLED;
- }
+ if (!image_pack_test(C, op)) {
+ return OPERATOR_CANCELLED;
+ }
- if (!as_png && (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))) {
- BKE_report(op->reports, RPT_ERROR, "Cannot pack edited image from disk, only as internal PNG");
- return OPERATOR_CANCELLED;
- }
+ if (!as_png && (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))) {
+ BKE_report(op->reports, RPT_ERROR, "Cannot pack edited image from disk, only as internal PNG");
+ return OPERATOR_CANCELLED;
+ }
- if (as_png) {
- BKE_image_memorypack(ima);
- }
- else {
- BKE_image_packfiles(op->reports, ima, ID_BLEND_PATH(bmain, &ima->id));
- }
+ if (as_png) {
+ BKE_image_memorypack(ima);
+ }
+ else {
+ BKE_image_packfiles(op->reports, ima, ID_BLEND_PATH(bmain, &ima->id));
+ }
- WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
+ WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
- BKE_image_release_ibuf(ima, ibuf, NULL);
+ BKE_image_release_ibuf(ima, ibuf, NULL);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
static int image_pack_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- Image *ima = CTX_data_edit_image(C);
- ImBuf *ibuf;
- uiPopupMenu *pup;
- uiLayout *layout;
- const bool as_png = RNA_boolean_get(op->ptr, "as_png");
+ Image *ima = CTX_data_edit_image(C);
+ ImBuf *ibuf;
+ uiPopupMenu *pup;
+ uiLayout *layout;
+ const bool as_png = RNA_boolean_get(op->ptr, "as_png");
- if (!image_pack_test(C, op)) {
- return OPERATOR_CANCELLED;
- }
+ if (!image_pack_test(C, op)) {
+ return OPERATOR_CANCELLED;
+ }
- ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
+ ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
- if (!as_png && (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))) {
- pup = UI_popup_menu_begin(C, IFACE_("OK"), ICON_QUESTION);
- layout = UI_popup_menu_layout(pup);
- uiItemBooleanO(layout, IFACE_("Can't pack edited image from disk, pack as internal PNG?"), ICON_NONE,
- op->idname, "as_png", 1);
- UI_popup_menu_end(C, pup);
+ if (!as_png && (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))) {
+ pup = UI_popup_menu_begin(C, IFACE_("OK"), ICON_QUESTION);
+ layout = UI_popup_menu_layout(pup);
+ uiItemBooleanO(layout,
+ IFACE_("Can't pack edited image from disk, pack as internal PNG?"),
+ ICON_NONE,
+ op->idname,
+ "as_png",
+ 1);
+ UI_popup_menu_end(C, pup);
- BKE_image_release_ibuf(ima, ibuf, NULL);
+ BKE_image_release_ibuf(ima, ibuf, NULL);
- return OPERATOR_INTERFACE;
- }
+ return OPERATOR_INTERFACE;
+ }
- BKE_image_release_ibuf(ima, ibuf, NULL);
+ BKE_image_release_ibuf(ima, ibuf, NULL);
- return image_pack_exec(C, op);
+ return image_pack_exec(C, op);
}
void IMAGE_OT_pack(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Pack Image";
- ot->description = "Pack an image as embedded data into the .blend file";
- ot->idname = "IMAGE_OT_pack";
+ /* identifiers */
+ ot->name = "Pack Image";
+ ot->description = "Pack an image as embedded data into the .blend file";
+ ot->idname = "IMAGE_OT_pack";
- /* api callbacks */
- ot->exec = image_pack_exec;
- ot->invoke = image_pack_invoke;
+ /* api callbacks */
+ ot->exec = image_pack_exec;
+ ot->invoke = image_pack_invoke;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
- /* properties */
- RNA_def_boolean(ot->srna, "as_png", 0, "Pack As PNG", "Pack image as lossless PNG");
+ /* properties */
+ RNA_def_boolean(ot->srna, "as_png", 0, "Pack As PNG", "Pack image as lossless PNG");
}
/********************* unpack operator *********************/
static int image_unpack_exec(bContext *C, wmOperator *op)
{
- Image *ima = CTX_data_edit_image(C);
- int method = RNA_enum_get(op->ptr, "method");
+ Image *ima = CTX_data_edit_image(C);
+ int method = RNA_enum_get(op->ptr, "method");
- /* find the suppplied image by name */
- if (RNA_struct_property_is_set(op->ptr, "id")) {
- char imaname[MAX_ID_NAME - 2];
- RNA_string_get(op->ptr, "id", imaname);
- ima = BLI_findstring(&CTX_data_main(C)->images, imaname, offsetof(ID, name) + 2);
- if (!ima) {
- ima = CTX_data_edit_image(C);
- }
- }
+ /* find the suppplied image by name */
+ if (RNA_struct_property_is_set(op->ptr, "id")) {
+ char imaname[MAX_ID_NAME - 2];
+ RNA_string_get(op->ptr, "id", imaname);
+ ima = BLI_findstring(&CTX_data_main(C)->images, imaname, offsetof(ID, name) + 2);
+ if (!ima) {
+ ima = CTX_data_edit_image(C);
+ }
+ }
- if (!ima || !BKE_image_has_packedfile(ima)) {
- return OPERATOR_CANCELLED;
- }
+ if (!ima || !BKE_image_has_packedfile(ima)) {
+ return OPERATOR_CANCELLED;
+ }
- if (ima->source == IMA_SRC_SEQUENCE || ima->source == IMA_SRC_MOVIE) {
- BKE_report(op->reports, RPT_ERROR, "Unpacking movies or image sequences not supported");
- return OPERATOR_CANCELLED;
- }
+ if (ima->source == IMA_SRC_SEQUENCE || ima->source == IMA_SRC_MOVIE) {
+ BKE_report(op->reports, RPT_ERROR, "Unpacking movies or image sequences not supported");
+ return OPERATOR_CANCELLED;
+ }
- if (G.fileflags & G_FILE_AUTOPACK) {
- BKE_report(op->reports, RPT_WARNING, "AutoPack is enabled, so image will be packed again on file save");
- }
+ if (G.fileflags & G_FILE_AUTOPACK) {
+ BKE_report(op->reports,
+ RPT_WARNING,
+ "AutoPack is enabled, so image will be packed again on file save");
+ }
- /* XXX unpackImage frees image buffers */
- ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
+ /* XXX unpackImage frees image buffers */
+ ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
- unpackImage(CTX_data_main(C), op->reports, ima, method);
+ unpackImage(CTX_data_main(C), op->reports, ima, method);
- WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
+ WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
static int image_unpack_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- Image *ima = CTX_data_edit_image(C);
+ Image *ima = CTX_data_edit_image(C);
- if (RNA_struct_property_is_set(op->ptr, "id")) {
- return image_unpack_exec(C, op);
- }
+ if (RNA_struct_property_is_set(op->ptr, "id")) {
+ return image_unpack_exec(C, op);
+ }
- if (!ima || !BKE_image_has_packedfile(ima)) {
- return OPERATOR_CANCELLED;
- }
+ if (!ima || !BKE_image_has_packedfile(ima)) {
+ return OPERATOR_CANCELLED;
+ }
- if (ima->source == IMA_SRC_SEQUENCE || ima->source == IMA_SRC_MOVIE) {
- BKE_report(op->reports, RPT_ERROR, "Unpacking movies or image sequences not supported");
- return OPERATOR_CANCELLED;
- }
+ if (ima->source == IMA_SRC_SEQUENCE || ima->source == IMA_SRC_MOVIE) {
+ BKE_report(op->reports, RPT_ERROR, "Unpacking movies or image sequences not supported");
+ return OPERATOR_CANCELLED;
+ }
- if (G.fileflags & G_FILE_AUTOPACK) {
- BKE_report(op->reports, RPT_WARNING, "AutoPack is enabled, so image will be packed again on file save");
- }
+ if (G.fileflags & G_FILE_AUTOPACK) {
+ BKE_report(op->reports,
+ RPT_WARNING,
+ "AutoPack is enabled, so image will be packed again on file save");
+ }
- unpack_menu(C, "IMAGE_OT_unpack", ima->id.name + 2, ima->name, "textures", BKE_image_has_packedfile(ima) ? ((ImagePackedFile *)ima->packedfiles.first)->packedfile : NULL);
+ unpack_menu(C,
+ "IMAGE_OT_unpack",
+ ima->id.name + 2,
+ ima->name,
+ "textures",
+ BKE_image_has_packedfile(ima) ?
+ ((ImagePackedFile *)ima->packedfiles.first)->packedfile :
+ NULL);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void IMAGE_OT_unpack(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Unpack Image";
- ot->description = "Save an image packed in the .blend file to disk";
- ot->idname = "IMAGE_OT_unpack";
+ /* identifiers */
+ ot->name = "Unpack Image";
+ ot->description = "Save an image packed in the .blend file to disk";
+ ot->idname = "IMAGE_OT_unpack";
- /* api callbacks */
- ot->exec = image_unpack_exec;
- ot->invoke = image_unpack_invoke;
+ /* api callbacks */
+ ot->exec = image_unpack_exec;
+ ot->invoke = image_unpack_invoke;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
- /* properties */
- RNA_def_enum(ot->srna, "method", rna_enum_unpack_method_items, PF_USE_LOCAL, "Method", "How to unpack");
- /* XXX, weak!, will fail with library, name collisions */
- RNA_def_string(ot->srna, "id", NULL, MAX_ID_NAME - 2, "Image Name", "Image data-block name to unpack");
+ /* properties */
+ RNA_def_enum(
+ ot->srna, "method", rna_enum_unpack_method_items, PF_USE_LOCAL, "Method", "How to unpack");
+ /* XXX, weak!, will fail with library, name collisions */
+ RNA_def_string(
+ ot->srna, "id", NULL, MAX_ID_NAME - 2, "Image Name", "Image data-block name to unpack");
}
/******************** sample image operator ********************/
typedef struct ImageSampleInfo {
- ARegionType *art;
- void *draw_handle;
- int x, y;
- int channels;
-
- int width, height;
- int sample_size;
-
- unsigned char col[4];
- float colf[4];
- float linearcol[4];
- int z;
- float zf;
-
- unsigned char *colp;
- const float *colfp;
- int *zp;
- float *zfp;
-
- bool draw;
- bool color_manage;
- int use_default_view;
+ ARegionType *art;
+ void *draw_handle;
+ int x, y;
+ int channels;
+
+ int width, height;
+ int sample_size;
+
+ unsigned char col[4];
+ float colf[4];
+ float linearcol[4];
+ int z;
+ float zf;
+
+ unsigned char *colp;
+ const float *colfp;
+ int *zp;
+ float *zfp;
+
+ bool draw;
+ bool color_manage;
+ int use_default_view;
} ImageSampleInfo;
static void image_sample_draw(const bContext *C, ARegion *ar, void *arg_info)
{
- ImageSampleInfo *info = arg_info;
- if (!info->draw) {
- return;
- }
-
- Scene *scene = CTX_data_scene(C);
- ED_image_draw_info(
- scene, ar, info->color_manage, info->use_default_view, info->channels,
- info->x, info->y, info->colp, info->colfp, info->linearcol, info->zp, info->zfp);
-
- if (info->sample_size > 1) {
- const wmWindow *win = CTX_wm_window(C);
- const wmEvent *event = win->eventstate;
-
- SpaceImage *sima = CTX_wm_space_image(C);
- GPUVertFormat *format = immVertexFormat();
- uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
-
- const float color[3] = {1, 1, 1};
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- immUniformColor3fv(color);
-
- /* TODO(campbell): lock to pixels. */
- rctf sample_rect_fl;
- BLI_rctf_init_pt_radius(
- &sample_rect_fl,
- (float[2]){event->x - ar->winrct.xmin, event->y - ar->winrct.ymin},
- (float)(info->sample_size / 2.0f) * sima->zoom);
-
- glEnable(GL_COLOR_LOGIC_OP);
- glLogicOp(GL_XOR);
- imm_draw_box_wire_2d(
- pos,
- (float)sample_rect_fl.xmin,
- (float)sample_rect_fl.ymin,
- (float)sample_rect_fl.xmax,
- (float)sample_rect_fl.ymax);
- glDisable(GL_COLOR_LOGIC_OP);
-
- immUnbindProgram();
- }
+ ImageSampleInfo *info = arg_info;
+ if (!info->draw) {
+ return;
+ }
+
+ Scene *scene = CTX_data_scene(C);
+ ED_image_draw_info(scene,
+ ar,
+ info->color_manage,
+ info->use_default_view,
+ info->channels,
+ info->x,
+ info->y,
+ info->colp,
+ info->colfp,
+ info->linearcol,
+ info->zp,
+ info->zfp);
+
+ if (info->sample_size > 1) {
+ const wmWindow *win = CTX_wm_window(C);
+ const wmEvent *event = win->eventstate;
+
+ SpaceImage *sima = CTX_wm_space_image(C);
+ GPUVertFormat *format = immVertexFormat();
+ uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+
+ const float color[3] = {1, 1, 1};
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor3fv(color);
+
+ /* TODO(campbell): lock to pixels. */
+ rctf sample_rect_fl;
+ BLI_rctf_init_pt_radius(&sample_rect_fl,
+ (float[2]){event->x - ar->winrct.xmin, event->y - ar->winrct.ymin},
+ (float)(info->sample_size / 2.0f) * sima->zoom);
+
+ glEnable(GL_COLOR_LOGIC_OP);
+ glLogicOp(GL_XOR);
+ imm_draw_box_wire_2d(pos,
+ (float)sample_rect_fl.xmin,
+ (float)sample_rect_fl.ymin,
+ (float)sample_rect_fl.xmax,
+ (float)sample_rect_fl.ymax);
+ glDisable(GL_COLOR_LOGIC_OP);
+
+ immUnbindProgram();
+ }
}
/* Returns color in linear space, matching ED_space_node_color_sample(). */
bool ED_space_image_color_sample(SpaceImage *sima, ARegion *ar, int mval[2], float r_col[3])
{
- void *lock;
- ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
- float fx, fy;
- bool ret = false;
+ void *lock;
+ ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
+ float fx, fy;
+ bool ret = false;
- if (ibuf == NULL) {
- ED_space_image_release_buffer(sima, ibuf, lock);
- return false;
- }
+ if (ibuf == NULL) {
+ ED_space_image_release_buffer(sima, ibuf, lock);
+ return false;
+ }
- UI_view2d_region_to_view(&ar->v2d, mval[0], mval[1], &fx, &fy);
+ UI_view2d_region_to_view(&ar->v2d, mval[0], mval[1], &fx, &fy);
- if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) {
- const float *fp;
- unsigned char *cp;
- int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y);
+ if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) {
+ const 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);
+ 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));
- 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);
- IMB_colormanagement_colorspace_to_scene_linear_v3(r_col, ibuf->rect_colorspace);
- ret = true;
- }
- }
+ if (ibuf->rect_float) {
+ fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x));
+ 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);
+ IMB_colormanagement_colorspace_to_scene_linear_v3(r_col, ibuf->rect_colorspace);
+ ret = true;
+ }
+ }
- ED_space_image_release_buffer(sima, ibuf, lock);
- return ret;
+ ED_space_image_release_buffer(sima, ibuf, lock);
+ return ret;
}
-
/* -------------------------------------------------------------------- */
/** \name Image Pixel Sample
* \{ */
-static void image_sample_pixel_color_ubyte(
- const ImBuf *ibuf, const int coord[2],
- uchar r_col[4], float r_col_linear[4])
+static void image_sample_pixel_color_ubyte(const ImBuf *ibuf,
+ const int coord[2],
+ uchar r_col[4],
+ float r_col_linear[4])
{
- const uchar *cp = (unsigned char *)(ibuf->rect + coord[1] * ibuf->x + coord[0]);
- copy_v4_v4_uchar(r_col, cp);
- rgba_uchar_to_float(r_col_linear, r_col);
- IMB_colormanagement_colorspace_to_scene_linear_v4(r_col_linear, false, ibuf->rect_colorspace);
+ const uchar *cp = (unsigned char *)(ibuf->rect + coord[1] * ibuf->x + coord[0]);
+ copy_v4_v4_uchar(r_col, cp);
+ rgba_uchar_to_float(r_col_linear, r_col);
+ IMB_colormanagement_colorspace_to_scene_linear_v4(r_col_linear, false, ibuf->rect_colorspace);
}
-static void image_sample_pixel_color_float(
- ImBuf *ibuf, const int coord[2],
- float r_col[4])
+static void image_sample_pixel_color_float(ImBuf *ibuf, const int coord[2], float r_col[4])
{
- const float *cp = ibuf->rect_float + (ibuf->channels) * (coord[1] * ibuf->x + coord[0]);
- copy_v4_v4(r_col, cp);
+ const float *cp = ibuf->rect_float + (ibuf->channels) * (coord[1] * ibuf->x + coord[0]);
+ copy_v4_v4(r_col, cp);
}
/** \} */
@@ -3059,541 +3242,541 @@ static void image_sample_pixel_color_float(
/** \name Image Pixel Region Sample
* \{ */
-static void image_sample_rect_color_ubyte(
- const ImBuf *ibuf, const rcti *rect,
- uchar r_col[4], float r_col_linear[4])
-{
- uint col_accum_ub[4] = {0, 0, 0, 0};
- zero_v4(r_col_linear);
- int col_tot = 0;
- int coord[2];
- for (coord[0] = rect->xmin; coord[0] <= rect->xmax; coord[0]++) {
- for (coord[1] = rect->ymin; coord[1] <= rect->ymax; coord[1]++) {
- float col_temp_fl[4];
- uchar col_temp_ub[4];
- image_sample_pixel_color_ubyte(ibuf, coord, col_temp_ub, col_temp_fl);
- add_v4_v4(r_col_linear, col_temp_fl);
- col_accum_ub[0] += (uint)col_temp_ub[0];
- col_accum_ub[1] += (uint)col_temp_ub[1];
- col_accum_ub[2] += (uint)col_temp_ub[2];
- col_accum_ub[3] += (uint)col_temp_ub[3];
- col_tot += 1;
- }
- }
- mul_v4_fl(r_col_linear, 1.0 / (float)col_tot);
-
- r_col[0] = MIN2(col_accum_ub[0] / col_tot, 255);
- r_col[1] = MIN2(col_accum_ub[1] / col_tot, 255);
- r_col[2] = MIN2(col_accum_ub[2] / col_tot, 255);
- r_col[3] = MIN2(col_accum_ub[3] / col_tot, 255);
-}
-
-
-static void image_sample_rect_color_float(
- ImBuf *ibuf, const rcti *rect,
- float r_col[4])
-{
- zero_v4(r_col);
- int col_tot = 0;
- int coord[2];
- for (coord[0] = rect->xmin; coord[0] <= rect->xmax; coord[0]++) {
- for (coord[1] = rect->ymin; coord[1] <= rect->ymax; coord[1]++) {
- float col_temp_fl[4];
- image_sample_pixel_color_float(ibuf, coord, col_temp_fl);
- add_v4_v4(r_col, col_temp_fl);
- col_tot += 1;
- }
- }
- mul_v4_fl(r_col, 1.0 / (float)col_tot);
+static void image_sample_rect_color_ubyte(const ImBuf *ibuf,
+ const rcti *rect,
+ uchar r_col[4],
+ float r_col_linear[4])
+{
+ uint col_accum_ub[4] = {0, 0, 0, 0};
+ zero_v4(r_col_linear);
+ int col_tot = 0;
+ int coord[2];
+ for (coord[0] = rect->xmin; coord[0] <= rect->xmax; coord[0]++) {
+ for (coord[1] = rect->ymin; coord[1] <= rect->ymax; coord[1]++) {
+ float col_temp_fl[4];
+ uchar col_temp_ub[4];
+ image_sample_pixel_color_ubyte(ibuf, coord, col_temp_ub, col_temp_fl);
+ add_v4_v4(r_col_linear, col_temp_fl);
+ col_accum_ub[0] += (uint)col_temp_ub[0];
+ col_accum_ub[1] += (uint)col_temp_ub[1];
+ col_accum_ub[2] += (uint)col_temp_ub[2];
+ col_accum_ub[3] += (uint)col_temp_ub[3];
+ col_tot += 1;
+ }
+ }
+ mul_v4_fl(r_col_linear, 1.0 / (float)col_tot);
+
+ r_col[0] = MIN2(col_accum_ub[0] / col_tot, 255);
+ r_col[1] = MIN2(col_accum_ub[1] / col_tot, 255);
+ r_col[2] = MIN2(col_accum_ub[2] / col_tot, 255);
+ r_col[3] = MIN2(col_accum_ub[3] / col_tot, 255);
+}
+
+static void image_sample_rect_color_float(ImBuf *ibuf, const rcti *rect, float r_col[4])
+{
+ zero_v4(r_col);
+ int col_tot = 0;
+ int coord[2];
+ for (coord[0] = rect->xmin; coord[0] <= rect->xmax; coord[0]++) {
+ for (coord[1] = rect->ymin; coord[1] <= rect->ymax; coord[1]++) {
+ float col_temp_fl[4];
+ image_sample_pixel_color_float(ibuf, coord, col_temp_fl);
+ add_v4_v4(r_col, col_temp_fl);
+ col_tot += 1;
+ }
+ }
+ mul_v4_fl(r_col, 1.0 / (float)col_tot);
}
/** \} */
static void image_sample_apply(bContext *C, wmOperator *op, const wmEvent *event)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- ARegion *ar = CTX_wm_region(C);
- void *lock;
- ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
- ImageSampleInfo *info = op->customdata;
- float fx, fy;
- Scene *scene = CTX_data_scene(C);
- CurveMapping *curve_mapping = scene->view_settings.curve_mapping;
-
- if (ibuf == NULL) {
- ED_space_image_release_buffer(sima, ibuf, lock);
- info->draw = false;
- return;
- }
-
- UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fx, &fy);
-
- if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) {
- int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y);
- Image *image = ED_space_image(sima);
-
- CLAMP(x, 0, ibuf->x - 1);
- CLAMP(y, 0, ibuf->y - 1);
-
- info->width = ibuf->x;
- info->height = ibuf->y;
- info->x = x;
- info->y = y;
-
- info->draw = true;
- info->channels = ibuf->channels;
-
- info->colp = NULL;
- info->colfp = NULL;
- info->zp = NULL;
- info->zfp = NULL;
-
- info->use_default_view = (image->flag & IMA_VIEW_AS_RENDER) ? false : true;
-
- rcti sample_rect;
- sample_rect.xmin = max_ii(0, x - info->sample_size / 2);
- sample_rect.ymin = max_ii(0, y - info->sample_size / 2);
- sample_rect.xmax = min_ii(ibuf->x, sample_rect.xmin + info->sample_size) - 1;
- sample_rect.ymax = min_ii(ibuf->y, sample_rect.ymin + info->sample_size) - 1;
-
- if (ibuf->rect) {
- image_sample_rect_color_ubyte(ibuf, &sample_rect, info->col, info->linearcol);
- rgba_uchar_to_float(info->colf, info->col);
-
- info->colp = info->col;
- info->colfp = info->colf;
- info->color_manage = true;
- }
- if (ibuf->rect_float) {
- image_sample_rect_color_float(ibuf, &sample_rect, info->colf);
-
- if (ibuf->channels == 4) {
- /* pass */
- }
- else if (ibuf->channels == 3) {
- info->colf[3] = 1.0f;
- }
- else {
- info->colf[1] = info->colf[0];
- info->colf[2] = info->colf[0];
- info->colf[3] = 1.0f;
- }
- info->colfp = info->colf;
-
- copy_v4_v4(info->linearcol, info->colf);
-
- info->color_manage = true;
- }
-
- if (ibuf->zbuf) {
- /* TODO, blend depth (not urgent). */
- info->z = ibuf->zbuf[y * ibuf->x + x];
- info->zp = &info->z;
- if (ibuf->zbuf == (int *)ibuf->rect) {
- info->colp = NULL;
- }
- }
- if (ibuf->zbuf_float) {
- /* TODO, blend depth (not urgent). */
- info->zf = ibuf->zbuf_float[y * ibuf->x + x];
- info->zfp = &info->zf;
- if (ibuf->zbuf_float == ibuf->rect_float) {
- info->colfp = NULL;
- }
- }
-
- if (curve_mapping && ibuf->channels == 4) {
- /* we reuse this callback for set curves point operators */
- if (RNA_struct_find_property(op->ptr, "point")) {
- int point = RNA_enum_get(op->ptr, "point");
-
- if (point == 1) {
- curvemapping_set_black_white(curve_mapping, NULL, info->linearcol);
- }
- else if (point == 0) {
- curvemapping_set_black_white(curve_mapping, info->linearcol, NULL);
- }
- WM_event_add_notifier(C, NC_WINDOW, NULL);
- }
- }
-
- // XXX node curve integration ..
+ SpaceImage *sima = CTX_wm_space_image(C);
+ ARegion *ar = CTX_wm_region(C);
+ void *lock;
+ ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
+ ImageSampleInfo *info = op->customdata;
+ float fx, fy;
+ Scene *scene = CTX_data_scene(C);
+ CurveMapping *curve_mapping = scene->view_settings.curve_mapping;
+
+ if (ibuf == NULL) {
+ ED_space_image_release_buffer(sima, ibuf, lock);
+ info->draw = false;
+ return;
+ }
+
+ UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fx, &fy);
+
+ if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) {
+ int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y);
+ Image *image = ED_space_image(sima);
+
+ CLAMP(x, 0, ibuf->x - 1);
+ CLAMP(y, 0, ibuf->y - 1);
+
+ info->width = ibuf->x;
+ info->height = ibuf->y;
+ info->x = x;
+ info->y = y;
+
+ info->draw = true;
+ info->channels = ibuf->channels;
+
+ info->colp = NULL;
+ info->colfp = NULL;
+ info->zp = NULL;
+ info->zfp = NULL;
+
+ info->use_default_view = (image->flag & IMA_VIEW_AS_RENDER) ? false : true;
+
+ rcti sample_rect;
+ sample_rect.xmin = max_ii(0, x - info->sample_size / 2);
+ sample_rect.ymin = max_ii(0, y - info->sample_size / 2);
+ sample_rect.xmax = min_ii(ibuf->x, sample_rect.xmin + info->sample_size) - 1;
+ sample_rect.ymax = min_ii(ibuf->y, sample_rect.ymin + info->sample_size) - 1;
+
+ if (ibuf->rect) {
+ image_sample_rect_color_ubyte(ibuf, &sample_rect, info->col, info->linearcol);
+ rgba_uchar_to_float(info->colf, info->col);
+
+ info->colp = info->col;
+ info->colfp = info->colf;
+ info->color_manage = true;
+ }
+ if (ibuf->rect_float) {
+ image_sample_rect_color_float(ibuf, &sample_rect, info->colf);
+
+ if (ibuf->channels == 4) {
+ /* pass */
+ }
+ else if (ibuf->channels == 3) {
+ info->colf[3] = 1.0f;
+ }
+ else {
+ info->colf[1] = info->colf[0];
+ info->colf[2] = info->colf[0];
+ info->colf[3] = 1.0f;
+ }
+ info->colfp = info->colf;
+
+ copy_v4_v4(info->linearcol, info->colf);
+
+ info->color_manage = true;
+ }
+
+ if (ibuf->zbuf) {
+ /* TODO, blend depth (not urgent). */
+ info->z = ibuf->zbuf[y * ibuf->x + x];
+ info->zp = &info->z;
+ if (ibuf->zbuf == (int *)ibuf->rect) {
+ info->colp = NULL;
+ }
+ }
+ if (ibuf->zbuf_float) {
+ /* TODO, blend depth (not urgent). */
+ info->zf = ibuf->zbuf_float[y * ibuf->x + x];
+ info->zfp = &info->zf;
+ if (ibuf->zbuf_float == ibuf->rect_float) {
+ info->colfp = NULL;
+ }
+ }
+
+ if (curve_mapping && ibuf->channels == 4) {
+ /* we reuse this callback for set curves point operators */
+ if (RNA_struct_find_property(op->ptr, "point")) {
+ int point = RNA_enum_get(op->ptr, "point");
+
+ if (point == 1) {
+ curvemapping_set_black_white(curve_mapping, NULL, info->linearcol);
+ }
+ else if (point == 0) {
+ curvemapping_set_black_white(curve_mapping, info->linearcol, NULL);
+ }
+ WM_event_add_notifier(C, NC_WINDOW, NULL);
+ }
+ }
+
+ // XXX node curve integration ..
#if 0
- {
- ScrArea *sa, *cur = curarea;
-
- node_curvemap_sample(fp); /* sends global to node editor */
- for (sa = G.curscreen->areabase.first; sa; sa = sa->next) {
- if (sa->spacetype == SPACE_NODE) {
- areawinset(sa->win);
- scrarea_do_windraw(sa);
- }
- }
- node_curvemap_sample(NULL); /* clears global in node editor */
- curarea = cur;
- }
+ {
+ ScrArea *sa, *cur = curarea;
+
+ node_curvemap_sample(fp); /* sends global to node editor */
+ for (sa = G.curscreen->areabase.first; sa; sa = sa->next) {
+ if (sa->spacetype == SPACE_NODE) {
+ areawinset(sa->win);
+ scrarea_do_windraw(sa);
+ }
+ }
+ node_curvemap_sample(NULL); /* clears global in node editor */
+ curarea = cur;
+ }
#endif
- }
- else {
- info->draw = 0;
- }
+ }
+ else {
+ info->draw = 0;
+ }
- ED_space_image_release_buffer(sima, ibuf, lock);
- ED_area_tag_redraw(CTX_wm_area(C));
+ ED_space_image_release_buffer(sima, ibuf, lock);
+ ED_area_tag_redraw(CTX_wm_area(C));
}
static void image_sample_exit(bContext *C, wmOperator *op)
{
- ImageSampleInfo *info = op->customdata;
+ ImageSampleInfo *info = op->customdata;
- ED_region_draw_cb_exit(info->art, info->draw_handle);
- ED_area_tag_redraw(CTX_wm_area(C));
- MEM_freeN(info);
+ ED_region_draw_cb_exit(info->art, info->draw_handle);
+ ED_area_tag_redraw(CTX_wm_area(C));
+ MEM_freeN(info);
}
static int image_sample_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- ARegion *ar = CTX_wm_region(C);
- ImageSampleInfo *info;
+ SpaceImage *sima = CTX_wm_space_image(C);
+ ARegion *ar = CTX_wm_region(C);
+ ImageSampleInfo *info;
- if (ar->regiontype == RGN_TYPE_WINDOW) {
- if (event->mval[1] <= 16 && ED_space_image_show_cache(sima)) {
- return OPERATOR_PASS_THROUGH;
- }
- }
+ if (ar->regiontype == RGN_TYPE_WINDOW) {
+ if (event->mval[1] <= 16 && ED_space_image_show_cache(sima)) {
+ return OPERATOR_PASS_THROUGH;
+ }
+ }
- if (!ED_space_image_has_buffer(sima)) {
- return OPERATOR_CANCELLED;
- }
+ if (!ED_space_image_has_buffer(sima)) {
+ return OPERATOR_CANCELLED;
+ }
- info = MEM_callocN(sizeof(ImageSampleInfo), "ImageSampleInfo");
+ info = MEM_callocN(sizeof(ImageSampleInfo), "ImageSampleInfo");
- info->art = ar->type;
- info->draw_handle = ED_region_draw_cb_activate(ar->type, image_sample_draw, info, REGION_DRAW_POST_PIXEL);
- info->sample_size = RNA_int_get(op->ptr, "size");
- op->customdata = info;
+ info->art = ar->type;
+ info->draw_handle = ED_region_draw_cb_activate(
+ ar->type, image_sample_draw, info, REGION_DRAW_POST_PIXEL);
+ info->sample_size = RNA_int_get(op->ptr, "size");
+ op->customdata = info;
- image_sample_apply(C, op, event);
+ image_sample_apply(C, op, event);
- WM_event_add_modal_handler(C, op);
+ WM_event_add_modal_handler(C, op);
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
static int image_sample_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
- switch (event->type) {
- case LEFTMOUSE:
- case RIGHTMOUSE: // XXX hardcoded
- if (event->val == KM_RELEASE) {
- image_sample_exit(C, op);
- return OPERATOR_CANCELLED;
- }
- break;
- case MOUSEMOVE:
- image_sample_apply(C, op, event);
- break;
- }
+ switch (event->type) {
+ case LEFTMOUSE:
+ case RIGHTMOUSE: // XXX hardcoded
+ if (event->val == KM_RELEASE) {
+ image_sample_exit(C, op);
+ return OPERATOR_CANCELLED;
+ }
+ break;
+ case MOUSEMOVE:
+ image_sample_apply(C, op, event);
+ break;
+ }
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
static void image_sample_cancel(bContext *C, wmOperator *op)
{
- image_sample_exit(C, op);
+ image_sample_exit(C, op);
}
void IMAGE_OT_sample(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Sample Color";
- ot->idname = "IMAGE_OT_sample";
- ot->description = "Use mouse to sample a color in current image";
+ /* identifiers */
+ ot->name = "Sample Color";
+ ot->idname = "IMAGE_OT_sample";
+ ot->description = "Use mouse to sample a color in current image";
- /* api callbacks */
- ot->invoke = image_sample_invoke;
- ot->modal = image_sample_modal;
- ot->cancel = image_sample_cancel;
- ot->poll = image_sample_poll;
+ /* api callbacks */
+ ot->invoke = image_sample_invoke;
+ ot->modal = image_sample_modal;
+ ot->cancel = image_sample_cancel;
+ ot->poll = image_sample_poll;
- /* flags */
- ot->flag = OPTYPE_BLOCKING;
+ /* flags */
+ ot->flag = OPTYPE_BLOCKING;
- PropertyRNA *prop;
- prop = RNA_def_int(ot->srna, "size", 1, 1, 128, "Sample Size", "", 1, 64);
- RNA_def_property_subtype(prop, PROP_PIXEL);
- RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ PropertyRNA *prop;
+ prop = RNA_def_int(ot->srna, "size", 1, 1, 128, "Sample Size", "", 1, 64);
+ RNA_def_property_subtype(prop, PROP_PIXEL);
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
/******************** sample line operator ********************/
static int image_sample_line_exec(bContext *C, wmOperator *op)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- ARegion *ar = CTX_wm_region(C);
- Scene *scene = CTX_data_scene(C);
+ SpaceImage *sima = CTX_wm_space_image(C);
+ ARegion *ar = CTX_wm_region(C);
+ Scene *scene = CTX_data_scene(C);
- int x_start = RNA_int_get(op->ptr, "xstart");
- int y_start = RNA_int_get(op->ptr, "ystart");
- int x_end = RNA_int_get(op->ptr, "xend");
- int y_end = RNA_int_get(op->ptr, "yend");
+ int x_start = RNA_int_get(op->ptr, "xstart");
+ int y_start = RNA_int_get(op->ptr, "ystart");
+ int x_end = RNA_int_get(op->ptr, "xend");
+ int y_end = RNA_int_get(op->ptr, "yend");
- void *lock;
- ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
- Histogram *hist = &sima->sample_line_hist;
+ void *lock;
+ ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
+ Histogram *hist = &sima->sample_line_hist;
- float x1f, y1f, x2f, y2f;
+ float x1f, y1f, x2f, y2f;
- if (ibuf == NULL) {
- ED_space_image_release_buffer(sima, ibuf, lock);
- return OPERATOR_CANCELLED;
- }
- /* hmmmm */
- if (ibuf->channels < 3) {
- ED_space_image_release_buffer(sima, ibuf, lock);
- return OPERATOR_CANCELLED;
- }
+ if (ibuf == NULL) {
+ ED_space_image_release_buffer(sima, ibuf, lock);
+ return OPERATOR_CANCELLED;
+ }
+ /* hmmmm */
+ if (ibuf->channels < 3) {
+ ED_space_image_release_buffer(sima, ibuf, lock);
+ return OPERATOR_CANCELLED;
+ }
- UI_view2d_region_to_view(&ar->v2d, x_start, y_start, &x1f, &y1f);
- UI_view2d_region_to_view(&ar->v2d, x_end, y_end, &x2f, &y2f);
+ UI_view2d_region_to_view(&ar->v2d, x_start, y_start, &x1f, &y1f);
+ UI_view2d_region_to_view(&ar->v2d, x_end, y_end, &x2f, &y2f);
- hist->co[0][0] = x1f;
- hist->co[0][1] = y1f;
- hist->co[1][0] = x2f;
- hist->co[1][1] = y2f;
+ hist->co[0][0] = x1f;
+ hist->co[0][1] = y1f;
+ hist->co[1][0] = x2f;
+ hist->co[1][1] = y2f;
- /* enable line drawing */
- hist->flag |= HISTO_FLAG_SAMPLELINE;
+ /* enable line drawing */
+ hist->flag |= HISTO_FLAG_SAMPLELINE;
- BKE_histogram_update_sample_line(hist, ibuf, &scene->view_settings, &scene->display_settings);
+ BKE_histogram_update_sample_line(hist, ibuf, &scene->view_settings, &scene->display_settings);
- /* reset y zoom */
- hist->ymax = 1.0f;
+ /* reset y zoom */
+ hist->ymax = 1.0f;
- ED_space_image_release_buffer(sima, ibuf, lock);
+ ED_space_image_release_buffer(sima, ibuf, lock);
- ED_area_tag_redraw(CTX_wm_area(C));
+ ED_area_tag_redraw(CTX_wm_area(C));
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
static int image_sample_line_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- SpaceImage *sima = CTX_wm_space_image(C);
+ SpaceImage *sima = CTX_wm_space_image(C);
- Histogram *hist = &sima->sample_line_hist;
- hist->flag &= ~HISTO_FLAG_SAMPLELINE;
+ Histogram *hist = &sima->sample_line_hist;
+ hist->flag &= ~HISTO_FLAG_SAMPLELINE;
- if (!ED_space_image_has_buffer(sima)) {
- return OPERATOR_CANCELLED;
- }
+ if (!ED_space_image_has_buffer(sima)) {
+ return OPERATOR_CANCELLED;
+ }
- return WM_gesture_straightline_invoke(C, op, event);
+ return WM_gesture_straightline_invoke(C, op, event);
}
void IMAGE_OT_sample_line(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Sample Line";
- ot->idname = "IMAGE_OT_sample_line";
- ot->description = "Sample a line and show it in Scope panels";
+ /* identifiers */
+ ot->name = "Sample Line";
+ ot->idname = "IMAGE_OT_sample_line";
+ ot->description = "Sample a line and show it in Scope panels";
- /* api callbacks */
- ot->invoke = image_sample_line_invoke;
- ot->modal = WM_gesture_straightline_modal;
- ot->exec = image_sample_line_exec;
- ot->poll = space_image_main_region_poll;
- ot->cancel = WM_gesture_straightline_cancel;
+ /* api callbacks */
+ ot->invoke = image_sample_line_invoke;
+ ot->modal = WM_gesture_straightline_modal;
+ ot->exec = image_sample_line_exec;
+ ot->poll = space_image_main_region_poll;
+ ot->cancel = WM_gesture_straightline_cancel;
- /* flags */
- ot->flag = 0; /* no undo/register since this operates on the space */
+ /* flags */
+ ot->flag = 0; /* no undo/register since this operates on the space */
- WM_operator_properties_gesture_straightline(ot, CURSOR_EDIT);
+ WM_operator_properties_gesture_straightline(ot, CURSOR_EDIT);
}
/******************** set curve point operator ********************/
void IMAGE_OT_curves_point_set(wmOperatorType *ot)
{
- static const EnumPropertyItem point_items[] = {
- {0, "BLACK_POINT", 0, "Black Point", ""},
- {1, "WHITE_POINT", 0, "White Point", ""},
- {0, NULL, 0, NULL, NULL},
- };
+ static const EnumPropertyItem point_items[] = {
+ {0, "BLACK_POINT", 0, "Black Point", ""},
+ {1, "WHITE_POINT", 0, "White Point", ""},
+ {0, NULL, 0, NULL, NULL},
+ };
- /* identifiers */
- ot->name = "Set Curves Point";
- ot->idname = "IMAGE_OT_curves_point_set";
- ot->description = "Set black point or white point for curves";
+ /* identifiers */
+ ot->name = "Set Curves Point";
+ ot->idname = "IMAGE_OT_curves_point_set";
+ ot->description = "Set black point or white point for curves";
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
- /* api callbacks */
- ot->invoke = image_sample_invoke;
- ot->modal = image_sample_modal;
- ot->cancel = image_sample_cancel;
- ot->poll = space_image_main_area_not_uv_brush_poll;
+ /* api callbacks */
+ ot->invoke = image_sample_invoke;
+ ot->modal = image_sample_modal;
+ ot->cancel = image_sample_cancel;
+ ot->poll = space_image_main_area_not_uv_brush_poll;
- /* properties */
- RNA_def_enum(ot->srna, "point", point_items, 0, "Point", "Set black point or white point for curves");
+ /* properties */
+ RNA_def_enum(
+ ot->srna, "point", point_items, 0, "Point", "Set black point or white point for curves");
- PropertyRNA *prop;
- prop = RNA_def_int(ot->srna, "size", 1, 1, 128, "Sample Size", "", 1, 64);
- RNA_def_property_subtype(prop, PROP_PIXEL);
- RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ PropertyRNA *prop;
+ prop = RNA_def_int(ot->srna, "size", 1, 1, 128, "Sample Size", "", 1, 64);
+ RNA_def_property_subtype(prop, PROP_PIXEL);
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
#if 0 /* Not ported to 2.5x yet */
/******************** record composite operator *********************/
typedef struct RecordCompositeData {
- wmTimer *timer;
- int old_cfra;
- int sfra, efra;
+ wmTimer *timer;
+ int old_cfra;
+ int sfra, efra;
} RecordCompositeData;
static int image_record_composite_apply(bContext *C, wmOperator *op)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- RecordCompositeData *rcd = op->customdata;
- Scene *scene = CTX_data_scene(C);
- ImBuf *ibuf;
+ SpaceImage *sima = CTX_wm_space_image(C);
+ RecordCompositeData *rcd = op->customdata;
+ Scene *scene = CTX_data_scene(C);
+ ImBuf *ibuf;
- WM_cursor_time(CTX_wm_window(C), scene->r.cfra);
+ WM_cursor_time(CTX_wm_window(C), scene->r.cfra);
- // XXX scene->nodetree->test_break = BKE_blender_test_break;
- // XXX scene->nodetree->test_break = NULL;
+ // XXX scene->nodetree->test_break = BKE_blender_test_break;
+ // XXX scene->nodetree->test_break = NULL;
- BKE_image_all_free_anim_ibufs(scene->r.cfra);
- ntreeCompositTagAnimated(scene->nodetree);
- ntreeCompositExecTree(scene->nodetree, &scene->r, 0, scene->r.cfra != rcd->old_cfra,
- &scene->view_settings, &scene->display_settings); /* 1 is no previews */
+ BKE_image_all_free_anim_ibufs(scene->r.cfra);
+ ntreeCompositTagAnimated(scene->nodetree);
+ ntreeCompositExecTree(scene->nodetree, &scene->r, 0, scene->r.cfra != rcd->old_cfra,
+ &scene->view_settings, &scene->display_settings); /* 1 is no previews */
- ED_area_tag_redraw(CTX_wm_area(C));
+ ED_area_tag_redraw(CTX_wm_area(C));
- ibuf = BKE_image_acquire_ibuf(sima->image, &sima->iuser, NULL);
- /* save memory in flipbooks */
- if (ibuf)
- imb_freerectfloatImBuf(ibuf);
+ ibuf = BKE_image_acquire_ibuf(sima->image, &sima->iuser, NULL);
+ /* save memory in flipbooks */
+ if (ibuf)
+ imb_freerectfloatImBuf(ibuf);
- BKE_image_release_ibuf(sima->image, ibuf, NULL);
+ BKE_image_release_ibuf(sima->image, ibuf, NULL);
- scene->r.cfra++;
+ scene->r.cfra++;
- return (scene->r.cfra <= rcd->efra);
+ return (scene->r.cfra <= rcd->efra);
}
static int image_record_composite_init(bContext *C, wmOperator *op)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- Scene *scene = CTX_data_scene(C);
- RecordCompositeData *rcd;
+ SpaceImage *sima = CTX_wm_space_image(C);
+ Scene *scene = CTX_data_scene(C);
+ RecordCompositeData *rcd;
- if (sima->iuser.frames < 2)
- return 0;
- if (scene->nodetree == NULL)
- return 0;
+ if (sima->iuser.frames < 2)
+ return 0;
+ if (scene->nodetree == NULL)
+ return 0;
- op->customdata = rcd = MEM_callocN(sizeof(RecordCompositeData), "ImageRecordCompositeData");
+ op->customdata = rcd = MEM_callocN(sizeof(RecordCompositeData), "ImageRecordCompositeData");
- rcd->old_cfra = scene->r.cfra;
- rcd->sfra = sima->iuser.sfra;
- rcd->efra = sima->iuser.sfra + sima->iuser.frames - 1;
- scene->r.cfra = rcd->sfra;
+ rcd->old_cfra = scene->r.cfra;
+ rcd->sfra = sima->iuser.sfra;
+ rcd->efra = sima->iuser.sfra + sima->iuser.frames - 1;
+ scene->r.cfra = rcd->sfra;
- return 1;
+ return 1;
}
static void image_record_composite_exit(bContext *C, wmOperator *op)
{
- Scene *scene = CTX_data_scene(C);
- SpaceImage *sima = CTX_wm_space_image(C);
- RecordCompositeData *rcd = op->customdata;
+ Scene *scene = CTX_data_scene(C);
+ SpaceImage *sima = CTX_wm_space_image(C);
+ RecordCompositeData *rcd = op->customdata;
- scene->r.cfra = rcd->old_cfra;
+ scene->r.cfra = rcd->old_cfra;
- WM_cursor_modal_restore(CTX_wm_window(C));
+ WM_cursor_modal_restore(CTX_wm_window(C));
- if (rcd->timer)
- WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), rcd->timer);
+ if (rcd->timer)
+ WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), rcd->timer);
- WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, sima->image);
+ WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, sima->image);
- // XXX play_anim(0);
- // XXX allqueue(REDRAWNODE, 1);
+ // XXX play_anim(0);
+ // XXX allqueue(REDRAWNODE, 1);
- MEM_freeN(rcd);
+ MEM_freeN(rcd);
}
static int image_record_composite_exec(bContext *C, wmOperator *op)
{
- if (!image_record_composite_init(C, op))
- return OPERATOR_CANCELLED;
+ if (!image_record_composite_init(C, op))
+ return OPERATOR_CANCELLED;
- while (image_record_composite_apply(C, op)) {}
+ while (image_record_composite_apply(C, op)) {}
- image_record_composite_exit(C, op);
+ image_record_composite_exit(C, op);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
static int image_record_composite_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- RecordCompositeData *rcd;
+ RecordCompositeData *rcd;
- if (!image_record_composite_init(C, op))
- return OPERATOR_CANCELLED;
+ if (!image_record_composite_init(C, op))
+ return OPERATOR_CANCELLED;
- rcd = op->customdata;
- rcd->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.0f);
- WM_event_add_modal_handler(C, op);
+ rcd = op->customdata;
+ rcd->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.0f);
+ WM_event_add_modal_handler(C, op);
- if (!image_record_composite_apply(C, op))
- return OPERATOR_FINISHED;
+ if (!image_record_composite_apply(C, op))
+ return OPERATOR_FINISHED;
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
static int image_record_composite_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
- RecordCompositeData *rcd = op->customdata;
+ RecordCompositeData *rcd = op->customdata;
- switch (event->type) {
- case TIMER:
- if (rcd->timer == event->customdata) {
- if (!image_record_composite_apply(C, op)) {
- image_record_composite_exit(C, op);
- return OPERATOR_FINISHED;
- }
- }
- break;
- case ESCKEY:
- image_record_composite_exit(C, op);
- return OPERATOR_FINISHED;
- }
+ switch (event->type) {
+ case TIMER:
+ if (rcd->timer == event->customdata) {
+ if (!image_record_composite_apply(C, op)) {
+ image_record_composite_exit(C, op);
+ return OPERATOR_FINISHED;
+ }
+ }
+ break;
+ case ESCKEY:
+ image_record_composite_exit(C, op);
+ return OPERATOR_FINISHED;
+ }
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
static void image_record_composite_cancel(bContext *C, wmOperator *op)
{
- image_record_composite_exit(C, op);
- return OPERATOR_CANCELLED;
+ image_record_composite_exit(C, op);
+ return OPERATOR_CANCELLED;
}
void IMAGE_OT_record_composite(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Record Composite";
- ot->idname = "IMAGE_OT_record_composite";
+ /* identifiers */
+ ot->name = "Record Composite";
+ ot->idname = "IMAGE_OT_record_composite";
- /* api callbacks */
- ot->exec = image_record_composite_exec;
- ot->invoke = image_record_composite_invoke;
- ot->modal = image_record_composite_modal;
- ot->cancel = image_record_composite_cancel;
- ot->poll = space_image_buffer_exists_poll;
+ /* api callbacks */
+ ot->exec = image_record_composite_exec;
+ ot->invoke = image_record_composite_invoke;
+ ot->modal = image_record_composite_modal;
+ ot->cancel = image_record_composite_cancel;
+ ot->poll = space_image_buffer_exists_poll;
}
#endif
@@ -3602,385 +3785,381 @@ void IMAGE_OT_record_composite(wmOperatorType *ot)
static bool image_cycle_render_slot_poll(bContext *C)
{
- Image *ima = CTX_data_edit_image(C);
+ Image *ima = CTX_data_edit_image(C);
- return (ima && ima->type == IMA_TYPE_R_RESULT);
+ return (ima && ima->type == IMA_TYPE_R_RESULT);
}
static int image_cycle_render_slot_exec(bContext *C, wmOperator *op)
{
- Image *ima = CTX_data_edit_image(C);
- const int direction = RNA_boolean_get(op->ptr, "reverse") ? -1 : 1;
+ Image *ima = CTX_data_edit_image(C);
+ const int direction = RNA_boolean_get(op->ptr, "reverse") ? -1 : 1;
- if (!ED_image_slot_cycle(ima, direction)) {
- return OPERATOR_CANCELLED;
- }
+ if (!ED_image_slot_cycle(ima, direction)) {
+ return OPERATOR_CANCELLED;
+ }
- WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL);
+ WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL);
- /* no undo push for browsing existing */
- RenderSlot *slot = BKE_image_get_renderslot(ima, ima->render_slot);
- if ((slot && slot->render) || ima->render_slot == ima->last_render_slot) {
- return OPERATOR_CANCELLED;
- }
+ /* no undo push for browsing existing */
+ RenderSlot *slot = BKE_image_get_renderslot(ima, ima->render_slot);
+ if ((slot && slot->render) || ima->render_slot == ima->last_render_slot) {
+ return OPERATOR_CANCELLED;
+ }
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void IMAGE_OT_cycle_render_slot(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Cycle Render Slot";
- ot->idname = "IMAGE_OT_cycle_render_slot";
- ot->description = "Cycle through all non-void render slots";
+ /* identifiers */
+ ot->name = "Cycle Render Slot";
+ ot->idname = "IMAGE_OT_cycle_render_slot";
+ ot->description = "Cycle through all non-void render slots";
- /* api callbacks */
- ot->exec = image_cycle_render_slot_exec;
- ot->poll = image_cycle_render_slot_poll;
+ /* api callbacks */
+ ot->exec = image_cycle_render_slot_exec;
+ ot->poll = image_cycle_render_slot_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER;
- RNA_def_boolean(ot->srna, "reverse", 0, "Cycle in Reverse", "");
+ RNA_def_boolean(ot->srna, "reverse", 0, "Cycle in Reverse", "");
}
/********************* clear render slot operator *********************/
static int image_clear_render_slot_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceImage *sima = CTX_wm_space_image(C);
- Image *ima = CTX_data_edit_image(C);
+ SpaceImage *sima = CTX_wm_space_image(C);
+ Image *ima = CTX_data_edit_image(C);
- if (!BKE_image_clear_renderslot(ima, &sima->iuser, ima->render_slot)) {
- return OPERATOR_CANCELLED;
- }
+ if (!BKE_image_clear_renderslot(ima, &sima->iuser, ima->render_slot)) {
+ return OPERATOR_CANCELLED;
+ }
- WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL);
+ WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void IMAGE_OT_clear_render_slot(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Clear Render Slot";
- ot->idname = "IMAGE_OT_clear_render_slot";
- ot->description = "Clear the currently selected render slot";
+ /* identifiers */
+ ot->name = "Clear Render Slot";
+ ot->idname = "IMAGE_OT_clear_render_slot";
+ ot->description = "Clear the currently selected render slot";
- /* api callbacks */
- ot->exec = image_clear_render_slot_exec;
- ot->poll = image_cycle_render_slot_poll;
+ /* api callbacks */
+ ot->exec = image_clear_render_slot_exec;
+ ot->poll = image_cycle_render_slot_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER;
}
/********************* add render slot operator *********************/
static int image_add_render_slot_exec(bContext *C, wmOperator *UNUSED(op))
{
- Image *ima = CTX_data_edit_image(C);
+ Image *ima = CTX_data_edit_image(C);
- RenderSlot *slot = BKE_image_add_renderslot(ima, NULL);
- ima->render_slot = BLI_findindex(&ima->renderslots, slot);
+ RenderSlot *slot = BKE_image_add_renderslot(ima, NULL);
+ ima->render_slot = BLI_findindex(&ima->renderslots, slot);
- WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL);
+ WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void IMAGE_OT_add_render_slot(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Add Render Slot";
- ot->idname = "IMAGE_OT_add_render_slot";
- ot->description = "Add a new render slot";
+ /* identifiers */
+ ot->name = "Add Render Slot";
+ ot->idname = "IMAGE_OT_add_render_slot";
+ ot->description = "Add a new render slot";
- /* api callbacks */
- ot->exec = image_add_render_slot_exec;
- ot->poll = image_cycle_render_slot_poll;
+ /* api callbacks */
+ ot->exec = image_add_render_slot_exec;
+ ot->poll = image_cycle_render_slot_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER;
}
/********************* remove render slot operator *********************/
static int image_remove_render_slot_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceImage *sima = CTX_wm_space_image(C);
- Image *ima = CTX_data_edit_image(C);
+ SpaceImage *sima = CTX_wm_space_image(C);
+ Image *ima = CTX_data_edit_image(C);
- if (!BKE_image_remove_renderslot(ima, &sima->iuser, ima->render_slot)) {
- return OPERATOR_CANCELLED;
- }
+ if (!BKE_image_remove_renderslot(ima, &sima->iuser, ima->render_slot)) {
+ return OPERATOR_CANCELLED;
+ }
- WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL);
+ WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void IMAGE_OT_remove_render_slot(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Remove Render Slot";
- ot->idname = "IMAGE_OT_remove_render_slot";
- ot->description = "Remove the current render slot";
+ /* identifiers */
+ ot->name = "Remove Render Slot";
+ ot->idname = "IMAGE_OT_remove_render_slot";
+ ot->description = "Remove the current render slot";
- /* api callbacks */
- ot->exec = image_remove_render_slot_exec;
- ot->poll = image_cycle_render_slot_poll;
+ /* api callbacks */
+ ot->exec = image_remove_render_slot_exec;
+ ot->poll = image_cycle_render_slot_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER;
}
/********************** change frame operator *********************/
static bool change_frame_poll(bContext *C)
{
- /* prevent changes during render */
- if (G.is_rendering) {
- return 0;
- }
+ /* prevent changes during render */
+ if (G.is_rendering) {
+ return 0;
+ }
- return space_image_main_region_poll(C);
+ return space_image_main_region_poll(C);
}
static void change_frame_apply(bContext *C, wmOperator *op)
{
- Scene *scene = CTX_data_scene(C);
+ Scene *scene = CTX_data_scene(C);
- /* set the new frame number */
- CFRA = RNA_int_get(op->ptr, "frame");
- FRAMENUMBER_MIN_CLAMP(CFRA);
- SUBFRA = 0.0f;
+ /* set the new frame number */
+ CFRA = RNA_int_get(op->ptr, "frame");
+ FRAMENUMBER_MIN_CLAMP(CFRA);
+ SUBFRA = 0.0f;
- /* do updates */
- BKE_sound_seek_scene(CTX_data_main(C), scene);
- WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
+ /* do updates */
+ BKE_sound_seek_scene(CTX_data_main(C), scene);
+ WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
}
static int change_frame_exec(bContext *C, wmOperator *op)
{
- change_frame_apply(C, op);
+ change_frame_apply(C, op);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
static int frame_from_event(bContext *C, const wmEvent *event)
{
- ARegion *ar = CTX_wm_region(C);
- Scene *scene = CTX_data_scene(C);
- int framenr = 0;
+ ARegion *ar = CTX_wm_region(C);
+ Scene *scene = CTX_data_scene(C);
+ int framenr = 0;
- if (ar->regiontype == RGN_TYPE_WINDOW) {
- float sfra = SFRA, efra = EFRA, framelen = ar->winx / (efra - sfra + 1);
+ if (ar->regiontype == RGN_TYPE_WINDOW) {
+ float sfra = SFRA, efra = EFRA, framelen = ar->winx / (efra - sfra + 1);
- framenr = sfra + event->mval[0] / framelen;
- }
- else {
- float viewx, viewy;
+ framenr = sfra + event->mval[0] / framelen;
+ }
+ else {
+ float viewx, viewy;
- UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &viewx, &viewy);
+ UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &viewx, &viewy);
- framenr = round_fl_to_int(viewx);
- }
+ framenr = round_fl_to_int(viewx);
+ }
- return framenr;
+ return framenr;
}
static int change_frame_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- ARegion *ar = CTX_wm_region(C);
+ ARegion *ar = CTX_wm_region(C);
- if (ar->regiontype == RGN_TYPE_WINDOW) {
- SpaceImage *sima = CTX_wm_space_image(C);
- if (event->mval[1] > 16 || !ED_space_image_show_cache(sima)) {
- return OPERATOR_PASS_THROUGH;
- }
- }
+ if (ar->regiontype == RGN_TYPE_WINDOW) {
+ SpaceImage *sima = CTX_wm_space_image(C);
+ if (event->mval[1] > 16 || !ED_space_image_show_cache(sima)) {
+ return OPERATOR_PASS_THROUGH;
+ }
+ }
- RNA_int_set(op->ptr, "frame", frame_from_event(C, event));
+ RNA_int_set(op->ptr, "frame", frame_from_event(C, event));
- change_frame_apply(C, op);
+ change_frame_apply(C, op);
- /* add temp handler */
- WM_event_add_modal_handler(C, op);
+ /* add temp handler */
+ WM_event_add_modal_handler(C, op);
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
static int change_frame_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
- switch (event->type) {
- case ESCKEY:
- return OPERATOR_FINISHED;
+ switch (event->type) {
+ case ESCKEY:
+ return OPERATOR_FINISHED;
- case MOUSEMOVE:
- RNA_int_set(op->ptr, "frame", frame_from_event(C, event));
- change_frame_apply(C, op);
- break;
+ case MOUSEMOVE:
+ RNA_int_set(op->ptr, "frame", frame_from_event(C, event));
+ change_frame_apply(C, op);
+ break;
- case LEFTMOUSE:
- case RIGHTMOUSE:
- if (event->val == KM_RELEASE) {
- return OPERATOR_FINISHED;
- }
- break;
- }
+ case LEFTMOUSE:
+ case RIGHTMOUSE:
+ if (event->val == KM_RELEASE) {
+ return OPERATOR_FINISHED;
+ }
+ break;
+ }
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
void IMAGE_OT_change_frame(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Change Frame";
- ot->idname = "IMAGE_OT_change_frame";
- ot->description = "Interactively change the current frame number";
+ /* identifiers */
+ ot->name = "Change Frame";
+ ot->idname = "IMAGE_OT_change_frame";
+ ot->description = "Interactively change the current frame number";
- /* api callbacks */
- ot->exec = change_frame_exec;
- ot->invoke = change_frame_invoke;
- ot->modal = change_frame_modal;
- ot->poll = change_frame_poll;
+ /* api callbacks */
+ ot->exec = change_frame_exec;
+ ot->invoke = change_frame_invoke;
+ ot->modal = change_frame_modal;
+ ot->poll = change_frame_poll;
- /* flags */
- ot->flag = OPTYPE_BLOCKING | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_BLOCKING | OPTYPE_UNDO;
- /* rna */
- RNA_def_int(ot->srna, "frame", 0, MINAFRAME, MAXFRAME, "Frame", "", MINAFRAME, MAXFRAME);
+ /* rna */
+ RNA_def_int(ot->srna, "frame", 0, MINAFRAME, MAXFRAME, "Frame", "", MINAFRAME, MAXFRAME);
}
/* Reload cached render results... */
/* goes over all scenes, reads render layers */
static int image_read_viewlayers_exec(bContext *C, wmOperator *UNUSED(op))
{
- Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
- SpaceImage *sima = CTX_wm_space_image(C);
- Image *ima;
+ Main *bmain = CTX_data_main(C);
+ Scene *scene = CTX_data_scene(C);
+ SpaceImage *sima = CTX_wm_space_image(C);
+ Image *ima;
- ima = BKE_image_verify_viewer(bmain, IMA_TYPE_R_RESULT, "Render Result");
- if (sima->image == NULL) {
- ED_space_image_set(bmain, sima, NULL, ima, false);
- }
+ ima = BKE_image_verify_viewer(bmain, IMA_TYPE_R_RESULT, "Render Result");
+ if (sima->image == NULL) {
+ ED_space_image_set(bmain, sima, NULL, ima, false);
+ }
- RE_ReadRenderResult(scene, scene);
+ RE_ReadRenderResult(scene, scene);
- WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
- return OPERATOR_FINISHED;
+ WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
+ return OPERATOR_FINISHED;
}
void IMAGE_OT_read_viewlayers(wmOperatorType *ot)
{
- ot->name = "Open Cached Render";
- ot->idname = "IMAGE_OT_read_viewlayers";
- ot->description = "Read all the current scene's view layers from cache, as needed";
+ ot->name = "Open Cached Render";
+ ot->idname = "IMAGE_OT_read_viewlayers";
+ ot->description = "Read all the current scene's view layers from cache, as needed";
- ot->poll = space_image_main_region_poll;
- ot->exec = image_read_viewlayers_exec;
+ ot->poll = space_image_main_region_poll;
+ ot->exec = image_read_viewlayers_exec;
- /* flags */
- ot->flag = 0;
+ /* flags */
+ ot->flag = 0;
}
/* ********************* Render border operator ****************** */
static int render_border_exec(bContext *C, wmOperator *op)
{
- ARegion *ar = CTX_wm_region(C);
- Scene *scene = CTX_data_scene(C);
- Render *re = RE_GetSceneRender(scene);
- RenderData *rd;
- rctf border;
-
- if (re == NULL) {
- /* Shouldn't happen, but better be safe close to the release. */
- return OPERATOR_CANCELLED;
- }
-
- rd = RE_engine_get_render_data(re);
- if ((rd->mode & (R_BORDER | R_CROP)) == (R_BORDER | R_CROP)) {
- BKE_report(op->reports, RPT_INFO, "Can not set border from a cropped render");
- return OPERATOR_CANCELLED;
- }
-
- /* get rectangle from operator */
- WM_operator_properties_border_to_rctf(op, &border);
- UI_view2d_region_to_view_rctf(&ar->v2d, &border, &border);
-
- /* actually set border */
- CLAMP(border.xmin, 0.0f, 1.0f);
- CLAMP(border.ymin, 0.0f, 1.0f);
- CLAMP(border.xmax, 0.0f, 1.0f);
- CLAMP(border.ymax, 0.0f, 1.0f);
- scene->r.border = border;
-
- /* drawing a border surrounding the entire camera view switches off border rendering
- * or the border covers no pixels */
- if ((border.xmin <= 0.0f && border.xmax >= 1.0f &&
- border.ymin <= 0.0f && border.ymax >= 1.0f) ||
- (border.xmin == border.xmax || border.ymin == border.ymax))
- {
- scene->r.mode &= ~R_BORDER;
- }
- else {
- scene->r.mode |= R_BORDER;
- }
-
- DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE);
- WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
- return OPERATOR_FINISHED;
-
+ ARegion *ar = CTX_wm_region(C);
+ Scene *scene = CTX_data_scene(C);
+ Render *re = RE_GetSceneRender(scene);
+ RenderData *rd;
+ rctf border;
+
+ if (re == NULL) {
+ /* Shouldn't happen, but better be safe close to the release. */
+ return OPERATOR_CANCELLED;
+ }
+
+ rd = RE_engine_get_render_data(re);
+ if ((rd->mode & (R_BORDER | R_CROP)) == (R_BORDER | R_CROP)) {
+ BKE_report(op->reports, RPT_INFO, "Can not set border from a cropped render");
+ return OPERATOR_CANCELLED;
+ }
+
+ /* get rectangle from operator */
+ WM_operator_properties_border_to_rctf(op, &border);
+ UI_view2d_region_to_view_rctf(&ar->v2d, &border, &border);
+
+ /* actually set border */
+ CLAMP(border.xmin, 0.0f, 1.0f);
+ CLAMP(border.ymin, 0.0f, 1.0f);
+ CLAMP(border.xmax, 0.0f, 1.0f);
+ CLAMP(border.ymax, 0.0f, 1.0f);
+ scene->r.border = border;
+
+ /* drawing a border surrounding the entire camera view switches off border rendering
+ * or the border covers no pixels */
+ if ((border.xmin <= 0.0f && border.xmax >= 1.0f && border.ymin <= 0.0f && border.ymax >= 1.0f) ||
+ (border.xmin == border.xmax || border.ymin == border.ymax)) {
+ scene->r.mode &= ~R_BORDER;
+ }
+ else {
+ scene->r.mode |= R_BORDER;
+ }
+
+ DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE);
+ WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, NULL);
+
+ return OPERATOR_FINISHED;
}
void IMAGE_OT_render_border(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Render Region";
- ot->description = "Set the boundaries of the render region and enable render region";
- ot->idname = "IMAGE_OT_render_border";
+ /* identifiers */
+ ot->name = "Render Region";
+ ot->description = "Set the boundaries of the render region and enable render region";
+ ot->idname = "IMAGE_OT_render_border";
- /* api callbacks */
- ot->invoke = WM_gesture_box_invoke;
- ot->exec = render_border_exec;
- ot->modal = WM_gesture_box_modal;
- ot->cancel = WM_gesture_box_cancel;
- ot->poll = image_cycle_render_slot_poll;
+ /* api callbacks */
+ ot->invoke = WM_gesture_box_invoke;
+ ot->exec = render_border_exec;
+ ot->modal = WM_gesture_box_modal;
+ ot->cancel = WM_gesture_box_cancel;
+ ot->poll = image_cycle_render_slot_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
- /* rna */
- WM_operator_properties_border(ot);
+ /* rna */
+ WM_operator_properties_border(ot);
}
/* ********************* Clear render border operator ****************** */
static int clear_render_border_exec(bContext *C, wmOperator *UNUSED(op))
{
- Scene *scene = CTX_data_scene(C);
- scene->r.mode &= ~R_BORDER;
- WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, NULL);
- BLI_rctf_init(&scene->r.border, 0.0f, 1.0f, 0.0f, 1.0f);
- return OPERATOR_FINISHED;
-
+ Scene *scene = CTX_data_scene(C);
+ scene->r.mode &= ~R_BORDER;
+ WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, NULL);
+ BLI_rctf_init(&scene->r.border, 0.0f, 1.0f, 0.0f, 1.0f);
+ return OPERATOR_FINISHED;
}
void IMAGE_OT_clear_render_border(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Clear Render Region";
- ot->description = "Clear the boundaries of the render region and disable render region";
- ot->idname = "IMAGE_OT_clear_render_border";
+ /* identifiers */
+ ot->name = "Clear Render Region";
+ ot->description = "Clear the boundaries of the render region and disable render region";
+ ot->idname = "IMAGE_OT_clear_render_border";
- /* api callbacks */
- ot->exec = clear_render_border_exec;
- ot->poll = image_cycle_render_slot_poll;
+ /* api callbacks */
+ ot->exec = clear_render_border_exec;
+ ot->poll = image_cycle_render_slot_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c
index d5eb0b485a1..e1875fd6129 100644
--- a/source/blender/editors/space_image/space_image.c
+++ b/source/blender/editors/space_image/space_image.c
@@ -64,7 +64,6 @@
#include "ED_uvedit.h"
#include "ED_transform.h"
-
#include "WM_api.h"
#include "WM_types.h"
#include "WM_message.h"
@@ -86,254 +85,255 @@
static void image_scopes_tag_refresh(ScrArea *sa)
{
- SpaceImage *sima = (SpaceImage *)sa->spacedata.first;
- ARegion *ar;
+ SpaceImage *sima = (SpaceImage *)sa->spacedata.first;
+ ARegion *ar;
- /* only while histogram is visible */
- for (ar = sa->regionbase.first; ar; ar = ar->next) {
- if (ar->regiontype == RGN_TYPE_TOOL_PROPS && ar->flag & RGN_FLAG_HIDDEN) {
- return;
- }
- }
+ /* only while histogram is visible */
+ for (ar = sa->regionbase.first; ar; ar = ar->next) {
+ if (ar->regiontype == RGN_TYPE_TOOL_PROPS && ar->flag & RGN_FLAG_HIDDEN) {
+ return;
+ }
+ }
- sima->scopes.ok = 0;
+ sima->scopes.ok = 0;
}
static void image_user_refresh_scene(const bContext *C, SpaceImage *sima)
{
- /* Update scene image user for acquiring render results. */
- sima->iuser.scene = CTX_data_scene(C);
-
- if (sima->image && sima->image->type == IMA_TYPE_R_RESULT) {
- /* While rendering, prefer scene that is being rendered. */
- Scene *render_scene = ED_render_job_get_current_scene(C);
- if (render_scene) {
- sima->iuser.scene = render_scene;
- }
- }
-
- /* Auto switch image to show in UV editor when selection changes. */
- ED_space_image_auto_set(C, sima);
+ /* Update scene image user for acquiring render results. */
+ sima->iuser.scene = CTX_data_scene(C);
+
+ if (sima->image && sima->image->type == IMA_TYPE_R_RESULT) {
+ /* While rendering, prefer scene that is being rendered. */
+ Scene *render_scene = ED_render_job_get_current_scene(C);
+ if (render_scene) {
+ sima->iuser.scene = render_scene;
+ }
+ }
+
+ /* Auto switch image to show in UV editor when selection changes. */
+ ED_space_image_auto_set(C, sima);
}
/* ******************** manage regions ********************* */
ARegion *image_has_buttons_region(ScrArea *sa)
{
- ARegion *ar, *arnew;
+ ARegion *ar, *arnew;
- ar = BKE_area_find_region_type(sa, RGN_TYPE_UI);
- if (ar) {
- return ar;
- }
+ ar = BKE_area_find_region_type(sa, RGN_TYPE_UI);
+ if (ar) {
+ return ar;
+ }
- /* add subdiv level; after header */
- ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
+ /* add subdiv level; after header */
+ ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
- /* is error! */
- if (ar == NULL) {
- return NULL;
- }
+ /* is error! */
+ if (ar == NULL) {
+ return NULL;
+ }
- arnew = MEM_callocN(sizeof(ARegion), "buttons for image");
+ arnew = MEM_callocN(sizeof(ARegion), "buttons for image");
- BLI_insertlinkafter(&sa->regionbase, ar, arnew);
- arnew->regiontype = RGN_TYPE_UI;
- arnew->alignment = RGN_ALIGN_RIGHT;
+ BLI_insertlinkafter(&sa->regionbase, ar, arnew);
+ arnew->regiontype = RGN_TYPE_UI;
+ arnew->alignment = RGN_ALIGN_RIGHT;
- arnew->flag = RGN_FLAG_HIDDEN;
+ arnew->flag = RGN_FLAG_HIDDEN;
- return arnew;
+ return arnew;
}
ARegion *image_has_tools_region(ScrArea *sa)
{
- ARegion *ar, *arnew;
+ ARegion *ar, *arnew;
- ar = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS);
- if (ar) {
- return ar;
- }
+ ar = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS);
+ if (ar) {
+ return ar;
+ }
- /* add subdiv level; after buttons */
- ar = BKE_area_find_region_type(sa, RGN_TYPE_UI);
+ /* add subdiv level; after buttons */
+ ar = BKE_area_find_region_type(sa, RGN_TYPE_UI);
- /* is error! */
- if (ar == NULL) {
- return NULL;
- }
+ /* is error! */
+ if (ar == NULL) {
+ return NULL;
+ }
- arnew = MEM_callocN(sizeof(ARegion), "scopes for image");
+ arnew = MEM_callocN(sizeof(ARegion), "scopes for image");
- BLI_insertlinkafter(&sa->regionbase, ar, arnew);
- arnew->regiontype = RGN_TYPE_TOOLS;
- arnew->alignment = RGN_ALIGN_LEFT;
+ BLI_insertlinkafter(&sa->regionbase, ar, arnew);
+ arnew->regiontype = RGN_TYPE_TOOLS;
+ arnew->alignment = RGN_ALIGN_LEFT;
- arnew->flag = RGN_FLAG_HIDDEN;
+ arnew->flag = RGN_FLAG_HIDDEN;
- image_scopes_tag_refresh(sa);
+ image_scopes_tag_refresh(sa);
- return arnew;
+ return arnew;
}
/* ******************** default callbacks for image space ***************** */
static SpaceLink *image_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
{
- ARegion *ar;
- SpaceImage *simage;
+ ARegion *ar;
+ SpaceImage *simage;
- simage = MEM_callocN(sizeof(SpaceImage), "initimage");
- simage->spacetype = SPACE_IMAGE;
- simage->zoom = 1.0f;
- simage->lock = true;
- simage->flag = SI_SHOW_GPENCIL | SI_USE_ALPHA | SI_COORDFLOATS;
+ simage = MEM_callocN(sizeof(SpaceImage), "initimage");
+ simage->spacetype = SPACE_IMAGE;
+ simage->zoom = 1.0f;
+ simage->lock = true;
+ simage->flag = SI_SHOW_GPENCIL | SI_USE_ALPHA | SI_COORDFLOATS;
- simage->iuser.ok = true;
- simage->iuser.frames = 100;
- simage->iuser.flag = IMA_SHOW_STEREO | IMA_ANIM_ALWAYS;
+ simage->iuser.ok = true;
+ simage->iuser.frames = 100;
+ simage->iuser.flag = IMA_SHOW_STEREO | IMA_ANIM_ALWAYS;
- scopes_new(&simage->scopes);
- simage->sample_line_hist.height = 100;
+ scopes_new(&simage->scopes);
+ simage->sample_line_hist.height = 100;
- /* header */
- ar = MEM_callocN(sizeof(ARegion), "header for image");
+ /* header */
+ ar = MEM_callocN(sizeof(ARegion), "header for image");
- BLI_addtail(&simage->regionbase, ar);
- ar->regiontype = RGN_TYPE_HEADER;
- ar->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP;
+ BLI_addtail(&simage->regionbase, ar);
+ ar->regiontype = RGN_TYPE_HEADER;
+ ar->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP;
- /* buttons/list view */
- ar = MEM_callocN(sizeof(ARegion), "buttons for image");
+ /* buttons/list view */
+ ar = MEM_callocN(sizeof(ARegion), "buttons for image");
- BLI_addtail(&simage->regionbase, ar);
- ar->regiontype = RGN_TYPE_UI;
- ar->alignment = RGN_ALIGN_RIGHT;
- ar->flag = RGN_FLAG_HIDDEN;
+ BLI_addtail(&simage->regionbase, ar);
+ ar->regiontype = RGN_TYPE_UI;
+ ar->alignment = RGN_ALIGN_RIGHT;
+ ar->flag = RGN_FLAG_HIDDEN;
- /* scopes/uv sculpt/paint */
- ar = MEM_callocN(sizeof(ARegion), "buttons for image");
+ /* scopes/uv sculpt/paint */
+ ar = MEM_callocN(sizeof(ARegion), "buttons for image");
- BLI_addtail(&simage->regionbase, ar);
- ar->regiontype = RGN_TYPE_TOOLS;
- ar->alignment = RGN_ALIGN_LEFT;
- ar->flag = RGN_FLAG_HIDDEN;
+ BLI_addtail(&simage->regionbase, ar);
+ ar->regiontype = RGN_TYPE_TOOLS;
+ ar->alignment = RGN_ALIGN_LEFT;
+ ar->flag = RGN_FLAG_HIDDEN;
- /* main area */
- ar = MEM_callocN(sizeof(ARegion), "main area for image");
+ /* main area */
+ ar = MEM_callocN(sizeof(ARegion), "main area for image");
- BLI_addtail(&simage->regionbase, ar);
- ar->regiontype = RGN_TYPE_WINDOW;
+ BLI_addtail(&simage->regionbase, ar);
+ ar->regiontype = RGN_TYPE_WINDOW;
- return (SpaceLink *)simage;
+ return (SpaceLink *)simage;
}
/* not spacelink itself */
static void image_free(SpaceLink *sl)
{
- SpaceImage *simage = (SpaceImage *) sl;
+ SpaceImage *simage = (SpaceImage *)sl;
- scopes_free(&simage->scopes);
+ scopes_free(&simage->scopes);
}
-
/* spacetype; init callback, add handlers */
static void image_init(struct wmWindowManager *UNUSED(wm), ScrArea *sa)
{
- ListBase *lb = WM_dropboxmap_find("Image", SPACE_IMAGE, 0);
-
- /* add drop boxes */
- WM_event_add_dropbox_handler(&sa->handlers, lb);
+ ListBase *lb = WM_dropboxmap_find("Image", SPACE_IMAGE, 0);
+ /* add drop boxes */
+ WM_event_add_dropbox_handler(&sa->handlers, lb);
}
static SpaceLink *image_duplicate(SpaceLink *sl)
{
- SpaceImage *simagen = MEM_dupallocN(sl);
+ SpaceImage *simagen = MEM_dupallocN(sl);
- /* clear or remove stuff from old */
+ /* clear or remove stuff from old */
- scopes_new(&simagen->scopes);
+ scopes_new(&simagen->scopes);
- return (SpaceLink *)simagen;
+ return (SpaceLink *)simagen;
}
static void image_operatortypes(void)
{
- WM_operatortype_append(IMAGE_OT_view_all);
- WM_operatortype_append(IMAGE_OT_view_pan);
- WM_operatortype_append(IMAGE_OT_view_selected);
- WM_operatortype_append(IMAGE_OT_view_zoom);
- WM_operatortype_append(IMAGE_OT_view_zoom_in);
- WM_operatortype_append(IMAGE_OT_view_zoom_out);
- WM_operatortype_append(IMAGE_OT_view_zoom_ratio);
- WM_operatortype_append(IMAGE_OT_view_zoom_border);
+ WM_operatortype_append(IMAGE_OT_view_all);
+ WM_operatortype_append(IMAGE_OT_view_pan);
+ WM_operatortype_append(IMAGE_OT_view_selected);
+ WM_operatortype_append(IMAGE_OT_view_zoom);
+ WM_operatortype_append(IMAGE_OT_view_zoom_in);
+ WM_operatortype_append(IMAGE_OT_view_zoom_out);
+ WM_operatortype_append(IMAGE_OT_view_zoom_ratio);
+ WM_operatortype_append(IMAGE_OT_view_zoom_border);
#ifdef WITH_INPUT_NDOF
- WM_operatortype_append(IMAGE_OT_view_ndof);
+ WM_operatortype_append(IMAGE_OT_view_ndof);
#endif
- WM_operatortype_append(IMAGE_OT_new);
- WM_operatortype_append(IMAGE_OT_open);
- WM_operatortype_append(IMAGE_OT_match_movie_length);
- WM_operatortype_append(IMAGE_OT_replace);
- WM_operatortype_append(IMAGE_OT_reload);
- WM_operatortype_append(IMAGE_OT_save);
- WM_operatortype_append(IMAGE_OT_save_as);
- WM_operatortype_append(IMAGE_OT_save_sequence);
- WM_operatortype_append(IMAGE_OT_pack);
- WM_operatortype_append(IMAGE_OT_unpack);
+ WM_operatortype_append(IMAGE_OT_new);
+ WM_operatortype_append(IMAGE_OT_open);
+ WM_operatortype_append(IMAGE_OT_match_movie_length);
+ WM_operatortype_append(IMAGE_OT_replace);
+ WM_operatortype_append(IMAGE_OT_reload);
+ WM_operatortype_append(IMAGE_OT_save);
+ WM_operatortype_append(IMAGE_OT_save_as);
+ WM_operatortype_append(IMAGE_OT_save_sequence);
+ WM_operatortype_append(IMAGE_OT_pack);
+ WM_operatortype_append(IMAGE_OT_unpack);
- WM_operatortype_append(IMAGE_OT_invert);
+ WM_operatortype_append(IMAGE_OT_invert);
- WM_operatortype_append(IMAGE_OT_cycle_render_slot);
- WM_operatortype_append(IMAGE_OT_clear_render_slot);
- WM_operatortype_append(IMAGE_OT_add_render_slot);
- WM_operatortype_append(IMAGE_OT_remove_render_slot);
+ WM_operatortype_append(IMAGE_OT_cycle_render_slot);
+ WM_operatortype_append(IMAGE_OT_clear_render_slot);
+ WM_operatortype_append(IMAGE_OT_add_render_slot);
+ WM_operatortype_append(IMAGE_OT_remove_render_slot);
- WM_operatortype_append(IMAGE_OT_sample);
- WM_operatortype_append(IMAGE_OT_sample_line);
- WM_operatortype_append(IMAGE_OT_curves_point_set);
+ WM_operatortype_append(IMAGE_OT_sample);
+ WM_operatortype_append(IMAGE_OT_sample_line);
+ WM_operatortype_append(IMAGE_OT_curves_point_set);
- WM_operatortype_append(IMAGE_OT_properties);
- WM_operatortype_append(IMAGE_OT_toolshelf);
+ WM_operatortype_append(IMAGE_OT_properties);
+ WM_operatortype_append(IMAGE_OT_toolshelf);
- WM_operatortype_append(IMAGE_OT_change_frame);
+ WM_operatortype_append(IMAGE_OT_change_frame);
- WM_operatortype_append(IMAGE_OT_read_viewlayers);
- WM_operatortype_append(IMAGE_OT_render_border);
- WM_operatortype_append(IMAGE_OT_clear_render_border);
+ WM_operatortype_append(IMAGE_OT_read_viewlayers);
+ WM_operatortype_append(IMAGE_OT_render_border);
+ WM_operatortype_append(IMAGE_OT_clear_render_border);
}
static void image_keymap(struct wmKeyConfig *keyconf)
{
- WM_keymap_ensure(keyconf, "Image Generic", SPACE_IMAGE, 0);
- WM_keymap_ensure(keyconf, "Image", SPACE_IMAGE, 0);
+ WM_keymap_ensure(keyconf, "Image Generic", SPACE_IMAGE, 0);
+ WM_keymap_ensure(keyconf, "Image", SPACE_IMAGE, 0);
}
/* dropboxes */
-static bool image_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event), const char **UNUSED(tooltip))
+static bool image_drop_poll(bContext *UNUSED(C),
+ wmDrag *drag,
+ const wmEvent *UNUSED(event),
+ const char **UNUSED(tooltip))
{
- if (drag->type == WM_DRAG_PATH) {
- /* rule might not work? */
- if (ELEM(drag->icon, 0, ICON_FILE_IMAGE, ICON_FILE_MOVIE, ICON_FILE_BLANK)) {
- return 1;
- }
- }
- return 0;
+ if (drag->type == WM_DRAG_PATH) {
+ /* rule might not work? */
+ if (ELEM(drag->icon, 0, ICON_FILE_IMAGE, ICON_FILE_MOVIE, ICON_FILE_BLANK)) {
+ return 1;
+ }
+ }
+ return 0;
}
static void image_drop_copy(wmDrag *drag, wmDropBox *drop)
{
- /* copy drag path to properties */
- RNA_string_set(drop->ptr, "filepath", drag->path);
+ /* copy drag path to properties */
+ RNA_string_set(drop->ptr, "filepath", drag->path);
}
/* area+region dropbox definition */
static void image_dropboxes(void)
{
- ListBase *lb = WM_dropboxmap_find("Image", SPACE_IMAGE, 0);
+ ListBase *lb = WM_dropboxmap_find("Image", SPACE_IMAGE, 0);
- WM_dropbox_add(lb, "IMAGE_OT_open", image_drop_poll, image_drop_copy);
+ WM_dropbox_add(lb, "IMAGE_OT_open", image_drop_poll, image_drop_copy);
}
/**
@@ -342,192 +342,187 @@ static void image_dropboxes(void)
*/
static void image_refresh(const bContext *C, ScrArea *sa)
{
- Scene *scene = CTX_data_scene(C);
- SpaceImage *sima = sa->spacedata.first;
- Image *ima;
-
- ima = ED_space_image(sima);
-
- BKE_image_user_frame_calc(&sima->iuser, scene->r.cfra);
-
- /* check if we have to set the image from the editmesh */
- if (ima && (ima->source == IMA_SRC_VIEWER && sima->mode == SI_MODE_MASK)) {
- if (scene->nodetree) {
- Mask *mask = ED_space_image_get_mask(sima);
- if (mask) {
- ED_node_composite_job(C, scene->nodetree, scene);
- }
- }
- }
+ Scene *scene = CTX_data_scene(C);
+ SpaceImage *sima = sa->spacedata.first;
+ Image *ima;
+
+ ima = ED_space_image(sima);
+
+ BKE_image_user_frame_calc(&sima->iuser, scene->r.cfra);
+
+ /* check if we have to set the image from the editmesh */
+ if (ima && (ima->source == IMA_SRC_VIEWER && sima->mode == SI_MODE_MASK)) {
+ if (scene->nodetree) {
+ Mask *mask = ED_space_image_get_mask(sima);
+ if (mask) {
+ ED_node_composite_job(C, scene->nodetree, scene);
+ }
+ }
+ }
}
static void image_listener(wmWindow *win, ScrArea *sa, wmNotifier *wmn, Scene *UNUSED(scene))
{
- SpaceImage *sima = (SpaceImage *)sa->spacedata.first;
-
- /* context changes */
- switch (wmn->category) {
- case NC_WINDOW:
- /* notifier comes from editing color space */
- image_scopes_tag_refresh(sa);
- ED_area_tag_redraw(sa);
- break;
- case NC_SCENE:
- switch (wmn->data) {
- case ND_FRAME:
- image_scopes_tag_refresh(sa);
- ED_area_tag_refresh(sa);
- ED_area_tag_redraw(sa);
- break;
- case ND_MODE:
- if (wmn->subtype == NS_EDITMODE_MESH) {
- ED_area_tag_refresh(sa);
- }
- ED_area_tag_redraw(sa);
- break;
- case ND_RENDER_RESULT:
- case ND_RENDER_OPTIONS:
- case ND_COMPO_RESULT:
- if (ED_space_image_show_render(sima)) {
- image_scopes_tag_refresh(sa);
- }
- ED_area_tag_redraw(sa);
- break;
- }
- break;
- case NC_IMAGE:
- if (wmn->reference == sima->image || !wmn->reference) {
- if (wmn->action != NA_PAINTING) {
- image_scopes_tag_refresh(sa);
- ED_area_tag_refresh(sa);
- ED_area_tag_redraw(sa);
- }
- }
- break;
- case NC_SPACE:
- if (wmn->data == ND_SPACE_IMAGE) {
- image_scopes_tag_refresh(sa);
- ED_area_tag_redraw(sa);
- }
- break;
- case NC_MASK:
- {
- // Scene *scene = wmn->window->screen->scene;
- /* ideally would check for: ED_space_image_check_show_maskedit(scene, sima)
- * but we cant get the scene */
- if (sima->mode == SI_MODE_MASK) {
- switch (wmn->data) {
- case ND_SELECT:
- ED_area_tag_redraw(sa);
- break;
- case ND_DATA:
- case ND_DRAW:
- /* causes node-recalc */
- ED_area_tag_redraw(sa);
- ED_area_tag_refresh(sa);
- break;
- }
- switch (wmn->action) {
- case NA_SELECTED:
- ED_area_tag_redraw(sa);
- break;
- case NA_EDITED:
- /* causes node-recalc */
- ED_area_tag_redraw(sa);
- ED_area_tag_refresh(sa);
- break;
- }
- }
- break;
- }
- case NC_GEOM:
- {
- switch (wmn->data) {
- case ND_DATA:
- case ND_SELECT:
- image_scopes_tag_refresh(sa);
- ED_area_tag_refresh(sa);
- ED_area_tag_redraw(sa);
- break;
- }
- break;
- }
- case NC_OBJECT:
- {
- switch (wmn->data) {
- case ND_TRANSFORM:
- case ND_MODIFIER:
- {
- ViewLayer *view_layer = WM_window_get_active_view_layer(win);
- Object *ob = OBACT(view_layer);
- if (ob && (ob == wmn->reference) && (ob->mode & OB_MODE_EDIT)) {
- if (sima->lock && (sima->flag & SI_DRAWSHADOW)) {
- ED_area_tag_refresh(sa);
- ED_area_tag_redraw(sa);
- }
- }
- break;
- }
- }
-
- break;
- }
- case NC_ID:
- {
- if (wmn->action == NA_RENAME) {
- ED_area_tag_redraw(sa);
- }
- break;
- }
- case NC_WM:
- if (wmn->data == ND_UNDO) {
- ED_area_tag_redraw(sa);
- ED_area_tag_refresh(sa);
- }
- break;
- }
+ SpaceImage *sima = (SpaceImage *)sa->spacedata.first;
+
+ /* context changes */
+ switch (wmn->category) {
+ case NC_WINDOW:
+ /* notifier comes from editing color space */
+ image_scopes_tag_refresh(sa);
+ ED_area_tag_redraw(sa);
+ break;
+ case NC_SCENE:
+ switch (wmn->data) {
+ case ND_FRAME:
+ image_scopes_tag_refresh(sa);
+ ED_area_tag_refresh(sa);
+ ED_area_tag_redraw(sa);
+ break;
+ case ND_MODE:
+ if (wmn->subtype == NS_EDITMODE_MESH) {
+ ED_area_tag_refresh(sa);
+ }
+ ED_area_tag_redraw(sa);
+ break;
+ case ND_RENDER_RESULT:
+ case ND_RENDER_OPTIONS:
+ case ND_COMPO_RESULT:
+ if (ED_space_image_show_render(sima)) {
+ image_scopes_tag_refresh(sa);
+ }
+ ED_area_tag_redraw(sa);
+ break;
+ }
+ break;
+ case NC_IMAGE:
+ if (wmn->reference == sima->image || !wmn->reference) {
+ if (wmn->action != NA_PAINTING) {
+ image_scopes_tag_refresh(sa);
+ ED_area_tag_refresh(sa);
+ ED_area_tag_redraw(sa);
+ }
+ }
+ break;
+ case NC_SPACE:
+ if (wmn->data == ND_SPACE_IMAGE) {
+ image_scopes_tag_refresh(sa);
+ ED_area_tag_redraw(sa);
+ }
+ break;
+ case NC_MASK: {
+ // Scene *scene = wmn->window->screen->scene;
+ /* ideally would check for: ED_space_image_check_show_maskedit(scene, sima)
+ * but we cant get the scene */
+ if (sima->mode == SI_MODE_MASK) {
+ switch (wmn->data) {
+ case ND_SELECT:
+ ED_area_tag_redraw(sa);
+ break;
+ case ND_DATA:
+ case ND_DRAW:
+ /* causes node-recalc */
+ ED_area_tag_redraw(sa);
+ ED_area_tag_refresh(sa);
+ break;
+ }
+ switch (wmn->action) {
+ case NA_SELECTED:
+ ED_area_tag_redraw(sa);
+ break;
+ case NA_EDITED:
+ /* causes node-recalc */
+ ED_area_tag_redraw(sa);
+ ED_area_tag_refresh(sa);
+ break;
+ }
+ }
+ break;
+ }
+ case NC_GEOM: {
+ switch (wmn->data) {
+ case ND_DATA:
+ case ND_SELECT:
+ image_scopes_tag_refresh(sa);
+ ED_area_tag_refresh(sa);
+ ED_area_tag_redraw(sa);
+ break;
+ }
+ break;
+ }
+ case NC_OBJECT: {
+ switch (wmn->data) {
+ case ND_TRANSFORM:
+ case ND_MODIFIER: {
+ ViewLayer *view_layer = WM_window_get_active_view_layer(win);
+ Object *ob = OBACT(view_layer);
+ if (ob && (ob == wmn->reference) && (ob->mode & OB_MODE_EDIT)) {
+ if (sima->lock && (sima->flag & SI_DRAWSHADOW)) {
+ ED_area_tag_refresh(sa);
+ ED_area_tag_redraw(sa);
+ }
+ }
+ break;
+ }
+ }
+
+ break;
+ }
+ case NC_ID: {
+ if (wmn->action == NA_RENAME) {
+ ED_area_tag_redraw(sa);
+ }
+ break;
+ }
+ case NC_WM:
+ if (wmn->data == ND_UNDO) {
+ ED_area_tag_redraw(sa);
+ ED_area_tag_refresh(sa);
+ }
+ break;
+ }
}
const char *image_context_dir[] = {"edit_image", "edit_mask", NULL};
static int image_context(const bContext *C, const char *member, bContextDataResult *result)
{
- SpaceImage *sima = CTX_wm_space_image(C);
-
- if (CTX_data_dir(member)) {
- CTX_data_dir_set(result, image_context_dir);
- }
- else if (CTX_data_equals(member, "edit_image")) {
- CTX_data_id_pointer_set(result, (ID *)ED_space_image(sima));
- return 1;
- }
- else if (CTX_data_equals(member, "edit_mask")) {
- Mask *mask = ED_space_image_get_mask(sima);
- if (mask) {
- CTX_data_id_pointer_set(result, &mask->id);
- }
- return true;
- }
- return 0;
+ SpaceImage *sima = CTX_wm_space_image(C);
+
+ if (CTX_data_dir(member)) {
+ CTX_data_dir_set(result, image_context_dir);
+ }
+ else if (CTX_data_equals(member, "edit_image")) {
+ CTX_data_id_pointer_set(result, (ID *)ED_space_image(sima));
+ return 1;
+ }
+ else if (CTX_data_equals(member, "edit_mask")) {
+ Mask *mask = ED_space_image_get_mask(sima);
+ if (mask) {
+ CTX_data_id_pointer_set(result, &mask->id);
+ }
+ return true;
+ }
+ return 0;
}
static void IMAGE_GGT_gizmo2d(wmGizmoGroupType *gzgt)
{
- gzgt->name = "UV Transform Gizmo";
- gzgt->idname = "IMAGE_GGT_gizmo2d";
+ gzgt->name = "UV Transform Gizmo";
+ gzgt->idname = "IMAGE_GGT_gizmo2d";
- gzgt->gzmap_params.spaceid = SPACE_IMAGE;
- gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW;
+ gzgt->gzmap_params.spaceid = SPACE_IMAGE;
+ gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW;
- gzgt->poll = ED_widgetgroup_gizmo2d_poll;
- gzgt->setup = ED_widgetgroup_gizmo2d_setup;
- gzgt->refresh = ED_widgetgroup_gizmo2d_refresh;
- gzgt->draw_prepare = ED_widgetgroup_gizmo2d_draw_prepare;
+ gzgt->poll = ED_widgetgroup_gizmo2d_poll;
+ gzgt->setup = ED_widgetgroup_gizmo2d_setup;
+ gzgt->refresh = ED_widgetgroup_gizmo2d_refresh;
+ gzgt->draw_prepare = ED_widgetgroup_gizmo2d_draw_prepare;
}
static void image_widgets(void)
{
- WM_gizmogrouptype_append(IMAGE_GGT_gizmo2d);
+ WM_gizmogrouptype_append(IMAGE_GGT_gizmo2d);
}
/************************** main region ***************************/
@@ -535,261 +530,266 @@ static void image_widgets(void)
/* sets up the fields of the View2D from zoom and offset */
static void image_main_region_set_view2d(SpaceImage *sima, ARegion *ar)
{
- Image *ima = ED_space_image(sima);
+ Image *ima = ED_space_image(sima);
- int width, height;
- ED_space_image_get_size(sima, &width, &height);
+ int width, height;
+ ED_space_image_get_size(sima, &width, &height);
- float w = width;
- float h = height;
+ float w = width;
+ float h = height;
- if (ima) {
- h *= ima->aspy / ima->aspx;
- }
+ if (ima) {
+ h *= ima->aspy / ima->aspx;
+ }
- int winx = BLI_rcti_size_x(&ar->winrct) + 1;
- int winy = BLI_rcti_size_y(&ar->winrct) + 1;
+ int winx = BLI_rcti_size_x(&ar->winrct) + 1;
+ int winy = BLI_rcti_size_y(&ar->winrct) + 1;
- /* For region overlap, move center so image doesn't overlap header. */
- rcti visible_rect;
- ED_region_visible_rect(ar, &visible_rect);
- const int visible_winy = BLI_rcti_size_y(&visible_rect) + 1;
- int visible_centerx = 0;
- int visible_centery = visible_rect.ymin + (visible_winy - winy) / 2;
+ /* For region overlap, move center so image doesn't overlap header. */
+ rcti visible_rect;
+ ED_region_visible_rect(ar, &visible_rect);
+ const int visible_winy = BLI_rcti_size_y(&visible_rect) + 1;
+ int visible_centerx = 0;
+ int visible_centery = visible_rect.ymin + (visible_winy - winy) / 2;
- ar->v2d.tot.xmin = 0;
- ar->v2d.tot.ymin = 0;
- ar->v2d.tot.xmax = w;
- ar->v2d.tot.ymax = h;
+ ar->v2d.tot.xmin = 0;
+ ar->v2d.tot.ymin = 0;
+ ar->v2d.tot.xmax = w;
+ ar->v2d.tot.ymax = h;
- ar->v2d.mask.xmin = ar->v2d.mask.ymin = 0;
- ar->v2d.mask.xmax = winx;
- ar->v2d.mask.ymax = winy;
+ ar->v2d.mask.xmin = ar->v2d.mask.ymin = 0;
+ ar->v2d.mask.xmax = winx;
+ ar->v2d.mask.ymax = winy;
- /* which part of the image space do we see? */
- float x1 = ar->winrct.xmin + visible_centerx + (winx - sima->zoom * w) / 2.0f;
- float y1 = ar->winrct.ymin + visible_centery + (winy - sima->zoom * h) / 2.0f;
+ /* which part of the image space do we see? */
+ float x1 = ar->winrct.xmin + visible_centerx + (winx - sima->zoom * w) / 2.0f;
+ float y1 = ar->winrct.ymin + visible_centery + (winy - sima->zoom * h) / 2.0f;
- x1 -= sima->zoom * sima->xof;
- y1 -= sima->zoom * sima->yof;
+ x1 -= sima->zoom * sima->xof;
+ y1 -= sima->zoom * sima->yof;
- /* relative display right */
- ar->v2d.cur.xmin = ((ar->winrct.xmin - (float)x1) / sima->zoom);
- ar->v2d.cur.xmax = ar->v2d.cur.xmin + ((float)winx / sima->zoom);
+ /* relative display right */
+ ar->v2d.cur.xmin = ((ar->winrct.xmin - (float)x1) / sima->zoom);
+ ar->v2d.cur.xmax = ar->v2d.cur.xmin + ((float)winx / sima->zoom);
- /* relative display left */
- ar->v2d.cur.ymin = ((ar->winrct.ymin - (float)y1) / sima->zoom);
- ar->v2d.cur.ymax = ar->v2d.cur.ymin + ((float)winy / sima->zoom);
+ /* relative display left */
+ ar->v2d.cur.ymin = ((ar->winrct.ymin - (float)y1) / sima->zoom);
+ ar->v2d.cur.ymax = ar->v2d.cur.ymin + ((float)winy / sima->zoom);
- /* normalize 0.0..1.0 */
- ar->v2d.cur.xmin /= w;
- ar->v2d.cur.xmax /= w;
- ar->v2d.cur.ymin /= h;
- ar->v2d.cur.ymax /= h;
+ /* normalize 0.0..1.0 */
+ ar->v2d.cur.xmin /= w;
+ ar->v2d.cur.xmax /= w;
+ ar->v2d.cur.ymin /= h;
+ ar->v2d.cur.ymax /= h;
}
/* add handlers, stuff you only do once or on area/region changes */
static void image_main_region_init(wmWindowManager *wm, ARegion *ar)
{
- wmKeyMap *keymap;
+ wmKeyMap *keymap;
- // image space manages own v2d
- // UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
+ // image space manages own v2d
+ // UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
- /* mask polls mode */
- keymap = WM_keymap_ensure(wm->defaultconf, "Mask Editing", 0, 0);
- WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+ /* mask polls mode */
+ keymap = WM_keymap_ensure(wm->defaultconf, "Mask Editing", 0, 0);
+ WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
- /* image paint polls for mode */
- keymap = WM_keymap_ensure(wm->defaultconf, "Curve", 0, 0);
- WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+ /* image paint polls for mode */
+ keymap = WM_keymap_ensure(wm->defaultconf, "Curve", 0, 0);
+ WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
- keymap = WM_keymap_ensure(wm->defaultconf, "Paint Curve", 0, 0);
- WM_event_add_keymap_handler(&ar->handlers, keymap);
+ keymap = WM_keymap_ensure(wm->defaultconf, "Paint Curve", 0, 0);
+ WM_event_add_keymap_handler(&ar->handlers, keymap);
- keymap = WM_keymap_ensure(wm->defaultconf, "Image Paint", 0, 0);
- WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+ keymap = WM_keymap_ensure(wm->defaultconf, "Image Paint", 0, 0);
+ WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
- keymap = WM_keymap_ensure(wm->defaultconf, "UV Editor", 0, 0);
- WM_event_add_keymap_handler(&ar->handlers, keymap);
+ keymap = WM_keymap_ensure(wm->defaultconf, "UV Editor", 0, 0);
+ WM_event_add_keymap_handler(&ar->handlers, keymap);
- keymap = WM_keymap_ensure(wm->defaultconf, "UV Sculpt", 0, 0);
- WM_event_add_keymap_handler(&ar->handlers, keymap);
+ keymap = WM_keymap_ensure(wm->defaultconf, "UV Sculpt", 0, 0);
+ WM_event_add_keymap_handler(&ar->handlers, keymap);
- /* own keymaps */
- keymap = WM_keymap_ensure(wm->defaultconf, "Image Generic", SPACE_IMAGE, 0);
- WM_event_add_keymap_handler(&ar->handlers, keymap);
- keymap = WM_keymap_ensure(wm->defaultconf, "Image", SPACE_IMAGE, 0);
- WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+ /* own keymaps */
+ keymap = WM_keymap_ensure(wm->defaultconf, "Image Generic", SPACE_IMAGE, 0);
+ WM_event_add_keymap_handler(&ar->handlers, keymap);
+ keymap = WM_keymap_ensure(wm->defaultconf, "Image", SPACE_IMAGE, 0);
+ WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
}
static void image_main_region_draw(const bContext *C, ARegion *ar)
{
- /* draw entirely, view changes should be handled here */
- SpaceImage *sima = CTX_wm_space_image(C);
- Object *obact = CTX_data_active_object(C);
- Object *obedit = CTX_data_edit_object(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
- Mask *mask = NULL;
- bool curve = false;
- Scene *scene = CTX_data_scene(C);
- ViewLayer *view_layer = CTX_data_view_layer(C);
- View2D *v2d = &ar->v2d;
- //View2DScrollers *scrollers;
- float col[3];
-
- /* XXX This is in order to draw UI batches with the DRW
- * olg context since we now use it for drawing the entire area */
- gpu_batch_presets_reset();
-
- /* TODO(fclem) port to draw manager and remove the depth buffer allocation. */
- GPUViewport *viewport = ar->draw_buffer->viewport[ar->draw_buffer->stereo ? sima->iuser.multiview_eye : 0];
- DefaultFramebufferList *fbl = GPU_viewport_framebuffer_list_get(viewport);
- GPU_framebuffer_bind(fbl->color_only_fb);
-
- /* XXX not supported yet, disabling for now */
- scene->r.scemode &= ~R_COMP_CROP;
-
- /* clear and setup matrix */
- UI_GetThemeColor3fv(TH_BACK, col);
- GPU_clear_color(col[0], col[1], col[2], 0.0);
- GPU_clear(GPU_COLOR_BIT);
-
- image_user_refresh_scene(C, sima);
-
- /* we set view2d from own zoom and offset each time */
- image_main_region_set_view2d(sima, ar);
-
- /* we draw image in pixelspace */
- draw_image_main(C, ar);
-
- /* and uvs in 0.0-1.0 space */
- UI_view2d_view_ortho(v2d);
-
- ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
-
- ED_uvedit_draw_main(sima, ar, scene, view_layer, obedit, obact, depsgraph);
-
- /* check for mask (delay draw) */
- if (ED_space_image_show_uvedit(sima, obedit)) {
- /* pass */
- }
- else if (sima->mode == SI_MODE_MASK) {
- mask = ED_space_image_get_mask(sima);
- }
- else if (ED_space_image_paint_curve(C)) {
- curve = true;
- }
-
- ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
-
- if (sima->flag & SI_SHOW_GPENCIL) {
- /* Grease Pencil too (in addition to UV's) */
- draw_image_grease_pencil((bContext *)C, true);
- }
-
- /* sample line */
- draw_image_sample_line(sima);
-
- UI_view2d_view_restore(C);
-
- if (sima->flag & SI_SHOW_GPENCIL) {
- /* draw Grease Pencil - screen space only */
- draw_image_grease_pencil((bContext *)C, false);
- }
-
- if (mask) {
- Image *image = ED_space_image(sima);
- int width, height, show_viewer;
- float aspx, aspy;
-
- show_viewer = (image && image->source == IMA_SRC_VIEWER);
-
- if (show_viewer) {
- /* ED_space_image_get* will acquire image buffer which requires
- * lock here by the same reason why lock is needed in draw_image_main
- */
- BLI_thread_lock(LOCK_DRAW_IMAGE);
- }
-
- ED_space_image_get_size(sima, &width, &height);
- ED_space_image_get_aspect(sima, &aspx, &aspy);
-
- if (show_viewer) {
- BLI_thread_unlock(LOCK_DRAW_IMAGE);
- }
-
- ED_mask_draw_region(mask, ar,
- sima->mask_info.draw_flag,
- sima->mask_info.draw_type,
- sima->mask_info.overlay_mode,
- width, height,
- aspx, aspy,
- true, false,
- NULL, C);
-
- UI_view2d_view_ortho(v2d);
- ED_image_draw_cursor(ar, sima->cursor);
- UI_view2d_view_restore(C);
- }
- else if (curve) {
- UI_view2d_view_ortho(v2d);
- ED_image_draw_cursor(ar, sima->cursor);
- UI_view2d_view_restore(C);
- }
-
- WM_gizmomap_draw(ar->gizmo_map, C, WM_GIZMOMAP_DRAWSTEP_2D);
-
- draw_image_cache(C, ar);
-
- /* scrollers? */
+ /* draw entirely, view changes should be handled here */
+ SpaceImage *sima = CTX_wm_space_image(C);
+ Object *obact = CTX_data_active_object(C);
+ Object *obedit = CTX_data_edit_object(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ Mask *mask = NULL;
+ bool curve = false;
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ View2D *v2d = &ar->v2d;
+ //View2DScrollers *scrollers;
+ float col[3];
+
+ /* XXX This is in order to draw UI batches with the DRW
+ * olg context since we now use it for drawing the entire area */
+ gpu_batch_presets_reset();
+
+ /* TODO(fclem) port to draw manager and remove the depth buffer allocation. */
+ GPUViewport *viewport =
+ ar->draw_buffer->viewport[ar->draw_buffer->stereo ? sima->iuser.multiview_eye : 0];
+ DefaultFramebufferList *fbl = GPU_viewport_framebuffer_list_get(viewport);
+ GPU_framebuffer_bind(fbl->color_only_fb);
+
+ /* XXX not supported yet, disabling for now */
+ scene->r.scemode &= ~R_COMP_CROP;
+
+ /* clear and setup matrix */
+ UI_GetThemeColor3fv(TH_BACK, col);
+ GPU_clear_color(col[0], col[1], col[2], 0.0);
+ GPU_clear(GPU_COLOR_BIT);
+
+ image_user_refresh_scene(C, sima);
+
+ /* we set view2d from own zoom and offset each time */
+ image_main_region_set_view2d(sima, ar);
+
+ /* we draw image in pixelspace */
+ draw_image_main(C, ar);
+
+ /* and uvs in 0.0-1.0 space */
+ UI_view2d_view_ortho(v2d);
+
+ ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
+
+ ED_uvedit_draw_main(sima, ar, scene, view_layer, obedit, obact, depsgraph);
+
+ /* check for mask (delay draw) */
+ if (ED_space_image_show_uvedit(sima, obedit)) {
+ /* pass */
+ }
+ else if (sima->mode == SI_MODE_MASK) {
+ mask = ED_space_image_get_mask(sima);
+ }
+ else if (ED_space_image_paint_curve(C)) {
+ curve = true;
+ }
+
+ ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
+
+ if (sima->flag & SI_SHOW_GPENCIL) {
+ /* Grease Pencil too (in addition to UV's) */
+ draw_image_grease_pencil((bContext *)C, true);
+ }
+
+ /* sample line */
+ draw_image_sample_line(sima);
+
+ UI_view2d_view_restore(C);
+
+ if (sima->flag & SI_SHOW_GPENCIL) {
+ /* draw Grease Pencil - screen space only */
+ draw_image_grease_pencil((bContext *)C, false);
+ }
+
+ if (mask) {
+ Image *image = ED_space_image(sima);
+ int width, height, show_viewer;
+ float aspx, aspy;
+
+ show_viewer = (image && image->source == IMA_SRC_VIEWER);
+
+ if (show_viewer) {
+ /* ED_space_image_get* will acquire image buffer which requires
+ * lock here by the same reason why lock is needed in draw_image_main
+ */
+ BLI_thread_lock(LOCK_DRAW_IMAGE);
+ }
+
+ ED_space_image_get_size(sima, &width, &height);
+ ED_space_image_get_aspect(sima, &aspx, &aspy);
+
+ if (show_viewer) {
+ BLI_thread_unlock(LOCK_DRAW_IMAGE);
+ }
+
+ ED_mask_draw_region(mask,
+ ar,
+ sima->mask_info.draw_flag,
+ sima->mask_info.draw_type,
+ sima->mask_info.overlay_mode,
+ width,
+ height,
+ aspx,
+ aspy,
+ true,
+ false,
+ NULL,
+ C);
+
+ UI_view2d_view_ortho(v2d);
+ ED_image_draw_cursor(ar, sima->cursor);
+ UI_view2d_view_restore(C);
+ }
+ else if (curve) {
+ UI_view2d_view_ortho(v2d);
+ ED_image_draw_cursor(ar, sima->cursor);
+ UI_view2d_view_restore(C);
+ }
+
+ WM_gizmomap_draw(ar->gizmo_map, C, WM_GIZMOMAP_DRAWSTEP_2D);
+
+ draw_image_cache(C, ar);
+
+ /* scrollers? */
#if 0
- scrollers = UI_view2d_scrollers_calc(C, v2d, V2D_UNIT_VALUES, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
- UI_view2d_scrollers_draw(C, v2d, scrollers);
- UI_view2d_scrollers_free(scrollers);
+ scrollers = UI_view2d_scrollers_calc(C, v2d, V2D_UNIT_VALUES, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
+ UI_view2d_scrollers_draw(C, v2d, scrollers);
+ UI_view2d_scrollers_free(scrollers);
#endif
}
static void image_main_region_listener(
- wmWindow *UNUSED(win), ScrArea *sa, ARegion *ar,
- wmNotifier *wmn, const Scene *UNUSED(scene))
+ wmWindow *UNUSED(win), ScrArea *sa, ARegion *ar, wmNotifier *wmn, const Scene *UNUSED(scene))
{
- /* context changes */
- switch (wmn->category) {
- case NC_GEOM:
- if (ELEM(wmn->data, ND_DATA, ND_SELECT)) {
- WM_gizmomap_tag_refresh(ar->gizmo_map);
- }
- break;
- case NC_GPENCIL:
- if (ELEM(wmn->action, NA_EDITED, NA_SELECTED)) {
- ED_region_tag_redraw(ar);
- }
- else if (wmn->data & ND_GPENCIL_EDITMODE) {
- ED_region_tag_redraw(ar);
- }
- break;
- case NC_IMAGE:
- if (wmn->action == NA_PAINTING) {
- ED_region_tag_redraw(ar);
- }
- WM_gizmomap_tag_refresh(ar->gizmo_map);
- break;
- case NC_MATERIAL:
- if (wmn->data == ND_SHADING_LINKS) {
- SpaceImage *sima = sa->spacedata.first;
-
- if (sima->iuser.scene && (sima->iuser.scene->toolsettings->uv_flag & UV_SHOW_SAME_IMAGE)) {
- ED_region_tag_redraw(ar);
- }
- }
- break;
- case NC_SCREEN:
- if (ELEM(wmn->data, ND_LAYER)) {
- ED_region_tag_redraw(ar);
- }
- break;
- }
+ /* context changes */
+ switch (wmn->category) {
+ case NC_GEOM:
+ if (ELEM(wmn->data, ND_DATA, ND_SELECT)) {
+ WM_gizmomap_tag_refresh(ar->gizmo_map);
+ }
+ break;
+ case NC_GPENCIL:
+ if (ELEM(wmn->action, NA_EDITED, NA_SELECTED)) {
+ ED_region_tag_redraw(ar);
+ }
+ else if (wmn->data & ND_GPENCIL_EDITMODE) {
+ ED_region_tag_redraw(ar);
+ }
+ break;
+ case NC_IMAGE:
+ if (wmn->action == NA_PAINTING) {
+ ED_region_tag_redraw(ar);
+ }
+ WM_gizmomap_tag_refresh(ar->gizmo_map);
+ break;
+ case NC_MATERIAL:
+ if (wmn->data == ND_SHADING_LINKS) {
+ SpaceImage *sima = sa->spacedata.first;
+
+ if (sima->iuser.scene && (sima->iuser.scene->toolsettings->uv_flag & UV_SHOW_SAME_IMAGE)) {
+ ED_region_tag_redraw(ar);
+ }
+ }
+ break;
+ case NC_SCREEN:
+ if (ELEM(wmn->data, ND_LAYER)) {
+ ED_region_tag_redraw(ar);
+ }
+ break;
+ }
}
/* *********************** buttons region ************************ */
@@ -797,78 +797,81 @@ static void image_main_region_listener(
/* add handlers, stuff you only do once or on area/region changes */
static void image_buttons_region_init(wmWindowManager *wm, ARegion *ar)
{
- wmKeyMap *keymap;
+ wmKeyMap *keymap;
- ar->v2d.scroll = V2D_SCROLL_RIGHT | V2D_SCROLL_VERTICAL_HIDE;
- ED_region_panels_init(wm, ar);
+ ar->v2d.scroll = V2D_SCROLL_RIGHT | V2D_SCROLL_VERTICAL_HIDE;
+ ED_region_panels_init(wm, ar);
- keymap = WM_keymap_ensure(wm->defaultconf, "Image Generic", SPACE_IMAGE, 0);
- WM_event_add_keymap_handler(&ar->handlers, keymap);
+ keymap = WM_keymap_ensure(wm->defaultconf, "Image Generic", SPACE_IMAGE, 0);
+ WM_event_add_keymap_handler(&ar->handlers, keymap);
}
static void image_buttons_region_draw(const bContext *C, ARegion *ar)
{
- SpaceImage *sima = CTX_wm_space_image(C);
- Scene *scene = CTX_data_scene(C);
- void *lock;
- ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
- /* XXX performance regression if name of scopes category changes! */
- PanelCategoryStack *category = UI_panel_category_active_find(ar, "Scopes");
-
- /* only update scopes if scope category is active */
- if (category) {
- if (ibuf) {
- if (!sima->scopes.ok) {
- BKE_histogram_update_sample_line(&sima->sample_line_hist, ibuf, &scene->view_settings, &scene->display_settings);
- }
- if (sima->image->flag & IMA_VIEW_AS_RENDER) {
- ED_space_image_scopes_update(C, sima, ibuf, true);
- }
- else {
- ED_space_image_scopes_update(C, sima, ibuf, false);
- }
- }
- }
- ED_space_image_release_buffer(sima, ibuf, lock);
-
- ED_region_panels(C, ar);
+ SpaceImage *sima = CTX_wm_space_image(C);
+ Scene *scene = CTX_data_scene(C);
+ void *lock;
+ ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
+ /* XXX performance regression if name of scopes category changes! */
+ PanelCategoryStack *category = UI_panel_category_active_find(ar, "Scopes");
+
+ /* only update scopes if scope category is active */
+ if (category) {
+ if (ibuf) {
+ if (!sima->scopes.ok) {
+ BKE_histogram_update_sample_line(
+ &sima->sample_line_hist, ibuf, &scene->view_settings, &scene->display_settings);
+ }
+ if (sima->image->flag & IMA_VIEW_AS_RENDER) {
+ ED_space_image_scopes_update(C, sima, ibuf, true);
+ }
+ else {
+ ED_space_image_scopes_update(C, sima, ibuf, false);
+ }
+ }
+ }
+ ED_space_image_release_buffer(sima, ibuf, lock);
+
+ ED_region_panels(C, ar);
}
-static void image_buttons_region_listener(
- wmWindow *UNUSED(win), ScrArea *UNUSED(sa), ARegion *ar,
- wmNotifier *wmn, const Scene *UNUSED(scene))
+static void image_buttons_region_listener(wmWindow *UNUSED(win),
+ ScrArea *UNUSED(sa),
+ ARegion *ar,
+ wmNotifier *wmn,
+ const Scene *UNUSED(scene))
{
- /* context changes */
- switch (wmn->category) {
- case NC_TEXTURE:
- case NC_MATERIAL:
- /* sending by texture render job and needed to properly update displaying
- * brush texture icon */
- ED_region_tag_redraw(ar);
- break;
- case NC_SCENE:
- switch (wmn->data) {
- case ND_MODE:
- case ND_RENDER_RESULT:
- case ND_COMPO_RESULT:
- ED_region_tag_redraw(ar);
- break;
- }
- break;
- case NC_IMAGE:
- if (wmn->action != NA_PAINTING) {
- ED_region_tag_redraw(ar);
- }
- break;
- case NC_NODE:
- ED_region_tag_redraw(ar);
- break;
- case NC_GPENCIL:
- if (ELEM(wmn->action, NA_EDITED, NA_SELECTED)) {
- ED_region_tag_redraw(ar);
- }
- break;
- }
+ /* context changes */
+ switch (wmn->category) {
+ case NC_TEXTURE:
+ case NC_MATERIAL:
+ /* sending by texture render job and needed to properly update displaying
+ * brush texture icon */
+ ED_region_tag_redraw(ar);
+ break;
+ case NC_SCENE:
+ switch (wmn->data) {
+ case ND_MODE:
+ case ND_RENDER_RESULT:
+ case ND_COMPO_RESULT:
+ ED_region_tag_redraw(ar);
+ break;
+ }
+ break;
+ case NC_IMAGE:
+ if (wmn->action != NA_PAINTING) {
+ ED_region_tag_redraw(ar);
+ }
+ break;
+ case NC_NODE:
+ ED_region_tag_redraw(ar);
+ break;
+ case NC_GPENCIL:
+ if (ELEM(wmn->action, NA_EDITED, NA_SELECTED)) {
+ ED_region_tag_redraw(ar);
+ }
+ break;
+ }
}
/* *********************** scopes region ************************ */
@@ -876,56 +879,57 @@ static void image_buttons_region_listener(
/* add handlers, stuff you only do once or on area/region changes */
static void image_tools_region_init(wmWindowManager *wm, ARegion *ar)
{
- wmKeyMap *keymap;
+ wmKeyMap *keymap;
- ar->v2d.scroll = V2D_SCROLL_RIGHT | V2D_SCROLL_VERTICAL_HIDE;
- ED_region_panels_init(wm, ar);
+ ar->v2d.scroll = V2D_SCROLL_RIGHT | V2D_SCROLL_VERTICAL_HIDE;
+ ED_region_panels_init(wm, ar);
- keymap = WM_keymap_ensure(wm->defaultconf, "Image Generic", SPACE_IMAGE, 0);
- WM_event_add_keymap_handler(&ar->handlers, keymap);
+ keymap = WM_keymap_ensure(wm->defaultconf, "Image Generic", SPACE_IMAGE, 0);
+ WM_event_add_keymap_handler(&ar->handlers, keymap);
}
static void image_tools_region_draw(const bContext *C, ARegion *ar)
{
- ED_region_panels(C, ar);
+ ED_region_panels(C, ar);
}
-static void image_tools_region_listener(
- wmWindow *UNUSED(win), ScrArea *UNUSED(sa), ARegion *ar,
- wmNotifier *wmn, const Scene *UNUSED(scene))
+static void image_tools_region_listener(wmWindow *UNUSED(win),
+ ScrArea *UNUSED(sa),
+ ARegion *ar,
+ wmNotifier *wmn,
+ const Scene *UNUSED(scene))
{
- /* context changes */
- switch (wmn->category) {
- case NC_GPENCIL:
- if (wmn->data == ND_DATA || ELEM(wmn->action, NA_EDITED, NA_SELECTED)) {
- ED_region_tag_redraw(ar);
- }
- break;
- case NC_BRUSH:
- /* NA_SELECTED is used on brush changes */
- if (ELEM(wmn->action, NA_EDITED, NA_SELECTED)) {
- ED_region_tag_redraw(ar);
- }
- break;
- case NC_SCENE:
- switch (wmn->data) {
- case ND_MODE:
- case ND_RENDER_RESULT:
- case ND_COMPO_RESULT:
- ED_region_tag_redraw(ar);
- break;
- }
- break;
- case NC_IMAGE:
- if (wmn->action != NA_PAINTING) {
- ED_region_tag_redraw(ar);
- }
- break;
- case NC_NODE:
- ED_region_tag_redraw(ar);
- break;
-
- }
+ /* context changes */
+ switch (wmn->category) {
+ case NC_GPENCIL:
+ if (wmn->data == ND_DATA || ELEM(wmn->action, NA_EDITED, NA_SELECTED)) {
+ ED_region_tag_redraw(ar);
+ }
+ break;
+ case NC_BRUSH:
+ /* NA_SELECTED is used on brush changes */
+ if (ELEM(wmn->action, NA_EDITED, NA_SELECTED)) {
+ ED_region_tag_redraw(ar);
+ }
+ break;
+ case NC_SCENE:
+ switch (wmn->data) {
+ case ND_MODE:
+ case ND_RENDER_RESULT:
+ case ND_COMPO_RESULT:
+ ED_region_tag_redraw(ar);
+ break;
+ }
+ break;
+ case NC_IMAGE:
+ if (wmn->action != NA_PAINTING) {
+ ED_region_tag_redraw(ar);
+ }
+ break;
+ case NC_NODE:
+ ED_region_tag_redraw(ar);
+ break;
+ }
}
/************************* header region **************************/
@@ -933,67 +937,69 @@ static void image_tools_region_listener(
/* add handlers, stuff you only do once or on area/region changes */
static void image_header_region_init(wmWindowManager *UNUSED(wm), ARegion *ar)
{
- ED_region_header_init(ar);
+ ED_region_header_init(ar);
}
static void image_header_region_draw(const bContext *C, ARegion *ar)
{
- ScrArea *sa = CTX_wm_area(C);
- SpaceImage *sima = sa->spacedata.first;
+ ScrArea *sa = CTX_wm_area(C);
+ SpaceImage *sima = sa->spacedata.first;
- image_user_refresh_scene(C, sima);
+ image_user_refresh_scene(C, sima);
- ED_region_header(C, ar);
+ ED_region_header(C, ar);
}
-static void image_header_region_listener(
- wmWindow *UNUSED(win), ScrArea *UNUSED(sa), ARegion *ar,
- wmNotifier *wmn, const Scene *UNUSED(scene))
+static void image_header_region_listener(wmWindow *UNUSED(win),
+ ScrArea *UNUSED(sa),
+ ARegion *ar,
+ wmNotifier *wmn,
+ const Scene *UNUSED(scene))
{
- /* context changes */
- switch (wmn->category) {
- case NC_SCENE:
- switch (wmn->data) {
- case ND_MODE:
- case ND_TOOLSETTINGS:
- ED_region_tag_redraw(ar);
- break;
- }
- break;
- case NC_GEOM:
- switch (wmn->data) {
- case ND_DATA:
- case ND_SELECT:
- ED_region_tag_redraw(ar);
- break;
- }
- break;
- }
+ /* context changes */
+ switch (wmn->category) {
+ case NC_SCENE:
+ switch (wmn->data) {
+ case ND_MODE:
+ case ND_TOOLSETTINGS:
+ ED_region_tag_redraw(ar);
+ break;
+ }
+ break;
+ case NC_GEOM:
+ switch (wmn->data) {
+ case ND_DATA:
+ case ND_SELECT:
+ ED_region_tag_redraw(ar);
+ break;
+ }
+ break;
+ }
}
static void image_id_remap(ScrArea *UNUSED(sa), SpaceLink *slink, ID *old_id, ID *new_id)
{
- SpaceImage *simg = (SpaceImage *)slink;
-
- if (!ELEM(GS(old_id->name), ID_IM, ID_GD, ID_MSK)) {
- return;
- }
-
- if ((ID *)simg->image == old_id) {
- simg->image = (Image *)new_id;
- id_us_ensure_real(new_id);
- }
-
- if ((ID *)simg->gpd == old_id) {
- simg->gpd = (bGPdata *)new_id;
- id_us_min(old_id);
- id_us_plus(new_id);
- }
-
- if ((ID *)simg->mask_info.mask == old_id) {
- simg->mask_info.mask = (Mask *)new_id;
- id_us_ensure_real(new_id);
- }
+ SpaceImage *simg = (SpaceImage *)slink;
+
+ if (!ELEM(GS(old_id->name), ID_IM, ID_GD, ID_MSK)) {
+ return;
+ }
+
+ if ((ID *)simg->image == old_id) {
+ simg->image = (Image *)new_id;
+ id_us_ensure_real(new_id);
+ }
+
+ if ((ID *)simg->gpd == old_id) {
+ simg->gpd = (bGPdata *)new_id;
+ id_us_min(old_id);
+ id_us_plus(new_id);
+ }
+
+ if ((ID *)simg->mask_info.mask == old_id) {
+ simg->mask_info.mask = (Mask *)new_id;
+ id_us_ensure_real(new_id);
+ }
}
/**
@@ -1003,28 +1009,29 @@ static void image_id_remap(ScrArea *UNUSED(sa), SpaceLink *slink, ID *old_id, ID
*/
static int image_space_subtype_get(ScrArea *sa)
{
- SpaceImage *sima = sa->spacedata.first;
- return sima->mode == SI_MODE_UV ? SI_MODE_UV : SI_MODE_VIEW;
+ SpaceImage *sima = sa->spacedata.first;
+ return sima->mode == SI_MODE_UV ? SI_MODE_UV : SI_MODE_VIEW;
}
static void image_space_subtype_set(ScrArea *sa, int value)
{
- SpaceImage *sima = sa->spacedata.first;
- if (value == SI_MODE_UV) {
- if (sima->mode != SI_MODE_UV) {
- sima->mode_prev = sima->mode;
- }
- sima->mode = value;
- }
- else {
- sima->mode = sima->mode_prev;
- }
+ SpaceImage *sima = sa->spacedata.first;
+ if (value == SI_MODE_UV) {
+ if (sima->mode != SI_MODE_UV) {
+ sima->mode_prev = sima->mode;
+ }
+ sima->mode = value;
+ }
+ else {
+ sima->mode = sima->mode_prev;
+ }
}
-static void image_space_subtype_item_extend(
- bContext *UNUSED(C), EnumPropertyItem **item, int *totitem)
+static void image_space_subtype_item_extend(bContext *UNUSED(C),
+ EnumPropertyItem **item,
+ int *totitem)
{
- RNA_enum_items_add(item, totitem, rna_enum_space_image_mode_items);
+ RNA_enum_items_add(item, totitem, rna_enum_space_image_mode_items);
}
/**************************** spacetype *****************************/
@@ -1032,77 +1039,77 @@ static void image_space_subtype_item_extend(
/* only called once, from space/spacetypes.c */
void ED_spacetype_image(void)
{
- SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype image");
- ARegionType *art;
-
- st->spaceid = SPACE_IMAGE;
- strncpy(st->name, "Image", BKE_ST_MAXNAME);
-
- st->new = image_new;
- st->free = image_free;
- st->init = image_init;
- st->duplicate = image_duplicate;
- st->operatortypes = image_operatortypes;
- st->keymap = image_keymap;
- st->dropboxes = image_dropboxes;
- st->refresh = image_refresh;
- st->listener = image_listener;
- st->context = image_context;
- st->gizmos = image_widgets;
- st->id_remap = image_id_remap;
- st->space_subtype_item_extend = image_space_subtype_item_extend;
- st->space_subtype_get = image_space_subtype_get;
- st->space_subtype_set = image_space_subtype_set;
-
- /* regions: main window */
- art = MEM_callocN(sizeof(ARegionType), "spacetype image region");
- art->regionid = RGN_TYPE_WINDOW;
- art->keymapflag = ED_KEYMAP_GIZMO | ED_KEYMAP_TOOL | ED_KEYMAP_FRAMES | ED_KEYMAP_GPENCIL;
- art->init = image_main_region_init;
- art->draw = image_main_region_draw;
- art->listener = image_main_region_listener;
- BLI_addhead(&st->regiontypes, art);
-
- /* regions: listview/buttons/scopes */
- art = MEM_callocN(sizeof(ARegionType), "spacetype image region");
- art->regionid = RGN_TYPE_UI;
- art->prefsizex = 220; // XXX
- art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
- art->listener = image_buttons_region_listener;
- art->init = image_buttons_region_init;
- art->draw = image_buttons_region_draw;
- BLI_addhead(&st->regiontypes, art);
-
- ED_uvedit_buttons_register(art);
- image_buttons_register(art);
-
- /* regions: tool(bar) */
- art = MEM_callocN(sizeof(ARegionType), "spacetype image region");
- art->regionid = RGN_TYPE_TOOLS;
- art->prefsizex = 58; /* XXX */
- art->prefsizey = 50; /* XXX */
- art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
- art->listener = image_tools_region_listener;
- art->message_subscribe = ED_region_generic_tools_region_message_subscribe;
- art->snap_size = ED_region_generic_tools_region_snap_size;
- art->init = image_tools_region_init;
- art->draw = image_tools_region_draw;
- BLI_addhead(&st->regiontypes, art);
-
- /* regions: header */
- art = MEM_callocN(sizeof(ARegionType), "spacetype image region");
- art->regionid = RGN_TYPE_HEADER;
- art->prefsizey = HEADERY;
- art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER;
- art->listener = image_header_region_listener;
- art->init = image_header_region_init;
- art->draw = image_header_region_draw;
-
- BLI_addhead(&st->regiontypes, art);
-
- /* regions: hud */
- art = ED_area_type_hud(st->spaceid);
- BLI_addhead(&st->regiontypes, art);
-
- BKE_spacetype_register(st);
+ SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype image");
+ ARegionType *art;
+
+ st->spaceid = SPACE_IMAGE;
+ strncpy(st->name, "Image", BKE_ST_MAXNAME);
+
+ st->new = image_new;
+ st->free = image_free;
+ st->init = image_init;
+ st->duplicate = image_duplicate;
+ st->operatortypes = image_operatortypes;
+ st->keymap = image_keymap;
+ st->dropboxes = image_dropboxes;
+ st->refresh = image_refresh;
+ st->listener = image_listener;
+ st->context = image_context;
+ st->gizmos = image_widgets;
+ st->id_remap = image_id_remap;
+ st->space_subtype_item_extend = image_space_subtype_item_extend;
+ st->space_subtype_get = image_space_subtype_get;
+ st->space_subtype_set = image_space_subtype_set;
+
+ /* regions: main window */
+ art = MEM_callocN(sizeof(ARegionType), "spacetype image region");
+ art->regionid = RGN_TYPE_WINDOW;
+ art->keymapflag = ED_KEYMAP_GIZMO | ED_KEYMAP_TOOL | ED_KEYMAP_FRAMES | ED_KEYMAP_GPENCIL;
+ art->init = image_main_region_init;
+ art->draw = image_main_region_draw;
+ art->listener = image_main_region_listener;
+ BLI_addhead(&st->regiontypes, art);
+
+ /* regions: listview/buttons/scopes */
+ art = MEM_callocN(sizeof(ARegionType), "spacetype image region");
+ art->regionid = RGN_TYPE_UI;
+ art->prefsizex = 220; // XXX
+ art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
+ art->listener = image_buttons_region_listener;
+ art->init = image_buttons_region_init;
+ art->draw = image_buttons_region_draw;
+ BLI_addhead(&st->regiontypes, art);
+
+ ED_uvedit_buttons_register(art);
+ image_buttons_register(art);
+
+ /* regions: tool(bar) */
+ art = MEM_callocN(sizeof(ARegionType), "spacetype image region");
+ art->regionid = RGN_TYPE_TOOLS;
+ art->prefsizex = 58; /* XXX */
+ art->prefsizey = 50; /* XXX */
+ art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
+ art->listener = image_tools_region_listener;
+ art->message_subscribe = ED_region_generic_tools_region_message_subscribe;
+ art->snap_size = ED_region_generic_tools_region_snap_size;
+ art->init = image_tools_region_init;
+ art->draw = image_tools_region_draw;
+ BLI_addhead(&st->regiontypes, art);
+
+ /* regions: header */
+ art = MEM_callocN(sizeof(ARegionType), "spacetype image region");
+ art->regionid = RGN_TYPE_HEADER;
+ art->prefsizey = HEADERY;
+ art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER;
+ art->listener = image_header_region_listener;
+ art->init = image_header_region_init;
+ art->draw = image_header_region_draw;
+
+ BLI_addhead(&st->regiontypes, art);
+
+ /* regions: hud */
+ art = ED_area_type_hud(st->spaceid);
+ BLI_addhead(&st->regiontypes, art);
+
+ BKE_spacetype_register(st);
}