From b1c1c86346d23042377deca1644e19959b93f68d Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 29 Jan 2013 02:17:37 -0500 Subject: [PATCH] make PNG and TIFF support optional - closes #1704 --- SConstruct | 41 +++++++++++++++++++------ bindings/python/build.py | 3 +- bindings/python/mapnik_image.cpp | 11 ------- bindings/python/mapnik_image_view.cpp | 12 ++------ include/mapnik/png_io.hpp | 6 ++-- src/image_util.cpp | 43 ++++++++++++++++++++------- 6 files changed, 72 insertions(+), 44 deletions(-) diff --git a/SConstruct b/SConstruct index cfc77df43..f021968d1 100644 --- a/SConstruct +++ b/SConstruct @@ -305,14 +305,17 @@ opts.AddVariables( ('XML2_CONFIG', 'The path to the xml2-config executable.', 'xml2-config'), PathVariable('ICU_INCLUDES', 'Search path for ICU include files', '/usr/include', PathVariable.PathAccept), PathVariable('ICU_LIBS','Search path for ICU include files','/usr/' + LIBDIR_SCHEMA_DEFAULT, PathVariable.PathAccept), - ('ICU_LIB_NAME', 'The library name for icu (such as icuuc, sicuuc, or icucore)', 'icuuc'), - PathVariable('PNG_INCLUDES', 'Search path for libpng include files', '/usr/include', PathVariable.PathAccept), - PathVariable('PNG_LIBS','Search path for libpng library files','/usr/' + LIBDIR_SCHEMA_DEFAULT, PathVariable.PathAccept), + ('ICU_LIB_NAME', 'The library name for icu (such as icuuc, sicuuc, or icucore)', 'icuuc', +PathVariable.PathAccept), PathVariable('LTDL_INCLUDES', 'Search path for libltdl (part of libtool) include files', '/usr/include', PathVariable.PathAccept), PathVariable('LTDL_LIBS','Search path for libltdl (ltdl.h) library files','/usr/' + LIBDIR_SCHEMA_DEFAULT, PathVariable.PathAccept), + BoolVariable('PNG', 'Build Mapnik with PNG read and write support', 'True'), + PathVariable('PNG_INCLUDES', 'Search path for libpng include files', '/usr/include', PathVariable.PathAccept), + PathVariable('PNG_LIBS','Search path for libpng library files','/usr/' + LIBDIR_SCHEMA_DEFAULT, PathVariable.PathAccept), BoolVariable('JPEG', 'Build Mapnik with JPEG read and write support', 'True'), PathVariable('JPEG_INCLUDES', 'Search path for libjpeg include files', '/usr/include', PathVariable.PathAccept), PathVariable('JPEG_LIBS', 'Search path for libjpeg library files', '/usr/' + LIBDIR_SCHEMA_DEFAULT, PathVariable.PathAccept), + BoolVariable('TIFF', 'Build Mapnik with TIFF read and write support', 'True'), PathVariable('TIFF_INCLUDES', 'Search path for libtiff include files', '/usr/include', PathVariable.PathAccept), PathVariable('TIFF_LIBS', 'Search path for libtiff library files', '/usr/' + LIBDIR_SCHEMA_DEFAULT, PathVariable.PathAccept), PathVariable('PROJ_INCLUDES', 'Search path for PROJ.4 include files', '/usr/include', PathVariable.PathAccept), @@ -1059,7 +1062,7 @@ if not preconfigured: # Adding the required prerequisite library directories to the include path for # compiling and the library path for linking, respectively. - for required in ('PNG', 'JPEG', 'TIFF','PROJ','ICU', 'SQLITE', 'LTDL'): + for required in ('PROJ', 'ICU', 'SQLITE', 'LTDL'): inc_path = env['%s_INCLUDES' % required] lib_path = env['%s_LIBS' % required] env.AppendUnique(CPPPATH = os.path.realpath(inc_path)) @@ -1083,21 +1086,41 @@ if not preconfigured: env['HAS_LIBXML2'] = True LIBSHEADERS = [ - ['m', 'math.h', True,'C'], - ['ltdl', 'ltdl.h', True,'C'], - ['png', 'png.h', True,'C'], - ['tiff', 'tiff.h', True,'C'], ['z', 'zlib.h', True,'C'], - ['proj', 'proj_api.h', True,'C'], + ['ltdl', 'ltdl.h', True,'C'], [env['ICU_LIB_NAME'],'unicode/unistr.h',True,'C++'], ] if env['JPEG']: env.Append(CXXFLAGS = '-DHAVE_JPEG') LIBSHEADERS.append(['jpeg', ['stdio.h', 'jpeglib.h'], True,'C']) + inc_path = env['%s_INCLUDES' % 'JPEG'] + lib_path = env['%s_LIBS' % 'JPEG'] + env.AppendUnique(CPPPATH = os.path.realpath(inc_path)) + env.AppendUnique(LIBPATH = os.path.realpath(lib_path)) else: env['SKIPPED_DEPS'].extend(['jpeg']) + if env['PNG']: + env.Append(CXXFLAGS = '-DHAVE_PNG') + LIBSHEADERS.append(['png', 'png.h', True,'C']) + inc_path = env['%s_INCLUDES' % 'PNG'] + lib_path = env['%s_LIBS' % 'PNG'] + env.AppendUnique(CPPPATH = os.path.realpath(inc_path)) + env.AppendUnique(LIBPATH = os.path.realpath(lib_path)) + else: + env['SKIPPED_DEPS'].extend(['png']) + + if env['TIFF']: + env.Append(CXXFLAGS = '-DHAVE_TIFF') + LIBSHEADERS.append(['tiff', 'tiff.h', True,'C']) + inc_path = env['%s_INCLUDES' % 'TIFF'] + lib_path = env['%s_LIBS' % 'TIFF'] + env.AppendUnique(CPPPATH = os.path.realpath(inc_path)) + env.AppendUnique(LIBPATH = os.path.realpath(lib_path)) + else: + env['SKIPPED_DEPS'].extend(['tiff']) + # if requested, sort LIBPATH and CPPPATH before running CheckLibWithHeader tests if env['PRIORITIZE_LINKING']: conf.prioritize_paths(silent=False) diff --git a/bindings/python/build.py b/bindings/python/build.py index 3b6d1590b..a16bb4533 100644 --- a/bindings/python/build.py +++ b/bindings/python/build.py @@ -48,7 +48,8 @@ libraries = ['mapnik',env['BOOST_PYTHON_LIB']] # TODO - do solaris/fedora need direct linking too? if env['PLATFORM'] == 'Darwin': if not env['PYTHON_DYNAMIC_LOOKUP']: - libraries.append('png') + if env['PNG']: + libraries.append('png') if env['JPEG']: libraries.append('jpeg') libraries.append(env['ICU_LIB_NAME']) diff --git a/bindings/python/mapnik_image.cpp b/bindings/python/mapnik_image.cpp index 1b8b8b85d..9c7c1fd1e 100644 --- a/bindings/python/mapnik_image.cpp +++ b/bindings/python/mapnik_image.cpp @@ -20,11 +20,6 @@ * *****************************************************************************/ -extern "C" -{ -#include -} - // boost #include #include @@ -35,15 +30,9 @@ extern "C" #include #include #include -#include #include #include -// jpeg -#if defined(HAVE_JPEG) -#include -#endif - // cairo #if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO) #include diff --git a/bindings/python/mapnik_image_view.cpp b/bindings/python/mapnik_image_view.cpp index f3cf2e44f..18a0831b6 100644 --- a/bindings/python/mapnik_image_view.cpp +++ b/bindings/python/mapnik_image_view.cpp @@ -20,23 +20,15 @@ * *****************************************************************************/ -extern "C" -{ -#include -} #include +#include +#include #include #include #include -#include #include -// jpeg -#if defined(HAVE_JPEG) -#include -#endif - using mapnik::image_data_32; using mapnik::image_view; using mapnik::save_to_file; diff --git a/include/mapnik/png_io.hpp b/include/mapnik/png_io.hpp index d23ed715d..a1719e278 100644 --- a/include/mapnik/png_io.hpp +++ b/include/mapnik/png_io.hpp @@ -24,7 +24,6 @@ #define MAPNIK_PNG_IO_HPP // mapnik -#include #include #include #include @@ -32,11 +31,14 @@ #include // zlib -#include +#include // for Z_DEFAULT_COMPRESSION // boost #include +// stl +#include + extern "C" { #include diff --git a/src/image_util.cpp b/src/image_util.cpp index 024ce13c4..9b8ec651a 100644 --- a/src/image_util.cpp +++ b/src/image_util.cpp @@ -20,15 +20,27 @@ * *****************************************************************************/ +#if defined(HAVE_PNG) extern "C" { #include } +#endif // mapnik -#include +#if defined(HAVE_PNG) #include +#endif + +#if defined(HAVE_TIFF) #include +#endif + +#if defined(HAVE_JPEG) +#include +#endif + +#include #include #include #include @@ -36,10 +48,6 @@ extern "C" #include #include #include -// jpeg -#if defined(HAVE_JPEG) -#include -#endif #ifdef HAVE_CAIRO #include @@ -53,7 +61,6 @@ extern "C" #ifdef CAIRO_HAS_SVG_SURFACE #include #endif // CAIRO_HAS_SVG_SURFACE - #endif // boost @@ -117,6 +124,7 @@ void save_to_file(T const& image, else throw ImageWriterException("Could not write file to " + filename ); } +#if defined(HAVE_PNG) void handle_png_options(std::string const& type, int * colors, int * compression, @@ -227,6 +235,7 @@ void handle_png_options(std::string const& type, } } } +#endif template void save_to_stream(T const& image, @@ -240,6 +249,7 @@ void save_to_stream(T const& image, std::transform(t.begin(), t.end(), t.begin(), ::tolower); if (t == "png" || boost::algorithm::starts_with(t, "png")) { +#if defined(HAVE_PNG) int colors = 256; int compression = Z_DEFAULT_COMPRESSION; int strategy = Z_DEFAULT_STRATEGY; @@ -273,17 +283,18 @@ void save_to_stream(T const& image, { save_as_png8_hex(stream, image, colors, compression, strategy, trans_mode, gamma, use_miniz); } +#else + throw ImageWriterException("png output is not enabled in your build of Mapnik"); +#endif } else if (boost::algorithm::starts_with(t, "tif")) { throw ImageWriterException("palettes are not currently supported when writing to tiff format (yet)"); } -#if defined(HAVE_JPEG) else if (boost::algorithm::starts_with(t, "jpeg")) { throw ImageWriterException("palettes are not currently supported when writing to jpeg format"); } -#endif else throw ImageWriterException("unknown file type: " + type); } else throw ImageWriterException("Could not write to empty stream" ); @@ -301,6 +312,7 @@ void save_to_stream(T const& image, std::transform(t.begin(), t.end(), t.begin(), ::tolower); if (t == "png" || boost::algorithm::starts_with(t, "png")) { +#if defined(HAVE_PNG) int colors = 256; int compression = Z_DEFAULT_COMPRESSION; // usually mapped to z=6 in zlib int strategy = Z_DEFAULT_STRATEGY; @@ -330,14 +342,21 @@ void save_to_stream(T const& image, { save_as_png8_hex(stream, image, colors, compression, strategy, trans_mode, gamma, use_miniz); } +#else + throw ImageWriterException("png output is not enabled in your build of Mapnik"); +#endif } else if (boost::algorithm::starts_with(t, "tif")) { - save_as_tiff(stream, image); - } #if defined(HAVE_JPEG) + save_as_tiff(stream, image); +#else + throw ImageWriterException("tiff output is not enabled in your build of Mapnik"); +#endif + } else if (boost::algorithm::starts_with(t, "jpeg")) { +#if defined(HAVE_JPEG) int quality = 85; std::string const& val = t.substr(4); if (!val.empty()) @@ -348,8 +367,10 @@ void save_to_stream(T const& image, } } save_as_jpeg(stream, quality, image); - } +#else + throw ImageWriterException("jpeg output is not enabled in your build of Mapnik"); #endif + } else throw ImageWriterException("unknown file type: " + type); } else throw ImageWriterException("Could not write to empty stream" );