add initial support for writing image_data_gray16 ( only TIFF supported )

This commit is contained in:
artemp 2015-01-07 18:17:44 +01:00
parent cd0ac2d0f6
commit 00a20b78da
3 changed files with 26 additions and 3 deletions

View File

@ -23,7 +23,6 @@
#ifndef MAPNIK_IMAGE_HPP
#define MAPNIK_IMAGE_HPP
#include <mapnik/noncopyable.hpp>
#include <mapnik/image_data_any.hpp>
namespace mapnik {

View File

@ -261,7 +261,7 @@ struct tag_setter
tiff_config config_;
};
void set_tiff_config(TIFF* output, tiff_config & config)
inline void set_tiff_config(TIFF* output, tiff_config & config)
{
// Set some constant tiff information that doesn't vary based on type of data
// or image size

View File

@ -23,6 +23,9 @@
#include <mapnik/image.hpp>
#include <mapnik/image_reader.hpp>
#include <mapnik/image_util.hpp>
#include <mapnik/tiff_io.hpp>
#include <fstream>
namespace mapnik {
@ -63,8 +66,29 @@ struct save_to_file_visitor
save_to_file(data,filename_, format_);
}
void operator() (image_data_gray16 const& data) const
{
if (format_ == "tiff") // only TIFF supported
{
std::ofstream file (filename_.c_str(), std::ios::out| std::ios::trunc|std::ios::binary);
if (file)
{
tiff_config config;
save_as_tiff(file, data, config);
}
else throw ImageWriterException("Could not write file to " + filename_ );
}
else
{
throw std::runtime_error("Error: saving gray16 image as " + format_ + " is not supported");
}
}
template <typename T>
void operator() (T const& data) const {}
void operator() (T const& data) const
{
throw std::runtime_error("Error: saving " + std::string(typeid(data).name()) + " as " + format_ + " is not supported");
}
std::string const& filename_;
std::string const& format_;