Author: akv
Date: 2012-09-04 23:55:49 +0200 (Tue, 04 Sep 2012)
New Revision: 4278

Modified:
   trunk/librawstudio/rs-curve.c
   trunk/librawstudio/rs-curve.h
Log:
Copied code from application.c to rs-curve.c to calculate the best values to 
set endpoints of curve - attempt to make a auto levels. Might need some work...

Modified: trunk/librawstudio/rs-curve.c
===================================================================
--- trunk/librawstudio/rs-curve.c       2012-09-04 21:16:39 UTC (rev 4277)
+++ trunk/librawstudio/rs-curve.c       2012-09-04 21:55:49 UTC (rev 4278)
@@ -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: trunk/librawstudio/rs-curve.h
===================================================================
--- trunk/librawstudio/rs-curve.h       2012-09-04 21:16:39 UTC (rev 4277)
+++ trunk/librawstudio/rs-curve.h       2012-09-04 21:55:49 UTC (rev 4278)
@@ -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))


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

Reply via email to