[giv] Added option to turn off auto-contrast when loading images.



commit 2c16f322e6e2d0463ce8124f9cac9a1add6fff9b
Author: Dov Grobgeld <dov grobgeld gmail com>
Date:   Tue Sep 13 21:24:46 2011 +0300

    Added option to turn off auto-contrast when loading images.

 src/giv-contrast.gob |    7 +
 src/giv-histo.gob    |   24 +-
 src/giv-win.gob      |   53 +-
 src/giv-window.gob   | 3136 --------------------------------------------------
 src/givimage.c       |   19 +-
 src/menu-top.xml     |    1 +
 6 files changed, 68 insertions(+), 3172 deletions(-)
---
diff --git a/src/giv-contrast.gob b/src/giv-contrast.gob
index e29d1a2..09ca379 100644
--- a/src/giv-contrast.gob
+++ b/src/giv-contrast.gob
@@ -186,6 +186,13 @@ class Giv:Contrast from Gtk:Dialog {
         giv_histo_set_cursor_gl(GIV_HISTO(selfp->w_histo), gl);
     }
 
+    public void
+    set_do_auto_contrast(self,
+                         gboolean do_auto_contrast)
+    {
+      giv_histo_set_do_auto_contrast(GIV_HISTO(selfp->w_histo), do_auto_contrast);
+    }
+
     override (Gtk:Dialog) void
     response (Gtk:Dialog *_self,
               gint response_id)
diff --git a/src/giv-histo.gob b/src/giv-histo.gob
index 4a55a97..088bef3 100644
--- a/src/giv-histo.gob
+++ b/src/giv-histo.gob
@@ -30,6 +30,7 @@ class Giv:Histo from Gtk:Drawing:Area {
     private gdouble cursor_x2 = 200;
     private FocusPos focus_pos = FOCUS_NONE;
     private gboolean dragging = FALSE;
+    private gboolean do_auto_contrast = TRUE; 
     private gdouble dragging_x = -1;
     private gdouble dragging_y = -1;
     private double contrast_gl_min = -1;
@@ -76,15 +77,16 @@ class Giv:Histo from Gtk:Drawing:Area {
     {
         if (!image)
             return;
-        // calculate the histogram
-        giv_image_get_min_max(image,
-                              &selfp->img_gl_min, &selfp->img_gl_max);
-        selfp->contrast_gl_min = selfp->img_gl_min;
-        selfp->contrast_gl_max = selfp->img_gl_max;
 
-        // short cuts
-        double min = selfp->contrast_gl_min;
-        double max = selfp->contrast_gl_max;
+        double min, max;
+        giv_image_get_min_max(image,
+                              &min, &max);
+        selfp->img_gl_min = min;
+        selfp->img_gl_max = max;
+        if (selfp->do_auto_contrast) {
+            selfp->contrast_gl_min = min;
+            selfp->contrast_gl_max = max;
+        }
 
         selfp->histo_max = 0;
         for (int i=0; i<256; i++) 
@@ -352,6 +354,12 @@ class Giv:Histo from Gtk:Drawing:Area {
         gtk_widget_queue_draw(GTK_WIDGET(self));
     }
 
+    public void set_do_auto_contrast(self,
+                                     bool do_auto_contrast)
+    {
+        selfp->do_auto_contrast = do_auto_contrast;
+    }
+
     public void auto_contrast(self)
     {
         selfp->contrast_gl_min = selfp->img_gl_min;
diff --git a/src/giv-win.gob b/src/giv-win.gob
index e3dbf41..ce11047 100644
--- a/src/giv-win.gob
+++ b/src/giv-win.gob
@@ -101,6 +101,7 @@ static void cb_view_vflip (GtkAction *action, gpointer data);
 static void cb_view_colormap (GtkAction *action, gpointer data);
 static void cb_view_cross_hair (GtkAction *action, gpointer data);
 static void cb_view_auto_resize (GtkAction *action, gpointer data);
+static void cb_view_auto_contrast (GtkAction *action, gpointer data);
 static void cb_view_auto_reload (GtkAction *action, gpointer data);
 static void cb_menu_measure_distance (GtkAction *action, gpointer data);
 static void cb_menu_calibrate (GtkAction *action, gpointer data);
@@ -180,10 +181,6 @@ static gint
 cb_motion_event(GtkWidget *widget,
                 GdkEventMotion *event,
                 gpointer user_data);
-static gint
-cb_leave_notify_event(GtkWidget *widget,
-                      GdkEventCrossing *event,
-                      gpointer user_data);
 
 static void
 apply_color_map(GivWin *self);
@@ -374,6 +371,11 @@ static GtkToggleActionEntry toggle_entries[] =
     "_Auto Resize", NULL,    
     "Auto Resize",
     G_CALLBACK (cb_view_auto_resize), TRUE },
+  { "AutoContrast",
+    NULL,
+    "_Auto Contrast", NULL,    
+    "Auto Resize",
+    G_CALLBACK (cb_view_auto_contrast), TRUE },
   { "AutoReload",
     NULL,
     "A_uto Reload", NULL,    
@@ -475,6 +477,7 @@ class Giv:Win from Gtk:Window
     private bool do_square_aspect_ratio = true;
     private bool do_auto_fit_marks = TRUE;
     private bool do_auto_reload = FALSE;
+    private bool do_auto_contrast = TRUE;
     private bool do_no_transparency = FALSE;
     private gdouble last_move_x=-1;
     private gdouble last_move_y=-1;
@@ -972,10 +975,11 @@ class Giv:Win from Gtk:Window
         }
 
         selfp->img_org = new_img;
-        giv_image_get_min_max(new_img,
-                              // output
-                              &selfp->contrast_min,
-                              &selfp->contrast_max);
+        if (selfp->do_auto_contrast)
+            giv_image_get_min_max(new_img,
+                                  // output
+                                  &selfp->contrast_min,
+                                  &selfp->contrast_max);
         if (new_img->img_type == GIVIMAGE_U8
             || new_img->img_type == GIVIMAGE_RGB_U8
             || new_img->img_type == GIVIMAGE_RGBA_U8) {
@@ -1998,6 +2002,23 @@ static void cb_view_auto_resize (GtkAction *action, gpointer data)
         fit_marks_in_window(self);
 }
 
+static void cb_view_auto_contrast (GtkAction *action, gpointer data)
+{
+    GivWin *self = GIV_WIN(data);
+
+    selfp->do_auto_contrast = !selfp->do_auto_contrast;
+    giv_contrast_set_do_auto_contrast(GIV_CONTRAST(selfp->w_contrast_view),
+                                      selfp->do_auto_contrast);
+    gtk_check_menu_item_set_active(
+        GTK_CHECK_MENU_ITEM(
+            gtk_ui_manager_get_widget(selfp->menu_manager,
+                                      "/menubar/ViewMenu/AutoContrast")),
+        selfp->do_auto_contrast);
+
+    if (selfp->do_auto_contrast)
+        cb_load_image_when_idle(self);
+}
+
 static void cb_view_auto_reload (GtkAction *action, gpointer data)
 {
     GivWin *self = GIV_WIN(data);
@@ -2930,6 +2951,7 @@ line_ver_line_intersect(double x0, double y0, double x1, double y1,
   return (*y_cross >= line_y0 && *y_cross <= line_y1 && *x_cross >= x0 && *x_cross <= x1);
 }
 
+#if 0
 static gboolean
 giv_check_img_for_mono(GdkPixbuf *im)
 {
@@ -2946,6 +2968,7 @@ giv_check_img_for_mono(GdkPixbuf *im)
     }
     return TRUE;
 }
+#endif
 
 static gboolean
 giv_check_img_for_mono(GivImage *im)
@@ -3203,6 +3226,7 @@ static void cb_image_reference(GtkWidget *widget,
 
 }
 
+#if 0
 static void cb_set_orientation(giv_parser_orientation_t hflip,
                                giv_parser_orientation_t vflip,
                                gpointer user_data)
@@ -3222,6 +3246,7 @@ static void cb_set_orientation(giv_parser_orientation_t hflip,
                         self);
     }
 }       
+#endif
 
 static void
 cb_file_list_drag_data_received (GtkWidget          *widget,
@@ -3322,8 +3347,6 @@ fit_marks_in_window(GivWin *self)
     printf("min_x min_y max_x max_y = %f %f %f %f\n",
            min_x, min_y, max_x, max_y);
 #endif
-    double scroll_x_dist, scroll_y_dist, scroll_x_center, scroll_y_center;
-    double scroll_min_x, scroll_min_y, scroll_max_x, scroll_max_y;
     double margin = 0;
     
 #if 0
@@ -3343,16 +3366,6 @@ fit_marks_in_window(GivWin *self)
     else {
         margin= 10;
 
-        scroll_x_dist = max_x - min_x;
-        scroll_y_dist = max_y - min_y;
-        scroll_x_center = 0.5*(max_x + min_x);
-        scroll_y_center = 0.5*(max_y + min_y);
-        
-        scroll_min_x = scroll_x_center - scroll_x_dist * 0.5;
-        scroll_max_x = scroll_x_center + scroll_x_dist * 0.5;
-        scroll_min_y = scroll_y_center - scroll_y_dist * 0.5;
-        scroll_max_y = scroll_y_center + scroll_y_dist * 0.5;
-
         // The following is a hack around the problem of too thin
         // data in x or y... It should be solved in the gtk_image_viewer.
         if (max_x - min_x < max_y-min_y) {
diff --git a/src/givimage.c b/src/givimage.c
index 59d70dd..eadc3cb 100644
--- a/src/givimage.c
+++ b/src/givimage.c
@@ -106,19 +106,22 @@ GivImage *giv_image_new_from_file(const char *filename,
         gboolean is_mono = TRUE;
 
         // Check if the file is monochrome.
-        int pix_idx;
+        int row_idx,col_idx;
         int width = gdk_pixbuf_get_width(pixbuf);
         int height = gdk_pixbuf_get_height(pixbuf);
         guint8 *buf = gdk_pixbuf_get_pixels(pixbuf);
         int row_stride = gdk_pixbuf_get_rowstride(pixbuf);
-        
-        for(pix_idx=0; pix_idx<width * height; pix_idx++) {
-            if (buf[0] != buf[1]
-                || buf[0] != buf[2]) {
-                is_mono = FALSE;
-                break;
+
+        for (row_idx=0; row_idx<height; row_idx++) {
+            guint8 *p = buf + row_idx * row_stride;
+            for (col_idx=0; col_idx<width; col_idx++) {
+                if (p[0] != p[1]
+                    || p[0] != p[2]) {
+                    is_mono = FALSE;
+                    break;
+                }
+                p+= 3;
             }
-            buf+= 3;
         }
 
         if (is_mono) {
diff --git a/src/menu-top.xml b/src/menu-top.xml
index d9f640e..1c2ac59 100644
--- a/src/menu-top.xml
+++ b/src/menu-top.xml
@@ -19,6 +19,7 @@
       <menuitem name="CrossHair" action="ViewCrossHair" />
       <menuitem name="ColorMapBar" action="ViewColorMap" />
       <menuitem name="AutoResize" action="AutoResize" />
+      <menuitem name="AutoContrast" action="AutoContrast" />
       <menuitem name="AutoReload" action="AutoReload" />
       <menu name="ColorTableMenu" action="ColorTableMenuAction">
         <menuitem name="PseudoColorOff" action="PseudoColorNone" />



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]