Changeset 652

Show
Ignore:
Timestamp:
02/19/08 06:28:20 (9 months ago)
Author:
artem
Message:

implemented Image open method :

im = Image.open("map.png")


Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/bindings/python/mapnik_image.cpp

    r642 r652  
    3636#include <mapnik/jpeg_io.hpp> 
    3737#include <mapnik/png_io.hpp> 
     38#include <mapnik/image_reader.hpp> 
    3839#include <sstream> 
    3940 
    4041using mapnik::Image32; 
     42using mapnik::ImageReader; 
     43using mapnik::get_image_reader; 
     44using mapnik::type_from_filename; 
    4145using namespace boost::python; 
    4246using mapnik::save_to_file; 
     
    6367void (*save_to_file2)( mapnik::Image32 const&, std::string const&) = mapnik::save_to_file; 
    6468 
     69boost::shared_ptr<Image32> open_from_file(std::string const& filename) 
     70{ 
     71   std::auto_ptr<ImageReader> reader(get_image_reader(filename,type_from_filename(filename))); 
     72   if (reader.get()) 
     73   { 
     74      boost::shared_ptr<Image32> image_ptr(new Image32(reader->width(),reader->height())); 
     75      reader->read(0,0,image_ptr->data()); 
     76      return image_ptr; 
     77   } 
     78   throw mapnik::ImageReaderException("FIXME: " + filename);   
     79} 
     80 
    6581void blend (Image32 & im, unsigned x, unsigned y, Image32 const& im2, float opacity) 
    6682{ 
     
    7187{ 
    7288    using namespace boost::python; 
    73     class_<Image32>("Image","This class represents a 32 bit RGBA image.",init<int,int>()) 
     89    class_<Image32,boost::shared_ptr<Image32> >("Image","This class represents a 32 bit RGBA image.",init<int,int>()) 
    7490       .def("width",&Image32::width) 
    7591       .def("height",&Image32::height) 
     
    8399       .def("save", save_to_file1) 
    84100       .def("save", save_to_file2) 
     101       .def("open",open_from_file) 
     102       .staticmethod("open") 
    85103       ;     
     104     
    86105}