Get rid of some explicit new allocation

This commit is contained in:
2023-06-17 20:32:58 +02:00
parent 31cf1ee2b1
commit 7e39304799
2 changed files with 7 additions and 7 deletions
+5 -5
View File
@@ -31,7 +31,7 @@ void RawImage::allocate(uint32_t w, uint32_t h, uint32_t ch, DataType type)
m_channels = ch; m_channels = ch;
m_ch = ch == 3 ? 4 : ch; m_ch = ch == 3 ? 4 : ch;
m_origType = m_type = type; m_origType = m_type = type;
m_pixels.reset(new PixelType[m_width * m_height * m_ch * typeSize(type)]); m_pixels = std::make_unique<PixelType[]>(m_width * m_height * m_ch * typeSize(type));
} }
RawImage::RawImage() RawImage::RawImage()
@@ -301,7 +301,8 @@ void *RawImage::origData(uint32_t row, uint32_t col) const
void RawImage::convertToThumbnail() void RawImage::convertToThumbnail()
{ {
m_thumbAspect = (float)width() / height(); m_thumbAspect = (float)width() / height();
uint16_t *out = reinterpret_cast<uint16_t*>(new uint8_t[THUMB_SIZE * THUMB_SIZE * 4 * sizeof(uint16_t)]); std::unique_ptr<PixelType[]> outptr = std::make_unique<PixelType[]>(THUMB_SIZE * THUMB_SIZE * 4 * sizeof(uint16_t));
uint16_t *out = reinterpret_cast<uint16_t*>(outptr.get());
auto loop = [&](uint16_t *out, auto *in, auto scale) auto loop = [&](uint16_t *out, auto *in, auto scale)
{ {
@@ -341,12 +342,11 @@ void RawImage::convertToThumbnail()
loop(out, reinterpret_cast<float*>(m_pixels.get()), 65535.0); loop(out, reinterpret_cast<float*>(m_pixels.get()), 65535.0);
break; break;
default: default:
qDebug() << "Should not happend"; qWarning() << "FLOAT64 should not happend";
delete [] out;
return; return;
} }
m_pixels.reset(reinterpret_cast<uint8_t*>(out)); m_pixels = std::move(outptr);
m_width = THUMB_SIZE; m_width = THUMB_SIZE;
m_height = THUMB_SIZE; m_height = THUMB_SIZE;
m_ch = 4; m_ch = 4;
+2 -2
View File
@@ -58,8 +58,8 @@ protected:
double m_max[4] = {0.0}; double m_max[4] = {0.0};
double m_mad[4] = {0.0}; double m_mad[4] = {0.0};
}; };
std::unique_ptr<PixelType> m_pixels; std::unique_ptr<PixelType[]> m_pixels;
std::unique_ptr<PixelType> m_original; std::unique_ptr<PixelType[]> m_original;
uint32_t m_width = 0; uint32_t m_width = 0;
uint32_t m_height = 0; uint32_t m_height = 0;
uint32_t m_channels = 0; uint32_t m_channels = 0;