Skip to content

Commit f9a89ce

Browse files
committed
Added new giv command $pixelsize to change the pixelsize for a measurements
1 parent 99e78f3 commit f9a89ce

File tree

5 files changed

+88
-16
lines changed

5 files changed

+88
-16
lines changed

giv.nsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ File ${SYSROOT}\mingw\bin\libstdc++-6.dll
4343
File ${SYSROOT}\mingw\bin\iconv.dll
4444
File ${SYSROOT}\mingw\bin\libpcre-1.dll
4545
File ${SYSROOT}\mingw\bin\libintl-8.dll
46-
File ${SYSROOT}\mingw\bin\libffi-6.dll
46+
File ${SYSROOT}\mingw\bin\libffi-8.dll
4747
File ${SYSROOT}\mingw\bin\libgdk_pixbuf*.dll
4848
File ${SYSROOT}\mingw\bin\libgtk-3-0.dll
4949
File ${SYSROOT}\mingw\bin\libgdk-3-0.dll

src/giv-parser.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ enum
7272
STRING_HIDE,
7373
STRING_IGNORE,
7474
STRING_TEXT_STYLE,
75+
STRING_PIXEL_SIZE
7576
};
7677

7778
#define COLOR_NONE 0xfffe
@@ -453,6 +454,10 @@ parse_string (const WordBoundaries& wb,
453454
{
454455
type = STRING_HIDE;
455456
}
457+
if (wb.CheckMatch(0, "$pixelsize"))
458+
{
459+
type = STRING_PIXEL_SIZE;
460+
}
456461
#if 0
457462
if (type == -1)
458463
{
@@ -926,6 +931,19 @@ giv_parser_giv_marks_data_add_line(GivParser *gp,
926931
g_free(text_style);
927932
break;
928933
}
934+
case STRING_PIXEL_SIZE:
935+
{
936+
double pixel_size = wb.GetFloat(1);
937+
char *pixelsize_unit = NULL;
938+
if (wb.size() > 1)
939+
pixelsize_unit = strdup(wb.GetRestAsString(2));
940+
if (gp->cb_set_pixelsize)
941+
(*(gp->cb_set_pixelsize))(pixel_size, pixelsize_unit, gp->cb_set_pixelsize_data);
942+
if (pixelsize_unit)
943+
g_free(pixelsize_unit);
944+
945+
break;
946+
}
929947
default:
930948
;
931949
#if 0
@@ -1089,6 +1107,15 @@ giv_parser_set_orientation_callback(GivParser *gp,
10891107
gp->cb_set_orientation_data = user_data;
10901108
}
10911109

1110+
void
1111+
giv_parser_set_pixelsize_callback(GivParser *gp,
1112+
giv_parser_set_pixelsize_t cb,
1113+
gpointer user_data)
1114+
{
1115+
gp->cb_set_pixelsize = cb;
1116+
gp->cb_set_pixelsize_data = user_data;
1117+
}
1118+
10921119
void
10931120
giv_parser_set_vlock_callback(GivParser *gp,
10941121
giv_parser_set_vlock_t cb,

src/giv-parser.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,22 @@ typedef void (*giv_parser_set_orientation_t)(giv_parser_orientation_t horint,
2222
giv_parser_orientation_t vorint,
2323
gpointer data);
2424

25+
typedef void (*giv_parser_set_pixelsize_t)(double pixel_size,
26+
const gchar *pixelsize_unit,
27+
gpointer data);
2528
typedef void (*giv_parser_set_vlock_t)(gboolean vlock, gpointer data);
2629

27-
typedef struct {
30+
struct GivParser {
2831
GPtrArray* giv_datasets;
2932
GHashTable *style_hash;
30-
giv_parser_file_reference_t cb_file_reference;
33+
giv_parser_file_reference_t cb_file_reference=nullptr;
3134
gpointer cb_file_reference_data;
32-
giv_parser_set_orientation_t cb_set_orientation;
35+
giv_parser_set_orientation_t cb_set_orientation=nullptr;
3336
gpointer cb_set_orientation_data;
3437
giv_parser_set_vlock_t cb_set_vlock;
3538
gpointer cb_set_vlock_data;
39+
giv_parser_set_pixelsize_t cb_set_pixelsize;
40+
gpointer cb_set_pixelsize_data;
3641

3742
// Bounding box of data
3843
double global_mark_max_x;
@@ -41,7 +46,7 @@ typedef struct {
4146
double global_mark_min_y;
4247

4348
double quiver_scale;
44-
} GivParser;
49+
};
4550

4651
GivParser *giv_parser_new();
4752
void giv_parser_free(GivParser *giv_parser);
@@ -51,6 +56,9 @@ void giv_parser_set_reference_callback(GivParser *giv_parser,
5156
void giv_parser_set_orientation_callback(GivParser *giv_parser,
5257
giv_parser_set_orientation_t fr,
5358
gpointer user_data);
59+
void giv_parser_set_pixelsize_callback(GivParser *giv_parser,
60+
giv_parser_set_pixelsize_t cb,
61+
gpointer user_data);
5462
void giv_parser_set_vlock_callback(GivParser *giv_parser,
5563
giv_parser_set_vlock_t vlock,
5664
gpointer user_data);

src/giv-widget.gob

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@ static void cb_image_reference(const char *filename,
6565
gpointer self);
6666
static void cb_set_orientation(giv_parser_orientation_t hflip,
6767
giv_parser_orientation_t vflip,
68-
gpointer self);
68+
gpointer user_data);
69+
static void cb_set_pixelsize(double pixelsize,
70+
const gchar *unit,
71+
gpointer user_data);
6972
static void cb_set_vlock(gboolean vlock,
70-
gpointer self);
73+
gpointer user_data);
7174

7275
%}
7376

@@ -142,6 +145,9 @@ class Giv:Widget from Gtk:Image:Viewer
142145
&cb_image_reference, (gpointer)self);
143146
giv_parser_set_orientation_callback(selfp->giv_parser,
144147
&cb_set_orientation, (gpointer)self);
148+
giv_parser_set_pixelsize_callback(selfp->giv_parser,
149+
&cb_set_pixelsize,
150+
(gpointer)self);
145151
giv_parser_set_vlock_callback(selfp->giv_parser,
146152
&cb_set_vlock,
147153
(gpointer)self);
@@ -250,7 +256,7 @@ class Giv:Widget from Gtk:Image:Viewer
250256
mark_set->path_name);
251257
else {
252258
GString *balloon_string = g_string_new("");
253-
g_string_sprintfa(balloon_string, "label = %d", label);
259+
g_string_append_printf(balloon_string, "label = %d", label);
254260
gtk_label_set_text(GTK_LABEL(selfp->w_balloon_label),
255261
balloon_string->str);
256262
g_string_free(balloon_string, TRUE);
@@ -674,6 +680,8 @@ class Giv:Widget from Gtk:Image:Viewer
674680
signal last NONE (POINTER)
675681
void file_reference(self, const gchar *filename);
676682

683+
signal last NONE (DOUBLE, POINTER)
684+
void set_pixelsize(self, double pixelsize, const gchar *unit);
677685
}
678686

679687
%{
@@ -1065,6 +1073,16 @@ static void cb_set_orientation(giv_parser_orientation_t orientation_hflip,
10651073
hflip, vflip);
10661074
}
10671075

1076+
static void cb_set_pixelsize(double pixelsize,
1077+
const gchar *unit,
1078+
gpointer user_data)
1079+
{
1080+
GivWidget *self = GIV_WIDGET(user_data);
1081+
1082+
// Emit a signal
1083+
giv_widget_set_pixelsize(self, pixelsize, unit);
1084+
}
1085+
10681086
static void cb_set_vlock(gboolean vlock,
10691087
gpointer user_data)
10701088
{

src/giv-win.gob

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ static void cb_change_pseudo_color(GtkRadioAction* action,
149149
static void cb_image_reference(GtkWidget *widget,
150150
const char *filename,
151151
gpointer user_data);
152+
static void cb_set_pixelsize(GtkWidget *widget,
153+
double pixelsize,
154+
const gchar *pixelsize_unit,
155+
gpointer user_data);
152156
static void menu_add_widget (GtkUIManager *ui, GtkWidget *widget, GtkContainer *container);
153157
static void
154158
cb_balloon_changed(GtkWidget *widget,
@@ -859,6 +863,8 @@ class Giv:Win from Gtk:Window
859863
gtk_widget_show(selfp->w_imgv);
860864
g_signal_connect(selfp->w_imgv, "file-reference",
861865
G_CALLBACK(cb_image_reference), self);
866+
g_signal_connect(selfp->w_imgv, "set-pixelsize",
867+
G_CALLBACK(cb_set_pixelsize), self);
862868
g_signal_connect(selfp->w_imgv, "button-press-event",
863869
G_CALLBACK(cb_button_press_event), self);
864870
g_signal_connect(selfp->w_imgv, "button-release-event",
@@ -1063,7 +1069,7 @@ class Giv:Win from Gtk:Window
10631069
}
10641070

10651071
selfp->idle_index = selfp->filename_list_index;
1066-
selfp->do_fit_on_load_image = TRUE;
1072+
selfp->do_fit_on_load_image = FALSE;
10671073
selfp->idle_handle = g_idle_add(cb_load_image_when_idle,
10681074
self);
10691075
#if 0
@@ -2122,9 +2128,9 @@ cb_motion_event(GtkWidget *widget,
21222128
do_update_label = false;
21232129
}
21242130
else if (selfp->do_show_sub_pixel)
2125-
g_string_sprintf(info_label, " (%7.3f, %7.3f)", x, y);
2131+
g_string_printf(info_label, " (%7.3f, %7.3f)", x, y);
21262132
else
2127-
g_string_sprintf(info_label, " (%4.0f, %4.0f)", floor(x), floor(y));
2133+
g_string_printf(info_label, " (%4.0f, %4.0f)", floor(x), floor(y));
21282134

21292135
if (do_update_measure_distance) {
21302136
double m_dist = sqrt(sqr(selfp->measure_x2 - selfp->measure_x1)
@@ -2153,11 +2159,11 @@ cb_motion_event(GtkWidget *widget,
21532159
// TBD - clean this up so it works for arbitrary size date
21542160
double val = giv_image_get_value(selfp->img_org,
21552161
(int)x, (int)y, selfp->current_slice);
2156-
g_string_sprintfa(info_label, " [");
2157-
g_string_sprintfa(info_label,
2162+
g_string_append_printf(info_label, " [");
2163+
g_string_append_printf(info_label,
21582164
selfp->format,
21592165
val);
2160-
g_string_sprintfa(info_label,
2166+
g_string_append_printf(info_label,
21612167
"] = #%02X",
21622168
(int)val);
21632169
if (selfp->w_contrast_view)
@@ -2168,7 +2174,7 @@ cb_motion_event(GtkWidget *widget,
21682174
|| selfp->img_org->img_type == GIVIMAGE_RGBA_U16) {
21692175
GivImageRgbAlpha16 rgba = giv_image_get_rgba_value(selfp->img_org,
21702176
(int)x, (int)y, selfp->current_slice);
2171-
g_string_sprintfa(info_label,
2177+
g_string_append_printf(info_label,
21722178
" [%3d %3d %3d %3d] = #%08lX",
21732179
rgba.red, rgba.green, rgba.blue, rgba.alpha,
21742180
(unsigned long)(rgba.red<<24)
@@ -2179,7 +2185,7 @@ cb_motion_event(GtkWidget *widget,
21792185
else {
21802186
GivImageRgb16 rgb = giv_image_get_rgb_value(selfp->img_org,
21812187
(int)x, (int)y, 0);
2182-
g_string_sprintfa(info_label,
2188+
g_string_append_printf(info_label,
21832189
" [%3d %3d %3d] = #%6X",
21842190
rgb.red, rgb.green, rgb.blue,
21852191
(int)(rgb.red<<16) + (rgb.green<<8) + rgb.blue);
@@ -3669,6 +3675,19 @@ static void cb_image_reference(GtkWidget *widget,
36693675

36703676
}
36713677

3678+
// Update the pixel size from the giv file
3679+
static void cb_set_pixelsize(GtkWidget *widget,
3680+
double pixelsize,
3681+
const gchar *pixelsize_unit,
3682+
gpointer user_data)
3683+
{
3684+
GivWin *self = (GivWin *)user_data;
3685+
selfp->pixelsize = pixelsize;
3686+
if (selfp->pixelsize_unit)
3687+
g_free(selfp->pixelsize_unit);
3688+
selfp->pixelsize_unit = g_strdup(pixelsize_unit);
3689+
}
3690+
36723691
#if 0
36733692
static void cb_set_orientation(giv_parser_orientation_t hflip,
36743693
giv_parser_orientation_t vflip,

0 commit comments

Comments
 (0)