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-10-01 17:24:21 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-10-01 17:44:17 +0300
commitb155ece0c0e5feb5f51690989687d4b825cd848c (patch)
treecd48d69b8992ae9b5e2f0cf80eb30e9f16bd582e /source/blender/editors/space_image
parent151cc02b6f8234c94a65618ae0437403e1aba689 (diff)
Image: add resize operator
Now possible with new image undo, was added for testing but seems generally useful.
Diffstat (limited to 'source/blender/editors/space_image')
-rw-r--r--source/blender/editors/space_image/image_intern.h1
-rw-r--r--source/blender/editors/space_image/image_ops.c98
-rw-r--r--source/blender/editors/space_image/space_image.c1
3 files changed, 92 insertions, 8 deletions
diff --git a/source/blender/editors/space_image/image_intern.h b/source/blender/editors/space_image/image_intern.h
index 6f1ce01ceac..f8ce065d46c 100644
--- a/source/blender/editors/space_image/image_intern.h
+++ b/source/blender/editors/space_image/image_intern.h
@@ -72,6 +72,7 @@ void IMAGE_OT_pack(struct wmOperatorType *ot);
void IMAGE_OT_unpack(struct wmOperatorType *ot);
void IMAGE_OT_invert(struct wmOperatorType *ot);
+void IMAGE_OT_resize(struct wmOperatorType *ot);
void IMAGE_OT_cycle_render_slot(struct wmOperatorType *ot);
void IMAGE_OT_clear_render_slot(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 5fa51170f0e..b9d5c927092 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -213,6 +213,13 @@ static ImageUser *image_user_from_context(const bContext *C)
}
}
+static bool image_buffer_exists_from_context_no_image_user(bContext *C)
+{
+ Image *ima = image_from_context(C);
+
+ return BKE_image_has_ibuf(ima, NULL);
+}
+
static bool image_buffer_exists_from_context(bContext *C)
{
Image *ima = image_from_context(C);
@@ -2753,13 +2760,6 @@ void IMAGE_OT_new(wmOperatorType *ot)
/** \name Invert Operators
* \{ */
-static bool image_invert_poll(bContext *C)
-{
- Image *ima = image_from_context(C);
-
- return BKE_image_has_ibuf(ima, NULL);
-}
-
static int image_invert_exec(bContext *C, wmOperator *op)
{
Image *ima = image_from_context(C);
@@ -2862,7 +2862,7 @@ void IMAGE_OT_invert(wmOperatorType *ot)
/* api callbacks */
ot->exec = image_invert_exec;
- ot->poll = image_invert_poll;
+ ot->poll = image_buffer_exists_from_context_no_image_user;
/* properties */
prop = RNA_def_boolean(ot->srna, "invert_r", 0, "Red", "Invert Red Channel");
@@ -2881,6 +2881,88 @@ void IMAGE_OT_invert(wmOperatorType *ot)
/** \} */
/* -------------------------------------------------------------------- */
+/** \name Scale Operator
+ * \{ */
+
+static int image_scale_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+ Image *ima = image_from_context(C);
+ PropertyRNA *prop = RNA_struct_find_property(op->ptr, "size");
+ if (!RNA_property_is_set(op->ptr, prop)) {
+ ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
+ const int size[2] = {ibuf->x, ibuf->y};
+ RNA_property_int_set_array(op->ptr, prop, size);
+ BKE_image_release_ibuf(ima, ibuf, NULL);
+ }
+ return WM_operator_props_dialog_popup(C, op, 200, 200);
+}
+
+static int image_scale_exec(bContext *C, wmOperator *op)
+{
+ Image *ima = image_from_context(C);
+ ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
+ SpaceImage *sima = CTX_wm_space_image(C);
+ const bool is_paint = ((sima != NULL) && (sima->mode == SI_MODE_PAINT));
+
+ if (ibuf == NULL) {
+ /* TODO: this should actually never happen, but does for render-results -> cleanup */
+ return OPERATOR_CANCELLED;
+ }
+
+ if (is_paint) {
+ ED_imapaint_clear_partial_redraw();
+ }
+
+ PropertyRNA *prop = RNA_struct_find_property(op->ptr, "size");
+ int size[2];
+ if (RNA_property_is_set(op->ptr, prop)) {
+ RNA_property_int_get_array(op->ptr, prop, size);
+ }
+ else {
+ size[0] = ibuf->x;
+ size[1] = ibuf->y;
+ RNA_property_int_set_array(op->ptr, prop, size);
+ }
+
+ ED_image_undo_push_begin_with_image(op->type->name, ima, ibuf);
+
+ ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID;
+ IMB_scaleImBuf(ibuf, size[0], size[1]);
+ BKE_image_release_ibuf(ima, ibuf, NULL);
+
+ ED_image_undo_push_end();
+
+ /* force GPU reupload, all image is invalid */
+ GPU_free_image(ima);
+
+ DEG_id_tag_update(&ima->id, 0);
+ WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
+
+ return OPERATOR_FINISHED;
+}
+
+void IMAGE_OT_resize(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Resize Image";
+ ot->idname = "IMAGE_OT_resize";
+ ot->description = "Resize the image";
+
+ /* api callbacks */
+ ot->invoke = image_scale_invoke;
+ ot->exec = image_scale_exec;
+ ot->poll = image_buffer_exists_from_context_no_image_user;
+
+ /* properties */
+ RNA_def_int_vector(ot->srna, "size", 2, NULL, 1, INT_MAX, "Size", "", 1, SHRT_MAX);
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
/** \name Pack Operator
* \{ */
diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c
index 749266149c1..a88ecc91868 100644
--- a/source/blender/editors/space_image/space_image.c
+++ b/source/blender/editors/space_image/space_image.c
@@ -230,6 +230,7 @@ static void image_operatortypes(void)
WM_operatortype_append(IMAGE_OT_unpack);
WM_operatortype_append(IMAGE_OT_invert);
+ WM_operatortype_append(IMAGE_OT_resize);
WM_operatortype_append(IMAGE_OT_cycle_render_slot);
WM_operatortype_append(IMAGE_OT_clear_render_slot);