added default point_symbolizer 4x4px black square

This commit is contained in:
Artem Pavlenko 2006-05-22 10:30:55 +00:00
parent 0c745b9d3a
commit ef5931d915
3 changed files with 107 additions and 98 deletions

View file

@ -32,93 +32,93 @@ namespace mapnik
template <class T> class ImageData
{
private:
const unsigned width_;
const unsigned height_;
T *pData_;
ImageData& operator=(const ImageData&);
const unsigned width_;
const unsigned height_;
T *pData_;
ImageData& operator=(const ImageData&);
public:
ImageData(unsigned width,unsigned height)
: width_(width),
height_(height),
pData_((width!=0 && height!=0)? static_cast<T*>(::operator new(sizeof(T)*width*height)):0)
{
if (pData_) memset(pData_,0,sizeof(T)*width_*height_);
}
ImageData(unsigned width,unsigned height)
: width_(width),
height_(height),
pData_((width!=0 && height!=0)? static_cast<T*>(::operator new(sizeof(T)*width*height)):0)
{
if (pData_) memset(pData_,0,sizeof(T)*width_*height_);
}
ImageData(const ImageData<T>& rhs)
:width_(rhs.width_),
height_(rhs.height_),
pData_((rhs.width_!=0 && rhs.height_!=0)? new T[rhs.width_*rhs.height_]:0)
{
if (pData_) memcpy(pData_,rhs.pData_,sizeof(T)*rhs.width_* rhs.height_);
}
inline T& operator() (unsigned i,unsigned j)
{
assert(i<width_ && j<height_);
return pData_[j*width_+i];
}
inline const T& operator() (unsigned i,unsigned j) const
{
assert(i<width_ && j<height_);
return pData_[j*width_+i];
}
inline unsigned width() const
{
return width_;
}
inline unsigned height() const
{
return height_;
}
inline void set(const T& t)
{
for (unsigned i=0;i<width_;++i)
{
for (unsigned j=0;j<height_;++j)
{
(*this)(i,j)=t;
}
}
}
inline const T* getData() const
{
return pData_;
}
ImageData(const ImageData<T>& rhs)
:width_(rhs.width_),
height_(rhs.height_),
pData_((rhs.width_!=0 && rhs.height_!=0)? new T[rhs.width_*rhs.height_]:0)
{
if (pData_) memcpy(pData_,rhs.pData_,sizeof(T)*rhs.width_* rhs.height_);
}
inline T& operator() (unsigned i,unsigned j)
{
assert(i<width_ && j<height_);
return pData_[j*width_+i];
}
inline const T& operator() (unsigned i,unsigned j) const
{
assert(i<width_ && j<height_);
return pData_[j*width_+i];
}
inline unsigned width() const
{
return width_;
}
inline unsigned height() const
{
return height_;
}
inline void set(const T& t)
{
for (unsigned i=0;i<width_;++i)
{
for (unsigned j=0;j<height_;++j)
{
(*this)(i,j)=t;
}
}
}
inline const T* getData() const
{
return pData_;
}
inline T* getData()
{
return pData_;
}
inline T* getData()
{
return pData_;
}
inline const unsigned char* getBytes() const
{
return (unsigned char*)pData_;
}
inline const unsigned char* getBytes() const
{
return (unsigned char*)pData_;
}
inline unsigned char* getBytes()
{
return (unsigned char*)pData_;
}
inline unsigned char* getBytes()
{
return (unsigned char*)pData_;
}
inline const T* getRow(unsigned row) const
{
return pData_+row*width_;
}
inline void setRow(unsigned row,const T* buf,unsigned size)
{
assert(row<height_);
assert(size<=(width_*sizeof(T)));
memcpy(pData_+row*width_,buf,size*sizeof(T));
}
inline void setRow(unsigned row,unsigned x0,unsigned x1,const T* buf)
{
memcpy(pData_+row*width_+x0,buf,(x1-x0)*sizeof(T));
}
inline const T* getRow(unsigned row) const
{
return pData_+row*width_;
}
inline void setRow(unsigned row,const T* buf,unsigned size)
{
assert(row<height_);
assert(size<=(width_*sizeof(T)));
memcpy(pData_+row*width_,buf,size*sizeof(T));
}
inline void setRow(unsigned row,unsigned x0,unsigned x1,const T* buf)
{
memcpy(pData_+row*width_+x0,buf,(x1-x0)*sizeof(T));
}
inline ~ImageData()
{
::operator delete(pData_),pData_=0;
}
inline ~ImageData()
{
::operator delete(pData_),pData_=0;
}
};

View file

@ -31,6 +31,7 @@ namespace mapnik
{
struct MAPNIK_DECL point_symbolizer
{
explicit point_symbolizer();
point_symbolizer(std::string const& file,
std::string const& type,
unsigned width,unsigned height);

View file

@ -22,38 +22,46 @@
//$Id$
#include <boost/scoped_ptr.hpp>
#include "point_symbolizer.hpp"
#include "image_data.hpp"
#include "image_reader.hpp"
namespace mapnik
{
point_symbolizer::point_symbolizer(std::string const& file,
std::string const& type,
unsigned width,unsigned height)
: symbol_(new ImageData32(width,height))
point_symbolizer::point_symbolizer()
: symbol_(new ImageData32(4,4))
{
try
{
std::auto_ptr<ImageReader> reader(get_image_reader(type,file));
if (reader.get())
{
reader->read(0,0,*symbol_);
}
}
catch (...)
{
std::clog<<"exception caught..." << std::endl;
}
//default point symbol is black 4x4px square
symbol_->set(0xff000000);
}
point_symbolizer::point_symbolizer(std::string const& file,
std::string const& type,
unsigned width,unsigned height)
: symbol_(new ImageData32(width,height))
{
try
{
boost::scoped_ptr<ImageReader> reader(get_image_reader(type,file));
if (reader.get())
{
reader->read(0,0,*symbol_);
}
}
catch (...)
{
std::clog<<"exception caught..." << std::endl;
}
}
point_symbolizer::point_symbolizer(point_symbolizer const& rhs)
: symbol_(rhs.symbol_)
: symbol_(rhs.symbol_)
{}
ImageData32 const& point_symbolizer::get_data() const
{
return *(symbol_.get());
return *(symbol_.get());
}
}