From f9a89ce88d0d4fab6fbbe0d61d51a3e8fa8069e4 Mon Sep 17 00:00:00 2001 From: Dov Grobgeld Date: Mon, 4 Apr 2022 23:03:47 +0300 Subject: [PATCH] Added new giv command $pixelsize to change the pixelsize for a measurements --- giv.nsi | 2 +- src/giv-parser.cc | 27 +++++++++++++++++++++++++++ src/giv-parser.h | 16 ++++++++++++---- src/giv-widget.gob | 24 +++++++++++++++++++++--- src/giv-win.gob | 35 +++++++++++++++++++++++++++-------- 5 files changed, 88 insertions(+), 16 deletions(-) diff --git a/giv.nsi b/giv.nsi index 6afb45e..eb49a82 100644 --- a/giv.nsi +++ b/giv.nsi @@ -43,7 +43,7 @@ File ${SYSROOT}\mingw\bin\libstdc++-6.dll File ${SYSROOT}\mingw\bin\iconv.dll File ${SYSROOT}\mingw\bin\libpcre-1.dll File ${SYSROOT}\mingw\bin\libintl-8.dll -File ${SYSROOT}\mingw\bin\libffi-6.dll +File ${SYSROOT}\mingw\bin\libffi-8.dll File ${SYSROOT}\mingw\bin\libgdk_pixbuf*.dll File ${SYSROOT}\mingw\bin\libgtk-3-0.dll File ${SYSROOT}\mingw\bin\libgdk-3-0.dll diff --git a/src/giv-parser.cc b/src/giv-parser.cc index 1e69783..71a3e8d 100644 --- a/src/giv-parser.cc +++ b/src/giv-parser.cc @@ -72,6 +72,7 @@ enum STRING_HIDE, STRING_IGNORE, STRING_TEXT_STYLE, + STRING_PIXEL_SIZE }; #define COLOR_NONE 0xfffe @@ -453,6 +454,10 @@ parse_string (const WordBoundaries& wb, { type = STRING_HIDE; } + if (wb.CheckMatch(0, "$pixelsize")) + { + type = STRING_PIXEL_SIZE; + } #if 0 if (type == -1) { @@ -926,6 +931,19 @@ giv_parser_giv_marks_data_add_line(GivParser *gp, g_free(text_style); break; } + case STRING_PIXEL_SIZE: + { + double pixel_size = wb.GetFloat(1); + char *pixelsize_unit = NULL; + if (wb.size() > 1) + pixelsize_unit = strdup(wb.GetRestAsString(2)); + if (gp->cb_set_pixelsize) + (*(gp->cb_set_pixelsize))(pixel_size, pixelsize_unit, gp->cb_set_pixelsize_data); + if (pixelsize_unit) + g_free(pixelsize_unit); + + break; + } default: ; #if 0 @@ -1089,6 +1107,15 @@ giv_parser_set_orientation_callback(GivParser *gp, gp->cb_set_orientation_data = user_data; } +void +giv_parser_set_pixelsize_callback(GivParser *gp, + giv_parser_set_pixelsize_t cb, + gpointer user_data) +{ + gp->cb_set_pixelsize = cb; + gp->cb_set_pixelsize_data = user_data; +} + void giv_parser_set_vlock_callback(GivParser *gp, giv_parser_set_vlock_t cb, diff --git a/src/giv-parser.h b/src/giv-parser.h index 83916b1..0f0d1f0 100644 --- a/src/giv-parser.h +++ b/src/giv-parser.h @@ -22,17 +22,22 @@ typedef void (*giv_parser_set_orientation_t)(giv_parser_orientation_t horint, giv_parser_orientation_t vorint, gpointer data); +typedef void (*giv_parser_set_pixelsize_t)(double pixel_size, + const gchar *pixelsize_unit, + gpointer data); typedef void (*giv_parser_set_vlock_t)(gboolean vlock, gpointer data); -typedef struct { +struct GivParser { GPtrArray* giv_datasets; GHashTable *style_hash; - giv_parser_file_reference_t cb_file_reference; + giv_parser_file_reference_t cb_file_reference=nullptr; gpointer cb_file_reference_data; - giv_parser_set_orientation_t cb_set_orientation; + giv_parser_set_orientation_t cb_set_orientation=nullptr; gpointer cb_set_orientation_data; giv_parser_set_vlock_t cb_set_vlock; gpointer cb_set_vlock_data; + giv_parser_set_pixelsize_t cb_set_pixelsize; + gpointer cb_set_pixelsize_data; // Bounding box of data double global_mark_max_x; @@ -41,7 +46,7 @@ typedef struct { double global_mark_min_y; double quiver_scale; -} GivParser; +}; GivParser *giv_parser_new(); void giv_parser_free(GivParser *giv_parser); @@ -51,6 +56,9 @@ void giv_parser_set_reference_callback(GivParser *giv_parser, void giv_parser_set_orientation_callback(GivParser *giv_parser, giv_parser_set_orientation_t fr, gpointer user_data); +void giv_parser_set_pixelsize_callback(GivParser *giv_parser, + giv_parser_set_pixelsize_t cb, + gpointer user_data); void giv_parser_set_vlock_callback(GivParser *giv_parser, giv_parser_set_vlock_t vlock, gpointer user_data); diff --git a/src/giv-widget.gob b/src/giv-widget.gob index 50d4029..2fcab6a 100644 --- a/src/giv-widget.gob +++ b/src/giv-widget.gob @@ -65,9 +65,12 @@ static void cb_image_reference(const char *filename, gpointer self); static void cb_set_orientation(giv_parser_orientation_t hflip, giv_parser_orientation_t vflip, - gpointer self); + gpointer user_data); +static void cb_set_pixelsize(double pixelsize, + const gchar *unit, + gpointer user_data); static void cb_set_vlock(gboolean vlock, - gpointer self); + gpointer user_data); %} @@ -142,6 +145,9 @@ class Giv:Widget from Gtk:Image:Viewer &cb_image_reference, (gpointer)self); giv_parser_set_orientation_callback(selfp->giv_parser, &cb_set_orientation, (gpointer)self); + giv_parser_set_pixelsize_callback(selfp->giv_parser, + &cb_set_pixelsize, + (gpointer)self); giv_parser_set_vlock_callback(selfp->giv_parser, &cb_set_vlock, (gpointer)self); @@ -250,7 +256,7 @@ class Giv:Widget from Gtk:Image:Viewer mark_set->path_name); else { GString *balloon_string = g_string_new(""); - g_string_sprintfa(balloon_string, "label = %d", label); + g_string_append_printf(balloon_string, "label = %d", label); gtk_label_set_text(GTK_LABEL(selfp->w_balloon_label), balloon_string->str); g_string_free(balloon_string, TRUE); @@ -674,6 +680,8 @@ class Giv:Widget from Gtk:Image:Viewer signal last NONE (POINTER) void file_reference(self, const gchar *filename); + signal last NONE (DOUBLE, POINTER) + void set_pixelsize(self, double pixelsize, const gchar *unit); } %{ @@ -1065,6 +1073,16 @@ static void cb_set_orientation(giv_parser_orientation_t orientation_hflip, hflip, vflip); } +static void cb_set_pixelsize(double pixelsize, + const gchar *unit, + gpointer user_data) +{ + GivWidget *self = GIV_WIDGET(user_data); + + // Emit a signal + giv_widget_set_pixelsize(self, pixelsize, unit); +} + static void cb_set_vlock(gboolean vlock, gpointer user_data) { diff --git a/src/giv-win.gob b/src/giv-win.gob index 58b816c..490c3c9 100644 --- a/src/giv-win.gob +++ b/src/giv-win.gob @@ -149,6 +149,10 @@ static void cb_change_pseudo_color(GtkRadioAction* action, static void cb_image_reference(GtkWidget *widget, const char *filename, gpointer user_data); +static void cb_set_pixelsize(GtkWidget *widget, + double pixelsize, + const gchar *pixelsize_unit, + gpointer user_data); static void menu_add_widget (GtkUIManager *ui, GtkWidget *widget, GtkContainer *container); static void cb_balloon_changed(GtkWidget *widget, @@ -859,6 +863,8 @@ class Giv:Win from Gtk:Window gtk_widget_show(selfp->w_imgv); g_signal_connect(selfp->w_imgv, "file-reference", G_CALLBACK(cb_image_reference), self); + g_signal_connect(selfp->w_imgv, "set-pixelsize", + G_CALLBACK(cb_set_pixelsize), self); g_signal_connect(selfp->w_imgv, "button-press-event", G_CALLBACK(cb_button_press_event), self); g_signal_connect(selfp->w_imgv, "button-release-event", @@ -1063,7 +1069,7 @@ class Giv:Win from Gtk:Window } selfp->idle_index = selfp->filename_list_index; - selfp->do_fit_on_load_image = TRUE; + selfp->do_fit_on_load_image = FALSE; selfp->idle_handle = g_idle_add(cb_load_image_when_idle, self); #if 0 @@ -2122,9 +2128,9 @@ cb_motion_event(GtkWidget *widget, do_update_label = false; } else if (selfp->do_show_sub_pixel) - g_string_sprintf(info_label, " (%7.3f, %7.3f)", x, y); + g_string_printf(info_label, " (%7.3f, %7.3f)", x, y); else - g_string_sprintf(info_label, " (%4.0f, %4.0f)", floor(x), floor(y)); + g_string_printf(info_label, " (%4.0f, %4.0f)", floor(x), floor(y)); if (do_update_measure_distance) { double m_dist = sqrt(sqr(selfp->measure_x2 - selfp->measure_x1) @@ -2153,11 +2159,11 @@ cb_motion_event(GtkWidget *widget, // TBD - clean this up so it works for arbitrary size date double val = giv_image_get_value(selfp->img_org, (int)x, (int)y, selfp->current_slice); - g_string_sprintfa(info_label, " ["); - g_string_sprintfa(info_label, + g_string_append_printf(info_label, " ["); + g_string_append_printf(info_label, selfp->format, val); - g_string_sprintfa(info_label, + g_string_append_printf(info_label, "] = #%02X", (int)val); if (selfp->w_contrast_view) @@ -2168,7 +2174,7 @@ cb_motion_event(GtkWidget *widget, || selfp->img_org->img_type == GIVIMAGE_RGBA_U16) { GivImageRgbAlpha16 rgba = giv_image_get_rgba_value(selfp->img_org, (int)x, (int)y, selfp->current_slice); - g_string_sprintfa(info_label, + g_string_append_printf(info_label, " [%3d %3d %3d %3d] = #%08lX", rgba.red, rgba.green, rgba.blue, rgba.alpha, (unsigned long)(rgba.red<<24) @@ -2179,7 +2185,7 @@ cb_motion_event(GtkWidget *widget, else { GivImageRgb16 rgb = giv_image_get_rgb_value(selfp->img_org, (int)x, (int)y, 0); - g_string_sprintfa(info_label, + g_string_append_printf(info_label, " [%3d %3d %3d] = #%6X", rgb.red, rgb.green, rgb.blue, (int)(rgb.red<<16) + (rgb.green<<8) + rgb.blue); @@ -3669,6 +3675,19 @@ static void cb_image_reference(GtkWidget *widget, } +// Update the pixel size from the giv file +static void cb_set_pixelsize(GtkWidget *widget, + double pixelsize, + const gchar *pixelsize_unit, + gpointer user_data) +{ + GivWin *self = (GivWin *)user_data; + selfp->pixelsize = pixelsize; + if (selfp->pixelsize_unit) + g_free(selfp->pixelsize_unit); + selfp->pixelsize_unit = g_strdup(pixelsize_unit); +} + #if 0 static void cb_set_orientation(giv_parser_orientation_t hflip, giv_parser_orientation_t vflip,