[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47667] trunk/blender: mango request

Campbell Barton ideasman42 at gmail.com
Sun Jun 10 14:09:34 CEST 2012


Revision: 47667
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47667
Author:   campbellbarton
Date:     2012-06-10 12:09:25 +0000 (Sun, 10 Jun 2012)
Log Message:
-----------
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).

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

Modified: trunk/blender/release/scripts/startup/bl_ui/space_image.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_image.py	2012-06-10 10:48:06 UTC (rev 47666)
+++ trunk/blender/release/scripts/startup/bl_ui/space_image.py	2012-06-10 12:09:25 UTC (rev 47667)
@@ -502,9 +502,12 @@
         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 @@
         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):

Modified: trunk/blender/source/blender/editors/interface/interface_draw.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_draw.c	2012-06-10 10:48:06 UTC (rev 47666)
+++ trunk/blender/source/blender/editors/interface/interface_draw.c	2012-06-10 12:09:25 UTC (rev 47667)
@@ -658,37 +658,59 @@
 }
 
 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 @@
 	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 @@
 	}
 	
 	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 */

Modified: trunk/blender/source/blender/editors/space_image/image_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_draw.c	2012-06-10 10:48:06 UTC (rev 47666)
+++ trunk/blender/source/blender/editors/space_image/image_draw.c	2012-06-10 12:09:25 UTC (rev 47667)
@@ -578,6 +578,28 @@
 	}
 }
 
+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)

Modified: trunk/blender/source/blender/editors/space_image/image_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_intern.h	2012-06-10 10:48:06 UTC (rev 47666)
+++ trunk/blender/source/blender/editors/space_image/image_intern.h	2012-06-10 12:09:25 UTC (rev 47667)
@@ -54,6 +54,7 @@
 /* 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);

Modified: trunk/blender/source/blender/editors/space_image/image_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_ops.c	2012-06-10 10:48:06 UTC (rev 47666)
+++ trunk/blender/source/blender/editors/space_image/image_ops.c	2012-06-10 12:09:25 UTC (rev 47667)
@@ -2137,7 +2137,14 @@
 	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_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;
 	

Modified: trunk/blender/source/blender/editors/space_image/space_image.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/space_image.c	2012-06-10 10:48:06 UTC (rev 47666)
+++ trunk/blender/source/blender/editors/space_image/space_image.c	2012-06-10 12:09:25 UTC (rev 47667)
@@ -824,15 +824,18 @@
 	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);

Modified: trunk/blender/source/blender/makesdna/DNA_color_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_color_types.h	2012-06-10 10:48:06 UTC (rev 47666)
+++ trunk/blender/source/blender/makesdna/DNA_color_types.h	2012-06-10 12:09:25 UTC (rev 47667)
@@ -102,6 +102,11 @@
 #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 @@
 	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;

Modified: trunk/blender/source/blender/makesrna/intern/rna_color.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_color.c	2012-06-10 10:48:06 UTC (rev 47666)
+++ trunk/blender/source/blender/makesrna/intern/rna_color.c	2012-06-10 12:09:25 UTC (rev 47667)
@@ -570,11 +570,11 @@
 	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 @@
 	RNA_def_property_enum_sdna(prop, NULL, "mode");
 	RNA_def_property_enum_items(prop, prop_mode_items);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list