allow external image data - refs #2002
This commit is contained in:
parent
8457f8a852
commit
96a93c4b14
2 changed files with 34 additions and 5 deletions
|
@ -39,9 +39,10 @@ template <class T> class ImageData
|
|||
public:
|
||||
typedef T pixel_type;
|
||||
|
||||
ImageData(int width,int height)
|
||||
ImageData(int width, int height)
|
||||
: width_(static_cast<unsigned>(width)),
|
||||
height_(static_cast<unsigned>(height))
|
||||
height_(static_cast<unsigned>(height)),
|
||||
owns_data_(true)
|
||||
{
|
||||
if (width < 0)
|
||||
{
|
||||
|
@ -55,9 +56,26 @@ public:
|
|||
if (pData_) std::memset(pData_,0,sizeof(T)*width_*height_);
|
||||
}
|
||||
|
||||
ImageData(int width, int height, T * data)
|
||||
: width_(static_cast<unsigned>(width)),
|
||||
height_(static_cast<unsigned>(height)),
|
||||
owns_data_(false),
|
||||
pData_(data)
|
||||
{
|
||||
if (width < 0)
|
||||
{
|
||||
throw std::runtime_error("negative width not allowed for image_data");
|
||||
}
|
||||
if (height < 0)
|
||||
{
|
||||
throw std::runtime_error("negative height not allowed for image_data");
|
||||
}
|
||||
}
|
||||
|
||||
ImageData(const ImageData<T>& rhs)
|
||||
:width_(rhs.width_),
|
||||
height_(rhs.height_),
|
||||
owns_data_(true),
|
||||
pData_((rhs.width_!=0 && rhs.height_!=0)?
|
||||
static_cast<T*>(::operator new(sizeof(T)*rhs.width_*rhs.height_)) :0)
|
||||
{
|
||||
|
@ -136,14 +154,18 @@ public:
|
|||
|
||||
inline ~ImageData()
|
||||
{
|
||||
::operator delete(pData_),pData_=0;
|
||||
if (owns_data_)
|
||||
{
|
||||
::operator delete(pData_),pData_=0;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const unsigned width_;
|
||||
const unsigned height_;
|
||||
bool owns_data_;
|
||||
T *pData_;
|
||||
ImageData& operator=(const ImageData&);
|
||||
ImageData& operator=(ImageData const&);
|
||||
};
|
||||
|
||||
typedef ImageData<unsigned> image_data_32;
|
||||
|
|
|
@ -23,8 +23,15 @@ int main(int argc, char** argv)
|
|||
boost::optional<std::string> type;
|
||||
try
|
||||
{
|
||||
BOOST_TEST(set_working_dir(args));
|
||||
mapnik::image_data_32 im(256,256);
|
||||
unsigned char* bytes = im.getBytes();
|
||||
mapnik::image_data_32 * im_ptr = new mapnik::image_data_32(256,256,(unsigned int *)bytes);
|
||||
unsigned char* same_bytes = im_ptr->getBytes();
|
||||
BOOST_TEST(bytes == same_bytes);
|
||||
delete im_ptr;
|
||||
BOOST_TEST(bytes == same_bytes);
|
||||
|
||||
BOOST_TEST(set_working_dir(args));
|
||||
|
||||
#if defined(HAVE_JPEG)
|
||||
should_throw = "./tests/cpp_tests/data/blank.jpg";
|
||||
|
|
Loading…
Add table
Reference in a new issue