Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_image/image_ops.c
| Show First 20 Lines • Show All 2,729 Lines • ▼ Show 20 Lines | static bool image_invert_poll(bContext *C) | ||||
| return BKE_image_has_ibuf(ima, NULL); | return BKE_image_has_ibuf(ima, NULL); | ||||
| } | } | ||||
| static int image_invert_exec(bContext *C, wmOperator *op) | static int image_invert_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Image *ima = image_from_context(C); | Image *ima = image_from_context(C); | ||||
| ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL); | ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL); | ||||
| SpaceImage *sima = CTX_wm_space_image(C); | SpaceImage *sima = CTX_wm_space_image(C); | ||||
| /* undo is supported only on image paint mode currently */ | const bool is_paint = ((sima != NULL) && (sima->mode == SI_MODE_PAINT)); | ||||
| bool support_undo = ((sima != NULL) && (sima->mode == SI_MODE_PAINT)); | |||||
| /* flags indicate if this channel should be inverted */ | /* flags indicate if this channel should be inverted */ | ||||
| const bool r = RNA_boolean_get(op->ptr, "invert_r"); | const bool r = RNA_boolean_get(op->ptr, "invert_r"); | ||||
| const bool g = RNA_boolean_get(op->ptr, "invert_g"); | const bool g = RNA_boolean_get(op->ptr, "invert_g"); | ||||
| const bool b = RNA_boolean_get(op->ptr, "invert_b"); | const bool b = RNA_boolean_get(op->ptr, "invert_b"); | ||||
| const bool a = RNA_boolean_get(op->ptr, "invert_a"); | const bool a = RNA_boolean_get(op->ptr, "invert_a"); | ||||
| size_t i; | size_t i; | ||||
| if (ibuf == NULL) { | if (ibuf == NULL) { | ||||
| /* TODO: this should actually never happen, but does for render-results -> cleanup */ | /* TODO: this should actually never happen, but does for render-results -> cleanup */ | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| if (support_undo) { | ED_image_undo_push_begin_with_image(op->type->name, ima, ibuf); | ||||
| 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 | if (is_paint) { | ||||
| * 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_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!? */ | /* TODO: make this into an IMB_invert_channels(ibuf,r,g,b,a) method!? */ | ||||
| if (ibuf->rect_float) { | if (ibuf->rect_float) { | ||||
| float *fp = (float *)ibuf->rect_float; | float *fp = (float *)ibuf->rect_float; | ||||
| for (i = ((size_t)ibuf->x) * ibuf->y; i > 0; i--, fp += 4) { | for (i = ((size_t)ibuf->x) * ibuf->y; i > 0; i--, fp += 4) { | ||||
| if (r) { | if (r) { | ||||
| fp[0] = 1.0f - fp[0]; | fp[0] = 1.0f - fp[0]; | ||||
| } | } | ||||
| Show All 37 Lines | static int image_invert_exec(bContext *C, wmOperator *op) | ||||
| ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID; | ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID; | ||||
| BKE_image_mark_dirty(ima, ibuf); | BKE_image_mark_dirty(ima, ibuf); | ||||
| if (ibuf->mipmap[0]) { | if (ibuf->mipmap[0]) { | ||||
| ibuf->userflags |= IB_MIPMAP_INVALID; | ibuf->userflags |= IB_MIPMAP_INVALID; | ||||
| } | } | ||||
| if (support_undo) { | |||||
| ED_image_undo_push_end(); | ED_image_undo_push_end(); | ||||
| } | |||||
| /* force GPU reupload, all image is invalid */ | /* force GPU reupload, all image is invalid */ | ||||
| GPU_free_image(ima); | GPU_free_image(ima); | ||||
| 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); | ||||
| Show All 19 Lines | void IMAGE_OT_invert(wmOperatorType *ot) | ||||
| prop = RNA_def_boolean(ot->srna, "invert_g", 0, "Green", "Invert Green Channel"); | prop = RNA_def_boolean(ot->srna, "invert_g", 0, "Green", "Invert Green Channel"); | ||||
| RNA_def_property_flag(prop, PROP_SKIP_SAVE); | RNA_def_property_flag(prop, PROP_SKIP_SAVE); | ||||
| prop = RNA_def_boolean(ot->srna, "invert_b", 0, "Blue", "Invert Blue Channel"); | prop = RNA_def_boolean(ot->srna, "invert_b", 0, "Blue", "Invert Blue Channel"); | ||||
| RNA_def_property_flag(prop, PROP_SKIP_SAVE); | RNA_def_property_flag(prop, PROP_SKIP_SAVE); | ||||
| prop = RNA_def_boolean(ot->srna, "invert_a", 0, "Alpha", "Invert Alpha Channel"); | prop = RNA_def_boolean(ot->srna, "invert_a", 0, "Alpha", "Invert Alpha Channel"); | ||||
| RNA_def_property_flag(prop, PROP_SKIP_SAVE); | RNA_def_property_flag(prop, PROP_SKIP_SAVE); | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER; | ||||
| } | |||||
| /** \} */ | |||||
| /* -------------------------------------------------------------------- */ | |||||
| /** \name Scale Operator | |||||
| * \{ */ | |||||
| static bool image_scale_poll(bContext *C) | |||||
| { | |||||
| Image *ima = image_from_context(C); | |||||
| return BKE_image_has_ibuf(ima, NULL); | |||||
| } | |||||
| 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)); | |||||
| PropertyRNA *prop = RNA_struct_find_property(op->ptr, "size"); | |||||
| 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(); | |||||
| } | |||||
| int size[2]; | |||||
| RNA_property_int_get_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_threaded(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); | |||||
| WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima); | |||||
sergey: `DEG_id_tag_update(&ima->id, 0);` to inform textures and such about the change. | |||||
| return OPERATOR_FINISHED; | |||||
| } | |||||
| void IMAGE_OT_scale(wmOperatorType *ot) | |||||
| { | |||||
| /* identifiers */ | |||||
| ot->name = "Scale Image"; | |||||
| ot->idname = "IMAGE_OT_scale"; | |||||
| ot->description = "Resize the image"; | |||||
| /* api callbacks */ | |||||
| ot->invoke = image_scale_invoke; | |||||
| ot->exec = image_scale_exec; | |||||
| ot->poll = image_scale_poll; | |||||
| /* properties */ | |||||
| RNA_def_int_vector(ot->srna, | |||||
| "size", | |||||
| 2, | |||||
| NULL, | |||||
| 1, | |||||
Not Done Inline ActionsSize is going to 0 by default, which I guess will fail in exec. I think we can initialize to something arbitrary like 1024. brecht: Size is going to 0 by default, which I guess will fail in `exec`. I think we can initialize to… | |||||
| SHRT_MAX, | |||||
| "Size", | |||||
| "Location of vertex in area space", | |||||
| 1, | |||||
Not Done Inline ActionsUpdate this comment. brecht: Update this comment. | |||||
| SHRT_MAX); | |||||
| /* flags */ | |||||
| ot->flag = OPTYPE_REGISTER; | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Pack Operator | /** \name Pack Operator | ||||
| * \{ */ | * \{ */ | ||||
| ▲ Show 20 Lines • Show All 1,111 Lines • Show Last 20 Lines | |||||
DEG_id_tag_update(&ima->id, 0); to inform textures and such about the change.