[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26090] trunk/blender: Finished some work from the weekend to keep local tree clean..

Matt Ebb matt at mke3.net
Tue Jan 19 02:32:06 CET 2010


Revision: 26090
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26090
Author:   broken
Date:     2010-01-19 02:32:06 +0100 (Tue, 19 Jan 2010)

Log Message:
-----------
Finished some work from the weekend to keep local tree clean..

* Added a generic 'histogram' ui control, currently available in new image editor 
'scopes' region (shortcut P). Shows the histogram of the currently viewed image.

It's a baby step in unifying the functionality and code from the sequence editor, 
so eventually we can migrate the sequence preview to the image editor too, 
like compositor.

Still a couple of rough edges to tweak, regarding when it updates. Also would 
be very nice to have this region as a partially transparent overlapping region...

Modified Paths:
--------------
    trunk/blender/release/scripts/ui/space_image.py
    trunk/blender/release/scripts/ui/space_userpref.py
    trunk/blender/source/blender/blenkernel/BKE_colortools.h
    trunk/blender/source/blender/blenkernel/intern/colortools.c
    trunk/blender/source/blender/editors/include/UI_interface.h
    trunk/blender/source/blender/editors/include/UI_resources.h
    trunk/blender/source/blender/editors/interface/interface_draw.c
    trunk/blender/source/blender/editors/interface/interface_handlers.c
    trunk/blender/source/blender/editors/interface/interface_intern.h
    trunk/blender/source/blender/editors/interface/interface_panel.c
    trunk/blender/source/blender/editors/interface/interface_templates.c
    trunk/blender/source/blender/editors/interface/interface_widgets.c
    trunk/blender/source/blender/editors/interface/resources.c
    trunk/blender/source/blender/editors/screen/area.c
    trunk/blender/source/blender/editors/space_image/image_buttons.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/makesdna/DNA_space_types.h
    trunk/blender/source/blender/makesdna/DNA_userdef_types.h
    trunk/blender/source/blender/makesrna/RNA_access.h
    trunk/blender/source/blender/makesrna/intern/rna_color.c
    trunk/blender/source/blender/makesrna/intern/rna_space.c
    trunk/blender/source/blender/makesrna/intern/rna_ui_api.c
    trunk/blender/source/blender/makesrna/intern/rna_userdef.c

Modified: trunk/blender/release/scripts/ui/space_image.py
===================================================================
--- trunk/blender/release/scripts/ui/space_image.py	2010-01-19 00:59:36 UTC (rev 26089)
+++ trunk/blender/release/scripts/ui/space_image.py	2010-01-19 01:32:06 UTC (rev 26090)
@@ -35,6 +35,7 @@
         show_uvedit = sima.show_uvedit
 
         layout.operator("image.properties", icon='MENU_PANEL')
+        layout.operator("image.scopes", icon='MENU_PANEL')
 
         layout.separator()
 
@@ -386,7 +387,22 @@
         col.separator()
         col.prop(ima, "mapping", expand=True)
 
+class IMAGE_PT_view_histogram(bpy.types.Panel):
+    bl_space_type = 'IMAGE_EDITOR'
+    bl_region_type = 'PREVIEW'
+    bl_label = "Histogram"
+    
+    def poll(self, context):
+        sima = context.space_data
+        return (sima and sima.image)
+    
+    def draw(self, context):
+        layout = self.layout
 
+        sima = context.space_data
+                        
+        layout.template_histogram(sima, "histogram")
+
 class IMAGE_PT_view_properties(bpy.types.Panel):
     bl_space_type = 'IMAGE_EDITOR'
     bl_region_type = 'UI'
@@ -417,6 +433,7 @@
             col.prop(sima, "draw_repeated", text="Repeat")
             if show_uvedit:
                 col.prop(uvedit, "normalized_coordinates", text="Normalized")
+
         elif show_uvedit:
             col.label(text="Coordinates:")
             col.prop(uvedit, "normalized_coordinates", text="Normalized")
@@ -562,3 +579,4 @@
 bpy.types.register(IMAGE_PT_paint_curve)
 bpy.types.register(IMAGE_PT_game_properties)
 bpy.types.register(IMAGE_PT_view_properties)
+bpy.types.register(IMAGE_PT_view_histogram)

Modified: trunk/blender/release/scripts/ui/space_userpref.py
===================================================================
--- trunk/blender/release/scripts/ui/space_userpref.py	2010-01-19 00:59:36 UTC (rev 26089)
+++ trunk/blender/release/scripts/ui/space_userpref.py	2010-01-19 01:32:06 UTC (rev 26090)
@@ -735,6 +735,7 @@
 
             col = split.column()
             col.prop(image, "back")
+            col.prop(image, "scope_back")
             col.prop(image, "button")
 
             col = split.column()

Modified: trunk/blender/source/blender/blenkernel/BKE_colortools.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_colortools.h	2010-01-19 00:59:36 UTC (rev 26089)
+++ trunk/blender/source/blender/blenkernel/BKE_colortools.h	2010-01-19 01:32:06 UTC (rev 26090)
@@ -31,6 +31,7 @@
 
 struct CurveMapping;
 struct CurveMap;
+struct Histogram;
 struct ImBuf;
 struct rctf;
 
@@ -70,6 +71,7 @@
 void				curvemapping_table_RGBA(struct CurveMapping *cumap, float **array, int *size);
 void				colorcorrection_do_ibuf(struct ImBuf *ibuf, const char *profile);
 
+void				histogram_update(struct Histogram *hist, struct ImBuf *ibuf);
 
 #endif
 

Modified: trunk/blender/source/blender/blenkernel/intern/colortools.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/colortools.c	2010-01-19 00:59:36 UTC (rev 26089)
+++ trunk/blender/source/blender/blenkernel/intern/colortools.c	2010-01-19 01:32:06 UTC (rev 26090)
@@ -878,3 +878,85 @@
 	}
 }
 
+/* ***************** Histogram **************** */
+
+static inline int get_bin_float(float f)
+{
+	CLAMP(f, 0.0, 1.0);
+	
+	//return (int) (((f + 0.25) / 1.5) * 512);
+	
+	return (int)(f * 511);
+}
+
+
+void histogram_update(Histogram *hist, ImBuf *ibuf)
+{
+	int x, y, n;
+	double div;
+	float *rf;
+	unsigned char *rc;
+	unsigned int *bin_r, *bin_g, *bin_b;
+	
+	if (hist->ok == 1 ) return;
+	
+	/* hmmmm */
+	if (!(ELEM(ibuf->channels, 3, 4))) return;
+	
+	hist->channels = 3;
+	
+	bin_r = MEM_callocN(512 * sizeof(unsigned int), "temp historgram bins");
+	bin_g = MEM_callocN(512 * sizeof(unsigned int), "temp historgram bins");
+	bin_b = MEM_callocN(512 * sizeof(unsigned int), "temp historgram bins");
+	
+	if (ibuf->rect_float) {
+		hist->x_resolution = 512;
+		
+		/* divide into bins */
+		rf = ibuf->rect_float;
+		for (y = 0; y < ibuf->y; y++) {
+			for (x = 0; x < ibuf->x; x++) {
+				bin_r[ get_bin_float(rf[0]) ] += 1;
+				bin_g[ get_bin_float(rf[1]) ] += 1;
+				bin_b[ get_bin_float(rf[2]) ] += 1;
+				rf+= ibuf->channels;
+			}
+		}
+	}
+	else if (ibuf->rect) {
+		hist->x_resolution = 256;
+		
+		rc = (unsigned char *)ibuf->rect;
+		for (y = 0; y < ibuf->y; y++) {
+			for (x = 0; x < ibuf->x; x++) {
+				bin_r[ rc[0] ] += 1;
+				bin_g[ rc[1] ] += 1;
+				bin_b[ rc[2] ] += 1;
+				rc += ibuf->channels;
+			}
+		}
+	}
+	
+	/* convert to float */
+	n=0;
+	for (x=0; x<512; x++) {
+		if (bin_r[x] > n)
+			n = bin_r[x];
+		if (bin_g[x] > n)
+			n = bin_g[x];
+		if (bin_b[x] > n)
+			n = bin_b[x];
+	}
+	div = 1.f/(double)n;
+	for (x=0; x<512; x++) {
+		hist->data_r[x] = bin_r[x] * div;
+		hist->data_g[x] = bin_g[x] * div;
+		hist->data_b[x] = bin_b[x] * div;
+	}
+	
+	MEM_freeN(bin_r);
+	MEM_freeN(bin_g);
+	MEM_freeN(bin_b);
+	
+	hist->ok=1;
+}

Modified: trunk/blender/source/blender/editors/include/UI_interface.h
===================================================================
--- trunk/blender/source/blender/editors/include/UI_interface.h	2010-01-19 00:59:36 UTC (rev 26089)
+++ trunk/blender/source/blender/editors/include/UI_interface.h	2010-01-19 01:32:06 UTC (rev 26090)
@@ -216,6 +216,7 @@
 #define LISTROW		(44<<9)
 #define HOTKEYEVT	(45<<9)
 #define BUT_IMAGE	(46<<9)
+#define HISTOGRAM	(47<<9)
 
 #define BUTTYPE		(63<<9)
 
@@ -654,6 +655,7 @@
 uiLayout *uiTemplateConstraint(uiLayout *layout, struct PointerRNA *ptr);
 void uiTemplatePreview(uiLayout *layout, struct ID *id, struct ID *parent, struct MTex *slot);
 void uiTemplateColorRamp(uiLayout *layout, struct PointerRNA *ptr, char *propname, int expand);
+void uiTemplateHistogram(uiLayout *layout, struct PointerRNA *ptr, char *propname, int expand);
 void uiTemplateCurveMapping(uiLayout *layout, struct PointerRNA *ptr, char *propname, int type, int levels, int brush);
 void uiTemplateColorWheel(uiLayout *layout, struct PointerRNA *ptr, char *propname, int value_slider);
 void uiTemplateTriColorSet(uiLayout *layout, struct PointerRNA *ptr, char *propname);

Modified: trunk/blender/source/blender/editors/include/UI_resources.h
===================================================================
--- trunk/blender/source/blender/editors/include/UI_resources.h	2010-01-19 00:59:36 UTC (rev 26089)
+++ trunk/blender/source/blender/editors/include/UI_resources.h	2010-01-19 01:32:06 UTC (rev 26090)
@@ -207,6 +207,8 @@
 	
 	TH_DOPESHEET_CHANNELOB,
 	TH_DOPESHEET_CHANNELSUBOB,
+	
+	TH_PREVIEW_BACK,
 };
 /* XXX WARNING: previous is saved in file, so do not change order! */
 

Modified: trunk/blender/source/blender/editors/interface/interface_draw.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_draw.c	2010-01-19 00:59:36 UTC (rev 26089)
+++ trunk/blender/source/blender/editors/interface/interface_draw.c	2010-01-19 01:32:06 UTC (rev 26090)
@@ -691,6 +691,87 @@
 #endif // INTERNATIONAL
 #endif
 
+
+void ui_draw_but_HISTOGRAM(uiBut *but, uiWidgetColors *wcol, rcti *recti)
+{
+	Histogram *hist = (Histogram *)but->poin;
+	int res = hist->x_resolution;
+	rctf rect;
+	int i;
+	int rgb;
+	float w, h;
+	float alpha;
+	
+	if (hist==NULL) { printf("hist is null \n"); return; }
+	
+	rect.xmin = (float)recti->xmin;
+	rect.xmax = (float)recti->xmax;
+	rect.ymin = (float)recti->ymin;
+	rect.ymax = (float)recti->ymax;
+	
+	w = rect.xmax - rect.xmin;
+	h = rect.ymax - rect.ymin;
+	
+	glEnable(GL_BLEND);
+	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+	
+	glColor4f(0.f, 0.f, 0.f, 0.3f);
+	uiSetRoundBox(15);
+	gl_round_box(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f);
+	
+	glColor4f(1.f, 1.f, 1.f, 0.08f);
+	/* draw grid lines here */
+	for (i=1; i<4; i++) {
+		fdrawline(rect.xmin, rect.ymin+(i/4.f)*h, rect.xmax, rect.ymin+(i/4.f)*h);
+		fdrawline(rect.xmin+(i/4.f)*w, rect.ymin, rect.xmin+(i/4.f)*w, rect.ymax);
+	}
+	
+	for (rgb=0; rgb<3; rgb++) {
+		float *data;
+		
+		if (rgb==0)			data = hist->data_r;
+		else if (rgb==1)	data = hist->data_g;
+		else if (rgb==2)	data = hist->data_b;
+		
+		glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+		alpha = 0.75;
+		if (rgb==0)			glColor4f(1.f, 0.f, 0.f, alpha);
+		else if (rgb==1)	glColor4f(0.f, 1.f, 0.f, alpha);
+		else if (rgb==2)	glColor4f(0.f, 0.f, 1.f, alpha);
+		
+		glShadeModel(GL_FLAT);
+		glBegin(GL_QUAD_STRIP);
+		glVertex2f(rect.xmin, rect.ymin);
+		glVertex2f(rect.xmin, rect.ymin + (data[0]*h));
+		for (i=1; i < res; i++) {
+			float x = rect.xmin + i * (w/(float)res);
+			glVertex2f(x, rect.ymin + (data[i]*h));
+			glVertex2f(x, rect.ymin);
+		}
+		glEnd();
+		
+		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 x = rect.xmin + i * (w/(float)res);
+			glVertex2f(x, rect.ymin + (data[i]*h));
+		}
+		glEnd();
+		glDisable(GL_LINE_SMOOTH);
+	}
+	
+	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+	glColor4f(0.f, 0.f, 0.f, 0.5f);
+	uiSetRoundBox(15);
+	gl_round_box(GL_LINE_LOOP, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f);
+	
+	glDisable(GL_BLEND);
+}
+
+
 void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *wcol, rcti *rect)
 {
 	ColorBand *coba;

Modified: trunk/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_handlers.c	2010-01-19 00:59:36 UTC (rev 26089)
+++ trunk/blender/source/blender/editors/interface/interface_handlers.c	2010-01-19 01:32:06 UTC (rev 26090)
@@ -751,7 +751,13 @@
 static void ui_apply_but_IMAGE(bContext *C, uiBut *but, uiHandleButtonData *data)
 {
 	ui_apply_but_func(C, but);
+	data->retval= but->retval;
+	data->applied= 1;
+}
 
+static void ui_apply_but_HISTOGRAM(bContext *C, uiBut *but, uiHandleButtonData *data)
+{
+	ui_apply_but_func(C, but);
 	data->retval= but->retval;
 	data->applied= 1;
 }
@@ -878,6 +884,9 @@
 		case BUT_IMAGE:	
 			ui_apply_but_IMAGE(C, but, data);
 			break;
+		case HISTOGRAM:	
+			ui_apply_but_HISTOGRAM(C, but, data);
+			break;
 		default:
 			break;
 	}
@@ -3782,6 +3791,7 @@
 	case ROW:
 	case LISTROW:
 	case BUT_IMAGE:
+	case HISTOGRAM:
 		retval= ui_do_but_EXIT(C, but, data, event);
 		break;
 	case TEX:


@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list