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:
authorJeroen Bakker <jeroen@blender.org>2020-03-23 15:51:55 +0300
committerJeroen Bakker <jeroen@blender.org>2020-03-23 15:56:42 +0300
commit6a5bd812b569d5fe1f09bd5610ce9d0c119f1a21 (patch)
tree92c1b1038044aa53843a459623b5f2f8eba76da8 /source/blender/editors/space_image/image_edit.c
parent64982e213f014123d1b0406cf9ae893910a6a3d3 (diff)
Fix T74586: Image Editor Uses Invalid Display Channels
When using the image editor the display channels attribute can become invalid when selecting another image/buffer. This patch will check what display channels are valid and when an invalid channel is selected it will fall back to the color channel. To de-duplicate the code it also introduces a `ED_space_image_get_display_channel_mask` function that will determine the valid bitflags for the display channel of a given `ImBuf`.
Diffstat (limited to 'source/blender/editors/space_image/image_edit.c')
-rw-r--r--source/blender/editors/space_image/image_edit.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/source/blender/editors/space_image/image_edit.c b/source/blender/editors/space_image/image_edit.c
index 99190fa2d39..8da67effc94 100644
--- a/source/blender/editors/space_image/image_edit.c
+++ b/source/blender/editors/space_image/image_edit.c
@@ -175,6 +175,30 @@ void ED_space_image_release_buffer(SpaceImage *sima, ImBuf *ibuf, void *lock)
}
}
+/* Get the SpaceImage flag that is valid for the given ibuf. */
+int ED_space_image_get_display_channel_mask(ImBuf *ibuf)
+{
+ int result = (SI_USE_ALPHA | SI_SHOW_ALPHA | SI_SHOW_ZBUF | SI_SHOW_R | SI_SHOW_G | SI_SHOW_B);
+ if (!ibuf) {
+ return result;
+ }
+
+ const bool color = ibuf->channels >= 3;
+ const bool alpha = ibuf->channels == 4;
+ const bool zbuf = ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels == 1);
+
+ if (!alpha) {
+ result &= ~(SI_USE_ALPHA | SI_SHOW_ALPHA);
+ }
+ if (!zbuf) {
+ result &= ~(SI_SHOW_ZBUF);
+ }
+ if (!color) {
+ result &= ~(SI_SHOW_R | SI_SHOW_G | SI_SHOW_B);
+ }
+ return result;
+}
+
bool ED_space_image_has_buffer(SpaceImage *sima)
{
ImBuf *ibuf;