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 layout = self.layout
sima = context.space_data sima = context.space_data
hist = sima.scopes.histogram
layout.template_histogram(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): class IMAGE_PT_view_waveform(Panel):
@ -560,10 +563,13 @@ class IMAGE_PT_sample_line(Panel):
layout = self.layout layout = self.layout
sima = context.space_data sima = context.space_data
hist = sima.sample_histogram
layout.operator("image.sample_line") layout.operator("image.sample_line")
layout.template_histogram(sima, "sample_histogram") 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): class IMAGE_PT_scope_sample(Panel):

@ -658,10 +658,31 @@ static void draw_scope_end(rctf *rect, GLint *scissor)
} }
static void histogram_draw_one(float r, float g, float b, float alpha, 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; int i;
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);
}
else {
/* under the curve */ /* under the curve */
glBlendFunc(GL_SRC_ALPHA, GL_ONE); glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glColor4f(r, g, b, alpha); glColor4f(r, g, b, alpha);
@ -690,6 +711,7 @@ static void histogram_draw_one(float r, float g, float b, float alpha,
glEnd(); glEnd();
glDisable(GL_LINE_SMOOTH); glDisable(GL_LINE_SMOOTH);
} }
}
void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti) 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; rctf rect;
int i; int i;
float w, h; float w, h;
const short is_line = (hist->flag & HISTO_FLAG_LINE) != 0;
//float alpha; //float alpha;
GLint scissor[4]; 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) 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 { else {
if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_R) 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) 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) 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 */ /* 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 */ /* XXX becomes WM paint cursor */
#if 0 #if 0
static void draw_image_view_tool(Scene *scene) static void draw_image_view_tool(Scene *scene)

@ -54,6 +54,7 @@ extern const char *image_context_dir[]; /* doc access */
/* 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_grease_pencil(struct bContext *C, short onlyv2d); void draw_image_grease_pencil(struct bContext *C, short onlyv2d);
void draw_image_sample_line(struct SpaceImage *sima);
/* image_ops.c */ /* image_ops.c */
int space_image_main_area_poll(struct bContext *C); int space_image_main_area_poll(struct bContext *C);

@ -2138,6 +2138,13 @@ static int image_sample_line_exec(bContext *C, wmOperator *op)
hist->xmax = 1.0f; hist->xmax = 1.0f;
hist->ymax = 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++) { for (i = 0; i < 256; i++) {
x = (int)(0.5f + x1 + (float)i * (x2 - x1) / 255.0f); x = (int)(0.5f + x1 + (float)i * (x2 - x1) / 255.0f);
y = (int)(0.5f + y1 + (float)i * (y2 - y1) / 255.0f); y = (int)(0.5f + y1 + (float)i * (y2 - y1) / 255.0f);
@ -2180,6 +2187,9 @@ static int image_sample_line_invoke(bContext *C, wmOperator *op, wmEvent *event)
{ {
SpaceImage *sima = CTX_wm_space_image(C); 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)) if (!ED_space_image_has_buffer(sima))
return OPERATOR_CANCELLED; return OPERATOR_CANCELLED;

@ -828,6 +828,9 @@ static void image_main_area_draw(const bContext *C, ARegion *ar)
/* Grease Pencil too (in addition to UV's) */ /* Grease Pencil too (in addition to UV's) */
draw_image_grease_pencil((bContext *)C, 1); draw_image_grease_pencil((bContext *)C, 1);
/* sample line */
draw_image_sample_line(sima);
UI_view2d_view_restore(C); UI_view2d_view_restore(C);
/* draw Grease Pencil - screen space only */ /* draw Grease Pencil - screen space only */

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

@ -570,11 +570,11 @@ static void rna_def_histogram(BlenderRNA *brna)
PropertyRNA *prop; PropertyRNA *prop;
static EnumPropertyItem prop_mode_items[] = { static EnumPropertyItem prop_mode_items[] = {
{HISTO_MODE_LUMA, "LUMA", ICON_COLOR, "Luma", ""}, {HISTO_MODE_LUMA, "LUMA", 0, "Luma", "Luma"},
{HISTO_MODE_RGB, "RGB", ICON_COLOR, "Red Green Blue", ""}, {HISTO_MODE_RGB, "RGB", 0, "RGB", "Red Green Blue"},
{HISTO_MODE_R, "R", ICON_COLOR, "Red", ""}, {HISTO_MODE_R, "R", 0, "R", "Red"},
{HISTO_MODE_G, "G", ICON_COLOR, "Green", ""}, {HISTO_MODE_G, "G", 0, "G", "Green"},
{HISTO_MODE_B, "B", ICON_COLOR, "Blue", ""}, {HISTO_MODE_B, "B", 0, "B", "Blue"},
{0, NULL, 0, NULL, NULL} {0, NULL, 0, NULL, NULL}
}; };
@ -586,6 +586,10 @@ static void rna_def_histogram(BlenderRNA *brna)
RNA_def_property_enum_items(prop, prop_mode_items); RNA_def_property_enum_items(prop, prop_mode_items);
RNA_def_property_ui_text(prop, "Mode", "Channels to display when drawing the histogram"); 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) static void rna_def_scopes(BlenderRNA *brna)