make PNG and TIFF support optional - closes #1704

This commit is contained in:
Dane Springmeyer 2013-01-29 02:17:37 -05:00
parent c9635ef5a3
commit b1c1c86346
6 changed files with 72 additions and 44 deletions

View file

@ -305,14 +305,17 @@ opts.AddVariables(
('XML2_CONFIG', 'The path to the xml2-config executable.', 'xml2-config'), ('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_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), 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'), ('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.PathAccept),
PathVariable('PNG_LIBS','Search path for libpng library files','/usr/' + LIBDIR_SCHEMA_DEFAULT, PathVariable.PathAccept),
PathVariable('LTDL_INCLUDES', 'Search path for libltdl (part of libtool) include files', '/usr/include', 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), 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'), 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_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), 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_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('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), 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 # Adding the required prerequisite library directories to the include path for
# compiling and the library path for linking, respectively. # 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] inc_path = env['%s_INCLUDES' % required]
lib_path = env['%s_LIBS' % required] lib_path = env['%s_LIBS' % required]
env.AppendUnique(CPPPATH = os.path.realpath(inc_path)) env.AppendUnique(CPPPATH = os.path.realpath(inc_path))
@ -1083,21 +1086,41 @@ if not preconfigured:
env['HAS_LIBXML2'] = True env['HAS_LIBXML2'] = True
LIBSHEADERS = [ 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'], ['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++'], [env['ICU_LIB_NAME'],'unicode/unistr.h',True,'C++'],
] ]
if env['JPEG']: if env['JPEG']:
env.Append(CXXFLAGS = '-DHAVE_JPEG') env.Append(CXXFLAGS = '-DHAVE_JPEG')
LIBSHEADERS.append(['jpeg', ['stdio.h', 'jpeglib.h'], True,'C']) 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: else:
env['SKIPPED_DEPS'].extend(['jpeg']) 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 requested, sort LIBPATH and CPPPATH before running CheckLibWithHeader tests
if env['PRIORITIZE_LINKING']: if env['PRIORITIZE_LINKING']:
conf.prioritize_paths(silent=False) conf.prioritize_paths(silent=False)

View file

@ -48,7 +48,8 @@ libraries = ['mapnik',env['BOOST_PYTHON_LIB']]
# TODO - do solaris/fedora need direct linking too? # TODO - do solaris/fedora need direct linking too?
if env['PLATFORM'] == 'Darwin': if env['PLATFORM'] == 'Darwin':
if not env['PYTHON_DYNAMIC_LOOKUP']: if not env['PYTHON_DYNAMIC_LOOKUP']:
libraries.append('png') if env['PNG']:
libraries.append('png')
if env['JPEG']: if env['JPEG']:
libraries.append('jpeg') libraries.append('jpeg')
libraries.append(env['ICU_LIB_NAME']) libraries.append(env['ICU_LIB_NAME'])

View file

@ -20,11 +20,6 @@
* *
*****************************************************************************/ *****************************************************************************/
extern "C"
{
#include <png.h>
}
// boost // boost
#include <boost/python.hpp> #include <boost/python.hpp>
#include <boost/python/module.hpp> #include <boost/python/module.hpp>
@ -35,15 +30,9 @@ extern "C"
#include <mapnik/graphics.hpp> #include <mapnik/graphics.hpp>
#include <mapnik/palette.hpp> #include <mapnik/palette.hpp>
#include <mapnik/image_util.hpp> #include <mapnik/image_util.hpp>
#include <mapnik/png_io.hpp>
#include <mapnik/image_reader.hpp> #include <mapnik/image_reader.hpp>
#include <mapnik/image_compositing.hpp> #include <mapnik/image_compositing.hpp>
// jpeg
#if defined(HAVE_JPEG)
#include <mapnik/jpeg_io.hpp>
#endif
// cairo // cairo
#if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO) #if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO)
#include <mapnik/cairo_context.hpp> #include <mapnik/cairo_context.hpp>

View file

@ -20,23 +20,15 @@
* *
*****************************************************************************/ *****************************************************************************/
extern "C"
{
#include <png.h>
}
#include <boost/python.hpp> #include <boost/python.hpp>
#include <mapnik/image_data.hpp>
#include <mapnik/image_view.hpp>
#include <mapnik/image_util.hpp> #include <mapnik/image_util.hpp>
#include <mapnik/palette.hpp> #include <mapnik/palette.hpp>
#include <mapnik/image_view.hpp> #include <mapnik/image_view.hpp>
#include <mapnik/png_io.hpp>
#include <sstream> #include <sstream>
// jpeg
#if defined(HAVE_JPEG)
#include <mapnik/jpeg_io.hpp>
#endif
using mapnik::image_data_32; using mapnik::image_data_32;
using mapnik::image_view; using mapnik::image_view;
using mapnik::save_to_file; using mapnik::save_to_file;

View file

@ -24,7 +24,6 @@
#define MAPNIK_PNG_IO_HPP #define MAPNIK_PNG_IO_HPP
// mapnik // mapnik
#include <mapnik/global.hpp>
#include <mapnik/palette.hpp> #include <mapnik/palette.hpp>
#include <mapnik/octree.hpp> #include <mapnik/octree.hpp>
#include <mapnik/hextree.hpp> #include <mapnik/hextree.hpp>
@ -32,11 +31,14 @@
#include <mapnik/image_data.hpp> #include <mapnik/image_data.hpp>
// zlib // zlib
#include <zlib.h> #include <zlib.h> // for Z_DEFAULT_COMPRESSION
// boost // boost
#include <boost/scoped_array.hpp> #include <boost/scoped_array.hpp>
// stl
#include <cassert>
extern "C" extern "C"
{ {
#include <png.h> #include <png.h>

View file

@ -20,15 +20,27 @@
* *
*****************************************************************************/ *****************************************************************************/
#if defined(HAVE_PNG)
extern "C" extern "C"
{ {
#include <png.h> #include <png.h>
} }
#endif
// mapnik // mapnik
#include <mapnik/image_util.hpp> #if defined(HAVE_PNG)
#include <mapnik/png_io.hpp> #include <mapnik/png_io.hpp>
#endif
#if defined(HAVE_TIFF)
#include <mapnik/tiff_io.hpp> #include <mapnik/tiff_io.hpp>
#endif
#if defined(HAVE_JPEG)
#include <mapnik/jpeg_io.hpp>
#endif
#include <mapnik/image_util.hpp>
#include <mapnik/image_data.hpp> #include <mapnik/image_data.hpp>
#include <mapnik/graphics.hpp> #include <mapnik/graphics.hpp>
#include <mapnik/memory.hpp> #include <mapnik/memory.hpp>
@ -36,10 +48,6 @@ extern "C"
#include <mapnik/palette.hpp> #include <mapnik/palette.hpp>
#include <mapnik/map.hpp> #include <mapnik/map.hpp>
#include <mapnik/util/conversions.hpp> #include <mapnik/util/conversions.hpp>
// jpeg
#if defined(HAVE_JPEG)
#include <mapnik/jpeg_io.hpp>
#endif
#ifdef HAVE_CAIRO #ifdef HAVE_CAIRO
#include <mapnik/cairo_renderer.hpp> #include <mapnik/cairo_renderer.hpp>
@ -53,7 +61,6 @@ extern "C"
#ifdef CAIRO_HAS_SVG_SURFACE #ifdef CAIRO_HAS_SVG_SURFACE
#include <cairo-svg.h> #include <cairo-svg.h>
#endif // CAIRO_HAS_SVG_SURFACE #endif // CAIRO_HAS_SVG_SURFACE
#endif #endif
// boost // boost
@ -117,6 +124,7 @@ void save_to_file(T const& image,
else throw ImageWriterException("Could not write file to " + filename ); else throw ImageWriterException("Could not write file to " + filename );
} }
#if defined(HAVE_PNG)
void handle_png_options(std::string const& type, void handle_png_options(std::string const& type,
int * colors, int * colors,
int * compression, int * compression,
@ -227,6 +235,7 @@ void handle_png_options(std::string const& type,
} }
} }
} }
#endif
template <typename T> template <typename T>
void save_to_stream(T const& image, 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); std::transform(t.begin(), t.end(), t.begin(), ::tolower);
if (t == "png" || boost::algorithm::starts_with(t, "png")) if (t == "png" || boost::algorithm::starts_with(t, "png"))
{ {
#if defined(HAVE_PNG)
int colors = 256; int colors = 256;
int compression = Z_DEFAULT_COMPRESSION; int compression = Z_DEFAULT_COMPRESSION;
int strategy = Z_DEFAULT_STRATEGY; 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); 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")) else if (boost::algorithm::starts_with(t, "tif"))
{ {
throw ImageWriterException("palettes are not currently supported when writing to tiff format (yet)"); 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")) else if (boost::algorithm::starts_with(t, "jpeg"))
{ {
throw ImageWriterException("palettes are not currently supported when writing to jpeg format"); throw ImageWriterException("palettes are not currently supported when writing to jpeg format");
} }
#endif
else throw ImageWriterException("unknown file type: " + type); else throw ImageWriterException("unknown file type: " + type);
} }
else throw ImageWriterException("Could not write to empty stream" ); 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); std::transform(t.begin(), t.end(), t.begin(), ::tolower);
if (t == "png" || boost::algorithm::starts_with(t, "png")) if (t == "png" || boost::algorithm::starts_with(t, "png"))
{ {
#if defined(HAVE_PNG)
int colors = 256; int colors = 256;
int compression = Z_DEFAULT_COMPRESSION; // usually mapped to z=6 in zlib int compression = Z_DEFAULT_COMPRESSION; // usually mapped to z=6 in zlib
int strategy = Z_DEFAULT_STRATEGY; 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); 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")) else if (boost::algorithm::starts_with(t, "tif"))
{ {
save_as_tiff(stream, image);
}
#if defined(HAVE_JPEG) #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")) else if (boost::algorithm::starts_with(t, "jpeg"))
{ {
#if defined(HAVE_JPEG)
int quality = 85; int quality = 85;
std::string const& val = t.substr(4); std::string const& val = t.substr(4);
if (!val.empty()) if (!val.empty())
@ -348,8 +367,10 @@ void save_to_stream(T const& image,
} }
} }
save_as_jpeg(stream, quality, image); save_as_jpeg(stream, quality, image);
} #else
throw ImageWriterException("jpeg output is not enabled in your build of Mapnik");
#endif #endif
}
else throw ImageWriterException("unknown file type: " + type); else throw ImageWriterException("unknown file type: " + type);
} }
else throw ImageWriterException("Could not write to empty stream" ); else throw ImageWriterException("Could not write to empty stream" );