de-duplicate function copy-paste for node color sampling.

This commit is contained in:
Campbell Barton 2012-01-12 05:46:45 +00:00
parent de86d89a9f
commit 24bf175d7e
6 changed files with 11 additions and 210 deletions

@ -66,5 +66,8 @@ int ED_space_image_show_uvshadow(struct SpaceImage *sima, struct Object *obedit)
/* UI level image (texture) updating... render calls own stuff (too) */ /* UI level image (texture) updating... render calls own stuff (too) */
void ED_image_update_frame(const struct Main *mainp, int cfra); void ED_image_update_frame(const struct Main *mainp, int cfra);
void ED_image_draw_info(struct ARegion *ar, int color_manage, int channels,
int x, int y, const char cp[4], const float fp[4], int *zp, float *zpf);
#endif /* ED_IMAGE_H */ #endif /* ED_IMAGE_H */

@ -110,7 +110,8 @@ static void draw_render_info(Scene *scene, Image *ima, ARegion *ar)
BKE_image_release_renderresult(scene, ima); BKE_image_release_renderresult(scene, ima);
} }
void draw_image_info(ARegion *ar, int color_manage, int channels, int x, int y, const char cp[4], const float fp[4], int *zp, float *zpf) /* used by node view too */
void ED_image_draw_info(ARegion *ar, int color_manage, int channels, int x, int y, const char cp[4], const float fp[4], int *zp, float *zpf)
{ {
char str[256]; char str[256];
float dx= 6; float dx= 6;

@ -55,7 +55,6 @@ void IMAGE_OT_toolbox(struct wmOperatorType *ot);
/* image_draw.c */ /* image_draw.c */
void draw_image_main(struct SpaceImage *sima, struct ARegion *ar, struct Scene *scene); void draw_image_main(struct SpaceImage *sima, struct ARegion *ar, struct Scene *scene);
void draw_image_info(struct ARegion *ar, int color_manage, int channels, int x, int y, const char cp[4], const float fp[4], int *zp, float *zpf);
void draw_image_grease_pencil(struct bContext *C, short onlyv2d); void draw_image_grease_pencil(struct bContext *C, short onlyv2d);
/* image_ops.c */ /* image_ops.c */

@ -1772,7 +1772,7 @@ static void image_sample_draw(const bContext *UNUSED(C), ARegion *ar, void *arg_
ImageSampleInfo *info= arg_info; ImageSampleInfo *info= arg_info;
if(info->draw) { if(info->draw) {
/* no color management needed for images (color_manage=0) */ /* no color management needed for images (color_manage=0) */
draw_image_info(ar, 0, info->channels, info->x, info->y, info->colp, info->colfp, info->zp, info->zfp); ED_image_draw_info(ar, 0, info->channels, info->x, info->y, info->colp, info->colfp, info->zp, info->zfp);
} }
} }

@ -2279,211 +2279,6 @@ void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode, int color_manage)
} }
} }
void draw_nodespace_color_info(ARegion *ar, int color_manage, int channels, int x, int y, const char cp[4], const float fp[4])
{
char str[256];
float dx= 6;
/* text colors */
/* XXX colored text not allowed in Blender UI */
#if 0
unsigned char red[3] = {255, 50, 50};
unsigned char green[3] = {0, 255, 0};
unsigned char blue[3] = {100, 100, 255};
#else
unsigned char red[3] = {255, 255, 255};
unsigned char green[3] = {255, 255, 255};
unsigned char blue[3] = {255, 255, 255};
#endif
float hue=0, sat=0, val=0, lum=0, u=0, v=0;
float col[4], finalcol[4];
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
/* noisy, high contrast make impossible to read if lower alpha is used. */
glColor4ub(0, 0, 0, 190);
glRecti(0.0, 0.0, ar->winrct.xmax - ar->winrct.xmin + 1, 20);
glDisable(GL_BLEND);
BLF_size(blf_mono_font, 11, 72);
glColor3ub(255, 255, 255);
BLI_snprintf(str, sizeof(str), "X:%-4d Y:%-4d |", x, y);
// UI_DrawString(6, 6, str); // works ok but fixed width is nicer.
BLF_position(blf_mono_font, dx, 6, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
dx += BLF_width(blf_mono_font, str);
#if 0 /* XXX no Z value in compo backdrop atm */
if(zp) {
glColor3ub(255, 255, 255);
BLI_snprintf(str, sizeof(str), " Z:%-.4f |", 0.5f+0.5f*(((float)*zp)/(float)0x7fffffff));
BLF_position(blf_mono_font, dx, 6, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
dx += BLF_width(blf_mono_font, str);
}
if(zpf) {
glColor3ub(255, 255, 255);
BLI_snprintf(str, sizeof(str), " Z:%-.3f |", *zpf);
BLF_position(blf_mono_font, dx, 6, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
dx += BLF_width(blf_mono_font, str);
}
#endif
if(channels >= 3) {
glColor3ubv(red);
if (fp)
BLI_snprintf(str, sizeof(str), " R:%-.4f", fp[0]);
else if (cp)
BLI_snprintf(str, sizeof(str), " R:%-3d", cp[0]);
else
BLI_snprintf(str, sizeof(str), " R:-");
BLF_position(blf_mono_font, dx, 6, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
dx += BLF_width(blf_mono_font, str);
glColor3ubv(green);
if (fp)
BLI_snprintf(str, sizeof(str), " G:%-.4f", fp[1]);
else if (cp)
BLI_snprintf(str, sizeof(str), " G:%-3d", cp[1]);
else
BLI_snprintf(str, sizeof(str), " G:-");
BLF_position(blf_mono_font, dx, 6, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
dx += BLF_width(blf_mono_font, str);
glColor3ubv(blue);
if (fp)
BLI_snprintf(str, sizeof(str), " B:%-.4f", fp[2]);
else if (cp)
BLI_snprintf(str, sizeof(str), " B:%-3d", cp[2]);
else
BLI_snprintf(str, sizeof(str), " B:-");
BLF_position(blf_mono_font, dx, 6, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
dx += BLF_width(blf_mono_font, str);
if(channels == 4) {
glColor3ub(255, 255, 255);
if (fp)
BLI_snprintf(str, sizeof(str), " A:%-.4f", fp[3]);
else if (cp)
BLI_snprintf(str, sizeof(str), " A:%-3d", cp[3]);
else
BLI_snprintf(str, sizeof(str), "- ");
BLF_position(blf_mono_font, dx, 6, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
dx += BLF_width(blf_mono_font, str);
}
}
/* color rectangle */
if (channels==1) {
if (fp)
col[0] = col[1] = col[2] = fp[0];
else if (cp)
col[0] = col[1] = col[2] = (float)cp[0]/255.0f;
else
col[0] = col[1] = col[2] = 0.0f;
}
else if (channels==3) {
if (fp)
copy_v3_v3(col, fp);
else if (cp) {
col[0] = (float)cp[0]/255.0f;
col[1] = (float)cp[1]/255.0f;
col[2] = (float)cp[2]/255.0f;
}
else
zero_v3(col);
}
else if (channels==4) {
if (fp)
copy_v4_v4(col, fp);
else if (cp) {
col[0] = (float)cp[0]/255.0f;
col[1] = (float)cp[1]/255.0f;
col[2] = (float)cp[2]/255.0f;
col[3] = (float)cp[3]/255.0f;
}
else
zero_v4(col);
}
if (color_manage) {
linearrgb_to_srgb_v3_v3(finalcol, col);
finalcol[3] = col[3];
}
else {
copy_v4_v4(finalcol, col);
}
glDisable(GL_BLEND);
glColor3fv(finalcol);
dx += 5;
glBegin(GL_QUADS);
glVertex2f(dx, 3);
glVertex2f(dx, 17);
glVertex2f(dx+30, 17);
glVertex2f(dx+30, 3);
glEnd();
dx += 35;
glColor3ub(255, 255, 255);
if(channels == 1) {
if (fp) {
rgb_to_hsv(fp[0], fp[0], fp[0], &hue, &sat, &val);
rgb_to_yuv(fp[0], fp[0], fp[0], &lum, &u, &v);
}
else if (cp) {
rgb_to_hsv((float)cp[0]/255.0f, (float)cp[0]/255.0f, (float)cp[0]/255.0f, &hue, &sat, &val);
rgb_to_yuv((float)cp[0]/255.0f, (float)cp[0]/255.0f, (float)cp[0]/255.0f, &lum, &u, &v);
}
BLI_snprintf(str, sizeof(str), "V:%-.4f", val);
BLF_position(blf_mono_font, dx, 6, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
dx += BLF_width(blf_mono_font, str);
BLI_snprintf(str, sizeof(str), " L:%-.4f", lum);
BLF_position(blf_mono_font, dx, 6, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
dx += BLF_width(blf_mono_font, str);
}
else if(channels >= 3) {
if (fp) {
rgb_to_hsv(fp[0], fp[1], fp[2], &hue, &sat, &val);
rgb_to_yuv(fp[0], fp[1], fp[2], &lum, &u, &v);
}
else if (cp) {
rgb_to_hsv((float)cp[0]/255.0f, (float)cp[1]/255.0f, (float)cp[2]/255.0f, &hue, &sat, &val);
rgb_to_yuv((float)cp[0]/255.0f, (float)cp[1]/255.0f, (float)cp[2]/255.0f, &lum, &u, &v);
}
BLI_snprintf(str, sizeof(str), "H:%-.4f", hue);
BLF_position(blf_mono_font, dx, 6, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
dx += BLF_width(blf_mono_font, str);
BLI_snprintf(str, sizeof(str), " S:%-.4f", sat);
BLF_position(blf_mono_font, dx, 6, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
dx += BLF_width(blf_mono_font, str);
BLI_snprintf(str, sizeof(str), " V:%-.4f", val);
BLF_position(blf_mono_font, dx, 6, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
dx += BLF_width(blf_mono_font, str);
BLI_snprintf(str, sizeof(str), " L:%-.4f", lum);
BLF_position(blf_mono_font, dx, 6, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
dx += BLF_width(blf_mono_font, str);
}
(void)dx;
}
#if 0 #if 0
/* note: needs to be userpref or opengl profile option */ /* note: needs to be userpref or opengl profile option */
static void draw_nodespace_back_tex(ScrArea *sa, SpaceNode *snode) static void draw_nodespace_back_tex(ScrArea *sa, SpaceNode *snode)

@ -71,6 +71,7 @@
#include "IMB_imbuf_types.h" #include "IMB_imbuf_types.h"
#include "ED_node.h" #include "ED_node.h"
#include "ED_image.h"
#include "ED_screen.h" #include "ED_screen.h"
#include "ED_space_api.h" #include "ED_space_api.h"
#include "ED_render.h" #include "ED_render.h"
@ -1343,8 +1344,10 @@ static void sample_draw(const bContext *C, ARegion *ar, void *arg_info)
{ {
ImageSampleInfo *info= arg_info; ImageSampleInfo *info= arg_info;
draw_nodespace_color_info(ar, (CTX_data_scene(C)->r.color_mgt_flag & R_COLOR_MANAGEMENT), info->channels, ED_image_draw_info(ar, (CTX_data_scene(C)->r.color_mgt_flag & R_COLOR_MANAGEMENT), info->channels,
info->x, info->y, info->col, info->colf); info->x, info->y, info->col, info->colf,
NULL, NULL /* zbuf - unused for nodes */
);
} }
static void sample_apply(bContext *C, wmOperator *op, wmEvent *event) static void sample_apply(bContext *C, wmOperator *op, wmEvent *event)