diff options
author | Jeroen Bakker <jeroen@blender.org> | 2020-03-23 15:51:55 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2020-03-23 15:56:42 +0300 |
commit | 6a5bd812b569d5fe1f09bd5610ce9d0c119f1a21 (patch) | |
tree | 92c1b1038044aa53843a459623b5f2f8eba76da8 /source/blender/editors | |
parent | 64982e213f014123d1b0406cf9ae893910a6a3d3 (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')
-rw-r--r-- | source/blender/editors/include/ED_image.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_draw.c | 17 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_edit.c | 24 |
3 files changed, 34 insertions, 8 deletions
diff --git a/source/blender/editors/include/ED_image.h b/source/blender/editors/include/ED_image.h index 0e820a1c2d6..1c260bb826a 100644 --- a/source/blender/editors/include/ED_image.h +++ b/source/blender/editors/include/ED_image.h @@ -61,6 +61,7 @@ bool ED_space_image_color_sample(struct SpaceImage *sima, int mval[2], float r_col[3]); struct ImBuf *ED_space_image_acquire_buffer(struct SpaceImage *sima, void **r_lock, int tile); +int ED_space_image_get_display_channel_mask(struct ImBuf *ibuf); void ED_space_image_release_buffer(struct SpaceImage *sima, struct ImBuf *ibuf, void *lock); bool ED_space_image_has_buffer(struct SpaceImage *sima); diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c index a58abb2fbd5..85f7f744abc 100644 --- a/source/blender/editors/space_image/image_draw.c +++ b/source/blender/editors/space_image/image_draw.c @@ -576,12 +576,13 @@ static void draw_image_buffer(const bContext *C, float zoomy) { int x, y; + int sima_flag = sima->flag & ED_space_image_get_display_channel_mask(ibuf); /* find window pixel coordinates of origin */ UI_view2d_view_to_region(®ion->v2d, fx, fy, &x, &y); /* this part is generic image display */ - if (sima->flag & SI_SHOW_ZBUF && (ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels == 1))) { + if (sima_flag & SI_SHOW_ZBUF && (ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels == 1))) { if (ibuf->zbuf) { sima_draw_zbuf_pixels(x, y, ibuf->x, ibuf->y, ibuf->zbuf, zoomx, zoomy); } @@ -597,7 +598,7 @@ static void draw_image_buffer(const bContext *C, UI_view2d_view_to_region( ®ion->v2d, region->v2d.cur.xmax, region->v2d.cur.ymax, &clip_max_x, &clip_max_y); - if (sima->flag & SI_USE_ALPHA) { + if (sima_flag & SI_USE_ALPHA) { imm_draw_box_checker_2d(x, y, x + ibuf->x * zoomx, y + ibuf->y * zoomy); GPU_blend(true); @@ -606,7 +607,7 @@ static void draw_image_buffer(const bContext *C, } /* If RGBA display with color management */ - if ((sima->flag & (SI_SHOW_R | SI_SHOW_G | SI_SHOW_B | SI_SHOW_ALPHA)) == 0) { + if ((sima_flag & (SI_SHOW_R | SI_SHOW_G | SI_SHOW_B | SI_SHOW_ALPHA)) == 0) { ED_draw_imbuf_ctx_clipping( C, ibuf, x, y, GL_NEAREST, 0, 0, clip_max_x, clip_max_y, zoomx, zoomy); @@ -618,16 +619,16 @@ static void draw_image_buffer(const bContext *C, ColorManagedViewSettings *view_settings; ColorManagedDisplaySettings *display_settings; - if (sima->flag & SI_SHOW_R) { + if (sima_flag & SI_SHOW_R) { shuffle[0] = 1.0f; } - else if (sima->flag & SI_SHOW_G) { + else if (sima_flag & SI_SHOW_G) { shuffle[1] = 1.0f; } - else if (sima->flag & SI_SHOW_B) { + else if (sima_flag & SI_SHOW_B) { shuffle[2] = 1.0f; } - else if (sima->flag & SI_SHOW_ALPHA) { + else if (sima_flag & SI_SHOW_ALPHA) { shuffle[3] = 1.0f; } @@ -661,7 +662,7 @@ static void draw_image_buffer(const bContext *C, IMB_display_buffer_release(cache_handle); } - if (sima->flag & SI_USE_ALPHA) { + if (sima_flag & SI_USE_ALPHA) { GPU_blend(false); } } 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; |