Author: akv
Date: 2012-09-04 23:57:46 +0200 (Tue, 04 Sep 2012)
New Revision: 4280

Modified:
   branches/4175-enfuse/
   branches/4175-enfuse/librawstudio/rs-curve.c
   branches/4175-enfuse/librawstudio/rs-curve.h
   branches/4175-enfuse/src/rs-toolbox.c
Log:
Merged trunk into my enfuse branch.


Property changes on: branches/4175-enfuse
___________________________________________________________________
Modified: svn:mergeinfo
   - /trunk:4176-4269
   + /trunk:4176-4279

Modified: branches/4175-enfuse/librawstudio/rs-curve.c
===================================================================
--- branches/4175-enfuse/librawstudio/rs-curve.c        2012-09-04 21:56:26 UTC 
(rev 4279)
+++ branches/4175-enfuse/librawstudio/rs-curve.c        2012-09-04 21:57:46 UTC 
(rev 4280)
@@ -1074,6 +1074,46 @@
        curve->bg_buffer = NULL;
 }
 
+
+/* Added by Anders Kvist */
+void
+rs_curve_auto_adjust_ends(GtkWidget *widget) {
+
+  RSCurveWidget *curve = RS_CURVE_WIDGET(widget);
+
+  gint i = 0;
+  gdouble black_threshold = 0.003; // Percent underexposed pixels
+  gdouble white_threshold = 0.01; // Percent overexposed pixels
+  gdouble blackpoint;
+  gdouble whitepoint;
+  guint total = 0;
+
+  guint *hist;
+  hist = curve->histogram_data;
+
+  // calculate black point
+  while(i < 256) {
+    total += hist[i]+hist[i]+hist[i];
+    if ((total) > ((250*250)/100*black_threshold))
+      break;
+    i++;
+  }
+  blackpoint = (gdouble) i / (gdouble) 255;
+               
+  // calculate white point
+  i = 255;
+  while(i) {
+    total += hist[i]+hist[i]+hist[i];
+    if ((total) > ((250*250)/100*white_threshold))
+      break;
+    i--;
+  }
+  whitepoint = (gdouble) i / (gdouble) 255;
+
+  rs_curve_widget_move_knot(RS_CURVE_WIDGET(widget),0,blackpoint,0.0);
+  rs_curve_widget_move_knot(RS_CURVE_WIDGET(widget),-1,whitepoint,1.0);
+}
+
 #ifdef RS_CURVE_TEST
 
 void

Modified: branches/4175-enfuse/librawstudio/rs-curve.h
===================================================================
--- branches/4175-enfuse/librawstudio/rs-curve.h        2012-09-04 21:56:26 UTC 
(rev 4279)
+++ branches/4175-enfuse/librawstudio/rs-curve.h        2012-09-04 21:57:46 UTC 
(rev 4280)
@@ -152,6 +152,9 @@
 extern void
 rs_curve_set_histogram_data(RSCurveWidget *curve, const gint *input);
 
+extern void
+rs_curve_auto_adjust_ends(GtkWidget *widget);
+
 #define RS_CURVE_TYPE_WIDGET             (rs_curve_widget_get_type ())
 #define RS_CURVE_WIDGET(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
RS_CURVE_TYPE_WIDGET, RSCurveWidget))
 #define RS_CURVE_WIDGET_CLASS(obj)       (G_TYPE_CHECK_CLASS_CAST ((obj), 
RS_CURVE_WIDGET, RSCurveWidgetClass))

Modified: branches/4175-enfuse/src/rs-toolbox.c
===================================================================
--- branches/4175-enfuse/src/rs-toolbox.c       2012-09-04 21:56:26 UTC (rev 
4279)
+++ branches/4175-enfuse/src/rs-toolbox.c       2012-09-04 21:57:46 UTC (rev 
4280)
@@ -606,7 +606,7 @@
 static void
 curve_context_callback_white_black_point(GtkMenuItem *menuitem, gpointer 
user_data)
 {
-       /* FIXME: Stub. Convert this to an action */
+  rs_curve_auto_adjust_ends(GTK_WIDGET(user_data));
 }
 
 static void
@@ -723,7 +723,7 @@
        i = gtk_menu_item_new_with_label (_("Auto adjust curve ends"));
        gtk_widget_show (i);
        gtk_menu_attach (GTK_MENU (menu), i, 0, 1, n, n+1); n++;
-       g_signal_connect (i, "activate", G_CALLBACK 
(curve_context_callback_white_black_point), NULL);
+       g_signal_connect (i, "activate", G_CALLBACK 
(curve_context_callback_white_black_point), widget);
        gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, 
GDK_CURRENT_TIME);
 }
 


_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit

Reply via email to