D2607: Switch eye dropper to use linear color space internally

This switches the internal color representation of the eye dropper from display space to linear. Any time a linear color is requested and the color is picked from a linear object, the result is now precise to the bit as the color gets patched through directly. Color space conversion now only happens when a color is picked from non-linear display space objects or when the color is requested to be returned in non-linear space.

In addition, this patch changes the DifferenceMatte node to interpret a tolerance of 0.0 to accept colors that are identical bit by bit, as apposed to simply refusing all colors.
This commit is contained in:
Stefan Werner
2017-04-20 22:41:26 +02:00
parent b628f765b0
commit aeda1a16f3
8 changed files with 23 additions and 37 deletions

View File

@@ -65,11 +65,11 @@ void DifferenceMatteOperation::executePixelSampled(float output[4], float x, flo
difference = difference / 3.0f; difference = difference / 3.0f;
/* make 100% transparent */ /* make 100% transparent */
if (difference < tolerance) { if (difference <= tolerance) {
output[0] = 0.0f; output[0] = 0.0f;
} }
/*in the falloff region, make partially transparent */ /*in the falloff region, make partially transparent */
else if (difference < falloff + tolerance) { else if (difference <= falloff + tolerance) {
difference = difference - tolerance; difference = difference - tolerance;
alpha = difference / falloff; alpha = difference / falloff;
/*only change if more transparent than before */ /*only change if more transparent than before */

View File

@@ -63,7 +63,7 @@ int ED_space_clip_get_clip_frame_number(struct SpaceClip *sc);
struct ImBuf *ED_space_clip_get_buffer(struct SpaceClip *sc); struct ImBuf *ED_space_clip_get_buffer(struct SpaceClip *sc);
struct ImBuf *ED_space_clip_get_stable_buffer(struct SpaceClip *sc, float loc[2], float *scale, float *angle); struct ImBuf *ED_space_clip_get_stable_buffer(struct SpaceClip *sc, float loc[2], float *scale, float *angle);
bool ED_space_clip_color_sample(struct Scene *scene, struct SpaceClip *sc, struct ARegion *ar, int mval[2], float r_col[3]); bool ED_space_clip_color_sample(struct SpaceClip *sc, struct ARegion *ar, int mval[2], float r_col[3]);
void ED_clip_update_frame(const struct Main *mainp, int cfra); void ED_clip_update_frame(const struct Main *mainp, int cfra);
bool ED_clip_view_selection(const struct bContext *C, struct ARegion *ar, bool fit); bool ED_clip_view_selection(const struct bContext *C, struct ARegion *ar, bool fit);

View File

@@ -46,7 +46,7 @@ void ED_space_image_set(struct SpaceImage *sima, struct Scene *scene, s
struct Mask *ED_space_image_get_mask(struct SpaceImage *sima); struct Mask *ED_space_image_get_mask(struct SpaceImage *sima);
void ED_space_image_set_mask(struct bContext *C, struct SpaceImage *sima, struct Mask *mask); void ED_space_image_set_mask(struct bContext *C, struct SpaceImage *sima, struct Mask *mask);
bool ED_space_image_color_sample(struct Scene *scene, struct SpaceImage *sima, struct ARegion *ar, int mval[2], float r_col[3]); bool ED_space_image_color_sample(struct SpaceImage *sima, struct ARegion *ar, int mval[2], float r_col[3]);
struct ImBuf *ED_space_image_acquire_buffer(struct SpaceImage *sima, void **r_lock); struct ImBuf *ED_space_image_acquire_buffer(struct SpaceImage *sima, void **r_lock);
void ED_space_image_release_buffer(struct SpaceImage *sima, struct ImBuf *ibuf, void *lock); void ED_space_image_release_buffer(struct SpaceImage *sima, struct ImBuf *ibuf, void *lock);
bool ED_space_image_has_buffer(struct SpaceImage *sima); bool ED_space_image_has_buffer(struct SpaceImage *sima);

View File

@@ -107,7 +107,7 @@ void ED_node_composite_job(const struct bContext *C, struct bNodeTree *nodetree,
void ED_operatormacros_node(void); void ED_operatormacros_node(void);
/* node_view.c */ /* node_view.c */
bool ED_space_node_color_sample(struct Scene *scene, struct SpaceNode *snode, struct ARegion *ar, int mval[2], float r_col[3]); bool ED_space_node_color_sample(struct SpaceNode *snode, struct ARegion *ar, int mval[2], float r_col[3]);
#endif /* __ED_NODE_H__ */ #endif /* __ED_NODE_H__ */

View File

@@ -225,7 +225,7 @@ static bool eyedropper_init(bContext *C, wmOperator *op)
return false; return false;
} }
if (RNA_property_subtype(eye->prop) == PROP_COLOR) { if (RNA_property_subtype(eye->prop) != PROP_COLOR) {
const char *display_device; const char *display_device;
float col[4]; float col[4];
@@ -235,7 +235,7 @@ static bool eyedropper_init(bContext *C, wmOperator *op)
/* store inital color */ /* store inital color */
RNA_property_float_get_array(&eye->ptr, eye->prop, col); RNA_property_float_get_array(&eye->ptr, eye->prop, col);
if (eye->display) { if (eye->display) {
IMB_colormanagement_scene_linear_to_display_v3(col, eye->display); IMB_colormanagement_display_to_scene_linear_v3(col, eye->display);
} }
copy_v3_v3(eye->init_col, col); copy_v3_v3(eye->init_col, col);
} }
@@ -266,6 +266,8 @@ static void eyedropper_color_sample_fl(bContext *C, Eyedropper *UNUSED(eye), int
/* we could use some clever */ /* we could use some clever */
wmWindow *win = CTX_wm_window(C); wmWindow *win = CTX_wm_window(C);
ScrArea *sa = BKE_screen_find_area_xy(win->screen, SPACE_TYPE_ANY, mx, my); ScrArea *sa = BKE_screen_find_area_xy(win->screen, SPACE_TYPE_ANY, mx, my);
const char *display_device = CTX_data_scene(C)->display_settings.display_device;
struct ColorManagedDisplay *display = IMB_colormanagement_display_get_named(display_device);
if (sa) { if (sa) {
if (sa->spacetype == SPACE_IMAGE) { if (sa->spacetype == SPACE_IMAGE) {
@@ -275,7 +277,7 @@ static void eyedropper_color_sample_fl(bContext *C, Eyedropper *UNUSED(eye), int
int mval[2] = {mx - ar->winrct.xmin, int mval[2] = {mx - ar->winrct.xmin,
my - ar->winrct.ymin}; my - ar->winrct.ymin};
if (ED_space_image_color_sample(CTX_data_scene(C), sima, ar, mval, r_col)) { if (ED_space_image_color_sample(sima, ar, mval, r_col)) {
return; return;
} }
} }
@@ -287,7 +289,7 @@ static void eyedropper_color_sample_fl(bContext *C, Eyedropper *UNUSED(eye), int
int mval[2] = {mx - ar->winrct.xmin, int mval[2] = {mx - ar->winrct.xmin,
my - ar->winrct.ymin}; my - ar->winrct.ymin};
if (ED_space_node_color_sample(CTX_data_scene(C), snode, ar, mval, r_col)) { if (ED_space_node_color_sample(snode, ar, mval, r_col)) {
return; return;
} }
} }
@@ -299,7 +301,7 @@ static void eyedropper_color_sample_fl(bContext *C, Eyedropper *UNUSED(eye), int
int mval[2] = {mx - ar->winrct.xmin, int mval[2] = {mx - ar->winrct.xmin,
my - ar->winrct.ymin}; my - ar->winrct.ymin};
if (ED_space_clip_color_sample(CTX_data_scene(C), sc, ar, mval, r_col)) { if (ED_space_clip_color_sample(sc, ar, mval, r_col)) {
return; return;
} }
} }
@@ -310,6 +312,8 @@ static void eyedropper_color_sample_fl(bContext *C, Eyedropper *UNUSED(eye), int
glReadBuffer(GL_FRONT); glReadBuffer(GL_FRONT);
glReadPixels(mx, my, 1, 1, GL_RGB, GL_FLOAT, r_col); glReadPixels(mx, my, 1, 1, GL_RGB, GL_FLOAT, r_col);
glReadBuffer(GL_BACK); glReadBuffer(GL_BACK);
IMB_colormanagement_display_to_scene_linear_v3(r_col, display);
} }
/* sets the sample color RGB, maintaining A */ /* sets the sample color RGB, maintaining A */
@@ -320,10 +324,10 @@ static void eyedropper_color_set(bContext *C, Eyedropper *eye, const float col[3
/* to maintain alpha */ /* to maintain alpha */
RNA_property_float_get_array(&eye->ptr, eye->prop, col_conv); RNA_property_float_get_array(&eye->ptr, eye->prop, col_conv);
/* convert from display space to linear rgb space */ /* convert from linear rgb space to display space */
if (eye->display) { if (eye->display) {
copy_v3_v3(col_conv, col); copy_v3_v3(col_conv, col);
IMB_colormanagement_display_to_scene_linear_v3(col_conv, eye->display); IMB_colormanagement_scene_linear_to_display_v3(col_conv, eye->display);
} }
else { else {
copy_v3_v3(col_conv, col); copy_v3_v3(col_conv, col);

View File

@@ -259,11 +259,9 @@ ImBuf *ED_space_clip_get_stable_buffer(SpaceClip *sc, float loc[2], float *scale
return NULL; return NULL;
} }
/* Returns color in the display space, matching ED_space_image_color_sample(). */ /* Returns color in linear space, matching ED_space_image_color_sample(). */
bool ED_space_clip_color_sample(Scene *scene, SpaceClip *sc, ARegion *ar, int mval[2], float r_col[3]) bool ED_space_clip_color_sample(SpaceClip *sc, ARegion *ar, int mval[2], float r_col[3])
{ {
const char *display_device = scene->display_settings.display_device;
struct ColorManagedDisplay *display = IMB_colormanagement_display_get_named(display_device);
ImBuf *ibuf; ImBuf *ibuf;
float fx, fy, co[2]; float fx, fy, co[2];
bool ret = false; bool ret = false;
@@ -299,11 +297,7 @@ bool ED_space_clip_color_sample(Scene *scene, SpaceClip *sc, ARegion *ar, int mv
ret = true; ret = true;
} }
} }
if (ret) {
IMB_colormanagement_scene_linear_to_display_v3(r_col, display);
}
IMB_freeImBuf(ibuf); IMB_freeImBuf(ibuf);
return ret; return ret;

View File

@@ -2900,11 +2900,9 @@ static void image_sample_draw(const bContext *C, ARegion *ar, void *arg_info)
} }
} }
/* Returns color in the display space, matching ED_space_node_color_sample(). */ /* Returns color in linear space, matching ED_space_node_color_sample(). */
bool ED_space_image_color_sample(Scene *scene, SpaceImage *sima, ARegion *ar, int mval[2], float r_col[3]) bool ED_space_image_color_sample(SpaceImage *sima, ARegion *ar, int mval[2], float r_col[3])
{ {
const char *display_device = scene->display_settings.display_device;
struct ColorManagedDisplay *display = IMB_colormanagement_display_get_named(display_device);
void *lock; void *lock;
ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock); ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
float fx, fy; float fx, fy;
@@ -2938,10 +2936,6 @@ bool ED_space_image_color_sample(Scene *scene, SpaceImage *sima, ARegion *ar, in
} }
} }
if (ret) {
IMB_colormanagement_scene_linear_to_display_v3(r_col, display);
}
ED_space_image_release_buffer(sima, ibuf, lock); ED_space_image_release_buffer(sima, ibuf, lock);
return ret; return ret;
} }

View File

@@ -417,13 +417,11 @@ static void sample_draw(const bContext *C, ARegion *ar, void *arg_info)
} }
} }
/* Returns color in the display space, matching ED_space_image_color_sample(). /* Returns color in linear space, matching ED_space_image_color_sample().
* And here we've got recursion in the comments tips... * And here we've got recursion in the comments tips...
*/ */
bool ED_space_node_color_sample(Scene *scene, SpaceNode *snode, ARegion *ar, int mval[2], float r_col[3]) bool ED_space_node_color_sample(SpaceNode *snode, ARegion *ar, int mval[2], float r_col[3])
{ {
const char *display_device = scene->display_settings.display_device;
struct ColorManagedDisplay *display = IMB_colormanagement_display_get_named(display_device);
void *lock; void *lock;
Image *ima; Image *ima;
ImBuf *ibuf; ImBuf *ibuf;
@@ -471,10 +469,6 @@ bool ED_space_node_color_sample(Scene *scene, SpaceNode *snode, ARegion *ar, int
} }
} }
if (ret) {
IMB_colormanagement_scene_linear_to_display_v3(r_col, display);
}
BKE_image_release_ibuf(ima, ibuf, lock); BKE_image_release_ibuf(ima, ibuf, lock);
return ret; return ret;