You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.1 KiB
C++

#pragma once
#include <string>
#include <memory>
typedef unsigned char uchar;
namespace MN_VisionImage {
enum class ME_ImageType
{
E_GRAY = 0,
E_RGB,
E_RGBA
};
struct MS_ImageParam
{
//无参构造
MS_ImageParam() :
m_width(-1),
m_height(-1),
m_channels(0),
mImgType(MN_VisionImage::ME_ImageType::E_RGB)
{}
//有参构造函数
MS_ImageParam(uchar* _buffer, int _nW, int _nH, const ME_ImageType& _imgType)
{
int _nChannels = 0;
if (_imgType == ME_ImageType::E_GRAY)
{
_nChannels = 1;
}
else if (_imgType == ME_ImageType::E_RGBA)
{
_nChannels = 4;
}
else
{
_nChannels = 3;
}
m_width = _nW;
m_height = _nH;
m_channels = _nChannels;
mImgType = _imgType;
int iSize = _nW * _nH * _nChannels; //图像的像素数
m_data = std::shared_ptr<uchar>(new uchar[iSize], [](uchar* p) {
if (p != nullptr)
{
delete[] p;
p = nullptr;
}
});
memcpy(m_data.get(), _buffer, iSize);
}
std::shared_ptr<uchar> m_data; // 图像数据
int m_width; // 图像宽度
int m_height; // 图像高度
int m_channels; // 图像通道数
ME_ImageType mImgType; // 图像类型
};
}