diff options
author | Ethan-Hall <Ethan1080> | 2022-03-07 19:36:27 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2022-03-07 19:39:27 +0300 |
commit | 15186f4259a2e0611a64a3aed8db8858e8ca081f (patch) | |
tree | 00c278a96da0e9e937390a1fb8d7b40587a4fccd /source | |
parent | 5b4ab896634fd118cb46740f6f90e45f96d550ac (diff) |
Shader Nodes: added alpha mode selector to Image Texture node
Enables image user nodes to display the file alpha mode, similar to the
colorspace setting.
Also removes image_has_alpha in favor of using BKE_image_has_alpha, because it
did not check if the image actually had an alpha channel, just if the file format
was capable of supporting an alpha channel.
Differential Revision: https://developer.blender.org/D14153
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/space_image/image_buttons.c | 18 | ||||
-rw-r--r-- | source/blender/editors/space_node/drawnode.cc | 17 |
2 files changed, 14 insertions, 21 deletions
diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c index 6f3d40abce1..0af32a717a4 100644 --- a/source/blender/editors/space_image/image_buttons.c +++ b/source/blender/editors/space_image/image_buttons.c @@ -718,22 +718,6 @@ static void rna_update_cb(bContext *C, void *arg_cb, void *UNUSED(arg)) RNA_property_update(C, &cb->ptr, cb->prop); } -static bool image_has_alpha(Image *ima, ImageUser *iuser) -{ - ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL); - if (ibuf == NULL) { - return false; - } - - int imtype = BKE_image_ftype_to_imtype(ibuf->ftype, &ibuf->foptions); - char valid_channels = BKE_imtype_valid_channels(imtype, false); - bool has_alpha = (valid_channels & IMA_CHAN_FLAG_ALPHA) != 0; - - BKE_image_release_ibuf(ima, ibuf, NULL); - - return has_alpha; -} - void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, @@ -943,7 +927,7 @@ void uiTemplateImage(uiLayout *layout, if (compact == 0) { if (ima->source != IMA_SRC_GENERATED) { - if (image_has_alpha(ima, iuser)) { + if (BKE_image_has_alpha(ima)) { uiLayout *sub = uiLayoutColumn(col, false); uiItemR(sub, &imaptr, "alpha_mode", 0, IFACE_("Alpha"), ICON_NONE); diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc index afb205f9f9e..fab2946ad76 100644 --- a/source/blender/editors/space_node/drawnode.cc +++ b/source/blender/editors/space_node/drawnode.cc @@ -304,9 +304,11 @@ static void node_buts_image_user(uiLayout *layout, const bool show_layer_selection, const bool show_color_management) { - if (!imaptr->data) { + Image *image = (Image *)imaptr->data; + if (!image) { return; } + ImageUser *iuser = (ImageUser *)iuserptr->data; uiLayout *col = uiLayoutColumn(layout, false); @@ -318,8 +320,6 @@ static void node_buts_image_user(uiLayout *layout, /* don't use iuser->framenr directly * because it may not be updated if auto-refresh is off */ Scene *scene = CTX_data_scene(C); - ImageUser *iuser = (ImageUser *)iuserptr->data; - /* Image *ima = imaptr->data; */ /* UNUSED */ char numstr[32]; const int framenr = BKE_image_user_frame_get(iuser, CFRA, nullptr); @@ -343,11 +343,20 @@ static void node_buts_image_user(uiLayout *layout, } if (show_color_management) { - uiLayout *split = uiLayoutSplit(layout, 0.5f, true); + uiLayout *split = uiLayoutSplit(layout, 0.33f, true); PointerRNA colorspace_settings_ptr = RNA_pointer_get(imaptr, "colorspace_settings"); uiItemL(split, IFACE_("Color Space"), ICON_NONE); uiItemR(split, &colorspace_settings_ptr, "name", DEFAULT_FLAGS, "", ICON_NONE); + if (image->source != IMA_SRC_GENERATED) { + split = uiLayoutSplit(layout, 0.33f, true); + uiItemL(split, IFACE_("Alpha"), ICON_NONE); + uiItemR(split, imaptr, "alpha_mode", DEFAULT_FLAGS, "", ICON_NONE); + + bool is_data = IMB_colormanagement_space_name_is_data(image->colorspace_settings.name); + uiLayoutSetActive(split, !is_data); + } + /* Avoid losing changes image is painted. */ if (BKE_image_is_dirty((Image *)imaptr->data)) { uiLayoutSetEnabled(split, false); |