aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2009-12-16 10:36:53 -0800
committerThomas White <taw@bitwiz.org.uk>2009-12-16 10:36:53 -0800
commitd84fd5ff386a1393bbec3b67c8f165c95613a53e (patch)
treefcba5c62793a58522f17a3a860f997abc2e72ecc /src
parent5ee02bbd3e86bb6b83a457009ed0a4b5d864dec9 (diff)
Add number-viewing window, use signed values as well
Diffstat (limited to 'src')
-rw-r--r--src/detector.c12
-rw-r--r--src/displaywindow.c193
-rw-r--r--src/displaywindow.h10
-rw-r--r--src/hdf5-file.c32
-rw-r--r--src/hdf5-file.h8
-rw-r--r--src/image.h2
-rw-r--r--src/intensities.c2
-rw-r--r--src/render.c6
8 files changed, 238 insertions, 27 deletions
diff --git a/src/detector.c b/src/detector.c
index 3da5c643..bbfdcd98 100644
--- a/src/detector.c
+++ b/src/detector.c
@@ -75,15 +75,15 @@ static void bloom_values(int *tmp, int x, int y,
}
-static uint16_t *bloom(int *hdr_in, int width, int height)
+static int16_t *bloom(int *hdr_in, int width, int height)
{
int x, y;
- uint16_t *data;
+ int16_t *data;
int *tmp;
int *hdr;
int did_something;
- data = malloc(width * height * sizeof(uint16_t));
+ data = malloc(width * height * sizeof(int16_t));
tmp = malloc(width * height * sizeof(int));
hdr = malloc(width * height * sizeof(int));
@@ -131,7 +131,7 @@ static uint16_t *bloom(int *hdr_in, int width, int height)
/* Turn into integer array of counts */
for ( x=0; x<width; x++ ) {
for ( y=0; y<height; y++ ) {
- data[x + width*y] = (uint16_t)tmp[x + width*y];
+ data[x + width*y] = (int16_t)tmp[x + width*y];
}
}
@@ -218,13 +218,13 @@ void record_image(struct image *image, int do_water, int do_poisson,
image->data = bloom(image->hdr, image->width, image->height);
} else {
image->data = malloc(image->width * image->height
- * sizeof(uint16_t));
+ * sizeof(int16_t));
for ( x=0; x<image->width; x++ ) {
for ( y=0; y<image->height; y++ ) {
int val;
val = image->hdr[x + image->width*y];
if ( val > SATURATION ) val = SATURATION;
- image->data[x + image->width*y] = (uint16_t)val;
+ image->data[x + image->width*y] = (int16_t)val;
}
}
}
diff --git a/src/displaywindow.c b/src/displaywindow.c
index 2abfdab4..3b80b46e 100644
--- a/src/displaywindow.c
+++ b/src/displaywindow.c
@@ -451,6 +451,116 @@ static gint displaywindow_set_mono(GtkWidget *widget, DisplayWindow *dw)
}
+static gint displaywindow_numbers_response(GtkWidget *widget,
+ gint response, DisplayWindow *dw)
+{
+ gtk_widget_destroy(dw->numbers_window->window);
+ return 0;
+}
+
+
+static gint displaywindow_numbers_destroy(GtkWidget *widget, DisplayWindow *dw)
+{
+ free(dw->numbers_window);
+ dw->numbers_window = NULL;
+ return 0;
+}
+
+
+static gint displaywindow_show_numbers(GtkWidget *widget, DisplayWindow *dw)
+{
+ struct numberswindow *nw;
+ GtkWidget *vbox;
+ GtkWidget *hbox;
+ GtkWidget *table;
+ unsigned int x, y;
+
+ if ( dw->numbers_window != NULL ) {
+ return 0;
+ }
+
+ if ( dw->hdfile == NULL ) {
+ return 0;
+ }
+
+ nw = malloc(sizeof(struct numberswindow));
+ if ( nw == NULL ) return 0;
+ dw->numbers_window = nw;
+
+ nw->window = gtk_dialog_new_with_buttons("Numbers",
+ GTK_WINDOW(dw->window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
+ NULL);
+
+ vbox = gtk_vbox_new(FALSE, 0);
+ hbox = gtk_hbox_new(TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(nw->window)->vbox),
+ GTK_WIDGET(hbox), FALSE, FALSE, 7);
+ gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(vbox), FALSE, FALSE, 5);
+
+ table = gtk_table_new(17, 17, FALSE);
+ gtk_table_set_row_spacings(GTK_TABLE(table), 5);
+ gtk_table_set_col_spacings(GTK_TABLE(table), 5);
+ gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(table), FALSE, FALSE, 0);
+
+ for ( x=0; x<17; x++ ) {
+ for ( y=0; y<17; y++ ) {
+
+ GtkWidget *label;
+
+ label = gtk_label_new("--");
+ gtk_widget_set_size_request(GTK_WIDGET(label), 40, -1);
+
+ gtk_table_attach_defaults(GTK_TABLE(table), GTK_WIDGET(label),
+ x, x+1, y, y+1);
+
+ nw->labels[x+17*y] = label;
+
+ }
+ }
+
+ g_signal_connect(G_OBJECT(nw->window), "response",
+ G_CALLBACK(displaywindow_numbers_response), dw);
+ g_signal_connect(G_OBJECT(nw->window), "destroy",
+ G_CALLBACK(displaywindow_numbers_destroy), dw);
+ gtk_window_set_resizable(GTK_WINDOW(nw->window), FALSE);
+
+ gtk_widget_show_all(nw->window);
+
+ return 0;
+}
+
+
+static void numbers_update(DisplayWindow *dw)
+{
+ int px, py;
+
+ for ( px=0; px<17; px++ ) {
+ for ( py=0; py<17; py++ ) {
+
+ char s[32];
+ int16_t val;
+ GtkWidget *l;
+ int x, y;
+
+ x = dw->binning * dw->numbers_window->cx + (px-8);
+ y = dw->binning * (dw->height-dw->numbers_window->cy) + (py-8);
+
+ if ( (x>0) && (y>0) &&
+ !hdfile_get_unbinned_value(dw->hdfile, x, y, &val) ) {
+ snprintf(s, 31, "%i", val);
+ } else {
+ strcpy(s, "--");
+ }
+ l = dw->numbers_window->labels[px+17*py];
+ gtk_label_set_text(GTK_LABEL(l), s);
+
+ }
+ }
+}
+
+
static void displaywindow_addui_callback(GtkUIManager *ui, GtkWidget *widget,
GtkContainer *container)
{
@@ -478,8 +588,12 @@ static void displaywindow_addmenubar(DisplayWindow *dw, GtkWidget *vbox)
{ "BoostIntAction", NULL, "Boost Intensity...", "F5", NULL,
G_CALLBACK(displaywindow_set_boostint) },
+ { "ToolsAction", NULL, "_Tools", NULL, NULL, NULL },
+ { "NumbersAction", NULL, "View Numbers...", "F2", NULL,
+ G_CALLBACK(displaywindow_show_numbers) },
+
{ "HelpAction", NULL, "_Help", NULL, NULL, NULL },
- { "AboutAction", GTK_STOCK_ABOUT, "_About hdfileView...",
+ { "AboutAction", GTK_STOCK_ABOUT, "_About hdfsee...",
NULL, NULL,
G_CALLBACK(displaywindow_about) },
@@ -529,11 +643,73 @@ static void displaywindow_disable(DisplayWindow *dw)
gtk_widget_set_sensitive(GTK_WIDGET(w), FALSE);
w = gtk_ui_manager_get_widget(dw->ui,
- "/ui/displaywindow/tools/histogram");
+ "/ui/displaywindow/tools/numbers");
gtk_widget_set_sensitive(GTK_WIDGET(w), FALSE);
}
+static gint displaywindow_release(GtkWidget *widget, GdkEventButton *event,
+ DisplayWindow *dw)
+{
+ if ( (event->type == GDK_BUTTON_RELEASE) && (event->button == 1) ) {
+
+ g_signal_handler_disconnect(GTK_OBJECT(dw->drawingarea),
+ dw->motion_callback);
+ dw->motion_callback = 0;
+
+ }
+
+ return 0;
+}
+
+
+static gint displaywindow_motion(GtkWidget *widget, GdkEventMotion *event,
+ DisplayWindow *dw)
+{
+ if ( dw->numbers_window == NULL ) return 0;
+
+ dw->numbers_window->cx = event->x;
+ dw->numbers_window->cy = dw->height - 1 - event->y;
+
+ /* Schedule redraw */
+ gtk_widget_queue_draw_area(dw->drawingarea, 0, 0,
+ dw->width, dw->height);
+
+ /* Update numbers window */
+ numbers_update(dw);
+
+ return 0;
+
+}
+
+static gint displaywindow_press(GtkWidget *widget, GdkEventButton *event,
+ DisplayWindow *dw)
+{
+ if ( dw->motion_callback != 0 ) {
+ return 0;
+ }
+
+ if ( (event->type == GDK_BUTTON_PRESS) && (event->button == 1) ) {
+
+ dw->motion_callback = g_signal_connect(
+ GTK_OBJECT(dw->drawingarea),
+ "motion-notify-event",
+ G_CALLBACK(displaywindow_motion),
+ dw);
+
+ if ( dw->numbers_window != NULL ) {
+ dw->numbers_window->cx = event->x;
+ dw->numbers_window->cy = dw->height - 1 - event->y;
+ numbers_update(dw);
+ }
+
+ }
+
+ return 0;
+
+}
+
+
DisplayWindow *displaywindow_open(const char *filename)
{
DisplayWindow *dw;
@@ -549,6 +725,8 @@ DisplayWindow *displaywindow_open(const char *filename)
dw->monochrome = 0;
dw->boostint_dialog = NULL;
dw->boostint = 1;
+ dw->motion_callback = 0;
+ dw->numbers_window = NULL;
dw->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
@@ -598,5 +776,16 @@ DisplayWindow *displaywindow_open(const char *filename)
dw->binning = INITIAL_BINNING;
displaywindow_update(dw);
+ gtk_widget_add_events(GTK_WIDGET(dw->drawingarea),
+ GDK_BUTTON_PRESS_MASK
+ | GDK_BUTTON_RELEASE_MASK
+ | GDK_BUTTON1_MOTION_MASK);
+ g_object_set(G_OBJECT(dw->drawingarea), "can-focus", TRUE, NULL);
+
+ g_signal_connect(GTK_OBJECT(dw->drawingarea), "button-press-event",
+ G_CALLBACK(displaywindow_press), dw);
+ g_signal_connect(GTK_OBJECT(dw->drawingarea), "button-release-event",
+ G_CALLBACK(displaywindow_release), dw);
+
return dw;
}
diff --git a/src/displaywindow.h b/src/displaywindow.h
index 587cdb23..be8a04af 100644
--- a/src/displaywindow.h
+++ b/src/displaywindow.h
@@ -30,6 +30,14 @@ typedef struct {
} BoostIntDialog;
+struct numberswindow {
+ GtkWidget *window;
+ GtkWidget *labels[17*17];
+ unsigned int cx;
+ unsigned int cy;
+};
+
+
typedef struct {
GtkWidget *window;
@@ -37,12 +45,14 @@ typedef struct {
GtkUIManager *ui;
GtkActionGroup *action_group;
GdkPixbuf *pixbuf;
+ gulong motion_callback;
struct hdfile *hdfile;
/* Dialog boxes */
BinningDialog *binning_dialog;
BoostIntDialog *boostint_dialog;
+ struct numberswindow *numbers_window;
int width;
int height; /* Size of the drawing area */
diff --git a/src/hdf5-file.c b/src/hdf5-file.c
index 94845025..397e7a32 100644
--- a/src/hdf5-file.c
+++ b/src/hdf5-file.c
@@ -102,18 +102,18 @@ void hdfile_close(struct hdfile *f)
}
-static void *hdfile_bin(uint16_t *in, int inw, int inh,
- int binning, uint16_t *maxp)
+static void *hdfile_bin(int16_t *in, int inw, int inh,
+ int binning, int16_t *maxp)
{
- uint16_t *data;
+ int16_t *data;
int x, y;
int w, h;
- uint16_t max;
+ int16_t max;
w = inw / binning;
h = inh / binning; /* Some pixels might get discarded */
- data = malloc(w*h*sizeof(uint16_t));
+ data = malloc(w*h*sizeof(int16_t));
max = 0;
for ( x=0; x<w; x++ ) {
@@ -143,10 +143,10 @@ static void *hdfile_bin(uint16_t *in, int inw, int inh,
}
-uint16_t *hdfile_get_image_binned(struct hdfile *f, int binning, uint16_t *max)
+int16_t *hdfile_get_image_binned(struct hdfile *f, int binning, int16_t *max)
{
struct image *image;
- uint16_t *data;
+ int16_t *data;
image = malloc(sizeof(struct image));
if ( image == NULL ) return NULL;
@@ -160,7 +160,17 @@ uint16_t *hdfile_get_image_binned(struct hdfile *f, int binning, uint16_t *max)
}
-int hdf5_write(const char *filename, const uint16_t *data,
+int hdfile_get_unbinned_value(struct hdfile *f, int x, int y, int16_t *val)
+{
+ if ( (x>=f->image->width) || (y>=f->image->height) ) {
+ return 1;
+ }
+ *val = f->image->data[x+y*f->image->width];
+ return 0;
+}
+
+
+int hdf5_write(const char *filename, const int16_t *data,
int width, int height)
{
hid_t fh, gh, sh, dh; /* File, group, dataspace and data handles */
@@ -187,7 +197,7 @@ int hdf5_write(const char *filename, const uint16_t *data,
max_size[1] = height;
sh = H5Screate_simple(2, size, max_size);
- dh = H5Dcreate(gh, "data", H5T_NATIVE_UINT16, sh,
+ dh = H5Dcreate(gh, "data", H5T_NATIVE_INT16, sh,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
if ( dh < 0 ) {
ERROR("Couldn't create dataset\n");
@@ -218,11 +228,11 @@ int hdf5_write(const char *filename, const uint16_t *data,
int hdf5_read(struct hdfile *f, struct image *image)
{
herr_t r;
- uint16_t *buf;
+ int16_t *buf;
buf = malloc(sizeof(float)*f->nx*f->ny);
- r = H5Dread(f->dh, H5T_NATIVE_UINT16, H5S_ALL, H5S_ALL,
+ r = H5Dread(f->dh, H5T_NATIVE_INT16, H5S_ALL, H5S_ALL,
H5P_DEFAULT, buf);
if ( r < 0 ) {
ERROR("Couldn't read data\n");
diff --git a/src/hdf5-file.h b/src/hdf5-file.h
index ec9e3a85..528292ca 100644
--- a/src/hdf5-file.h
+++ b/src/hdf5-file.h
@@ -23,7 +23,7 @@
struct hdfile;
-extern int hdf5_write(const char *filename, const uint16_t *data,
+extern int hdf5_write(const char *filename, const int16_t *data,
int width, int height);
extern int hdf5_read(struct hdfile *f, struct image *image);
@@ -32,8 +32,10 @@ extern struct hdfile *hdfile_open(const char *filename);
extern int hdfile_set_image(struct hdfile *f, const char *path);
extern int hdfile_get_width(struct hdfile *f);
extern int hdfile_get_height(struct hdfile *f);
-extern uint16_t *hdfile_get_image_binned(struct hdfile *hdfile,
- int binning, uint16_t *maxp);
+extern int16_t *hdfile_get_image_binned(struct hdfile *hdfile,
+ int binning, int16_t *maxp);
+extern int hdfile_get_unbinned_value(struct hdfile *f, int x, int y,
+ int16_t *val);
extern void hdfile_close(struct hdfile *f);
#endif /* HDF5_H */
diff --git a/src/image.h b/src/image.h
index 01ebf8a1..9066a218 100644
--- a/src/image.h
+++ b/src/image.h
@@ -63,7 +63,7 @@ struct threevec
struct image {
int *hdr; /* Actual counts */
- uint16_t *data; /* Integer counts after bloom */
+ int16_t *data; /* Integer counts after bloom */
double complex *sfacs;
struct threevec *qvecs;
double *twotheta;
diff --git a/src/intensities.c b/src/intensities.c
index 1c6bb4ae..b48cbba8 100644
--- a/src/intensities.c
+++ b/src/intensities.c
@@ -34,7 +34,7 @@ struct reflhit {
};
-static int sum_nearby_points(uint16_t *data, int width, int x, int y)
+static int sum_nearby_points(int16_t *data, int width, int x, int y)
{
int dx, dy;
int intensity = 0;
diff --git a/src/render.c b/src/render.c
index 26deae91..bf6c0256 100644
--- a/src/render.c
+++ b/src/render.c
@@ -89,9 +89,9 @@ GdkPixbuf *render_get_image(struct hdfile *hdfile, int binning, int boostint,
{
int mw, mh, w, h;
guchar *data;
- uint16_t *hdr;
+ int16_t *hdr;
size_t x, y;
- uint16_t max;
+ int16_t max;
mw = hdfile_get_width(hdfile);
mh = hdfile_get_height(hdfile);
@@ -110,7 +110,7 @@ GdkPixbuf *render_get_image(struct hdfile *hdfile, int binning, int boostint,
}
max /= boostint;
- if ( max <= 0.0 ) { max = 10.0; }
+ if ( max <= 6 ) { max = 10; }
/* These x,y coordinates are measured relative to the bottom-left
* corner */
for ( y=0; y<h; y++ ) {