aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMake/FindGDK.cmake51
-rw-r--r--CMake/FindGdkPixbuf2.cmake51
-rw-r--r--CMakeLists.txt55
-rw-r--r--config.h.cmake.in3
-rw-r--r--src/dw-hdfsee.c9
-rw-r--r--src/geoptimiser.c43
-rw-r--r--src/hdfsee-render.c39
-rw-r--r--src/hdfsee-render.h16
8 files changed, 192 insertions, 75 deletions
diff --git a/CMake/FindGDK.cmake b/CMake/FindGDK.cmake
new file mode 100644
index 00000000..5de42303
--- /dev/null
+++ b/CMake/FindGDK.cmake
@@ -0,0 +1,51 @@
+# - Try to find the GDK library
+# Once done this will define
+#
+# GDK_FOUND - system has gdk
+# GDK_INCLUDE_DIRS - the gdk include directory
+# GDK_LIBRARIES - Link these to use gdk
+#
+# Define GDK_MIN_VERSION for which version desired.
+#
+
+include(FindPkgConfig)
+
+if (GDK_FIND_REQUIRED)
+ set(_pkgconfig_REQUIRED "REQUIRED")
+else (GDK_FIND_REQUIRED)
+ set(_pkgconfig_REQUIRED "")
+endif (GDK_FIND_REQUIRED)
+
+if (GDK_MIN_VERSION)
+ pkg_search_module(GDK ${_pkgconfig_REQUIRED} gdk-2.0>=${GDK_MIN_VERSION})
+else (GDK_MIN_VERSION)
+ pkg_search_module(GDK ${_pkgconfig_REQUIRED} gdk-2.0)
+endif (GDK_MIN_VERSION)
+
+if (GDK_FOUND)
+ message(STATUS "Found GDK (using pkg-config): ${GDK_LIBRARIES}")
+endif (GDK_FOUND)
+
+# Backup option if we don't have pkg-config
+if (NOT GDK_FOUND AND NOT PKG_CONFIG_FOUND)
+
+ find_path(GDK_INCLUDE_DIRS gdk/gdk.h)
+ find_library(GDK_LIBRARIES gdk)
+
+ if (GDK_LIBRARIES AND GDK_INCLUDE_DIRS)
+ set(GDK_FOUND 1)
+ if (NOT GDK_FIND_QUIETLY)
+ message(STATUS "Found GDK_LIBRARIES}")
+ endif(NOT GDK_FIND_QUIETLY)
+ else (GDK_LIBRARIES AND GDK_INCLUDE_DIRS)
+ if (GDK_FIND_REQUIRED)
+ message(SEND_ERROR "Could not find GDK")
+ else (GDK_FIND_REQUIRED)
+ if (NOT GDK_FIND_QUIETLY)
+ message(STATUS "Could not find GDK")
+ endif (NOT GDK_FIND_QUIETLY)
+ endif (GDK_FIND_REQUIRED)
+ endif (GDK_LIBRARIES AND GDK_INCLUDE_DIRS)
+
+endif (NOT GDK_FOUND AND NOT PKG_CONFIG_FOUND)
+
diff --git a/CMake/FindGdkPixbuf2.cmake b/CMake/FindGdkPixbuf2.cmake
new file mode 100644
index 00000000..dea84f4e
--- /dev/null
+++ b/CMake/FindGdkPixbuf2.cmake
@@ -0,0 +1,51 @@
+# - Try to find the gdk-pixbuf-2.0 library
+# Once done this will define
+#
+# GDKPIXBUF_FOUND - system has gdk-pixbuf
+# GDKPIXBUF_INCLUDE_DIRS - the gdk-pixbuf include directory
+# GDKPIXBUF_LIBRARIES - Link these to use gdk-pixbuf
+#
+# Define GDKPIXBUF_MIN_VERSION for which version desired.
+#
+
+include(FindPkgConfig)
+
+if (GdkPixbuf2_FIND_REQUIRED)
+ set(_pkgconfig_REQUIRED "REQUIRED")
+else (GdkPixbuf2_FIND_REQUIRED)
+ set(_pkgconfig_REQUIRED "")
+endif (GdkPixbuf2_FIND_REQUIRED)
+
+if (GDKPIXBUF_MIN_VERSION)
+ pkg_search_module(GDKPIXBUF ${_pkgconfig_REQUIRED} gdk-pixbuf-2.0>=${GDKPIXBUF_MIN_VERSION})
+else (GDKPIXBUF_MIN_VERSION)
+ pkg_search_module(GDKPIXBUF ${_pkgconfig_REQUIRED} gdk-pixbuf-2.0)
+endif (GDKPIXBUF_MIN_VERSION)
+
+if (GDKPIXBUF_FOUND)
+ message(STATUS "Found GdkPixbuf2 (using pkg-config): ${GDKPIXBUF_LIBRARIES}")
+endif (GDKPIXBUF_FOUND)
+
+# Backup option if we don't have pkg-config
+if (NOT GDKPIXBUF_FOUND AND NOT PKG_CONFIG_FOUND)
+
+ find_path(GDKPIXBUF_INCLUDE_DIRS gdk-pixbuf/gdk-pixbuf.h)
+ find_library(GDKPIXBUF_LIBRARIES gdk-pixbuf)
+
+ if (GDKPIXBUF_LIBRARIES AND GDKPIXBUF_INCLUDE_DIRS)
+ set(GDKPIXBUF_FOUND 1)
+ if (NOT GdkPixbuf2_FIND_QUIETLY)
+ message(STATUS "Found GdkPixbuf2: ${GDKPIXBUF_LIBRARIES}")
+ endif(NOT GdkPixbuf2_FIND_QUIETLY)
+ else (GDKPIXBUF_LIBRARIES AND GDKPIXBUF_INCLUDE_DIRS)
+ if (GdkPixbuf2_FIND_REQUIRED)
+ message(SEND_ERROR "Could not find GdkPixbuf2")
+ else (GdkPixbuf2_FIND_REQUIRED)
+ if (NOT GdkPixbuf2_FIND_QUIETLY)
+ message(STATUS "Could not find GdkPixbuf2")
+ endif (NOT GdkPixbuf2_FIND_QUIETLY)
+ endif (GdkPixbuf2_FIND_REQUIRED)
+ endif (GDKPIXBUF_LIBRARIES AND GDKPIXBUF_INCLUDE_DIRS)
+
+endif (NOT GDKPIXBUF_FOUND AND NOT PKG_CONFIG_FOUND)
+
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 124f17d9..3db2ab58 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,6 +13,8 @@ find_package(HDF5 REQUIRED COMPONENTS C)
find_package(Threads REQUIRED)
find_package(GSL REQUIRED)
find_package(GTK2 2.0.0 COMPONENTS gtk)
+find_package(GdkPixbuf2)
+find_package(GDK)
find_package(FFTW)
find_package(CBF)
find_package(TIFF)
@@ -63,6 +65,8 @@ set(HAVE_XGANDALF ${XGANDALF_FOUND})
set(HAVE_FDIP ${FDIP_FOUND})
set(HAVE_OPENCL ${OpenCL_FOUND})
set(HAVE_CBFLIB ${CBF_FOUND})
+set(HAVE_GDKPIXBUF ${GDKPIXBUF_FOUND})
+set(HAVE_GDK ${GDK_FOUND})
check_include_file(fcntl.h HAVE_FCNTL_H)
check_include_file(stdlib.h HAVE_STDLIB_H)
@@ -147,11 +151,12 @@ if(BUILD_HDFSEE AND GTK2_FOUND AND TIFF_FOUND)
add_executable(hdfsee ${HDFSEE_SOURCES})
target_include_directories(hdfsee PRIVATE
${COMMON_INCLUDES}
+ ${TIFF_INCLUDE_DIRS}
${GTK2_INCLUDE_DIRS}
)
target_link_libraries(hdfsee
${COMMON_LIBRARIES}
- TIFF::TIFF
+ ${TIFF_LIBRARIES}
${GTK2_LIBRARIES}
)
set_target_properties(hdfsee PROPERTIES
@@ -332,24 +337,36 @@ target_link_libraries(ambigator ${COMMON_LIBRARIES})
# Build Target
# geoptimiser
-if (CAIRO_FOUND AND GTK2_FOUND AND TIFF_FOUND)
- set(GEOPTIMISER_SOURCES
- src/geoptimiser.c
- src/hdfsee-render.c
- )
-
- add_executable(geoptimiser ${GEOPTIMISER_SOURCES})
- target_include_directories(geoptimiser PRIVATE ${COMMON_INCLUDES} ${CAIRO_INCLUDE_DIRS} ${GTK2_INCLUDE_DIRS})
- target_link_libraries(geoptimiser ${COMMON_LIBRARIES} ${CAIRO_LIBRARIES} ${GTK2_LIBRARIES} ${TIFF_LIBRARIES})
-
- install(
- TARGETS
- geoptimiser
-
- RUNTIME DESTINATION bin
- LIBRARY DESTINATION lib
- )
-endif (CAIRO_FOUND AND GTK2_FOUND AND TIFF_FOUND)
+set(GEOPTIMISER_SOURCES src/geoptimiser.c src/hdfsee-render.c)
+add_executable(geoptimiser ${GEOPTIMISER_SOURCES})
+target_include_directories(geoptimiser PRIVATE ${COMMON_INCLUDES})
+target_link_libraries(geoptimiser ${COMMON_LIBRARIES})
+
+# Add features one by one so that #ifdef HAVE_XX//#include XX.h always works
+# If Cairo, gdk-pixbuf and GDK are all found, geoptimiser will add PNG support
+if (CAIRO_FOUND)
+ target_include_directories(geoptimiser PRIVATE ${CAIRO_INCLUDE_DIRS})
+ target_link_libraries(geoptimiser ${CAIRO_LIBRARIES})
+endif (CAIRO_FOUND)
+
+if (GDKPIXBUF_FOUND)
+ target_include_directories(geoptimiser PRIVATE ${GDKPIXBUF_INCLUDE_DIRS})
+ target_link_libraries(geoptimiser ${GDKPIXBUF_LIBRARIES})
+endif (GDKPIXBUF_FOUND)
+
+if (GDK_FOUND)
+ target_include_directories(geoptimiser PRIVATE ${GDK_INCLUDE_DIRS})
+ target_link_libraries(geoptimiser ${GDK_LIBRARIES})
+endif (GDK_FOUND)
+
+if (TIFF_FOUND)
+ target_include_directories(geoptimiser PRIVATE ${TIFF_INCLUDE_DIRS})
+ target_link_libraries(geoptimiser ${TIFF_LIBRARIES})
+endif (TIFF_FOUND)
+
+install (TARGETS geoptimiser
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib)
# ----------------------------------------------------------------------
# Build Target
diff --git a/config.h.cmake.in b/config.h.cmake.in
index 1188c90e..5cf46cdd 100644
--- a/config.h.cmake.in
+++ b/config.h.cmake.in
@@ -3,6 +3,8 @@
#cmakedefine HAVE_CPU_AFFINITY
#cmakedefine HAVE_FFTW
#cmakedefine HAVE_GTK
+#cmakedefine HAVE_GDKPIXBUF
+#cmakedefine HAVE_GDK
#cmakedefine HAVE_OPENCL
#cmakedefine HAVE_CL_CL_H
#cmakedefine HAVE_TIFF
@@ -20,7 +22,6 @@
/* Implement us .... */
#undef HAVE_CURSES
#undef HAVE_CURSES_COLOR
-#undef HAVE_SAVE_TO_PNG
#define PACKAGE_VERSION "0.6.3"
diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c
index c1bb39cc..c5c4d85a 100644
--- a/src/dw-hdfsee.c
+++ b/src/dw-hdfsee.c
@@ -1653,7 +1653,8 @@ static gint displaywindow_save_response(GtkWidget *d, gint response,
"Therefore, it can't be saved as TIFF.");
r = 0;
} else {
- r = render_tiff_fp(dw, dw->image, file);
+ r = render_tiff_fp(dw->image, file, dw->min_x,
+ dw->max_x, dw->min_y, dw->max_y);
}
} else if ( type == 2 ) {
if ( !single_panel_data_source(dw->image->det, NULL) ) {
@@ -1662,8 +1663,10 @@ static gint displaywindow_save_response(GtkWidget *d, gint response,
"Therefore, it can't be saved as TIFF.");
r = 0;
} else {
- r = render_tiff_int16(dw, dw->image, file,
- dw->boostint);
+ r = render_tiff_int16(dw->image, file,
+ dw->boostint, dw->min_x,
+ dw->max_x, dw->min_y,
+ dw->max_y);
}
} else if ( type == 3 ) {
if ( !single_panel_data_source(dw->image->det, NULL) ) {
diff --git a/src/geoptimiser.c b/src/geoptimiser.c
index 3d859a61..f63ba81b 100644
--- a/src/geoptimiser.c
+++ b/src/geoptimiser.c
@@ -44,11 +44,14 @@
#include <gsl/gsl_sort.h>
#ifdef HAVE_CAIRO
-#ifdef HAVE_GTK
-#define HAVE_SAVE_TO_PNG 1
+#ifdef HAVE_GDK
+#ifdef HAVE_GDKPIXBUF
#include <cairo.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk/gdk.h>
-#endif /* HAVE_GTK */
+#define CAN_SAVE_TO_PNG
+#endif /* HAVE_GDKPIXBUF */
+#endif /* HAVE_GDK */
#endif /* HAVE_CAIRO */
#include "detector.h"
@@ -1636,7 +1639,7 @@ static double compute_rotation_and_stretch(struct rg_collection *connected,
}
-#ifdef HAVE_SAVE_TO_PNG
+#ifdef CAN_SAVE_TO_PNG
static void draw_panel(struct image *image, cairo_t *cr,
cairo_matrix_t *basic_m, GdkPixbuf **pixbufs, int i) {
@@ -1813,7 +1816,17 @@ static int save_data_to_png(char *filename, struct detector *det,
return 0;
}
-#endif /* HAVE_SAVE_TO_PNG */
+#else /* CAN_SAVE_TO_PNG */
+
+static int save_data_to_png(char *filename, struct detector *det,
+ struct gpanel *gpanels)
+{
+ ERROR("WARNING: geoptimiser was compiled without gdk-pixbuf and cairo "
+ "support. Error maps will not be saved.\n");
+ return 0; /* Return "success" so that program continues */
+}
+
+#endif /* CAN_SAVE_TO_PNG */
int check_and_enforce_cspad_dist(struct geoptimiser_params *gparams,
@@ -2212,8 +2225,6 @@ int optimize_geometry(struct geoptimiser_params *gparams,
STATUS("Saving error map before correction.\n");
-#ifdef HAVE_SAVE_TO_PNG
-
if ( save_data_to_png("error_map_before.png", det, gpanels) ) {
ERROR("Error while writing data to file.\n");
free(conn_data);
@@ -2221,12 +2232,6 @@ int optimize_geometry(struct geoptimiser_params *gparams,
return 1;
}
-#else /* HAVE_SAVE_TO_PNG */
-
- ERROR("WARNING: geoptimiser was compiled without GTK and cairo "
- "support. Error maps will not be saved.\n");
-
-#endif /* HAVE_SAVE_TO_PNG */
}
@@ -2265,7 +2270,7 @@ int optimize_geometry(struct geoptimiser_params *gparams,
if ( gparams->error_maps ) {
-#ifdef HAVE_SAVE_TO_PNG
+#ifdef CAN_SAVE_TO_PNG
STATUS("Saving error map after correction.\n");
@@ -2276,12 +2281,12 @@ int optimize_geometry(struct geoptimiser_params *gparams,
return 1;
}
-#else /* HAVE_SAVE_TO_PNG */
+#else /* CAN_SAVE_TO_PNG */
- STATUS("ERROR: geoptimiser was compiled without GTK and cairo "
+ STATUS("geoptimiser was compiled without GTK and Cairo "
"support.\n Error maps will not be saved.\n");
-#endif /* HAVE_SAVE_TO_PNG */
+#endif /* CAN_SAVE_TO_PNG */
}
@@ -2301,12 +2306,12 @@ int optimize_geometry(struct geoptimiser_params *gparams,
STATUS("All done!\n");
if ( gparams->error_maps ) {
-#ifdef HAVE_SAVE_TO_PNG
+#ifdef CAN_SAVE_TO_PNG
STATUS("Be sure to inspect error_map_before.png and "
"error_map_after.png !!\n");
-#endif /* HAVE_SAVE_TO_PNG */
+#endif /* CAN_SAVE_TO_PNG */
}
free(conn_data);
diff --git a/src/hdfsee-render.c b/src/hdfsee-render.c
index 5e1de2f1..d9da469e 100644
--- a/src/hdfsee-render.c
+++ b/src/hdfsee-render.c
@@ -30,15 +30,16 @@
#include <config.h>
#endif
-#ifdef HAVE_GTK
-
-#include <gdk-pixbuf/gdk-pixbuf.h>
-
#include <stdlib.h>
#include <math.h>
#include <stdint.h>
#include <assert.h>
+
+#ifdef HAVE_GDKPIXBUF
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#endif
+
#ifdef HAVE_TIFF
#include <tiffio.h>
#endif
@@ -46,8 +47,6 @@
#include <render.h>
#include <image.h>
-#include "dw-hdfsee.h"
-
static float *get_binned_panel(struct image *image, int binning,
int pi, double *max, int *pw, int *ph)
{
@@ -107,6 +106,8 @@ static float *get_binned_panel(struct image *image, int binning,
}
+#ifdef HAVE_GDKPIXBUF
+
/* NB This function is shared between render_get_image() and
* render_get_colour_scale() */
static void render_free_data(guchar *data, gpointer p)
@@ -260,17 +261,15 @@ GdkPixbuf *render_get_colour_scale(size_t w, size_t h, int scale)
w, h, w*3, render_free_data, NULL);
}
+#endif /* HAVE_GDKPIXBUF */
-int render_tiff_fp(DisplayWindow *dw, struct image *image, const char *filename)
+int render_tiff_fp(struct image *image, const char *filename, int min_x, int max_x,
+ int min_y, int max_y)
{
#ifdef HAVE_TIFF
TIFF *th;
int16_t *line;
int x, y;
- int min_x = (int)dw->min_x;
- int max_x = (int)dw->max_x;
- int min_y = (int)dw->min_y;
- int max_y = (int)dw->max_y;
int width = max_x - min_x;
int height = max_y - min_y;
float *buf;
@@ -331,24 +330,20 @@ int render_tiff_fp(DisplayWindow *dw, struct image *image, const char *filename)
TIFFClose(th);
free(buf);
-#else
+#else /* HAVE_TIFF */
STATUS("No TIFF support.\n");
-#endif
+#endif /* HAVE_TIFF */
return 0;
}
-int render_tiff_int16(DisplayWindow *dw, struct image *image,
- const char *filename, double boost)
+int render_tiff_int16(struct image *image, const char *filename, double boost,
+ int min_x, int max_x, int min_y, int max_y)
{
#ifdef HAVE_TIFF
TIFF *th;
int16_t *line;
int x, y;
- int min_x = (int)dw->min_x;
- int max_x = (int)dw->max_x;
- int min_y = (int)dw->min_y;
- int max_y = (int)dw->max_y;
int width = max_x - min_x;
int height = max_y - min_y;
int16_t *buf;
@@ -417,10 +412,8 @@ int render_tiff_int16(DisplayWindow *dw, struct image *image,
TIFFClose(th);
free(buf);
-#else
+#else /* HAVE_TIFF */
STATUS("No TIFF support.\n");
-#endif
+#endif /* HAVE_TIFF */
return 0;
}
-
-#endif /* HAVE_GTK */
diff --git a/src/hdfsee-render.h b/src/hdfsee-render.h
index 7e87b79e..414e6ecd 100644
--- a/src/hdfsee-render.h
+++ b/src/hdfsee-render.h
@@ -33,25 +33,21 @@
#include <config.h>
#endif
-
-#ifdef HAVE_GTK
-
+#ifdef HAVE_GDKPIXBUF
#include <gdk-pixbuf/gdk-pixbuf.h>
-#include "dw-hdfsee.h"
-
extern GdkPixbuf **render_panels(struct image *image,
int binning, int scale, double boost,
int *n_pixbufs);
extern GdkPixbuf *render_get_colour_scale(size_t w, size_t h, int scale);
-extern int render_tiff_fp(DisplayWindow *dw, struct image *image,
- const char *filename);
-extern int render_tiff_int16(DisplayWindow *dw, struct image *image,
- const char *filename, double boost);
+#endif /* HAVE_GDKPIXBUF */
-#endif /* HAVE_GTK */
+extern int render_tiff_fp(struct image *image, const char *filename, int min_x,
+ int max_x, int min_y, int max_y);
+extern int render_tiff_int16(struct image *image, const char *filename, double boost,
+ int min_x, int max_x, int min_y, int max_y);
#endif /* HDFSEE_RENDER_H */