make PNG and TIFF support optional - closes #1704
This commit is contained in:
parent
c9635ef5a3
commit
b1c1c86346
6 changed files with 72 additions and 44 deletions
41
SConstruct
41
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)
|
||||
|
|
|
@ -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'])
|
||||
|
|
|
@ -20,11 +20,6 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include <png.h>
|
||||
}
|
||||
|
||||
// boost
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/python/module.hpp>
|
||||
|
@ -35,15 +30,9 @@ extern "C"
|
|||
#include <mapnik/graphics.hpp>
|
||||
#include <mapnik/palette.hpp>
|
||||
#include <mapnik/image_util.hpp>
|
||||
#include <mapnik/png_io.hpp>
|
||||
#include <mapnik/image_reader.hpp>
|
||||
#include <mapnik/image_compositing.hpp>
|
||||
|
||||
// jpeg
|
||||
#if defined(HAVE_JPEG)
|
||||
#include <mapnik/jpeg_io.hpp>
|
||||
#endif
|
||||
|
||||
// cairo
|
||||
#if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO)
|
||||
#include <mapnik/cairo_context.hpp>
|
||||
|
|
|
@ -20,23 +20,15 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include <png.h>
|
||||
}
|
||||
|
||||
#include <boost/python.hpp>
|
||||
#include <mapnik/image_data.hpp>
|
||||
#include <mapnik/image_view.hpp>
|
||||
#include <mapnik/image_util.hpp>
|
||||
#include <mapnik/palette.hpp>
|
||||
#include <mapnik/image_view.hpp>
|
||||
#include <mapnik/png_io.hpp>
|
||||
#include <sstream>
|
||||
|
||||
// jpeg
|
||||
#if defined(HAVE_JPEG)
|
||||
#include <mapnik/jpeg_io.hpp>
|
||||
#endif
|
||||
|
||||
using mapnik::image_data_32;
|
||||
using mapnik::image_view;
|
||||
using mapnik::save_to_file;
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#define MAPNIK_PNG_IO_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/global.hpp>
|
||||
#include <mapnik/palette.hpp>
|
||||
#include <mapnik/octree.hpp>
|
||||
#include <mapnik/hextree.hpp>
|
||||
|
@ -32,11 +31,14 @@
|
|||
#include <mapnik/image_data.hpp>
|
||||
|
||||
// zlib
|
||||
#include <zlib.h>
|
||||
#include <zlib.h> // for Z_DEFAULT_COMPRESSION
|
||||
|
||||
// boost
|
||||
#include <boost/scoped_array.hpp>
|
||||
|
||||
// stl
|
||||
#include <cassert>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include <png.h>
|
||||
|
|
|
@ -20,15 +20,27 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#if defined(HAVE_PNG)
|
||||
extern "C"
|
||||
{
|
||||
#include <png.h>
|
||||
}
|
||||
#endif
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/image_util.hpp>
|
||||
#if defined(HAVE_PNG)
|
||||
#include <mapnik/png_io.hpp>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_TIFF)
|
||||
#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/graphics.hpp>
|
||||
#include <mapnik/memory.hpp>
|
||||
|
@ -36,10 +48,6 @@ extern "C"
|
|||
#include <mapnik/palette.hpp>
|
||||
#include <mapnik/map.hpp>
|
||||
#include <mapnik/util/conversions.hpp>
|
||||
// jpeg
|
||||
#if defined(HAVE_JPEG)
|
||||
#include <mapnik/jpeg_io.hpp>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CAIRO
|
||||
#include <mapnik/cairo_renderer.hpp>
|
||||
|
@ -53,7 +61,6 @@ extern "C"
|
|||
#ifdef CAIRO_HAS_SVG_SURFACE
|
||||
#include <cairo-svg.h>
|
||||
#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 <typename T>
|
||||
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" );
|
||||
|
|
Loading…
Reference in a new issue