[giv] 1bps tiff support and preserve pixelsize when moving between measure modes in pixel size tool. 2011-



commit e34e66c46d44891e06df1c27a4ba54f51d7d319d
Author: Dov Grobgeld <dov grobgeld gmail com>
Date:   Thu Apr 28 22:50:42 2011 +0300

    1bps tiff support and preserve pixelsize when moving between measure modes in pixel size tool.
    2011-04-28  Dov Grobgeld  <dov grobgeld gmail com>
    
            * configure.in : Bumped version to 0.9.19 .
    
            * plugins/tiff.c : Added support for 1bps files. (First page only).
    
            * giv-calibrate-dialog.gob : Made the text field change when
            switching between different reference units.
    
            * giv-win.gob : Made mouse release stop measuring. Was a second
            click.

 ChangeLog                    |   12 ++++++
 configure.in                 |    2 +-
 src/giv-calibrate-dialog.gob |   87 +++++++++++++++++++++++++++++++++---------
 src/giv-win.gob              |    3 +
 src/plugins/tiff.c           |   15 +++++++
 5 files changed, 100 insertions(+), 19 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9080dfc..66217be 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2011-04-28  Dov Grobgeld  <dov grobgeld gmail com>
+
+        * configure.in : Bumped version to 0.9.19 .
+
+        * plugins/tiff.c : Added support for 1bps files. (First page only).
+
+        * giv-calibrate-dialog.gob : Made the text field change when
+        switching between different reference units.
+
+        * giv-win.gob : Made mouse release stop measuring. Was a second
+        click.
+
 2011-04-27  Dov Grobgeld  <dov grobgeld gmail com>
 
         * giv-win.gob, GivRenderer.h, GivRenderer.cc : Added the
diff --git a/configure.in b/configure.in
index c28aedf..4e8db08 100644
--- a/configure.in
+++ b/configure.in
@@ -5,7 +5,7 @@ AM_CONFIG_HEADER(config.h)
 PACKAGE=givwidget
 GIVWIDGET_API_VERSION=2.0
 
-AM_INIT_AUTOMAKE(giv, 0.9.19beta3)
+AM_INIT_AUTOMAKE(giv, 0.9.19)
 
 dnl Use libtool to get shared libraries
 LT_PREREQ
diff --git a/src/giv-calibrate-dialog.gob b/src/giv-calibrate-dialog.gob
index 1360e73..642ca5a 100644
--- a/src/giv-calibrate-dialog.gob
+++ b/src/giv-calibrate-dialog.gob
@@ -14,6 +14,8 @@ requires 2.0.0
 
 %{
 static GtkWidget *label_left_new(const gchar *label);
+static void cb_combo_changed(GtkComboBox *widget,
+                             gpointer     user_data);
 
 // Make sure text below matches this enum
 enum {
@@ -30,7 +32,10 @@ class Giv:Calibrate:Dialog from Gtk:Dialog {
     private GtkWidget *w_combo_measure = NULL;
     private GtkWidget *w_entry_unit = NULL;
     private GtkWidget *w_entry_pixel_size = NULL;
-    private double last_measure_distance_in_pixels = -1; 
+    private double last_measure_distance_in_pixels = -1;
+
+    // The enum of the combo that is being used
+    private int current_ref = 0;
     public GtkWidget *
 
     new(GivWin *w_giv,
@@ -68,6 +73,7 @@ class Giv:Calibrate:Dialog from Gtk:Dialog {
                          0,0);
 
         GtkWidget *w_combo_measure = gtk_combo_box_new_text();
+        g_signal_connect(w_combo_measure,"changed", G_CALLBACK(cb_combo_changed), self);
         selfp->w_combo_measure = w_combo_measure;
         gtk_combo_box_append_text(GTK_COMBO_BOX(w_combo_measure), "Pixel");
         gtk_combo_box_append_text(GTK_COMBO_BOX(w_combo_measure), "Last measure");
@@ -91,7 +97,7 @@ class Giv:Calibrate:Dialog from Gtk:Dialog {
             
         GtkWidget *w_entry = gtk_entry_new();
         selfp->w_entry_pixel_size = w_entry;
-        gchar *ps_string = g_strdup_printf("%g", pixel_size);
+        gchar *ps_string = g_strdup_printf("%.4g", pixel_size);
         gtk_entry_set_text(GTK_ENTRY(w_entry), ps_string);
         g_free(ps_string);
         gtk_entry_set_width_chars(GTK_ENTRY(w_entry), 10);
@@ -155,6 +161,28 @@ class Giv:Calibrate:Dialog from Gtk:Dialog {
         selfp->last_measure_distance_in_pixels = last_measure_distance_in_pixels;
     }
 
+    private double calc_pixel_size(self)
+    {
+        if (!selfp->w_entry_pixel_size)
+            return 1.0;
+        double pixel_size = atof(gtk_entry_get_text(GTK_ENTRY(selfp->w_entry_pixel_size)));
+        
+        int measure_combo = selfp->current_ref;
+        if (measure_combo == MEASURE_COMBO_LAST_MEASURE)
+            pixel_size /= selfp->last_measure_distance_in_pixels;
+        else if (measure_combo == MEASURE_COMBO_IMAGE_WIDTH
+                 || measure_combo == MEASURE_COMBO_IMAGE_HEIGHT) {
+            GivImage *img = giv_win_get_image(GIV_WIN(selfp->w_giv));
+            if (img) {
+                if (measure_combo == MEASURE_COMBO_IMAGE_WIDTH)
+                    pixel_size /= img->width;
+                else
+                    pixel_size /= img->height;
+            }
+        }
+        return pixel_size;
+    }
+
     override (Gtk:Dialog) void
     response (Gtk:Dialog *_self,
               gint response_id)
@@ -164,24 +192,9 @@ class Giv:Calibrate:Dialog from Gtk:Dialog {
         if (response_id == GTK_RESPONSE_APPLY
             || response_id == GTK_RESPONSE_ACCEPT) {
           const gchar *new_unit = gtk_entry_get_text(GTK_ENTRY(selfp->w_entry_unit));
-          double new_pixel_size = atof(gtk_entry_get_text(GTK_ENTRY(selfp->w_entry_pixel_size)));
-
-          int measure_combo = gtk_combo_box_get_active(GTK_COMBO_BOX(selfp->w_combo_measure));
-          if (measure_combo == MEASURE_COMBO_LAST_MEASURE)
-              new_pixel_size /= selfp->last_measure_distance_in_pixels;
-          else if (measure_combo == MEASURE_COMBO_IMAGE_WIDTH
-                   || measure_combo == MEASURE_COMBO_IMAGE_HEIGHT) {
-              GivImage *img = giv_win_get_image(GIV_WIN(selfp->w_giv));
-              if (img) {
-                  if (measure_combo == MEASURE_COMBO_IMAGE_WIDTH)
-                      new_pixel_size /= img->width;
-                  else
-                      new_pixel_size /= img->height;
-              }
-          }
               
           giv_calibrate_dialog_calib_changed(self,
-                                             new_pixel_size,
+                                             giv_calibrate_dialog_calc_pixel_size(self),
                                              new_unit);
         }
 
@@ -209,4 +222,42 @@ static GtkWidget *label_left_new(const gchar *label)
     return w_label;
 }
  
+static void cb_combo_changed(GtkComboBox *widget,
+                             gpointer     user_data)
+{
+  GivCalibrateDialog *self = GIV_CALIBRATE_DIALOG(user_data);
+  int measure_combo = gtk_combo_box_get_active(GTK_COMBO_BOX(selfp->w_combo_measure));
+
+  // Update the entry text
+  double new_dist = giv_calibrate_dialog_calc_pixel_size(self);
+  switch(measure_combo) {
+  case MEASURE_COMBO_PIXEL :
+      break;
+  case MEASURE_COMBO_LAST_MEASURE :
+      new_dist *= selfp->last_measure_distance_in_pixels;
+      break;
+  case MEASURE_COMBO_IMAGE_WIDTH:
+  case MEASURE_COMBO_IMAGE_HEIGHT:
+      {
+          GivImage *img = giv_win_get_image(GIV_WIN(selfp->w_giv));
+          if (img) {
+              if (measure_combo == MEASURE_COMBO_IMAGE_WIDTH)
+                  new_dist *= img->width;
+              else
+                  new_dist *= img->height;
+          }
+          break;
+      }
+  default:
+      break;
+  };
+      
+  gchar *new_text = g_strdup_printf("%.4g", new_dist);
+  if (selfp->w_entry_pixel_size)
+      gtk_entry_set_text(GTK_ENTRY(selfp->w_entry_pixel_size),
+                         new_text);
+  g_free(new_text);
+  selfp->current_ref = measure_combo;
+}
+
 %}
diff --git a/src/giv-win.gob b/src/giv-win.gob
index 1d53082..e3dbf41 100644
--- a/src/giv-win.gob
+++ b/src/giv-win.gob
@@ -1532,6 +1532,7 @@ cb_button_release_event (GtkWidget * widget,
         giv_win_redraw(self);
     }
     selfp->picking_mode = 0;
+    selfp->measure_point_index = 0;
 
     return 0;
 }
@@ -2181,10 +2182,12 @@ cb_menu_measure_distance (GtkAction *action, gpointer data)
         selfp->lasso = dovtk_lasso_create(selfp->w_imgv,
                                           &my_lasso_draw,
                                           self);
+#if 0
         if (!selfp->cursor_plus) {
             selfp->cursor_plus = gdk_cursor_new(GDK_PLUS);
         }
         gdk_window_set_cursor(selfp->w_imgv->window, selfp->cursor_plus);
+#endif
     }
     else {
         //free_giv_backstore (selfp->back_store);
diff --git a/src/plugins/tiff.c b/src/plugins/tiff.c
index e018b50..5cc2eba 100644
--- a/src/plugins/tiff.c
+++ b/src/plugins/tiff.c
@@ -59,6 +59,7 @@ GivImage *giv_plugin_load_file(const char *filename,
 	uint8* raster;
         gboolean has_colormap = FALSE;
         uint16 *rmap, *gmap, *bmap;
+        uint16 pn=0, num_pages=0;
 
 	TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
 	TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
@@ -66,13 +67,16 @@ GivImage *giv_plugin_load_file(const char *filename,
         TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bps);
         TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &spp);
         TIFFGetField(tif, TIFFTAG_SAMPLEFORMAT, &sample_format);
+        TIFFGetField(tif, TIFFTAG_PAGENUMBER, &pn, &num_pages);
 
         if (TIFFGetField(tif, TIFFTAG_COLORMAP, &rmap, &gmap, &bmap))
             has_colormap = TRUE;
+
 #if 0
         printf("has_colormap= %d\n", has_colormap);
         
         printf("bps spp=%d %d\n", bps, spp);
+        printf("pn num_pages = %d %d\n", pn, num_pages);
 #endif
 
 	raster = (uint8*) _TIFFmalloc(TIFFScanlineSize(tif));
@@ -109,6 +113,8 @@ GivImage *giv_plugin_load_file(const char *filename,
                 image_type = GIVIMAGE_U16;
             else if (bps == 32)
                 image_type = GIVIMAGE_I32;
+            else if (bps == 1)
+                image_type = GIVIMAGE_U8;
             else {
                 printf("Unknown Tiff type!\n");
                 return NULL;
@@ -136,6 +142,15 @@ GivImage *giv_plugin_load_file(const char *filename,
                         *dst_ptr++ = bmap[src_gl] >> 8;
                     }
                 }
+                else if (bps == 1) {
+                    for (col_idx=0; col_idx<w/8; col_idx++) {
+                        int bit_idx;
+                        for (bit_idx=0; bit_idx<8; bit_idx++) {
+                            *dst_ptr++ = 1-((*src_ptr >> (7-bit_idx))&1);
+                        }
+                        src_ptr++;
+                    }
+                }
                 else {
                     for (col_idx=0; col_idx<w; col_idx++) {
                         for (clr_idx=0; clr_idx<spp*bps/8; clr_idx++) {



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