Fix #34672: Image sampling line didn't use color management for byte buffers

This makes it so sample line (for all image editor, sequencer and compositor)
displaying managed color for byte buffers as well. It was simply not implemented
before.
This commit is contained in:
Sergey Sharybin 2013-03-18 11:34:05 +00:00
parent 4c1d80bf86
commit b19155e76c
7 changed files with 62 additions and 30 deletions

@ -79,7 +79,7 @@ int ED_space_image_maskedit_mask_poll(struct bContext *C);
void ED_image_update_frame(const struct Main *mainp, int cfra);
void ED_image_draw_info(struct Scene *scene, struct ARegion *ar, int color_manage, int use_default_view, int channels, int x, int y,
const unsigned char cp[4], const float fp[4], int *zp, float *zpf);
const unsigned char cp[4], const float fp[4], const float linearcol[4], int *zp, float *zpf);
#endif /* __ED_IMAGE_H__ */

@ -162,7 +162,7 @@ static void draw_render_info(Scene *scene, Image *ima, ARegion *ar, float zoomx,
/* used by node view too */
void ED_image_draw_info(Scene *scene, ARegion *ar, int color_manage, int use_default_view, int channels, int x, int y,
const unsigned char cp[4], const float fp[4], int *zp, float *zpf)
const unsigned char cp[4], const float fp[4], const float linearcol[4], int *zp, float *zpf)
{
char str[256];
float dx = 6;
@ -258,15 +258,23 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, int color_manage, int use_def
dx += BLF_width(blf_mono_font, str);
}
if (color_manage && channels == 4) {
float pixel[4];
if (color_manage) {
float rgba[4];
copy_v3_v3(rgba, linearcol);
if (channels == 3)
rgba[3] = 1.0f;
else
rgba[3] = linearcol[3];
(void)color_manage;
if (use_default_view)
IMB_colormanagement_pixel_to_display_space_v4(pixel, fp, NULL, &scene->display_settings);
IMB_colormanagement_pixel_to_display_space_v4(rgba, rgba, NULL, &scene->display_settings);
else
IMB_colormanagement_pixel_to_display_space_v4(pixel, fp, &scene->view_settings, &scene->display_settings);
IMB_colormanagement_pixel_to_display_space_v4(rgba, rgba, &scene->view_settings, &scene->display_settings);
BLI_snprintf(str, sizeof(str), " | CM R:%-.4f G:%-.4f B:%-.4f", pixel[0], pixel[1], pixel[2]);
BLI_snprintf(str, sizeof(str), " | CM R:%-.4f G:%-.4f B:%-.4f", rgba[0], rgba[1], rgba[2]);
BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
dx += BLF_width(blf_mono_font, str);
@ -287,26 +295,11 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, int color_manage, int use_def
col[3] = 1.0f;
}
else if (channels == 3) {
if (fp) {
copy_v3_v3(col, fp);
}
else if (cp) {
rgb_uchar_to_float(col, cp);
}
else {
zero_v3(col);
}
copy_v3_v3(col, linearcol);
col[3] = 1.0f;
}
else if (channels == 4) {
if (fp)
copy_v4_v4(col, fp);
else if (cp) {
rgba_uchar_to_float(col, cp);
}
else {
zero_v4(col);
}
copy_v4_v4(col, linearcol);
}
else {
BLI_assert(0);

@ -2079,6 +2079,7 @@ typedef struct ImageSampleInfo {
unsigned char col[4];
float colf[4];
float linearcol[4];
int z;
float zf;
@ -2099,7 +2100,7 @@ static void image_sample_draw(const bContext *C, ARegion *ar, void *arg_info)
Scene *scene = CTX_data_scene(C);
ED_image_draw_info(scene, ar, info->color_manage, info->use_default_view, info->channels,
info->x, info->y, info->colp, info->colfp, info->zp, info->zfp);
info->x, info->y, info->colp, info->colfp, info->linearcol, info->zp, info->zfp);
}
}
@ -2198,7 +2199,10 @@ static void image_sample_apply(bContext *C, wmOperator *op, const wmEvent *event
info->colf[3] = (float)cp[3] / 255.0f;
info->colfp = info->colf;
info->color_manage = FALSE;
copy_v4_v4(info->linearcol, info->colf);
IMB_colormanagement_colorspace_to_scene_linear_v4(info->linearcol, false, ibuf->rect_colorspace);
info->color_manage = TRUE;
}
if (ibuf->rect_float) {
fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x));
@ -2209,6 +2213,8 @@ static void image_sample_apply(bContext *C, wmOperator *op, const wmEvent *event
info->colf[3] = fp[3];
info->colfp = info->colf;
copy_v4_v4(info->linearcol, info->colf);
info->color_manage = TRUE;
}

@ -56,6 +56,7 @@
#include "MEM_guardedalloc.h"
#include "IMB_colormanagement.h"
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
@ -335,6 +336,7 @@ typedef struct ImageSampleInfo {
unsigned char col[4];
float colf[4];
float linearcol[4];
int z;
float zf;
@ -353,7 +355,7 @@ static void sample_draw(const bContext *C, ARegion *ar, void *arg_info)
if (info->draw) {
ED_image_draw_info(scene, ar, info->color_manage, FALSE, info->channels,
info->x, info->y, info->col, info->colf,
info->x, info->y, info->col, info->colf, info->linearcol,
info->zp, info->zfp);
}
}
@ -469,7 +471,10 @@ static void sample_apply(bContext *C, wmOperator *op, const wmEvent *event)
info->colf[2] = (float)cp[2] / 255.0f;
info->colf[3] = (float)cp[3] / 255.0f;
info->color_manage = FALSE;
copy_v4_v4(info->linearcol, info->colf);
IMB_colormanagement_colorspace_to_scene_linear_v4(info->linearcol, false, ibuf->rect_colorspace);
info->color_manage = TRUE;
}
if (ibuf->rect_float) {
fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x));

@ -31,6 +31,7 @@
#include "MEM_guardedalloc.h"
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "DNA_scene_types.h"
@ -66,6 +67,7 @@ typedef struct ImageSampleInfo {
unsigned char col[4];
float colf[4];
float linearcol[4];
unsigned char *colp;
float *colfp;
@ -81,7 +83,8 @@ static void sample_draw(const bContext *C, ARegion *ar, void *arg_info)
if (info->draw) {
ED_image_draw_info(scene, ar, info->color_manage, FALSE, info->channels,
info->x, info->y, info->colp, info->colfp, NULL, NULL);
info->x, info->y, info->colp, info->colfp,
info->linearcol, NULL, NULL);
}
}
@ -134,7 +137,10 @@ static void sample_apply(bContext *C, wmOperator *op, const wmEvent *event)
info->colf[3] = (float)cp[3] / 255.0f;
info->colfp = info->colf;
info->color_manage = FALSE;
copy_v4_v4(info->linearcol, info->colf);
IMB_colormanagement_colorspace_to_scene_linear_v4(info->linearcol, false, ibuf->rect_colorspace);
info->color_manage = TRUE;
}
if (ibuf->rect_float) {
fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x));

@ -70,6 +70,8 @@ void IMB_colormanagement_transform_threaded(float *buffer, int width, int height
void IMB_colormanagement_transform_v4(float pixel[4], const char *from_colorspace, const char *to_colorspace);
void IMB_colormanagement_colorspace_to_scene_linear_v3(float pixel[3], struct ColorSpace *colorspace);
void IMB_colormanagement_colorspace_to_scene_linear_v4(float pixel[4], int predivide, struct ColorSpace *colorspace);
void IMB_colormanagement_scene_linear_to_colorspace_v3(float pixel[3], struct ColorSpace *colorspace);
void IMB_colormanagement_colorspace_to_scene_linear(float *buffer, int width, int height, int channels, struct ColorSpace *colorspace, int predivide);

@ -1583,6 +1583,26 @@ void IMB_colormanagement_scene_linear_to_colorspace_v3(float pixel[3], ColorSpac
OCIO_processorApplyRGB(processor, pixel);
}
void IMB_colormanagement_colorspace_to_scene_linear_v4(float pixel[4], int predivide, ColorSpace *colorspace)
{
OCIO_ConstProcessorRcPtr *processor;
if (!colorspace) {
/* should never happen */
printf("%s: perform conversion from unknown color space\n", __func__);
return;
}
processor = colorspace_to_scene_linear_processor(colorspace);
if (processor) {
if (predivide)
OCIO_processorApplyRGBA_predivide(processor, pixel);
else
OCIO_processorApplyRGBA(processor, pixel);
}
}
void IMB_colormanagement_colorspace_to_scene_linear(float *buffer, int width, int height, int channels, struct ColorSpace *colorspace, int predivide)
{
OCIO_ConstProcessorRcPtr *processor;