+ mapnik-centralise-image-tostring-functions.patch (jonb)
(moves Image.tostring() to core c++ code)
This commit is contained in:
parent
97ad49c067
commit
8b298729bf
4 changed files with 37 additions and 12 deletions
|
@ -60,12 +60,8 @@ PyObject* tostring1( Image32 const& im)
|
|||
// encode (png,jpeg)
|
||||
PyObject* tostring2(Image32 const & im, std::string const& format)
|
||||
{
|
||||
std::ostringstream ss(std::ios::out|std::ios::binary);
|
||||
if (format == "png") save_as_png(ss,im.data());
|
||||
else if (format == "png256") save_as_png256(ss,im.data());
|
||||
else if (format == "jpeg") save_as_jpeg(ss,85,im.data());
|
||||
else throw mapnik::ImageWriterException("unknown format: " + format);
|
||||
return ::PyString_FromStringAndSize((const char*)ss.str().c_str(),ss.str().size());
|
||||
std::string s = save_to_string(im, format);
|
||||
return ::PyString_FromStringAndSize(s.data(),s.size());
|
||||
}
|
||||
|
||||
void (*save_to_file1)( mapnik::Image32 const&, std::string const&,std::string const&) = mapnik::save_to_file;
|
||||
|
|
|
@ -52,12 +52,8 @@ PyObject* view_tostring1(image_view<ImageData32> const& view)
|
|||
// encode (png,jpeg)
|
||||
PyObject* view_tostring2(image_view<ImageData32> const & view, std::string const& format)
|
||||
{
|
||||
std::ostringstream ss(std::ios::out|std::ios::binary);
|
||||
if (format == "png") save_as_png(ss,view);
|
||||
else if (format == "png256") save_as_png256(ss,view);
|
||||
else if (format == "jpeg") save_as_jpeg(ss,85,view);
|
||||
else throw mapnik::ImageWriterException("unknown format: " + format);
|
||||
return ::PyString_FromStringAndSize((const char*)ss.str().c_str(),ss.str().size());
|
||||
std::string s = save_to_string(view, format);
|
||||
return ::PyString_FromStringAndSize(s.data(),s.size());
|
||||
}
|
||||
|
||||
void (*save_view1)(image_view<ImageData32> const&, std::string const&,std::string const&) = mapnik::save_to_file;
|
||||
|
|
|
@ -62,6 +62,10 @@ namespace mapnik {
|
|||
MAPNIK_DECL void save_to_file(T const& image,
|
||||
std::string const& filename);
|
||||
|
||||
template <typename T>
|
||||
MAPNIK_DECL std::string save_to_string(T const& image,
|
||||
std::string const& type);
|
||||
|
||||
template <typename T>
|
||||
void save_as_png(T const& image,
|
||||
std::string const& filename);
|
||||
|
@ -280,6 +284,12 @@ namespace mapnik {
|
|||
{
|
||||
save_to_file<ImageData32>(image.data(),file);
|
||||
}
|
||||
|
||||
inline MAPNIK_DECL std::string save_to_string(Image32 const& image,
|
||||
std::string const& type)
|
||||
{
|
||||
return save_to_string<ImageData32>(image.data(),type);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
template MAPNIK_DECL void save_to_file<ImageData32>(ImageData32 const&,
|
||||
|
@ -287,6 +297,8 @@ namespace mapnik {
|
|||
std::string const&);
|
||||
template MAPNIK_DECL void save_to_file<ImageData32>(ImageData32 const&,
|
||||
std::string const&);
|
||||
template MAPNIK_DECL std::string save_to_string<ImageData32>(ImageData32 const&,
|
||||
std::string const&);
|
||||
|
||||
template MAPNIK_DECL void save_to_file<image_view<ImageData32> > (image_view<ImageData32> const&,
|
||||
std::string const&,
|
||||
|
@ -295,6 +307,8 @@ namespace mapnik {
|
|||
template MAPNIK_DECL void save_to_file<image_view<ImageData32> > (image_view<ImageData32> const&,
|
||||
std::string const&);
|
||||
|
||||
template MAPNIK_DECL std:string save_to_string<image_view<ImageData32> > (image_view<ImageData32> const&,
|
||||
std::string const&);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
|
@ -37,6 +37,19 @@
|
|||
|
||||
namespace mapnik
|
||||
{
|
||||
template <typename T>
|
||||
std::string save_to_string(T const& image,
|
||||
std::string const& type)
|
||||
{
|
||||
std::ostringstream ss(std::ios::out|std::ios::binary);
|
||||
//all this should go into image_writer factory
|
||||
if (type=="png") save_as_png(ss,image);
|
||||
else if (type == "png256") save_as_png256(ss,image);
|
||||
else if (type=="jpeg") save_as_jpeg(ss,85,image);
|
||||
else throw ImageWriterException("unknown file type: " + type);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void save_to_file(T const& image,
|
||||
std::string const& filename,
|
||||
|
@ -68,6 +81,9 @@ namespace mapnik
|
|||
template void save_to_file<ImageData32>(ImageData32 const&,
|
||||
std::string const&);
|
||||
|
||||
template std::string save_to_string<ImageData32>(ImageData32 const&,
|
||||
std::string const&);
|
||||
|
||||
template void save_to_file<image_view<ImageData32> > (image_view<ImageData32> const&,
|
||||
std::string const&,
|
||||
std::string const&);
|
||||
|
@ -75,4 +91,7 @@ namespace mapnik
|
|||
template void save_to_file<image_view<ImageData32> > (image_view<ImageData32> const&,
|
||||
std::string const&);
|
||||
|
||||
template std::string save_to_string<image_view<ImageData32> > (image_view<ImageData32> const&,
|
||||
std::string const&);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue