Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_image/image_ops.c
| Show First 20 Lines • Show All 191 Lines • ▼ Show 20 Lines | if (iuser) { | ||||
| return iuser; | return iuser; | ||||
| } | } | ||||
| /* Image editor. */ | /* Image editor. */ | ||||
| SpaceImage *sima = CTX_wm_space_image(C); | SpaceImage *sima = CTX_wm_space_image(C); | ||||
| return (sima) ? &sima->iuser : NULL; | return (sima) ? &sima->iuser : NULL; | ||||
| } | } | ||||
| static ImageUser image_user_from_active_tile(Image *ima) | static void image_user_from_active_tile(Image *ima, ImageUser **iuser) | ||||
| { | { | ||||
| ImageUser iuser; | |||||
| BKE_imageuser_default(&iuser); | |||||
| /* Use the file associated with the active tile. Otherwise use the first tile. */ | /* Use the file associated with the active tile. Otherwise use the first tile. */ | ||||
| if (ima && ima->source == IMA_SRC_TILED) { | if (ima && ima->source == IMA_SRC_TILED) { | ||||
| const ImageTile *active = (ImageTile *)BLI_findlink(&ima->tiles, ima->active_tile_index); | const ImageTile *active = (ImageTile *)BLI_findlink(&ima->tiles, ima->active_tile_index); | ||||
| iuser.tile = active ? active->tile_number : ((ImageTile *)ima->tiles.first)->tile_number; | BKE_imageuser_default(*iuser); | ||||
| if (active) | |||||
| (*iuser)->tile = active->tile_number; | |||||
| else | |||||
| *iuser = NULL; | |||||
| } | |||||
| else { | |||||
| *iuser = NULL; | |||||
| } | } | ||||
| return iuser; | |||||
| } | } | ||||
| static bool image_from_context_has_data_poll(bContext *C) | static bool image_from_context_has_data_poll(bContext *C) | ||||
| { | { | ||||
| Image *ima = image_from_context(C); | Image *ima = image_from_context(C); | ||||
| ImageUser *iuser = image_user_from_context(C); | ImageUser *iuser = image_user_from_context(C); | ||||
| if (ima == NULL) { | if (ima == NULL) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| void *lock; | void *lock; | ||||
| ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, &lock); | ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, &lock); | ||||
| const bool has_buffer = (ibuf && (ibuf->rect || ibuf->rect_float)); | const bool has_buffer = (ibuf && (ibuf->rect || ibuf->rect_float)); | ||||
| BKE_image_release_ibuf(ima, ibuf, lock); | BKE_image_release_ibuf(ima, ibuf, lock); | ||||
| return has_buffer; | return has_buffer; | ||||
| } | } | ||||
| /** | /** | ||||
| * Use this when the image buffer is accessing the active tile without the image user. | * Use this when the image buffer is accessing the active tile without the image user. | ||||
| */ | */ | ||||
| static bool image_from_context_has_data_poll_active_tile(bContext *C) | static bool image_from_context_has_data_poll_active_tile(bContext *C) | ||||
| { | { | ||||
| Image *ima = image_from_context(C); | Image *ima = image_from_context(C); | ||||
| ImageUser iuser = image_user_from_active_tile(ima); | ImageUser tmp; | ||||
| ImageUser *iuser = &tmp; | |||||
| image_user_from_active_tile(ima, &iuser); | |||||
| return BKE_image_has_ibuf(ima, &iuser); | return BKE_image_has_ibuf(ima, iuser); | ||||
| } | } | ||||
| static bool image_not_packed_poll(bContext *C) | static bool image_not_packed_poll(bContext *C) | ||||
| { | { | ||||
| /* Do not run 'replace' on packed images, it does not give user expected results at all. */ | /* Do not run 'replace' on packed images, it does not give user expected results at all. */ | ||||
| Image *ima = image_from_context(C); | Image *ima = image_from_context(C); | ||||
| return (ima && BLI_listbase_is_empty(&ima->packedfiles)); | return (ima && BLI_listbase_is_empty(&ima->packedfiles)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 1,350 Lines • ▼ Show 20 Lines | if (event->modifier & (KM_SHIFT | KM_ALT)) { | ||||
| if (event->modifier & KM_ALT) { | if (event->modifier & KM_ALT) { | ||||
| char *lslash = (char *)BLI_path_slash_rfind(filepath); | char *lslash = (char *)BLI_path_slash_rfind(filepath); | ||||
| if (lslash) { | if (lslash) { | ||||
| *lslash = '\0'; | *lslash = '\0'; | ||||
| } | } | ||||
| } | } | ||||
| else if (ima->source == IMA_SRC_TILED) { | else if (ima->source == IMA_SRC_TILED) { | ||||
| ImageUser iuser = image_user_from_active_tile(ima); | ImageUser tmp; | ||||
| BKE_image_user_file_path(&iuser, ima, filepath); | ImageUser *iuser = &tmp; | ||||
| image_user_from_active_tile(ima, &iuser); | |||||
| if (iuser != NULL) | |||||
| BKE_image_user_file_path(iuser, ima, filepath); | |||||
| } | } | ||||
| WM_operator_properties_create_ptr(&props_ptr, ot); | WM_operator_properties_create_ptr(&props_ptr, ot); | ||||
| RNA_string_set(&props_ptr, "filepath", filepath); | RNA_string_set(&props_ptr, "filepath", filepath); | ||||
| WM_operator_name_call_ptr(C, ot, WM_OP_EXEC_DEFAULT, &props_ptr, NULL); | WM_operator_name_call_ptr(C, ot, WM_OP_EXEC_DEFAULT, &props_ptr, NULL); | ||||
| WM_operator_properties_free(&props_ptr); | WM_operator_properties_free(&props_ptr); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| ▲ Show 20 Lines • Show All 1,078 Lines • ▼ Show 20 Lines | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Flip Operator | /** \name Flip Operator | ||||
| * \{ */ | * \{ */ | ||||
| static int image_flip_exec(bContext *C, wmOperator *op) | static int image_flip_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Image *ima = image_from_context(C); | Image *ima = image_from_context(C); | ||||
| ImageUser iuser = image_user_from_active_tile(ima); | ImageUser tmp; | ||||
| ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL); | ImageUser *iuser = &tmp; | ||||
| image_user_from_active_tile(ima, &iuser); | |||||
| ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL); | |||||
| SpaceImage *sima = CTX_wm_space_image(C); | SpaceImage *sima = CTX_wm_space_image(C); | ||||
| const bool is_paint = ((sima != NULL) && (sima->mode == SI_MODE_PAINT)); | const bool is_paint = ((sima != NULL) && (sima->mode == SI_MODE_PAINT)); | ||||
| 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; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Invert Operators | /** \name Invert Operators | ||||
| * \{ */ | * \{ */ | ||||
| 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); | ||||
| ImageUser iuser = image_user_from_active_tile(ima); | ImageUser tmp; | ||||
| ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL); | ImageUser *iuser = &tmp; | ||||
| image_user_from_active_tile(ima, &iuser); | |||||
| ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL); | |||||
| SpaceImage *sima = CTX_wm_space_image(C); | SpaceImage *sima = CTX_wm_space_image(C); | ||||
| const bool is_paint = ((sima != NULL) && (sima->mode == SI_MODE_PAINT)); | const bool is_paint = ((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"); | ||||
| ▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Scale Operator | /** \name Scale Operator | ||||
| * \{ */ | * \{ */ | ||||
| static int image_scale_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | static int image_scale_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | ||||
| { | { | ||||
| Image *ima = image_from_context(C); | Image *ima = image_from_context(C); | ||||
| ImageUser iuser = image_user_from_active_tile(ima); | ImageUser tmp; | ||||
| ImageUser *iuser = &tmp; | |||||
| image_user_from_active_tile(ima, &iuser); | |||||
| PropertyRNA *prop = RNA_struct_find_property(op->ptr, "size"); | PropertyRNA *prop = RNA_struct_find_property(op->ptr, "size"); | ||||
| if (!RNA_property_is_set(op->ptr, prop)) { | if (!RNA_property_is_set(op->ptr, prop)) { | ||||
| ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL); | ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL); | ||||
| const int size[2] = {ibuf->x, ibuf->y}; | const int size[2] = {ibuf->x, ibuf->y}; | ||||
| RNA_property_int_set_array(op->ptr, prop, size); | RNA_property_int_set_array(op->ptr, prop, size); | ||||
| BKE_image_release_ibuf(ima, ibuf, NULL); | BKE_image_release_ibuf(ima, ibuf, NULL); | ||||
| } | } | ||||
| return WM_operator_props_dialog_popup(C, op, 200); | return WM_operator_props_dialog_popup(C, op, 200); | ||||
| } | } | ||||
| static int image_scale_exec(bContext *C, wmOperator *op) | static int image_scale_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Image *ima = image_from_context(C); | Image *ima = image_from_context(C); | ||||
| ImageUser iuser = image_user_from_active_tile(ima); | ImageUser tmp; | ||||
| ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL); | ImageUser *iuser = &tmp; | ||||
| image_user_from_active_tile(ima, &iuser); | |||||
| ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL); | |||||
| SpaceImage *sima = CTX_wm_space_image(C); | SpaceImage *sima = CTX_wm_space_image(C); | ||||
| const bool is_paint = ((sima != NULL) && (sima->mode == SI_MODE_PAINT)); | const bool is_paint = ((sima != NULL) && (sima->mode == SI_MODE_PAINT)); | ||||
| 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; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 992 Lines • Show Last 20 Lines | |||||