mango request
authorCampbell Barton <ideasman42@gmail.com>
Sun, 10 Jun 2012 12:09:25 +0000 (12:09 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 10 Jun 2012 12:09:25 +0000 (12:09 +0000)
- 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).

release/scripts/startup/bl_ui/space_image.py
source/blender/editors/interface/interface_draw.c
source/blender/editors/space_image/image_draw.c
source/blender/editors/space_image/image_intern.h
source/blender/editors/space_image/image_ops.c
source/blender/editors/space_image/space_image.c
source/blender/makesdna/DNA_color_types.h
source/blender/makesrna/intern/rna_color.c

index 861a5670393382bde933b604b1114075094cd010..44fb429ffe787427a5e52b76377c36baa85bb602 100644 (file)
@@ -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):
index a0b418c1a9a05f894455f81f773b363ae9604d05..1300c1d266c8636592287aac11c7eafa65b438cf 100644 (file)
@@ -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 */
index 0440aff3f659ce94a790c3b5e04faaeafe0227b5..998ebac1cb9b91e728bc9c24226941a73ebe1810 100644 (file)
@@ -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)
index 121130ec5366a25e46d82de8c220a09bcdc531d1..0d3a7614f1065a310c58efd499cea8a186d288ac 100644 (file)
@@ -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);
index 02b95f8e7c8bd984bd3c352ee5b3b8be5e625815..5075147869d836fd564e88b2f262c6c992247788 100644 (file)
@@ -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;
        
index a2a16fd84a8226c6d8dc8d45c68bd2593b4cb414..6652a7470c245366ba85c1613183277e186fc098 100644 (file)
@@ -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);
index 676389ffeeaf32972966da8eb6fac0460fc2cc95..dd2b38ffcf5122026166c312fbc110fa618dc3e7 100644 (file)
@@ -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;
index 9a69cfc7f15c64f0da6509a57884b61ca05c967e..bd0e6c36c48ff06532359c9ddccf75786bafbe91 100644 (file)
@@ -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)