diff --git a/include/color.hpp b/include/color.hpp index 653408901..dd52f048a 100644 --- a/include/color.hpp +++ b/include/color.hpp @@ -100,11 +100,11 @@ namespace mapnik { } inline std::string to_string() const - { + { std::stringstream ss; ss << "rgb (" << red() << "," << green() << "," << blue() <<")"; return ss.str(); - } + } }; } diff --git a/include/layer.hpp b/include/layer.hpp index c104c021c..f161ba3f3 100644 --- a/include/layer.hpp +++ b/include/layer.hpp @@ -53,11 +53,9 @@ namespace mapnik double maxZoom_; bool active_; bool selectable_; - - std::vector styles_; - std::string selection_style_; - mutable datasource_p ds_; + std::vector styles_; + std::string selection_style_; mutable std::vector > selection_; public: diff --git a/include/mapnik.hpp b/include/mapnik.hpp index 5e08e5aa9..ac77672ae 100644 --- a/include/mapnik.hpp +++ b/include/mapnik.hpp @@ -78,8 +78,8 @@ namespace mapnik { - void save_to_xml(Map const& map,const char* filename); - void load_from_xml(Map & map, const char * filename); + void MAPNIK_DECL save_to_xml(Map const& map,const char* filename); + void MAPNIK_DECL load_from_xml(Map & map, const char * filename); } #endif //MAPNIK_HPP diff --git a/src/layer.cpp b/src/layer.cpp index 943960f18..d67751439 100644 --- a/src/layer.cpp +++ b/src/layer.cpp @@ -85,11 +85,11 @@ namespace mapnik maxZoom_=rhs.maxZoom_; active_=rhs.active_; selectable_=rhs.selectable_; - //ds_=rhs.ds_; styles_=rhs.styles_; + ds_=rhs.ds_; selection_style_=rhs.selection_style_; } - + Layer::~Layer() {} parameters const& Layer::params() const diff --git a/src/line_pattern_symbolizer.cpp b/src/line_pattern_symbolizer.cpp index ded56ef73..6df471180 100644 --- a/src/line_pattern_symbolizer.cpp +++ b/src/line_pattern_symbolizer.cpp @@ -37,7 +37,8 @@ namespace mapnik try { std::auto_ptr reader(get_image_reader(type,file)); - reader->read(0,0,*pattern_); + if (reader.get()) + reader->read(0,0,*pattern_); } catch (...) { diff --git a/src/png_reader.cpp b/src/png_reader.cpp index f508a7b0c..b6787ce75 100644 --- a/src/png_reader.cpp +++ b/src/png_reader.cpp @@ -31,170 +31,185 @@ namespace mapnik class PngReader : public ImageReader { private: - std::string fileName_; - unsigned width_; - unsigned height_; - int bit_depth_; - int color_type_; + std::string fileName_; + unsigned width_; + unsigned height_; + int bit_depth_; + int color_type_; public: - explicit PngReader(const std::string& fileName); - ~PngReader(); - unsigned width() const; - unsigned height() const; - void read(unsigned x,unsigned y,ImageData32& image); + explicit PngReader(const std::string& fileName); + ~PngReader(); + unsigned width() const; + unsigned height() const; + void read(unsigned x,unsigned y,ImageData32& image); private: - PngReader(const PngReader&); - PngReader& operator=(const PngReader&); - void init(); + PngReader(const PngReader&); + PngReader& operator=(const PngReader&); + void init(); }; - + namespace { - ImageReader* createPngReader(const std::string& file) - { - return new PngReader(file); - } - const bool registered = register_image_reader("png",createPngReader); + ImageReader* createPngReader(const std::string& file) + { + return new PngReader(file); + } + const bool registered = register_image_reader("png",createPngReader); } PngReader::PngReader(const std::string& fileName) - : fileName_(fileName), + : fileName_(fileName), width_(0), height_(0), bit_depth_(0), color_type_(0) { - try - { - init(); - } - catch (const ImageReaderException& e) - { - std::clog<io_ptr); + + if (check != length) + { + png_error(png_ptr, "Read Error"); + } + } + + void PngReader::init() { - FILE *fp=fopen(fileName_.c_str(),"r"); - if (!fp) throw ImageReaderException("cannot open image file "+fileName_); - png_byte header[8]; - memset(header,0,8); - fread(header,1,8,fp); - int is_png=!png_sig_cmp(header,0,8); - if (!is_png) - { - fclose(fp); - throw ImageReaderException(fileName_ + " is not a png file"); - } + FILE *fp=fopen(fileName_.c_str(),"rb"); + if (!fp) throw ImageReaderException("cannot open image file "+fileName_); + png_byte header[8]; + memset(header,0,8); + fread(header,1,8,fp); + int is_png=!png_sig_cmp(header,0,8); + if (!is_png) + { + fclose(fp); + throw ImageReaderException(fileName_ + " is not a png file"); + } png_structp png_ptr = png_create_read_struct - (PNG_LIBPNG_VER_STRING,0,0,0); - - if (!png_ptr) - { - fclose(fp); - throw ImageReaderException("failed to allocate png_ptr"); - } - png_infop info_ptr = png_create_info_struct(png_ptr); - if (!info_ptr) - { - png_destroy_read_struct(&png_ptr,0,0); - fclose(fp); - throw ImageReaderException("failed to create info_ptr"); - } + (PNG_LIBPNG_VER_STRING,0,0,0); - png_init_io(png_ptr, fp); - png_set_sig_bytes(png_ptr,8); - png_read_info(png_ptr, info_ptr); + if (!png_ptr) + { + fclose(fp); + throw ImageReaderException("failed to allocate png_ptr"); + } + png_infop info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + { + png_destroy_read_struct(&png_ptr,0,0); + fclose(fp); + throw ImageReaderException("failed to create info_ptr"); + } - png_uint_32 width, height; - png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth_, &color_type_,0,0,0); - - width_=width; - height_=height; - - std::clog<<"bit_depth="<=libpng 1.2.7 - png_set_add_alpha(png_ptr,1,1); - - double gamma; - if (png_get_gAMA(png_ptr, info_ptr, &gamma)) - png_set_gamma(png_ptr, 2.2, gamma); + if (!png_ptr) + { + fclose(fp); + throw ImageReaderException("failed to allocate png_ptr"); + } - png_read_update_info(png_ptr, info_ptr); - - //START read image rows - unsigned w=std::min((unsigned)image.width(),width_); - unsigned h=std::min((unsigned)image.height(),height_); - - unsigned rowbytes=png_get_rowbytes(png_ptr, info_ptr); - unsigned char* row= new unsigned char[rowbytes]; - for (unsigned i=0;i=y0 && i=libpng 1.2.7 + png_set_add_alpha(png_ptr,1,1); + + double gamma; + if (png_get_gAMA(png_ptr, info_ptr, &gamma)) + png_set_gamma(png_ptr, 2.2, gamma); + + png_read_update_info(png_ptr, info_ptr); + + //START read image rows + unsigned w=std::min((unsigned)image.width(),width_); + unsigned h=std::min((unsigned)image.height(),height_); + + unsigned rowbytes=png_get_rowbytes(png_ptr, info_ptr); + unsigned char* row= new unsigned char[rowbytes]; + for (unsigned i=0;i=y0 && i reader(get_image_reader(type,file)); - reader->read(0,0,*symbol_); + if (reader.get()) + { + reader->read(0,0,*symbol_); + } } catch (...) { diff --git a/src/polygon_pattern_symbolizer.cpp b/src/polygon_pattern_symbolizer.cpp index 6754cce29..6d83c43d7 100644 --- a/src/polygon_pattern_symbolizer.cpp +++ b/src/polygon_pattern_symbolizer.cpp @@ -36,7 +36,8 @@ namespace mapnik try { std::auto_ptr reader(get_image_reader(type,file)); - reader->read(0,0,*pattern_); + if (reader.get()) + reader->read(0,0,*pattern_); } catch (...) { diff --git a/src/tiff_reader.cpp b/src/tiff_reader.cpp index cb5523b41..978221cba 100644 --- a/src/tiff_reader.cpp +++ b/src/tiff_reader.cpp @@ -29,9 +29,9 @@ namespace mapnik { - using std::min; - using std::max; - + using std::min; + using std::max; + class TiffReader : public ImageReader { private: @@ -44,11 +44,11 @@ namespace mapnik int tile_height_; public: enum - { - generic=1, - stripped, - tiled - }; + { + generic=1, + stripped, + tiled + }; explicit TiffReader(const std::string& file_name); virtual ~TiffReader(); unsigned width() const; @@ -65,16 +65,16 @@ namespace mapnik namespace { - ImageReader* createTiffReader(const std::string& file) - { - return new TiffReader(file); - } + ImageReader* createTiffReader(const std::string& file) + { + return new TiffReader(file); + } - const bool registered = register_image_reader("tiff",createTiffReader); + const bool registered = register_image_reader("tiff",createTiffReader); } TiffReader::TiffReader(const std::string& file_name) - : file_name_(file_name), + : file_name_(file_name), read_method_(generic), width_(0), height_(0), @@ -82,177 +82,177 @@ namespace mapnik tile_width_(0), tile_height_(0) { - try - { - init(); - } - catch (ImageReaderException& ex) - { - std::clog<=n0;--n) - { - image.setRow(row,tx0-x0,tx1-x0,(const unsigned*)&buf[n*tile_width_+tx0-x]); - ++row; - } - } - } - _TIFFfree(buf); - TIFFClose(tif); - } + if (!TIFFReadRGBATile(tif,x,y,buf)) break; + + tx0=max(x0,(unsigned)x); + tx1=min(width+x0,(unsigned)(x+tile_width_)); + row=y+ty0-y0; + for (int n=n1;n>=n0;--n) + { + image.setRow(row,tx0-x0,tx1-x0,(const unsigned*)&buf[n*tile_width_+tx0-x]); + ++row; + } + } + } + _TIFFfree(buf); + TIFFClose(tif); + } } void TiffReader::read_stripped(unsigned x0,unsigned y0,ImageData32& image) { - TIFF* tif = TIFFOpen(file_name_.c_str(), "r"); - if (tif) - { - uint32* buf = (uint32*)_TIFFmalloc(width_*rows_per_strip_*sizeof(uint32)); + TIFF* tif = TIFFOpen(file_name_.c_str(), "rb"); + if (tif) + { + uint32* buf = (uint32*)_TIFFmalloc(width_*rows_per_strip_*sizeof(uint32)); - int width=image.width(); - int height=image.height(); - - unsigned start_y=(y0/rows_per_strip_)*rows_per_strip_; - unsigned end_y=((y0+height)/rows_per_strip_+1)*rows_per_strip_; - bool laststrip=((unsigned)end_y > height_)?true:false; - int row,tx0,tx1,ty0,ty1; + int width=image.width(); + int height=image.height(); - tx0=x0; - tx1=min(width+x0,(unsigned)width_); + unsigned start_y=(y0/rows_per_strip_)*rows_per_strip_; + unsigned end_y=((y0+height)/rows_per_strip_+1)*rows_per_strip_; + bool laststrip=((unsigned)end_y > height_)?true:false; + int row,tx0,tx1,ty0,ty1; - for (unsigned y=start_y; y < end_y; y+=rows_per_strip_) - { - ty0 = max(y0,y)-y; - ty1 = min(height+y0,y+rows_per_strip_)-y; + tx0=x0; + tx1=min(width+x0,(unsigned)width_); - if (!TIFFReadRGBAStrip(tif,y,buf)) break; - - row=y+ty0-y0; - - int n0=laststrip ? 0:(rows_per_strip_-ty1); - int n1=laststrip ? (ty1-ty0-1):(rows_per_strip_-ty0-1); - for (int n=n1;n>=n0;--n) - { - image.setRow(row,tx0-x0,tx1-x0,(const unsigned*)&buf[n*width_+tx0]); - ++row; - } - } - _TIFFfree(buf); - TIFFClose(tif); - } + for (unsigned y=start_y; y < end_y; y+=rows_per_strip_) + { + ty0 = max(y0,y)-y; + ty1 = min(height+y0,y+rows_per_strip_)-y; + + if (!TIFFReadRGBAStrip(tif,y,buf)) break; + + row=y+ty0-y0; + + int n0=laststrip ? 0:(rows_per_strip_-ty1); + int n1=laststrip ? (ty1-ty0-1):(rows_per_strip_-ty0-1); + for (int n=n1;n>=n0;--n) + { + image.setRow(row,tx0-x0,tx1-x0,(const unsigned*)&buf[n*width_+tx0]); + ++row; + } + } + _TIFFfree(buf); + TIFFClose(tif); + } } }