mango request

- optionally display the histogram as lines (not filled areas).
- expand the enum for faster access.
- keep the sample line displayed after doing the line sample (running again clears).
This commit is contained in:
Campbell Barton 2012-06-10 12:09:25 +00:00
parent 6ba5650428
commit 5e29381825
8 changed files with 122 additions and 43 deletions

@ -502,9 +502,12 @@ class IMAGE_PT_view_histogram(Panel):
layout = self.layout
sima = context.space_data
hist = sima.scopes.histogram
layout.template_histogram(sima.scopes, "histogram")
layout.prop(sima.scopes.histogram, "mode", icon_only=True)
row = layout.row(align=True)
row.prop(hist, "mode", icon_only=True, expand=True)
row.prop(hist, "show_line", text="")
class IMAGE_PT_view_waveform(Panel):
@ -560,10 +563,13 @@ class IMAGE_PT_sample_line(Panel):
layout = self.layout
sima = context.space_data
hist = sima.sample_histogram
layout.operator("image.sample_line")
layout.template_histogram(sima, "sample_histogram")
layout.prop(sima.sample_histogram, "mode")
row = layout.row(align=True)
row.prop(hist, "mode", expand=True)
row.prop(hist, "show_line", text="")
class IMAGE_PT_scope_sample(Panel):

@ -658,37 +658,59 @@ static void draw_scope_end(rctf *rect, GLint *scissor)
}
static void histogram_draw_one(float r, float g, float b, float alpha,
float x, float y, float w, float h, float *data, int res)
float x, float y, float w, float h, float *data, int res, const short is_line)
{
int i;
/* under the curve */
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glColor4f(r, g, b, alpha);
glShadeModel(GL_FLAT);
glBegin(GL_QUAD_STRIP);
glVertex2f(x, y);
glVertex2f(x, y + (data[0] * h));
for (i = 1; i < res; i++) {
float x2 = x + i * (w / (float)res);
glVertex2f(x2, y + (data[i] * h));
glVertex2f(x2, y);
if (is_line) {
glLineWidth(1.5);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glColor4f(r, g, b, alpha);
/* curve outline */
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glEnable(GL_LINE_SMOOTH);
glBegin(GL_LINE_STRIP);
for (i = 0; i < res; i++) {
float x2 = x + i * (w / (float)res);
glVertex2f(x2, y + (data[i] * h));
}
glEnd();
glDisable(GL_LINE_SMOOTH);
glLineWidth(1.0);
}
glEnd();
/* curve outline */
glColor4f(0.f, 0.f, 0.f, 0.25f);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
glBegin(GL_LINE_STRIP);
for (i = 0; i < res; i++) {
float x2 = x + i * (w / (float)res);
glVertex2f(x2, y + (data[i] * h));
else {
/* under the curve */
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glColor4f(r, g, b, alpha);
glShadeModel(GL_FLAT);
glBegin(GL_QUAD_STRIP);
glVertex2f(x, y);
glVertex2f(x, y + (data[0] * h));
for (i = 1; i < res; i++) {
float x2 = x + i * (w / (float)res);
glVertex2f(x2, y + (data[i] * h));
glVertex2f(x2, y);
}
glEnd();
/* curve outline */
glColor4f(0.f, 0.f, 0.f, 0.25f);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
glBegin(GL_LINE_STRIP);
for (i = 0; i < res; i++) {
float x2 = x + i * (w / (float)res);
glVertex2f(x2, y + (data[i] * h));
}
glEnd();
glDisable(GL_LINE_SMOOTH);
}
glEnd();
glDisable(GL_LINE_SMOOTH);
}
void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti)
@ -698,6 +720,7 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol)
rctf rect;
int i;
float w, h;
const short is_line = (hist->flag & HISTO_FLAG_LINE) != 0;
//float alpha;
GLint scissor[4];
@ -731,14 +754,14 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol)
}
if (hist->mode == HISTO_MODE_LUMA)
histogram_draw_one(1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_luma, res);
histogram_draw_one(1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_luma, res, is_line);
else {
if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_R)
histogram_draw_one(1.0, 0.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_r, res);
histogram_draw_one(1.0, 0.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_r, res, is_line);
if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_G)
histogram_draw_one(0.0, 1.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_g, res);
histogram_draw_one(0.0, 1.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_g, res, is_line);
if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_B)
histogram_draw_one(0.0, 0.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_b, res);
histogram_draw_one(0.0, 0.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_b, res, is_line);
}
/* outline, scale gripper */

@ -578,6 +578,28 @@ void draw_image_grease_pencil(bContext *C, short onlyv2d)
}
}
void draw_image_sample_line(SpaceImage *sima)
{
if (sima->sample_line_hist.flag & HISTO_FLAG_SAMPLELINE) {
Histogram *hist = &sima->sample_line_hist;
glBegin(GL_LINES);
glColor3ub(0, 0, 0);
glVertex2fv(hist->co[0]);
glVertex2fv(hist->co[1]);
glEnd();
setlinestyle(1);
glBegin(GL_LINES);
glColor3ub(255, 255, 255);
glVertex2fv(hist->co[0]);
glVertex2fv(hist->co[1]);
glEnd();
setlinestyle(0);
}
}
/* XXX becomes WM paint cursor */
#if 0
static void draw_image_view_tool(Scene *scene)

@ -54,6 +54,7 @@ extern const char *image_context_dir[]; /* doc access */
/* image_draw.c */
void draw_image_main(struct SpaceImage *sima, struct ARegion *ar, struct Scene *scene);
void draw_image_grease_pencil(struct bContext *C, short onlyv2d);
void draw_image_sample_line(struct SpaceImage *sima);
/* image_ops.c */
int space_image_main_area_poll(struct bContext *C);

@ -2137,7 +2137,14 @@ static int image_sample_line_exec(bContext *C, wmOperator *op)
hist->x_resolution = 256;
hist->xmax = 1.0f;
hist->ymax = 1.0f;
/* persistent draw */
hist->co[0][0] = x1f;
hist->co[0][1] = y1f;
hist->co[1][0] = x2f;
hist->co[1][1] = y2f;
hist->flag |= HISTO_FLAG_SAMPLELINE; /* keep drawing the flag after */
for (i = 0; i < 256; i++) {
x = (int)(0.5f + x1 + (float)i * (x2 - x1) / 255.0f);
y = (int)(0.5f + y1 + (float)i * (y2 - y1) / 255.0f);
@ -2179,7 +2186,10 @@ static int image_sample_line_exec(bContext *C, wmOperator *op)
static int image_sample_line_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
SpaceImage *sima = CTX_wm_space_image(C);
Histogram *hist = &sima->sample_line_hist;
hist->flag &= ~HISTO_FLAG_SAMPLELINE;
if (!ED_space_image_has_buffer(sima))
return OPERATOR_CANCELLED;

@ -824,15 +824,18 @@ static void image_main_area_draw(const bContext *C, ARegion *ar)
draw_uvedit_main(sima, ar, scene, obedit, obact);
ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
/* Grease Pencil too (in addition to UV's) */
draw_image_grease_pencil((bContext *)C, 1);
/* sample line */
draw_image_sample_line(sima);
UI_view2d_view_restore(C);
/* draw Grease Pencil - screen space only */
draw_image_grease_pencil((bContext *)C, 0);
/* scrollers? */
#if 0
scrollers = UI_view2d_scrollers_calc(C, v2d, V2D_UNIT_VALUES, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);

@ -102,6 +102,11 @@ typedef enum CurveMappingPreset {
#define HISTO_MODE_G 3
#define HISTO_MODE_B 4
enum {
HISTO_FLAG_LINE = (1 << 0),
HISTO_FLAG_SAMPLELINE = (1 << 1)
};
typedef struct Histogram {
int channels;
int x_resolution;
@ -110,8 +115,13 @@ typedef struct Histogram {
float data_b[256];
float data_luma[256];
float xmax, ymax;
int mode;
short mode;
short flag;
int height;
/* sample line only */
/* image coords src -> est */
float co[2][2];
} Histogram;
struct ImBuf;

@ -570,11 +570,11 @@ static void rna_def_histogram(BlenderRNA *brna)
PropertyRNA *prop;
static EnumPropertyItem prop_mode_items[] = {
{HISTO_MODE_LUMA, "LUMA", ICON_COLOR, "Luma", ""},
{HISTO_MODE_RGB, "RGB", ICON_COLOR, "Red Green Blue", ""},
{HISTO_MODE_R, "R", ICON_COLOR, "Red", ""},
{HISTO_MODE_G, "G", ICON_COLOR, "Green", ""},
{HISTO_MODE_B, "B", ICON_COLOR, "Blue", ""},
{HISTO_MODE_LUMA, "LUMA", 0, "Luma", "Luma"},
{HISTO_MODE_RGB, "RGB", 0, "RGB", "Red Green Blue"},
{HISTO_MODE_R, "R", 0, "R", "Red"},
{HISTO_MODE_G, "G", 0, "G", "Green"},
{HISTO_MODE_B, "B", 0, "B", "Blue"},
{0, NULL, 0, NULL, NULL}
};
@ -585,7 +585,11 @@ static void rna_def_histogram(BlenderRNA *brna)
RNA_def_property_enum_sdna(prop, NULL, "mode");
RNA_def_property_enum_items(prop, prop_mode_items);
RNA_def_property_ui_text(prop, "Mode", "Channels to display when drawing the histogram");
prop = RNA_def_property(srna, "show_line", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", HISTO_FLAG_LINE);
RNA_def_property_ui_text(prop, "Show Line", "Displays lines rather then filled shapes");
RNA_def_property_ui_icon(prop, ICON_IPO, 0);
}
static void rna_def_scopes(BlenderRNA *brna)