我正在开发一个成像库,我正在努力处理图像数据数据类型
由于图像可以具有可变数据类型(每像素 8 位,每像素 16 位),我想实现我的图像数据指针
void* pimage_data;
但是 void* 会导致各种讨厌的事情,包括丑陋的指针算术,例如
pimage_data = &((unsigned char*)pimage_parent->m_pdata)[offset_y * pimage_parent->m_pitch + offset_x];
我怀疑这有问题,因为当我将它传递给另一个方法时
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;
}
新的回报std::bad_alloc
现在我必须同意 void* 不会直接导致 bad_alloc 但我很确定这里有问题。有什么提示吗?
编辑:
CImage 几乎没有
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;
}
尺寸为 x:746, y:325