diff --git a/CHANGELOG b/CHANGELOG index 80576fd10..6b4a3fa33 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -14,6 +14,8 @@ For a complete change history, see the SVN log. Mapnik Trunk ------------ +- Made libjpeg dependency optional at compile time and added mapnik2.has_jpeg() method to check for support in python (#545). + - Fixed reading of PostGIS data on Big Endian systems (#515) - PostGIS: Added better support for alterative schemas (#500) diff --git a/SConstruct b/SConstruct index e743add27..00fb95da6 100644 --- a/SConstruct +++ b/SConstruct @@ -258,6 +258,7 @@ opts.AddVariables( ('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 include files','/usr/' + LIBDIR_SCHEMA, 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, PathVariable.PathAccept), PathVariable('TIFF_INCLUDES', 'Search path for libtiff include files', '/usr/include', PathVariable.PathAccept), @@ -779,6 +780,7 @@ if not preconfigured: else: env['SKIPPED_DEPS'].extend(['cairo','cairomm']) + # allow for mac osx /usr/lib/libicucore.dylib compatibility # requires custom supplied headers since Apple does not include them # details: http://lists.apple.com/archives/xcode-users/2005/Jun/msg00633.html @@ -797,11 +799,16 @@ if not preconfigured: ['png', 'png.h', True,'C'], ['tiff', 'tiff.h', True,'C'], ['z', 'zlib.h', True,'C'], - ['jpeg', ['stdio.h', 'jpeglib.h'], True,'C'], ['proj', 'proj_api.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']) + else: + env['SKIPPED_DEPS'].extend(['jpeg']) + # if requested, sort LIBPATH and CPPPATH before running CheckLibWithHeader tests if env['PRIORITIZE_LINKING']: diff --git a/bindings/python/mapnik_image.cpp b/bindings/python/mapnik_image.cpp index 32a483dd3..a42621b24 100644 --- a/bindings/python/mapnik_image.cpp +++ b/bindings/python/mapnik_image.cpp @@ -30,13 +30,19 @@ extern "C" #include #include #include + // mapnik #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 cfa6bc36a..0d5e1b8cf 100644 --- a/bindings/python/mapnik_image_view.cpp +++ b/bindings/python/mapnik_image_view.cpp @@ -29,10 +29,14 @@ extern "C" #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/bindings/python/mapnik_python.cpp b/bindings/python/mapnik_python.cpp index 373d4c49d..49ff0edcb 100644 --- a/bindings/python/mapnik_python.cpp +++ b/bindings/python/mapnik_python.cpp @@ -256,6 +256,16 @@ unsigned mapnik_svn_revision() #endif } +// indicator for jpeg read/write support within libmapnik +bool has_jpeg() +{ +#if defined(HAVE_JPEG) + return true; +#else + return false; +#endif +} + // indicator for cairo rendering support inside libmapnik bool has_cairo() { @@ -495,6 +505,7 @@ BOOST_PYTHON_MODULE(_mapnik2) def("save_map_to_string", & save_map_to_string, save_map_to_string_overloads()); def("mapnik_version", &mapnik_version,"Get the Mapnik version number"); def("mapnik_svn_revision", &mapnik_svn_revision,"Get the Mapnik svn revision"); + def("has_jpeg", &has_jpeg, "Get jpeg read/write support status"); def("has_cairo", &has_cairo, "Get cairo library status"); def("has_pycairo", &has_pycairo, "Get pycairo module status"); diff --git a/include/mapnik/image_util.hpp b/include/mapnik/image_util.hpp index 66e5913c9..28cc532b3 100644 --- a/include/mapnik/image_util.hpp +++ b/include/mapnik/image_util.hpp @@ -76,23 +76,25 @@ MAPNIK_DECL std::string save_to_string(T const& image, template void save_as_png(T const& image, std::string const& filename); - + +#if defined(HAVE_JPEG) template void save_as_jpeg(std::string const& filename, int quality, T const& image); - +#endif + inline bool is_png (std::string const& filename) { return boost::algorithm::iends_with(filename,std::string(".png")); } - + inline bool is_jpeg (std::string const& filename) { return boost::algorithm::iends_with(filename,std::string(".jpg")) || boost::algorithm::iends_with(filename,std::string(".jpeg")); } - + inline bool is_tiff (std::string const& filename) { return boost::algorithm::iends_with(filename,std::string(".tif")) || diff --git a/include/mapnik/jpeg_io.hpp b/include/mapnik/jpeg_io.hpp index ad7b6168c..f6600a4ef 100644 --- a/include/mapnik/jpeg_io.hpp +++ b/include/mapnik/jpeg_io.hpp @@ -21,6 +21,7 @@ *****************************************************************************/ //$Id$ +#if defined(HAVE_JPEG) #include @@ -125,3 +126,5 @@ void save_as_jpeg(T1 & file,int quality, T2 const& image) jpeg_destroy_compress(&cinfo); } } + +#endif \ No newline at end of file diff --git a/src/image_util.cpp b/src/image_util.cpp index c16c9f5cb..b40774ab6 100644 --- a/src/image_util.cpp +++ b/src/image_util.cpp @@ -30,11 +30,15 @@ extern "C" // mapnik #include #include -#include #include #include #include +// jpeg +#if defined(HAVE_JPEG) +#include +#endif + #ifdef HAVE_CAIRO #include #endif @@ -149,6 +153,7 @@ void save_to_stream(T const& image, else save_as_png256_hex(stream, image, colors, trans_mode, gamma); } +#if defined(HAVE_JPEG) else if (boost::algorithm::istarts_with(type,std::string("jpeg"))) { int quality = 85; @@ -167,6 +172,7 @@ void save_to_stream(T const& image, throw ImageWriterException("invalid jpeg quality: " + type.substr(4) + " not a number"); } } +#endif else throw ImageWriterException("unknown file type: " + type); } else throw ImageWriterException("Could not write to empty stream" ); diff --git a/tests/python_tests/render_test.py b/tests/python_tests/render_test.py index 84027d553..08795fa39 100644 --- a/tests/python_tests/render_test.py +++ b/tests/python_tests/render_test.py @@ -31,7 +31,8 @@ def test_render_image_to_file(): i.background = mapnik2.Color('black') - i.save('test.jpg') + if mapnik2.has_jpeg(): + i.save('test.jpg') i.save('test.png', 'png') if os.path.exists('test.jpg'):