Fix T82093: Sampled Colors Mismatch When Painting (Partial)

When painting in the image editor on data images (Non-color, Raw) the
color mismatched between the sampled color and the actual effect that
the painting has on the image. The root cause is that the sampling is
color managed, but the painting still uses a fixed color management
pipeline with a lot of assumptions. Due to recent changes the drawing
of the image editor is color managed, but the painting isn't what made
these changes show up.

This patch is a work-a-round so that the sampled colors and the effect
the paint has on the texture matches. This isn't the correct solution
as that would be to migrate all the painting tools to use proper color
management.

Reviewed By: Pablo Dobarro

Differential Revision: https://developer.blender.org/D9411
This commit is contained in:
Jeroen Bakker 2020-11-12 09:10:26 +01:00 committed by Jeroen Bakker
parent f93081a01b
commit c08827e659
Notes: blender-bot 2023-12-22 20:14:11 +01:00
Referenced by issue #82093, Can't Sample the correct color from non-color images
4 changed files with 18 additions and 5 deletions

View File

@ -58,7 +58,8 @@ void ED_space_image_set_mask(struct bContext *C, struct SpaceImage *sima, struct
bool ED_space_image_color_sample(struct SpaceImage *sima,
struct ARegion *region,
int mval[2],
float r_col[3]);
float r_col[3],
bool *r_is_data);
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);

View File

@ -163,7 +163,7 @@ void eyedropper_color_sample_fl(bContext *C, int mx, int my, float r_col[3])
SpaceImage *sima = area->spacedata.first;
int mval[2] = {mx - region->winrct.xmin, my - region->winrct.ymin};
if (ED_space_image_color_sample(sima, region, mval, r_col)) {
if (ED_space_image_color_sample(sima, region, mval, r_col, NULL)) {
return;
}
}

View File

@ -581,8 +581,12 @@ void paint_sample_color(
/* Sample from the active image buffer. The sampled color is in
* Linear Scene Reference Space. */
float rgba_f[3];
if (ED_space_image_color_sample(sima, region, (int[2]){x, y}, rgba_f)) {
linearrgb_to_srgb_v3_v3(rgba_f, rgba_f);
bool is_data;
if (ED_space_image_color_sample(sima, region, (int[2]){x, y}, rgba_f, &is_data)) {
if (!is_data) {
linearrgb_to_srgb_v3_v3(rgba_f, rgba_f);
}
if (use_palette) {
copy_v3_v3(color->rgb, rgba_f);
}

View File

@ -3057,8 +3057,12 @@ void IMAGE_OT_unpack(wmOperatorType *ot)
* \{ */
/* Returns color in linear space, matching ED_space_node_color_sample(). */
bool ED_space_image_color_sample(SpaceImage *sima, ARegion *region, int mval[2], float r_col[3])
bool ED_space_image_color_sample(
SpaceImage *sima, ARegion *region, int mval[2], float r_col[3], bool *r_is_data)
{
if (r_is_data) {
*r_is_data = false;
}
if (sima->image == NULL) {
return false;
}
@ -3096,6 +3100,10 @@ bool ED_space_image_color_sample(SpaceImage *sima, ARegion *region, int mval[2],
}
}
if (r_is_data) {
*r_is_data = (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) != 0;
}
ED_space_image_release_buffer(sima, ibuf, lock);
return ret;
}