I'm developping an imaging library and I'm struggling with the image data datatype
Since images can have variable datatypes (8 bits per pixel, 16 bits per pixel) I thought of implementing my image data pointer to
void* pimage_data;
however void* leads to all kind of nastiness including ugly pointer arithmetics such as
pimage_data = &((unsigned char*)pimage_parent->m_pdata)[offset_y * pimage_parent->m_pitch + offset_x];
I suspect that something is wrong with this since when I pass it to another method
CImage* roi = CImage::create_image(size_x, size_y, pimage_parent->m_data_type, pimage_data);
CImage* CImage::create_image(int size_x, int size_y, E_DATA_TYPE data_type, void* pimage)
{
assert(size_x > 0);
assert(size_y > 0);
CImage* image = new CImage(size_x, size_y, data_type);
image->m_pdata = pimage;
return image;
}
the new returns std::bad_alloc
Now I must agree that void* does not directly lead to bad_alloc but I'm pretty sure something is wrong with it here. Any hints?
EDIT:
CImage does close to nothing
CImage::CImage(int size_x, int size_y, E_DATA_TYPE data_type)
{
assert(size_x > 0);
assert(size_y > 0);
// Copy of the parameter to the class members
this->m_size_x = size_x;
this->m_size_y = size_y;
this->m_data_type = data_type;
this->m_pitch = size_x;
// The ctor simply create a standalone image for now
this->m_pimage_child = NULL;
this->m_pimage_parent = NULL;
}
sizes are x:746, y:325