TIFF I/O - use memory mapping in tiff_reader.cpp when MAPNIK_MEMORY_MAPPED_FILE is defined.

This commit is contained in:
artemp 2017-05-22 16:29:22 +02:00
parent 34a622f48e
commit 3a475517c0
2 changed files with 39 additions and 22 deletions

View file

@ -113,11 +113,13 @@ struct tiff_io_traits
using input_stream_type = std::istream; using input_stream_type = std::istream;
}; };
#if defined(MAPNIK_MEMORY_MAPPED_FILE)
template <> template <>
struct tiff_io_traits<boost::interprocess::ibufferstream> struct tiff_io_traits<boost::interprocess::ibufferstream>
{ {
using input_stream_type = boost::interprocess::ibufferstream; using input_stream_type = boost::interprocess::ibufferstream;
}; };
#endif
} }
template <typename T> template <typename T>
@ -208,8 +210,11 @@ namespace
image_reader* create_tiff_reader(std::string const& filename) image_reader* create_tiff_reader(std::string const& filename)
{ {
//return new tiff_reader<std::filebuf>(filename); #if defined(MAPNIK_MEMORY_MAPPED_FILE)
return new tiff_reader<boost::interprocess::ibufferstream>(filename); return new tiff_reader<boost::interprocess::ibufferstream>(filename);
#else
return new tiff_reader<std::filebuf>(filename);
#endif
} }
image_reader* create_tiff_reader2(char const * data, std::size_t size) image_reader* create_tiff_reader2(char const * data, std::size_t size)
@ -224,23 +229,29 @@ const bool registered2 = register_image_reader("tiff", create_tiff_reader2);
template <typename T> template <typename T>
tiff_reader<T>::tiff_reader(std::string const& filename) tiff_reader<T>::tiff_reader(std::string const& filename)
: source_(), :
stream_(),//&source_), #if defined(MAPNIK_MEMORY_MAPPED_FILE)
tif_(nullptr), stream_(),
read_method_(generic), #else
rows_per_strip_(0), source_(),
tile_width_(0), stream_(&source_),
tile_height_(0), #endif
width_(0),
height_(0), tif_(nullptr),
bps_(0), read_method_(generic),
sample_format_(SAMPLEFORMAT_UINT), rows_per_strip_(0),
photometric_(0), tile_width_(0),
bands_(1), tile_height_(0),
planar_config_(PLANARCONFIG_CONTIG), width_(0),
compression_(COMPRESSION_NONE), height_(0),
has_alpha_(false), bps_(0),
is_tiled_(false) sample_format_(SAMPLEFORMAT_UINT),
photometric_(0),
bands_(1),
planar_config_(PLANARCONFIG_CONTIG),
compression_(COMPRESSION_NONE),
has_alpha_(false),
is_tiled_(false)
{ {
#if defined(MAPNIK_MEMORY_MAPPED_FILE) #if defined(MAPNIK_MEMORY_MAPPED_FILE)

View file

@ -14,8 +14,14 @@
#include <boost/interprocess/streams/bufferstream.hpp> #include <boost/interprocess/streams/bufferstream.hpp>
#include "../../../src/tiff_reader.cpp" #include "../../../src/tiff_reader.cpp"
#if defined(MAPNIK_MEMORY_MAPPED_FILE)
using source_type = boost::interprocess::ibufferstream;
#else
using source_type = std::filebuf;
#endif
#define TIFF_ASSERT(filename) \ #define TIFF_ASSERT(filename) \
mapnik::tiff_reader<boost::interprocess::ibufferstream> tiff_reader(filename); \ mapnik::tiff_reader<source_type> tiff_reader(filename); \
REQUIRE( tiff_reader.width() == 256 ); \ REQUIRE( tiff_reader.width() == 256 ); \
REQUIRE( tiff_reader.height() == 256 ); \ REQUIRE( tiff_reader.height() == 256 ); \
REQUIRE( tiff_reader.planar_config() == PLANARCONFIG_CONTIG ); \ REQUIRE( tiff_reader.planar_config() == PLANARCONFIG_CONTIG ); \
@ -141,7 +147,7 @@ void test_tiff_reader(std::string const& pattern)
if (boost::iends_with(path,".tif") if (boost::iends_with(path,".tif")
&& boost::istarts_with(mapnik::util::basename(path), pattern)) && boost::istarts_with(mapnik::util::basename(path), pattern))
{ {
mapnik::tiff_reader< boost::interprocess::ibufferstream> tiff_reader(path); mapnik::tiff_reader<source_type> tiff_reader(path);
auto width = tiff_reader.width(); auto width = tiff_reader.width();
auto height = tiff_reader.height(); auto height = tiff_reader.height();
{ {
@ -180,7 +186,7 @@ TEST_CASE("tiff io")
SECTION("scan rgb8 striped") SECTION("scan rgb8 striped")
{ {
std::string filename("./test/data/tiff/scan_512x512_rgb8_striped.tif"); std::string filename("./test/data/tiff/scan_512x512_rgb8_striped.tif");
mapnik::tiff_reader< boost::interprocess::ibufferstream> tiff_reader(filename); mapnik::tiff_reader<source_type> tiff_reader(filename);
REQUIRE( tiff_reader.width() == 512 ); REQUIRE( tiff_reader.width() == 512 );
REQUIRE( tiff_reader.height() == 512 ); REQUIRE( tiff_reader.height() == 512 );
REQUIRE( tiff_reader.planar_config() == PLANARCONFIG_CONTIG ); REQUIRE( tiff_reader.planar_config() == PLANARCONFIG_CONTIG );
@ -210,7 +216,7 @@ TEST_CASE("tiff io")
SECTION("scan rgb8 tiled") { SECTION("scan rgb8 tiled") {
std::string filename("./test/data/tiff/scan_512x512_rgb8_tiled.tif"); std::string filename("./test/data/tiff/scan_512x512_rgb8_tiled.tif");
mapnik::tiff_reader< boost::interprocess::ibufferstream> tiff_reader(filename); mapnik::tiff_reader<source_type> tiff_reader(filename);
REQUIRE( tiff_reader.width() == 512 ); REQUIRE( tiff_reader.width() == 512 );
REQUIRE( tiff_reader.height() == 512 ); REQUIRE( tiff_reader.height() == 512 );
REQUIRE( tiff_reader.planar_config() == PLANARCONFIG_CONTIG ); REQUIRE( tiff_reader.planar_config() == PLANARCONFIG_CONTIG );