From ba129fceb3e4e0f6f33677bb2d5579130c179793 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 11 May 2017 17:08:10 +0100 Subject: [PATCH] better win32 compatibility try to fold the patches @tumagonx maintains into libvips master, see: https://github.com/tumagonx/pygi-mingw-patches/blob/master/vips-8.4.x.patch still missing the bindtextdomain() patch though --- configure.ac | 3 ++- libvips/Makefile.am | 2 +- libvips/colour/colour.c | 2 +- libvips/foreign/vips2jpeg.c | 2 +- libvips/foreign/vips2tiff.c | 3 ++- libvips/foreign/vipspng.c | 2 +- libvips/include/vips/util.h | 2 ++ libvips/iofuncs/util.c | 40 +++++++++++++++++++++++++++++++++++++ 8 files changed, 50 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index f5c2755c..28d80ec5 100644 --- a/configure.ac +++ b/configure.ac @@ -237,7 +237,8 @@ if test x"$vips_os_darwin" = x"yes"; then profile_dir="/Library/ColorSync/Profiles" elif test x"$vips_os_win32" = x"yes"; then # need double escapes since this will get pasted into a #define in a C - # header + # header ... the C:\Windows is usually overrwritten with the result of + # GetWindowsDirectoryW() profile_dir="C:\\\\Windows\\\\System32\\\\spool\\\\drivers\\\\color" else profile_dir="/usr/share/color/icc" diff --git a/libvips/Makefile.am b/libvips/Makefile.am index 4ad0b31b..e8c12991 100644 --- a/libvips/Makefile.am +++ b/libvips/Makefile.am @@ -109,7 +109,7 @@ INTROSPECTION_GIRS += Vips-8.0.gir # --warn-all --verbose # too annoying Vips_8_0_gir_SCANNERFLAGS = \ - --program=./introspect \ + --program=./introspect$(EXEEXT) \ --identifier-prefix=Vips \ --identifier-prefix=vips \ --symbol-prefix=vips diff --git a/libvips/colour/colour.c b/libvips/colour/colour.c index f57e0a08..4a1b117f 100644 --- a/libvips/colour/colour.c +++ b/libvips/colour/colour.c @@ -261,7 +261,7 @@ vips_colour_attach_profile( VipsImage *im, const char *filename ) char *data; size_t data_length; - if( !(data = vips__file_read_name( filename, VIPS_ICC_DIR, + if( !(data = vips__file_read_name( filename, vips__icc_dir(), &data_length )) ) return( -1 ); vips_image_set_blob( im, VIPS_META_ICC_NAME, diff --git a/libvips/foreign/vips2jpeg.c b/libvips/foreign/vips2jpeg.c index 1c878986..c9eb54dc 100644 --- a/libvips/foreign/vips2jpeg.c +++ b/libvips/foreign/vips2jpeg.c @@ -357,7 +357,7 @@ static int write_profile_file( Write *write, const char *profile ) { if( !(write->profile_bytes = - vips__file_read_name( profile, VIPS_ICC_DIR, + vips__file_read_name( profile, vips__icc_dir(), &write->profile_length )) ) return( -1 ); write_profile_data( &write->cinfo, diff --git a/libvips/foreign/vips2tiff.c b/libvips/foreign/vips2tiff.c index 621e092a..2e11472e 100644 --- a/libvips/foreign/vips2tiff.c +++ b/libvips/foreign/vips2tiff.c @@ -325,7 +325,8 @@ embed_profile_file( TIFF *tif, const char *profile ) char *buffer; size_t length; - if( !(buffer = vips__file_read_name( profile, VIPS_ICC_DIR, &length )) ) + if( !(buffer = vips__file_read_name( profile, + vips__icc_dir(), &length )) ) return( -1 ); TIFFSetField( tif, TIFFTAG_ICCPROFILE, length, buffer ); vips_free( buffer ); diff --git a/libvips/foreign/vipspng.c b/libvips/foreign/vipspng.c index 7c5b0809..2446ee18 100644 --- a/libvips/foreign/vipspng.c +++ b/libvips/foreign/vipspng.c @@ -954,7 +954,7 @@ write_vips( Write *write, size_t length; if( !(data = vips__file_read_name( profile, - VIPS_ICC_DIR, &length )) ) + vips__icc_dir(), &length )) ) return( -1 ); #ifdef DEBUG diff --git a/libvips/include/vips/util.h b/libvips/include/vips/util.h index 5ac2c450..b5a4f7a6 100644 --- a/libvips/include/vips/util.h +++ b/libvips/include/vips/util.h @@ -331,6 +331,8 @@ char *vips_realpath( const char *path ); guint32 vips__random( guint32 seed ); guint32 vips__random_add( guint32 seed, int value ); +const char *vips__icc_dir( void ); + #ifdef __cplusplus } #endif /*__cplusplus*/ diff --git a/libvips/iofuncs/util.c b/libvips/iofuncs/util.c index ceea8d3f..8ff1e631 100644 --- a/libvips/iofuncs/util.c +++ b/libvips/iofuncs/util.c @@ -1929,3 +1929,43 @@ vips__random_add( guint32 seed, int value ) return( vips__random( seed ) ); } + +static void * +vips_icc_dir_once( void *null ) +{ +#ifdef OS_WIN32 + /* From glib get_windows_directory_root() + */ + wchar_t wwindowsdir[MAX_PATH]; + + if( GetWindowsDirectoryW( wwindowsdir, G_N_ELEMENTS( wwindowsdir ) ) ) { + /* Usually X:\Windows, but in terminal server environments + * might be an UNC path, AFAIK. + */ + char *windowsdir; + + if( (windowsdir = g_utf16_to_utf8( wwindowsdir, + -1, NULL, NULL, NULL)) ) { + gchar *full_path; + + full_path = g_build_filename( windowsdir, + "system32", "spool", "drivers", "color", NULL ); + g_free( windowsdir ); + + return( (void *) full_path ); + } + } +#endif + + return( (void *) VIPS_ICC_DIR ); +} + +const char * +vips__icc_dir( void ) +{ + static GOnce once = G_ONCE_INIT; + + return( (const char *) g_once( &once, + (GThreadFunc) vips_icc_dir_once, NULL ) ); +} +