Image: modernize C++11

* use nullptr
This commit is contained in:
wmayer
2022-03-23 18:42:42 +01:00
parent d430940515
commit 58d1cc4818
5 changed files with 17 additions and 17 deletions

View File

@@ -26,7 +26,7 @@ using namespace Image;
// Constructor (constructs an empty image)
ImageBase::ImageBase()
{
_pPixelData = NULL;
_pPixelData = nullptr;
_owner = true;
_width = 0;
_height = 0;
@@ -50,7 +50,7 @@ ImageBase::ImageBase(const ImageBase &rhs)
if (rhs._owner == true)
{
// rhs is the owner - do a deep copy
_pPixelData = NULL;
_pPixelData = nullptr;
_owner = false; // avoids a superfluous delete
if (createCopy((void *)(rhs._pPixelData), rhs._width, rhs._height, rhs._format, rhs._numSigBitsPerSample) != 0)
throw Base::RuntimeError("ImageBase::ImageBase. Error creating copy of image");
@@ -105,12 +105,12 @@ void ImageBase::clear()
if (_owner == true)
{
delete [] _pPixelData;
_pPixelData = NULL;
_pPixelData = nullptr;
}
// Else just reset the pointer (the owner of the pixel data must be responsible for deleting it)
else
{
_pPixelData = NULL;
_pPixelData = nullptr;
}
// Re-initialise the other variables
@@ -201,7 +201,7 @@ int ImageBase::_setColorFormat(int format, unsigned short numSigBitsPerSample)
int ImageBase::_allocate()
{
// Check that pixel data pointer is null
if (_pPixelData != NULL)
if (_pPixelData != nullptr)
return -1;
// Allocate the space needed to store the pixel data
@@ -296,7 +296,7 @@ int ImageBase::pointTo(void* pSrcPixelData, unsigned long width, unsigned long h
// if there is no image data
int ImageBase::getSample(int x, int y, unsigned short sampleIndex, double &value)
{
if ((_pPixelData == NULL) ||
if ((_pPixelData == nullptr) ||
(sampleIndex >= _numSamples) ||
(x < 0) || (x >= (int)_width) ||
(y < 0) || (y >= (int)_height))

View File

@@ -44,7 +44,7 @@ public:
ImageBase(const ImageBase &rhs);
ImageBase & operator=(const ImageBase &rhs);
bool hasValidData() const { return (_pPixelData != 0); }
bool hasValidData() const { return (_pPixelData != nullptr); }
void* getPixelDataPtr() { return (void *)_pPixelData; }
bool isOwner() const { return _owner; }
unsigned long getWidth() const { return _width; }

View File

@@ -74,7 +74,7 @@ private:
// Extract image into a general RGB format recognised by the ImageView class
int format = IB_CF_RGB24;
unsigned char *pPixelData = NULL;
unsigned char *pPixelData = nullptr;
if (imageq.isNull() == false) {
pPixelData = new unsigned char[3 * (unsigned long)imageq.width() * (unsigned long)imageq.height()];
unsigned char *pPix = pPixelData;

View File

@@ -101,7 +101,7 @@ GLImageBox::GLImageBox(QWidget * parent, Qt::WindowFlags f)
_zoomFactor = 1.0;
_base_x0 = 0;
_base_y0 = 0;
_pColorMap = 0;
_pColorMap = nullptr;
_numMapEntries = 0;
#if defined(_DEBUG) && 0
@@ -243,7 +243,7 @@ void GLImageBox::drawImage()
glPixelTransferf(GL_BLUE_SCALE, (float)scale);
// Load the color map if present
if (_pColorMap != 0)
if (_pColorMap != nullptr)
{
if (!haveMesa) glPixelTransferf(GL_MAP_COLOR, 1.0);
glPixelMapfv(GL_PIXEL_MAP_R_TO_R, _numMapEntries, _pColorMap);
@@ -254,10 +254,10 @@ void GLImageBox::drawImage()
else
{
glPixelTransferf(GL_MAP_COLOR, 0.0);
glPixelMapfv(GL_PIXEL_MAP_R_TO_R, 0, NULL);
glPixelMapfv(GL_PIXEL_MAP_G_TO_G, 0, NULL);
glPixelMapfv(GL_PIXEL_MAP_B_TO_B, 0, NULL);
glPixelMapfv(GL_PIXEL_MAP_A_TO_A, 0, NULL);
glPixelMapfv(GL_PIXEL_MAP_R_TO_R, 0, nullptr);
glPixelMapfv(GL_PIXEL_MAP_G_TO_G, 0, nullptr);
glPixelMapfv(GL_PIXEL_MAP_B_TO_B, 0, nullptr);
glPixelMapfv(GL_PIXEL_MAP_A_TO_A, 0, nullptr);
}
// Get the pixel format
@@ -698,7 +698,7 @@ void GLImageBox::resetDisplay()
void GLImageBox::clearColorMap()
{
delete [] _pColorMap;
_pColorMap = 0;
_pColorMap = nullptr;
_numMapEntries = 0;
}
@@ -851,7 +851,7 @@ int GLImageBox::setColorMapAlphaValue(int index, float value)
// Helper function to convert a pixel's value (of a sample) to the color map index (i.e. the map index that will be used for that pixel value)
unsigned int GLImageBox::pixValToMapIndex(double PixVal)
{
if (_pColorMap != NULL)
if (_pColorMap != nullptr)
{
double MaxVal = pow(2.0, _image.getNumBitsPerSample()) - 1.0;
double Scale = (pow(2.0, _image.getNumBitsPerSample()) - 1.0) / (pow(2.0, _image.getNumSigBitsPerSample()) - 1.0);

View File

@@ -37,7 +37,7 @@ class ImageGuiExport GLImageBox : public QOpenGLWidget
public:
GLImageBox(QWidget * parent = 0, Qt::WindowFlags f = Qt::WindowFlags());
GLImageBox(QWidget * parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
~GLImageBox();
Image::ImageBase *getImageBasePtr() { return &_image; }