Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

remove

Shinya Kitaoka79e39bd35ab7
diff --git a/toonz/sources/common/tvectorimage/tcomputeregions.cpp b/toonz/sources/common/tvectorimage/tcomputeregions.cpp
index 68b6567e1..6a9bafb36 100644
--- a/toonz/sources/common/tvectorimage/tcomputeregions.cpp
+++ b/toonz/sources/common/tvectorimage/tcomputeregions.cpp
@@ -612,7 +612,7 @@ void TVectorImage::Imp::doEraseIntersection(int index, vector<int> *toBeDeleted)
//-----------------------------------------------------------------------------
-UINT TVectorImage::Imp::getFillData(IntersectionBranch *&v)
+UINT TVectorImage::Imp::getFillData(std::unique_ptr<IntersectionBranch[]>& v)
{
//print(m_intersectionData->m_intList, "C:\\temp\\intersectionPrimaSave.txt");
@@ -636,7 +636,7 @@ UINT TVectorImage::Imp::getFillData(IntersectionBranch *&v)
branchesBefore[currInt + 1] = branchesBefore[currInt] + strokeListSize;
}
- v = new IntersectionBranch[size];
+ v.reset(new IntersectionBranch[size]);
currInt = 0;
p1 = m_intersectionData->m_intList.first();
for (; p1; p1 = p1->next(), currInt++) {
@@ -737,7 +737,7 @@ TStroke *reconstructAutocloseStroke(Intersection *p1,
} //namespace
//-----------------------------------------------------------------------------
-void TVectorImage::Imp::setFillData(IntersectionBranch *v, UINT branchCount, bool doComputeRegions)
+void TVectorImage::Imp::setFillData(std::unique_ptr<IntersectionBranch[]> const& v, UINT branchCount, bool doComputeRegions)
{
#ifdef _DEBUG
/*ofstream of("C:\\temp\\fillDataIn.txt");
diff --git a/toonz/sources/common/tvectorimage/tvectorimage.cpp b/toonz/sources/common/tvectorimage/tvectorimage.cpp
index d514bd891..f9289aa3c 100644
--- a/toonz/sources/common/tvectorimage/tvectorimage.cpp
+++ b/toonz/sources/common/tvectorimage/tvectorimage.cpp
@@ -1177,14 +1177,9 @@ void TVectorImage::putRegion(TRegion *region)
void TVectorImage::Imp::cloneRegions(TVectorImage::Imp &out, bool doComputeRegions)
{
- IntersectionBranch *v;
- UINT size;
-
- size = getFillData(v);
+ std::unique_ptr<IntersectionBranch[]> v;
+ UINT size = getFillData(v);
out.setFillData(v, size, doComputeRegions);
-
- if (size)
- delete[] v;
}
//-----------------------------------------------------------------------------
@@ -1635,14 +1630,14 @@ void TVectorImage::invalidateBBox()
*/
//-----------------------------------------------------------------------------
-void TVectorImage::setFillData(IntersectionBranch *v, UINT branchCount, bool doComputeRegions)
+void TVectorImage::setFillData(std::unique_ptr<IntersectionBranch[]> const& v, UINT branchCount, bool doComputeRegions)
{
m_imp->setFillData(v, branchCount, doComputeRegions);
}
//-----------------------------------------------------------------------------
-UINT TVectorImage::getFillData(IntersectionBranch *&v)
+UINT TVectorImage::getFillData(std::unique_ptr<IntersectionBranch[]>& v)
{
return m_imp->getFillData(v);
}
diff --git a/toonz/sources/common/tvectorimage/tvectorimageP.h b/toonz/sources/common/tvectorimage/tvectorimageP.h
index e81e7b8b3..3d206544a 100644
--- a/toonz/sources/common/tvectorimage/tvectorimageP.h
+++ b/toonz/sources/common/tvectorimage/tvectorimageP.h
@@ -164,8 +164,8 @@ public:
void cloneRegions(TVectorImage::Imp &out, bool doComputeRegions = true);
void eraseIntersection(int index);
- UINT getFillData(TVectorImage::IntersectionBranch *&v);
- void setFillData(TVectorImage::IntersectionBranch *v, UINT branchCount, bool doComputeRegions = true);
+ UINT getFillData(std::unique_ptr<TVectorImage::IntersectionBranch[]>& v);
+ void setFillData(std::unique_ptr<TVectorImage::IntersectionBranch[]> const& v, UINT branchCount, bool doComputeRegions = true);
void notifyChangedStrokes(const vector<int> &strokeIndexArray, const vector<TStroke *> &oldVectorStrokeArray, bool areFlipped);
void insertStrokeAt(VIStroke *stroke, int strokeIndex, bool recomputeRegions = true);
void moveStroke(int fromIndex, int toIndex);
diff --git a/toonz/sources/image/pli/pli_io.cpp b/toonz/sources/image/pli/pli_io.cpp
index c774fc947..ca493bdba 100644
--- a/toonz/sources/image/pli/pli_io.cpp
+++ b/toonz/sources/image/pli/pli_io.cpp
@@ -1,4 +1,4 @@
-
+#include <memory>
#ifndef XPRESS
@@ -365,7 +365,7 @@ public:
UCHAR m_currDinamicTypeBytesNum;
TUINT32 m_tagLength;
TUINT32 m_bufLength;
- UCHAR *m_buf;
+ std::unique_ptr<UCHAR[]> m_buf;
TAffine m_affine;
int m_precisionScale;
std::map<TFrameId, int> m_frameOffsInFile;
@@ -513,7 +513,20 @@ static inline short complement2(USHORT val)
/*=====================================================================*/
ParsedPliImp::ParsedPliImp()
- : m_majorVersionNumber(0), m_minorVersionNumber(0), m_framesNumber(0), m_thickRatio(1.0), m_maxThickness(0.0), m_firstTag(NULL), m_lastTag(NULL), m_currTag(NULL), m_iChan(), m_oChan(0), m_bufLength(0), m_buf(NULL), m_affine(), m_precisionScale(REGION_COMPUTING_PRECISION), m_creator("")
+ : m_majorVersionNumber(0)
+ , m_minorVersionNumber(0)
+ , m_framesNumber(0)
+ , m_thickRatio(1.0)
+ , m_maxThickness(0.0)
+ , m_firstTag(NULL)
+ , m_lastTag(NULL)
+ , m_currTag(NULL)
+ , m_iChan()
+ , m_oChan(0)
+ , m_bufLength(0)
+ , m_affine()
+ , m_precisionScale(REGION_COMPUTING_PRECISION)
+ , m_creator("")
{
}
@@ -525,8 +538,21 @@ ParsedPliImp::ParsedPliImp(UCHAR majorVersionNumber,
UCHAR precision,
UCHAR maxThickness,
double autocloseTolerance)
- : m_majorVersionNumber(majorVersionNumber), m_minorVersionNumber(minorVersionNumber), m_framesNumber(framesNumber), m_maxThickness(maxThickness), m_autocloseTolerance(autocloseTolerance), m_thickRatio(maxThickness / 255.0), m_firstTag(NULL), m_lastTag(NULL), m_currTag(NULL), m_iChan(), m_oChan(0), m_bufLength(0), m_buf(NULL), m_affine(TScale(1.0 / pow(10.0, precision))), m_precisionScale(REGION_COMPUTING_PRECISION), m_creator("")
-
+ : m_majorVersionNumber(majorVersionNumber)
+ , m_minorVersionNumber(minorVersionNumber)
+ , m_framesNumber(framesNumber)
+ , m_maxThickness(maxThickness)
+ , m_autocloseTolerance(autocloseTolerance)
+ , m_thickRatio(maxThickness / 255.0)
+ , m_firstTag(NULL)
+ , m_lastTag(NULL)
+ , m_currTag(NULL)
+ , m_iChan()
+ , m_oChan(0)
+ , m_bufLength(0)
+ , m_affine(TScale(1.0 / pow(10.0, precision)))
+ , m_precisionScale(REGION_COMPUTING_PRECISION)
+ , m_creator("")
{
}
@@ -534,9 +560,17 @@ ParsedPliImp::ParsedPliImp(UCHAR majorVersionNumber,
ParsedPliImp::ParsedPliImp(const TFilePath &filename, bool readInfo)
: m_majorVersionNumber(0), m_minorVersionNumber(0)
- // , m_filename(filename)
- ,
- m_framesNumber(0), m_thickRatio(1.0), m_maxThickness(0), m_firstTag(NULL), m_lastTag(NULL), m_currTag(NULL), m_iChan(), m_oChan(0), m_bufLength(0), m_buf(NULL), m_precisionScale(REGION_COMPUTING_PRECISION), m_creator("")
+ , m_framesNumber(0)
+ , m_thickRatio(1.0)
+ , m_maxThickness(0)
+ , m_firstTag(NULL)
+ , m_lastTag(NULL)
+ , m_currTag(NULL)
+ , m_iChan()
+ , m_oChan(0)
+ , m_bufLength(0)
+ , m_precisionScale(REGION_COMPUTING_PRECISION)
+ , m_creator("")
{
TUINT32 magic;
// TUINT32 fileLenght;
@@ -873,14 +907,12 @@ TagElem *ParsedPliImp::readTag()
}
if (m_bufLength < m_tagLength) {
- if (m_bufLength)
- delete[] m_buf;
m_bufLength = m_tagLength;
- m_buf = new UCHAR[m_bufLength];
+ m_buf.reset(new UCHAR[m_bufLength]);
}
if (m_tagLength) {
- m_iChan.read((char *)m_buf, (int)m_tagLength);
+ m_iChan.read((char *)m_buf.get(), (int)m_tagLength);
CHECK_FOR_READ_ERROR(m_filePath);
}
@@ -1031,7 +1063,7 @@ PliTag *ParsedPliImp::readTextTag()
if (m_tagLength == 0)
return new TextTag("");
- return new TextTag(string((char *)m_buf, m_tagLength));
+ return new TextTag(string((char *)m_buf.get(), m_tagLength));
}
/*=====================================================================*/
@@ -1087,7 +1119,6 @@ PliTag *ParsedPliImp::readThickQuadraticChainTag(bool isLoop)
TUINT32 bufOffs = 0;
double dx1, dy1, dx2, dy2;
TINT32 d;
- TThickQuadratic *quadratic;
TUINT32 numQuadratics = 0;
double scale;
@@ -1118,7 +1149,7 @@ PliTag *ParsedPliImp::readThickQuadraticChainTag(bool isLoop)
else
numQuadratics = (m_tagLength - 2 * m_currDinamicTypeBytesNum - 1) / (4 * m_currDinamicTypeBytesNum + 3);
- quadratic = new TThickQuadratic[numQuadratics];
+ std::unique_ptr<TThickQuadratic[]> quadratic(new TThickQuadratic[numQuadratics]);
for (unsigned int i = 0; i < numQuadratics; i++) {
quadratic[i].setThickP0(p);
@@ -1177,7 +1208,7 @@ PliTag *ParsedPliImp::readThickQuadraticChainTag(bool isLoop)
ThickQuadraticChainTag *tag = new ThickQuadraticChainTag();
tag->m_numCurves = numQuadratics;
- tag->m_curve = quadratic;
+ tag->m_curve = std::move(quadratic);
tag->m_isLoop = isLoop;
tag->m_maxThickness = maxThickness;
@@ -1188,40 +1219,35 @@ PliTag *ParsedPliImp::readThickQuadraticChainTag(bool isLoop)
PliTag *ParsedPliImp::readGroupTag()
{
- PliObjectTag **object;
- UCHAR type;
- TUINT32 numObjects, bufOffs = 0;
+ TUINT32 bufOffs = 0;
- type = m_buf[bufOffs++];
+ UCHAR type = m_buf[bufOffs++];
assert(type < GroupTag::TYPE_HOW_MANY);
- numObjects = (m_tagLength - 1) / m_currDinamicTypeBytesNum;
- object = new PliObjectTag *[numObjects];
+ TUINT32 numObjects = (m_tagLength - 1) / m_currDinamicTypeBytesNum;
+ std::unique_ptr<PliObjectTag*[]> object(new PliObjectTag *[numObjects]);
- TUINT32 *tagOffs = new TUINT32[numObjects];
+ std::unique_ptr<TUINT32[]> tagOffs(new TUINT32[numObjects]);
- unsigned int i = 0;
- for (i = 0; i < numObjects; i++) {
+ for (TUINT32 i = 0; i < numObjects; i++) {
readDinamicData(tagOffs[i], bufOffs);
}
TagElem *elem;
- for (i = 0; i < numObjects; i++)
+ for (TUINT32 i = 0; i < numObjects; i++)
while (!(object[i] = (PliObjectTag *)findTagFromOffset(tagOffs[i])))
if ((elem = readTag()))
addTag(*elem);
else
assert(false);
- GroupTag *tag = new GroupTag();
+ std::unique_ptr<GroupTag> tag(new GroupTag());
tag->m_type = type;
tag->m_numObjects = numObjects;
- tag->m_object = object;
- delete[] tagOffs;
- //delete object;
+ tag->m_object = std::move(object);
- return tag;
+ return tag.release();
}
/*=====================================================================*/
@@ -1239,7 +1265,7 @@ PliTag *ParsedPliImp::readColorTag()
assert(attribute < ColorTag::ATTRIBUTE_HOW_MANY);
TUINT32 numColors = (m_tagLength - 2) / m_currDinamicTypeBytesNum;
- TUINT32 *colorArray = new TUINT32[numColors];
+ std::unique_ptr<TUINT32[]> colorArray(new TUINT32[numColors]);
for (unsigned int i = 0; i < numColors; i++) {
TUINT32 color;
@@ -1248,11 +1274,8 @@ PliTag *ParsedPliImp::readColorTag()
colorArray[i] = color;
}
- ColorTag *tag = new ColorTag(style, attribute, numColors, colorArray);
-
- delete[] colorArray;
-
- return tag;
+ std::unique_ptr<ColorTag> tag(new ColorTag(style, attribute, numColors, std::move(colorArray)));
+ return tag.release();
}
/*=====================================================================*/
@@ -1306,7 +1329,7 @@ PliTag *ParsedPliImp::readStyleTag()
int paramArraySize = paramArray.size();
StyleTag *tag = new StyleTag(id, pageIndex, paramArraySize,
- (paramArraySize == 0) ? 0 : &(paramArray[0]));
+ (paramArraySize > 0) ? paramArray.data() : nullptr);
m_currDinamicTypeBytesNum = currDinamicTypeBytesNumSaved;
return tag;
@@ -1386,7 +1409,7 @@ UINT ParsedPliImp::readRasterData(TRaster32P &r, TUINT32 &bufOffs)
r.create((int)lx, (int)ly);
UINT size = lx * ly * 4;
r->lock();
- memcpy(r->getRawData(), m_buf + bufOffs, size);
+ memcpy(r->getRawData(), m_buf.get() + bufOffs, size);
r->unlock();
bufOffs += size;
return size + 2 + 2;
@@ -1527,7 +1550,7 @@ PliTag *ParsedPliImp::readBitmapTag()
r.create(lx, ly);
r->lock();
- memcpy(r->getRawData(), m_buf + bufOffs, lx * ly * 4);
+ memcpy(r->getRawData(), m_buf.get() + bufOffs, lx * ly * 4);
r->unlock();
BitmapTag *tag = new BitmapTag(r);
@@ -1538,9 +1561,8 @@ PliTag *ParsedPliImp::readBitmapTag()
PliTag *ParsedPliImp::readImageTag()
{
- PliObjectTag **object;
USHORT frame;
- TUINT32 numObjects, bufOffs = 0;
+ TUINT32 bufOffs = 0;
if (m_isIrixEndian)
frame = m_buf[bufOffs + 1] | (m_buf[bufOffs] << 8);
@@ -1556,28 +1578,24 @@ PliTag *ParsedPliImp::readImageTag()
++headerLength;
}
- numObjects = (m_tagLength - headerLength) / m_currDinamicTypeBytesNum;
- object = new PliObjectTag *[numObjects];
+ TUINT32 numObjects = (m_tagLength - headerLength) / m_currDinamicTypeBytesNum;
+ std::unique_ptr<PliObjectTag*[]> object(new PliObjectTag*[numObjects]);
- TUINT32 *tagOffs = new TUINT32[numObjects];
- unsigned int i;
- for (i = 0; i < numObjects; i++) {
+ std::unique_ptr<TUINT32[]> tagOffs(new TUINT32[numObjects]);
+ for (TUINT32 i = 0; i < numObjects; i++) {
readDinamicData(tagOffs[i], bufOffs);
}
TagElem *elem;
- for (i = 0; i < numObjects; i++)
+ for (TUINT32 i = 0; i < numObjects; i++)
while (!(object[i] = (PliObjectTag *)findTagFromOffset(tagOffs[i])))
if ((elem = readTag()))
addTag(*elem);
else
assert(false);
- ImageTag *tag = new ImageTag(TFrameId(frame, letter), numObjects, object);
- delete[] tagOffs;
- delete[] object;
-
- return tag;
+ std::unique_ptr<ImageTag[]> tag(new ImageTag(TFrameId(frame, letter), numObjects, std::move(object)));
+ return tag.release();
}
/*=====================================================================*/
@@ -1628,7 +1646,7 @@ PliTag *ParsedPliImp::readIntersectionDataTag()
readTUINT32Data(branchCount, bufOffs);
- IntersectionBranch *branchArray = new IntersectionBranch[branchCount];
+ std::unique_ptr<IntersectionBranch[]> branchArray(new IntersectionBranch[branchCount]);
UINT i;
for (i = 0; i < branchCount; i++) {
@@ -1667,7 +1685,7 @@ PliTag *ParsedPliImp::readIntersectionDataTag()
IntersectionDataTag *tag = new IntersectionDataTag();
tag->m_branchCount = branchCount;
- tag->m_branchArray = branchArray;
+ tag->m_branchArray = std::move(branchArray);
return tag;
}
@@ -2580,11 +2598,6 @@ double ParsedPli::getThickRatio() const
ParsedPliImp::~ParsedPliImp()
{
- if (m_buf) {
- delete[] m_buf;
- m_buf = NULL;
- }
-
TagElem *tag = m_firstTag;
while (tag) {
TagElem *auxTag = tag;
diff --git a/toonz/sources/image/pli/pli_io.h b/toonz/sources/image/pli/pli_io.h
index 1b5c9db4b..0e2fc2cbd 100644
--- a/toonz/sources/image/pli/pli_io.h
+++ b/toonz/sources/image/pli/pli_io.h
@@ -1,5 +1,3 @@
-
-
#ifndef _PLI_IO_H
#define _PLI_IO_H
@@ -8,6 +6,9 @@
#pragma warning(disable : 4018)
#endif
+#include <memory>
+#include <vector>
+
#include "tfilepath.h"
#include "tvectorimage.h"
#include "tstroke.h"
@@ -232,46 +233,47 @@ class ThickQuadraticChainTag : public PliGeometricTag
public:
TUINT32 m_numCurves;
- TThickQuadratic *m_curve;
+ std::unique_ptr<TThickQuadratic[]> m_curve;
bool m_isLoop;
double m_maxThickness;
TStroke::OutlineOptions m_outlineOptions;
ThickQuadraticChainTag()
- : PliGeometricTag(THICK_QUADRATIC_CHAIN_GOBJ), m_numCurves(0), m_curve(0), m_maxThickness(1) {}
+ : PliGeometricTag(THICK_QUADRATIC_CHAIN_GOBJ)
+ , m_numCurves(0)
+ , m_maxThickness(1)
+ {
+ }
ThickQuadraticChainTag(TUINT32 numCurves, const TThickQuadratic *curve, double maxThickness)
- : PliGeometricTag(THICK_QUADRATIC_CHAIN_GOBJ), m_numCurves(numCurves), m_maxThickness(maxThickness <= 0 ? 1 : maxThickness)
+ : PliGeometricTag(THICK_QUADRATIC_CHAIN_GOBJ)
+ , m_numCurves(numCurves)
+ , m_maxThickness(maxThickness <= 0 ? 1 : maxThickness)
{
- if (m_numCurves == 0)
- m_curve = 0;
- else {
- m_curve = new TThickQuadratic[m_numCurves];
- for (UINT i = 0; i < m_numCurves; i++)
+ if (m_numCurves > 0) {
+ m_curve.reset(new TThickQuadratic[m_numCurves]);
+ for (UINT i = 0; i < m_numCurves; i++) {
m_curve[i] = curve[i];
+ }
}
}
ThickQuadraticChainTag(const ThickQuadraticChainTag &chainTag)
- : PliGeometricTag(THICK_QUADRATIC_CHAIN_GOBJ), m_numCurves(chainTag.m_numCurves), m_maxThickness(chainTag.m_maxThickness)
+ : PliGeometricTag(THICK_QUADRATIC_CHAIN_GOBJ)
+ , m_numCurves(chainTag.m_numCurves)
+ , m_maxThickness(chainTag.m_maxThickness)
{
- if (m_numCurves == 0)
- m_curve = 0;
- else {
- m_curve = new TThickQuadratic[m_numCurves];
- for (UINT i = 0; i < m_numCurves; i++)
+ if (m_numCurves > 0) {
+ m_curve.reset(new TThickQuadratic[m_numCurves]);
+ for (UINT i = 0; i < m_numCurves; i++) {
m_curve[i] = chainTag.m_curve[i];
+ }
}
}
- ~ThickQuadraticChainTag()
- {
- delete[] m_curve;
- }
-
private:
// not implemented
- const ThickQuadraticChainTag &operator=(const ThickQuadraticChainTag &chainTag);
+ const ThickQuadraticChainTag &operator=(const ThickQuadraticChainTag &chainTag) = delete;
};
//=====================================================================
@@ -326,10 +328,10 @@ public:
attributeType m_attribute;
TUINT32 m_numColors;
- TUINT32 *m_color;
+ std::unique_ptr<TUINT32[]> m_color;
ColorTag();
- ColorTag(styleType style, attributeType attribute, TUINT32 numColors, TUINT32 *m_color);
+ ColorTag(styleType style, attributeType attribute, TUINT32 numColors, std::unique_ptr<TUINT32[]> color);
ColorTag(const ColorTag &colorTag);
~ColorTag();
};
@@ -342,7 +344,7 @@ public:
USHORT m_id;
USHORT m_pageIndex;
int m_numParams;
- TStyleParam *m_param;
+ std::unique_ptr<TStyleParam[]> m_param;
StyleTag();
StyleTag(int id, USHORT pagePaletteindex, int m_numParams, TStyleParam *m_params);
@@ -381,10 +383,11 @@ public:
UCHAR m_type;
TUINT32 m_numObjects;
- PliObjectTag **m_object;
+ std::unique_ptr<PliObjectTag*[]> m_object;
GroupTag();
- GroupTag(UCHAR type, TUINT32 numObjects, PliObjectTag **object);
+ GroupTag(UCHAR type, TUINT32 numObjects, PliObjectTag** object);
+ GroupTag(UCHAR type, TUINT32 numObjects, std::unique_ptr<PliObjectTag*[]> object);
GroupTag(const GroupTag &groupTag);
~GroupTag();
};
@@ -397,10 +400,11 @@ public:
TFrameId m_numFrame;
TUINT32 m_numObjects;
- PliObjectTag **m_object;
+ std::unique_ptr<PliObjectTag*[]> m_object;
//ImageTag();
- ImageTag(const TFrameId &frameId, TUINT32 numObjects, PliObjectTag **object);
+ ImageTag(const TFrameId &numFrame, TUINT32 numObjects, PliObjectTag** object);
+ ImageTag(const TFrameId &frameId, TUINT32 numObjects, std::unique_ptr<PliObjectTag*[]> object);
ImageTag(const ImageTag &imageTag);
~ImageTag();
};
@@ -424,10 +428,10 @@ class IntersectionDataTag : public PliObjectTag
{
public:
UINT m_branchCount;
- TVectorImage::IntersectionBranch *m_branchArray;
+ std::unique_ptr<TVectorImage::IntersectionBranch[]> m_branchArray;
IntersectionDataTag();
- IntersectionDataTag(UINT branchCount, TVectorImage::IntersectionBranch *branchArray);
+ IntersectionDataTag(UINT branchCount, std::unique_ptr<TVectorImage::IntersectionBranch[]> branchArray);
IntersectionDataTag(const IntersectionDataTag &tag);
~IntersectionDataTag();
diff --git a/toonz/sources/image/pli/tags.cpp b/toonz/sources/image/pli/tags.cpp
index 5d20f679f..c2d1d62c2 100644
--- a/toonz/sources/image/pli/tags.cpp
+++ b/toonz/sources/image/pli/tags.cpp
@@ -176,35 +176,46 @@ PaletteWithAlphaTag::~PaletteWithAlphaTag()
/*=====================================================================*/
GroupTag::GroupTag()
- : PliObjectTag(PliTag::GROUP_GOBJ), m_type(GroupTag::NONE), m_numObjects(0), m_object(NULL)
+ : PliObjectTag(PliTag::GROUP_GOBJ)
+ , m_type(GroupTag::NONE)
+ , m_numObjects(0)
{
}
/*=====================================================================*/
-
-GroupTag::GroupTag(UCHAR type, TUINT32 numObjects, PliObjectTag **object)
- : PliObjectTag(PliTag::GROUP_GOBJ), m_type(type), m_numObjects(numObjects)
+GroupTag::GroupTag(UCHAR type, TUINT32 numObjects, PliObjectTag** object)
+ : PliObjectTag(PliTag::GROUP_GOBJ)
+ , m_type(type)
+ , m_numObjects(numObjects)
{
- if (m_numObjects == 0)
- m_object = NULL;
- else {
- m_object = new PliObjectTag *[m_numObjects];
- for (UINT i = 0; i < m_numObjects; i++)
+ if (m_numObjects > 0) {
+ m_object.reset(new PliObjectTag*[m_numObjects]);
+ for (UINT i = 0; i < m_numObjects; i++) {
m_object[i] = object[i];
+ }
}
}
+GroupTag::GroupTag(UCHAR type, TUINT32 numObjects, std::unique_ptr<PliObjectTag*[]> object)
+ : PliObjectTag(PliTag::GROUP_GOBJ)
+ , m_type(type)
+ , m_numObjects(numObjects)
+ , m_object(std::move(object))
+{
+}
+
/*=====================================================================*/
GroupTag::GroupTag(const GroupTag &groupTag)
- : PliObjectTag(PliTag::GROUP_GOBJ), m_type(groupTag.m_type), m_numObjects(groupTag.m_numObjects)
+ : PliObjectTag(PliTag::GROUP_GOBJ)
+ , m_type(groupTag.m_type)
+ , m_numObjects(groupTag.m_numObjects)
{
- if (m_numObjects == 0)
- m_object = NULL;
- else {
- m_object = new PliObjectTag *[m_numObjects];
- for (UINT i = 0; i < m_numObjects; i++)
+ if (m_numObjects > 0) {
+ m_object.reset(new PliObjectTag*[m_numObjects]);
+ for (UINT i = 0; i < m_numObjects; i++) {
m_object[i] = groupTag.m_object[i];
+ }
}
}
@@ -212,47 +223,48 @@ GroupTag::GroupTag(const GroupTag &groupTag)
GroupTag::~GroupTag()
{
- if (m_numObjects)
- delete[] m_object;
}
/*=====================================================================*/
/*=====================================================================*/
StyleTag::StyleTag()
- : PliObjectTag(PliTag::STYLE_NGOBJ), m_id(0), m_numParams(0), m_pageIndex(0), m_param(NULL)
+ : PliObjectTag(PliTag::STYLE_NGOBJ)
+ , m_id(0)
+ , m_numParams(0)
+ , m_pageIndex(0)
{
}
/*=====================================================================*/
StyleTag::StyleTag(int id, USHORT pagePaletteIndex, int numParams, TStyleParam *param)
- : PliObjectTag(PliTag::STYLE_NGOBJ), m_id(id), m_numParams(numParams)
-{
- //assert(pagePaletteIndex>=0 && pagePaletteIndex<65536);
-
- m_pageIndex = pagePaletteIndex;
-
- if (numParams == 0)
- m_param = NULL;
- else {
- m_param = new TStyleParam[m_numParams];
- for (UINT i = 0; i < (UINT)m_numParams; i++)
+ : PliObjectTag(PliTag::STYLE_NGOBJ)
+ , m_id(id)
+ , m_pageIndex(pagePaletteIndex)
+ , m_numParams(numParams)
+{
+ if (numParams > 0) {
+ m_param.reset(new TStyleParam[m_numParams]);
+ for (UINT i = 0; i < (UINT)m_numParams; i++) {
m_param[i] = param[i];
+ }
}
}
/*=====================================================================*/
StyleTag::StyleTag(const StyleTag &styleTag)
- : PliObjectTag(PliTag::STYLE_NGOBJ), m_id(styleTag.m_id), m_pageIndex(styleTag.m_pageIndex), m_numParams(styleTag.m_numParams)
-{
- if (styleTag.m_numParams == 0)
- m_param = NULL;
- else {
- m_param = new TStyleParam[styleTag.m_numParams];
- for (UINT i = 0; i < (UINT)styleTag.m_numParams; i++)
+ : PliObjectTag(PliTag::STYLE_NGOBJ)
+ , m_id(styleTag.m_id)
+ , m_pageIndex(styleTag.m_pageIndex)
+ , m_numParams(styleTag.m_numParams)
+{
+ if (styleTag.m_numParams > 0) {
+ m_param.reset(new TStyleParam[styleTag.m_numParams]);
+ for (UINT i = 0; i < (UINT)styleTag.m_numParams; i++) {
m_param[i] = styleTag.m_param[i];
+ }
}
}
@@ -260,41 +272,42 @@ StyleTag::StyleTag(const StyleTag &styleTag)
StyleTag::~StyleTag()
{
- delete[] m_param;
}
//=====================================================================
ColorTag::ColorTag()
- : PliObjectTag(PliTag::COLOR_NGOBJ), m_style(STYLE_NONE), m_attribute(ATTRIBUTE_NONE), m_numColors(0), m_color(NULL)
+ : PliObjectTag(PliTag::COLOR_NGOBJ)
+ , m_style(STYLE_NONE)
+ , m_attribute(ATTRIBUTE_NONE)
+ , m_numColors(0)
{
}
/*=====================================================================*/
ColorTag::ColorTag(ColorTag::styleType style, ColorTag::attributeType attribute,
- TUINT32 numColors, TUINT32 *color)
- : PliObjectTag(PliTag::COLOR_NGOBJ), m_style(style), m_attribute(attribute), m_numColors(numColors)
+ TUINT32 numColors, std::unique_ptr<TUINT32[]> color)
+ : PliObjectTag(PliTag::COLOR_NGOBJ)
+ , m_style(style)
+ , m_attribute(attribute)
+ , m_numColors(numColors)
+ , m_color(std::move(color))
{
- if (m_numColors == 0)
- m_color = NULL;
- else {
- m_color = new TUINT32[m_numColors];
- for (UINT i = 0; i < m_numColors; i++)
- m_color[i] = color[i];
- }
}
/*=====================================================================*/
ColorTag::ColorTag(const ColorTag &tag)
- : PliObjectTag(PliTag::COLOR_NGOBJ), m_style(tag.m_style), m_attribute(tag.m_attribute), m_numColors(tag.m_numColors)
-{
- if (tag.m_numColors == 0)
- m_color = NULL;
- else {
- m_color = new TUINT32[m_numColors];
- for (UINT i = 0; i < m_numColors; i++)
+ : PliObjectTag(PliTag::COLOR_NGOBJ)
+ , m_style(tag.m_style)
+ , m_attribute(tag.m_attribute)
+ , m_numColors(tag.m_numColors)
+{
+ if (tag.m_numColors > 0) {
+ m_color.reset(new TUINT32[m_numColors]);
+ for (UINT i = 0; i < m_numColors; i++) {
m_color[i] = tag.m_color[i];
+ }
}
}
@@ -302,8 +315,6 @@ ColorTag::ColorTag(const ColorTag &tag)
ColorTag::~ColorTag()
{
- if (m_numColors)
- delete[] m_color;
}
/*=====================================================================*/
@@ -339,28 +350,31 @@ BitmapTag::~BitmapTag()
/*=====================================================================*/
IntersectionDataTag::IntersectionDataTag()
- : PliObjectTag(PliTag::INTERSECTION_DATA_GOBJ), m_branchCount(0), m_branchArray(0)
+ : PliObjectTag(PliTag::INTERSECTION_DATA_GOBJ)
+ , m_branchCount(0)
{
}
/*=====================================================================*/
-IntersectionDataTag::IntersectionDataTag(UINT branchCount, IntersectionBranch *branchArray)
- : PliObjectTag(PliTag::INTERSECTION_DATA_GOBJ), m_branchCount(branchCount), m_branchArray(branchArray)
+IntersectionDataTag::IntersectionDataTag(UINT branchCount, std::unique_ptr<IntersectionBranch[]> branchArray)
+ : PliObjectTag(PliTag::INTERSECTION_DATA_GOBJ)
+ , m_branchCount(branchCount)
+ , m_branchArray(std::move(branchArray))
{
}
/*=====================================================================*/
IntersectionDataTag::IntersectionDataTag(const IntersectionDataTag &tag)
- : PliObjectTag(PliTag::INTERSECTION_DATA_GOBJ), m_branchCount(tag.m_branchCount)
+ : PliObjectTag(PliTag::INTERSECTION_DATA_GOBJ)
+ , m_branchCount(tag.m_branchCount)
{
- if (m_branchCount == 0)
- m_branchArray = 0;
- else {
- m_branchArray = new IntersectionBranch[m_branchCount];
- for (UINT i = 0; i < m_branchCount; i++)
+ if (m_branchCount == 0) {
+ m_branchArray.reset(new IntersectionBranch[m_branchCount]);
+ for (UINT i = 0; i < m_branchCount; i++) {
m_branchArray[i] = tag.m_branchArray[i];
+ }
}
}
@@ -368,8 +382,6 @@ IntersectionDataTag::IntersectionDataTag(const IntersectionDataTag &tag)
IntersectionDataTag::~IntersectionDataTag()
{
- if (m_branchCount)
- delete[] m_branchArray;
}
/*=====================================================================*/
@@ -407,30 +419,39 @@ PrecisionScaleTag::PrecisionScaleTag(int precisionScale)
}*/
/*=====================================================================*/
-
-ImageTag::ImageTag(const TFrameId &numFrame, TUINT32 numObjects, PliObjectTag **object)
- : PliObjectTag(PliTag::IMAGE_GOBJ), m_numFrame(numFrame), m_numObjects(numObjects)
+ImageTag::ImageTag(const TFrameId &numFrame, TUINT32 numObjects, PliObjectTag** object)
+ : PliObjectTag(PliTag::IMAGE_GOBJ)
+ , m_numFrame(numFrame)
+ , m_numObjects(numObjects)
{
- if (m_numObjects == 0)
- m_object = NULL;
- else {
- m_object = new PliObjectTag *[m_numObjects];
- for (UINT i = 0; i < m_numObjects; i++)
+ if (m_numObjects > 0) {
+ m_object.reset(new PliObjectTag*[m_numObjects]);
+ for (UINT i = 0; i < m_numObjects; i++) {
m_object[i] = object[i];
+ }
}
}
+ImageTag::ImageTag(const TFrameId &numFrame, TUINT32 numObjects, std::unique_ptr<PliObjectTag*[]> object)
+ : PliObjectTag(PliTag::IMAGE_GOBJ)
+ , m_numFrame(numFrame)
+ , m_numObjects(numObjects)
+ , m_object(std::move(object))
+{
+}
+
/*=====================================================================*/
ImageTag::ImageTag(const ImageTag &imageTag)
- : PliObjectTag(PliTag::IMAGE_GOBJ), m_numFrame(imageTag.m_numFrame), m_numObjects(imageTag.m_numObjects)
+ : PliObjectTag(PliTag::IMAGE_GOBJ)
+ , m_numFrame(imageTag.m_numFrame)
+ , m_numObjects(imageTag.m_numObjects)
{
- if (m_numObjects == 0)
- m_object = NULL;
- else {
- m_object = new PliObjectTag *[m_numObjects];
- for (UINT i = 0; i < m_numObjects; i++)
+ if (m_numObjects > 0) {
+ m_object.reset(new PliObjectTag*[m_numObjects]);
+ for (UINT i = 0; i < m_numObjects; i++) {
m_object[i] = imageTag.m_object[i];
+ }
}
}
@@ -438,8 +459,6 @@ ImageTag::ImageTag(const ImageTag &imageTag)
ImageTag::~ImageTag()
{
- if (m_numObjects && m_object)
- delete[] m_object;
}
/*=====================================================================*/
diff --git a/toonz/sources/image/pli/tiio_pli.cpp b/toonz/sources/image/pli/tiio_pli.cpp
index 559f47df2..990076254 100644
--- a/toonz/sources/image/pli/tiio_pli.cpp
+++ b/toonz/sources/image/pli/tiio_pli.cpp
@@ -167,7 +167,6 @@ void buildPalette(ParsedPli *pli, const TImageP img)
// se c'e' una reference image, uso il primo stile della palette per memorizzare il path
TFilePath fp;
if ((fp = vPalette->getRefImgPath()) != TFilePath()) {
- //StyleTag *refImageTag = new StyleTag(0, 0, 1, &TStyleParam("refimage"+toString(fp)));
TStyleParam styleParam("refimage" + toString(fp));
StyleTag *refImageTag = new StyleTag(0, 0, 1, &styleParam);
pli->m_palette_tags.push_back((PliObjectTag *)refImageTag);
@@ -181,7 +180,7 @@ void buildPalette(ParsedPli *pli, const TImageP img)
vector<TStyleParam> pageNames(vPalette->getPageCount());
for (i = 0; i < pageNames.size(); i++)
pageNames[i] = TStyleParam(toString(vPalette->getPage(i)->getName()));
- StyleTag *pageNamesTag = new StyleTag(0, 0, pageNames.size(), &(pageNames[0]));
+ StyleTag *pageNamesTag = new StyleTag(0, 0, pageNames.size(), pageNames.data());
pli->m_palette_tags.push_back((PliObjectTag *)pageNamesTag);
@@ -206,7 +205,7 @@ void buildPalette(ParsedPli *pli, const TImageP img)
style->save(chan); //viene riempito lo stream;
assert(pageIndex >= 0 && pageIndex <= 65535);
- StyleTag *styleTag = new StyleTag(i, pageIndex, stream.size(), &(stream[0]));
+ StyleTag *styleTag = new StyleTag(i, pageIndex, stream.size(), stream.data());
pli->m_palette_tags.push_back((PliObjectTag *)styleTag);
}
@@ -238,7 +237,7 @@ void buildPalette(ParsedPli *pli, const TImageP img)
style->save(chan); //viene riempito lo stream;
assert(pageIndex >= 0 && pageIndex <= 65535);
- StyleTag *styleTag = new StyleTag(i, pageIndex, stream.size(), &(stream[0]));
+ StyleTag *styleTag = new StyleTag(i, pageIndex, stream.size(), stream.data());
pli->m_palette_tags.push_back((PliObjectTag *)styleTag);
}
}
@@ -470,12 +469,11 @@ void putStroke(TStroke *stroke, int &currStyleId, vector<PliObjectTag *> &tags)
assert(styleId >= 0);
if (currStyleId == -1 || styleId != currStyleId) {
currStyleId = styleId;
- TUINT32 color[1];
+ std::unique_ptr<TUINT32[]> color(new TUINT32[1]);
color[0] = (TUINT32)styleId;
- ColorTag *colorTag = new ColorTag(ColorTag::SOLID, ColorTag::STROKE_COLOR, 1, color);
- //pli->addTag((PliTag *)(colorTag));
- tags.push_back((PliObjectTag *)colorTag);
+ std::unique_ptr<ColorTag> colorTag(new ColorTag(ColorTag::SOLID, ColorTag::STROKE_COLOR, 1, std::move(color)));
+ tags.push_back(colorTag.release());
}
//If the outline options are non-standard (not round), add the outline infos
@@ -518,18 +516,17 @@ void TImageWriterPli::save(const TImageP &img)
// in modo da non incrementare il numero di frame correnti
++m_lwp->m_frameNumber;
- UINT intersectionSize;
- IntersectionBranch *v;
- intersectionSize = tempVecImg->getFillData(v);
+ std::unique_ptr<IntersectionBranch[]> v;
+ UINT intersectionSize = tempVecImg->getFillData(v);
// alloco l'oggetto m_lwp->m_pli ( di tipo ParsedPli ) che si occupa di costruire la struttura
if (!m_lwp->m_pli) {
- m_lwp->m_pli = new ParsedPli(m_lwp->m_frameNumber, m_precision, 40, tempVecImg->getAutocloseTolerance());
+ m_lwp->m_pli.reset(new ParsedPli(m_lwp->m_frameNumber, m_precision, 40, tempVecImg->getAutocloseTolerance()));
m_lwp->m_pli->setCreator(m_lwp->m_creator);
}
- buildPalette(m_lwp->m_pli, img);
+ buildPalette(m_lwp->m_pli.get(), img);
- ParsedPli *pli = m_lwp->m_pli;
+ ParsedPli *pli = m_lwp->m_pli.get();
/*
comunico che il numero di frame e' aumentato (il parsed lo riceve nel
@@ -562,27 +559,14 @@ void TImageWriterPli::save(const TImageP &img)
}
if (intersectionSize > 0) {
- PliTag *tag = new IntersectionDataTag(intersectionSize, v);
- //pli->addTag((PliTag *)tag);
+ PliTag *tag = new IntersectionDataTag(intersectionSize, std::move(v));
tags.push_back((PliObjectTag *)tag);
}
- /* questo campo per ora non viene utilizzato per l'attuale struttura delle stroke
- if (!tempVecImg->m_textLabel.empty())
- {
- groupTag[count] = new TextTag(tempVecImg->m_textLabel);
- pli->addTag(groupTag[count++]);
- }
- */
-
int tagsSize = tags.size();
- ImageTag *imageTagPtr = new ImageTag(m_frameId,
- tagsSize,
- (tagsSize == 0) ? 0 : &(tags[0])); //, true);
+ std::unique_ptr<ImageTag> imageTagPtr(new ImageTag(m_frameId, tagsSize, (tagsSize > 0) ? tags.data() : nullptr));
- pli->addTag(imageTagPtr);
- //for (i=0; i<tags->size(); i++)
- // pli->addTag((*tags)[i]);
+ pli->addTag(imageTagPtr.release());
// il ritorno e' fissato a false in quanto la
// scrittura avviene alla distruzione dello scrittore di livelli
@@ -591,7 +575,8 @@ void TImageWriterPli::save(const TImageP &img)
//=============================================================================
TLevelWriterPli::TLevelWriterPli(const TFilePath &path, TPropertyGroup *winfo)
- : TLevelWriter(path, winfo), m_pli(0), m_frameNumber(0)
+ : TLevelWriter(path, winfo)
+ , m_frameNumber(0)
{
}
@@ -599,31 +584,22 @@ TLevelWriterPli::TLevelWriterPli(const TFilePath &path, TPropertyGroup *winfo)
TLevelWriterPli::~TLevelWriterPli()
{
- if (m_pli) {
- try {
-
- // aggiungo il tag della palette
- CurrStyle = NULL;
- assert(!m_pli->m_palette_tags.empty());
- GroupTag *groupTag = new GroupTag(GroupTag::PALETTE, m_pli->m_palette_tags.size(), &(m_pli->m_palette_tags[0]));
- m_pli->addTag((PliTag *)groupTag, true);
- QString his;
- if (m_contentHistory) {
- his = m_contentHistory->serialize();
- TextTag *textTag = new TextTag(his.toStdString());
- m_pli->addTag((PliTag *)textTag, true);
- }
- //m_pli->addTag((PliTag *)(new PaletteWithAlphaTag(m_colorArray.size(), &m_colorArray[0])));
- m_pli->writePli(m_path);
- /*UINT i;
- for (i=0; i<groupTag->m_numObjects; i++)
- {
- delete groupTag->m_object[i];
- }*/
-
- delete m_pli;
- } catch (...) {
+ if (!m_pli) {
+ return;
+ }
+ try {
+ // aggiungo il tag della palette
+ CurrStyle = NULL;
+ assert(!m_pli->m_palette_tags.empty());
+ std::unique_ptr<GroupTag> groupTag(new GroupTag(GroupTag::PALETTE, m_pli->m_palette_tags.size(), m_pli->m_palette_tags.data()));
+ m_pli->addTag(groupTag.release(), true);
+ if (m_contentHistory) {
+ QString his = m_contentHistory->serialize();
+ std::unique_ptr<TextTag> textTag(new TextTag(his.toStdString()));
+ m_pli->addTag(textTag.release(), true);
}
+ m_pli->writePli(m_path);
+ } catch (...) {
}
}
@@ -843,7 +819,7 @@ GroupTag *makeGroup(TVectorImageP &vi, int &currStyleId, int &index, int currDep
assert(false);
}
index = i;
- return new GroupTag(GroupTag::STROKE, tags.size(), &(tags[0]));
+ return new GroupTag(GroupTag::STROKE, tags.size(), tags.data());
}
//=============================================================================
diff --git a/toonz/sources/image/pli/tiio_pli.h b/toonz/sources/image/pli/tiio_pli.h
index 81bdbd5f9..36cab36cf 100644
--- a/toonz/sources/image/pli/tiio_pli.h
+++ b/toonz/sources/image/pli/tiio_pli.h
@@ -1,8 +1,8 @@
-
-
#ifndef TTIO_PLI_INCLUDED
#define TTIO_PLI_INCLUDED
+#include <memory>
+
#include "tlevel_io.h"
class ParsedPli;
@@ -33,7 +33,7 @@ private:
class TLevelWriterPli : public TLevelWriter
{
//! object to manage a pli
- ParsedPli *m_pli;
+ std::unique_ptr<ParsedPli> m_pli;
//! number of frame in pli
UINT m_frameNumber;
diff --git a/toonz/sources/image/png/tiio_png.cpp b/toonz/sources/image/png/tiio_png.cpp
index af29db97e..1e4038fbe 100644
--- a/toonz/sources/image/png/tiio_png.cpp
+++ b/toonz/sources/image/png/tiio_png.cpp
@@ -2,6 +2,8 @@
#define _CRT_SECURE_NO_DEPRECATE 1
#endif
+#include <memory>
+
#include "tmachine.h"
#include "texception.h"
#include "tfilepath.h"
@@ -55,12 +57,24 @@ class PngReader : public Tiio::Reader
unsigned int m_sig_read;
int m_y;
bool m_is16bitEnabled;
- unsigned char *m_rowBuffer;
- unsigned char *m_tempBuffer; //Buffer temporaneo
+ std::unique_ptr<unsigned char[]> m_rowBuffer;
+ std::unique_ptr<unsigned char[]> m_tempBuffer; //Buffer temporaneo
int m_canDelete;
public:
PngReader()
- : m_chan(0), m_png_ptr(0), m_info_ptr(0), m_end_info_ptr(0), m_bit_depth(0), m_color_type(0), m_interlace_type(0), m_compression_type(0), m_filter_type(0), m_sig_read(0), m_y(0), m_is16bitEnabled(true), m_rowBuffer(0), m_tempBuffer(0), m_canDelete(0)
+ : m_chan(0)
+ , m_png_ptr(0)
+ , m_info_ptr(0)
+ , m_end_info_ptr(0)
+ , m_bit_depth(0)
+ , m_color_type(0)
+ , m_interlace_type(0)
+ , m_compression_type(0)
+ , m_filter_type(0)
+ , m_sig_read(0)
+ , m_y(0)
+ , m_is16bitEnabled(true)
+ , m_canDelete(0)
{
}
@@ -69,8 +83,6 @@ public:
if (m_canDelete == 1) {
png_destroy_read_struct(&m_png_ptr, &m_info_ptr, &m_end_info_ptr);
}
- delete[] m_rowBuffer;
- delete[] m_tempBuffer;
}
virtual bool read16BitIsEnabled() const { return m_is16bitEnabled; }
@@ -140,9 +152,6 @@ public:
}
int rowBytes = png_get_rowbytes(m_png_ptr, m_info_ptr);
- if (m_rowBuffer)
- delete[] m_rowBuffer;
- //m_rowBuffer = new unsigned char[rowBytes];
TUINT32 lx = 0, ly = 0;
png_get_IHDR(m_png_ptr, m_info_ptr, &lx, &ly, &m_bit_depth, &m_color_type,
@@ -157,11 +166,11 @@ public:
if (channels == 1 || channels == 2) {
if (m_bit_depth < 8) // (m_bit_depth == 1 || m_bit_depth == 2 || m_bit_depth == 4)
- m_rowBuffer = new unsigned char[lx * 3];
+ m_rowBuffer.reset(new unsigned char[lx * 3]);
else
- m_rowBuffer = new unsigned char[rowBytes * 4];
+ m_rowBuffer.reset(new unsigned char[rowBytes * 4]);
} else {
- m_rowBuffer = new unsigned char[rowBytes];
+ m_rowBuffer.reset(new unsigned char[rowBytes]);
}
if (m_color_type == PNG_COLOR_TYPE_PALETTE) {
@@ -211,11 +220,11 @@ public:
if (m_interlace_type == 1) {
if (channels == 1 || channels == 2) {
if (m_bit_depth < 8)
- m_tempBuffer = new unsigned char[ly * lx * 3];
+ m_tempBuffer.reset(new unsigned char[ly * lx * 3]);
else
- m_tempBuffer = new unsigned char[ly * rowBytes * 4];
+ m_tempBuffer.reset(new unsigned char[ly * rowBytes * 4]);
} else {
- m_tempBuffer = new unsigned char[ly * rowBytes];
+ m_tempBuffer.reset(new unsigned char[ly * rowBytes]);
}
}
}
@@ -225,8 +234,7 @@ public:
readLineInterlace(&buffer[0], x0, x1, shrink);
m_y++;
if (m_tempBuffer && m_y == ly) {
- delete[] m_tempBuffer;
- m_tempBuffer = 0;
+ m_tempBuffer.reset();
}
return;
}
@@ -236,14 +244,13 @@ public:
return;
m_y++;
- png_bytep row_pointer = m_rowBuffer;
+ png_bytep row_pointer = m_rowBuffer.get();
png_read_row(m_png_ptr, row_pointer, NULL);
writeRow(buffer);
if (m_tempBuffer && m_y == ly) {
- delete[] m_tempBuffer;
- m_tempBuffer = 0;
+ m_tempBuffer.reset();
}
}
@@ -257,11 +264,11 @@ public:
if (m_interlace_type == 1) {
if (channels == 1 || channels == 2) {
if (m_bit_depth < 8) // (m_bit_depth == 1 || m_bit_depth == 2 || m_bit_depth == 4)
- m_tempBuffer = new unsigned char[ly * lx * 3];
+ m_tempBuffer.reset(new unsigned char[ly * lx * 3]);
else
- m_tempBuffer = new unsigned char[ly * rowBytes * 4];
+ m_tempBuffer.reset(new unsigned char[ly * rowBytes * 4]);
} else {
- m_tempBuffer = new unsigned char[ly * rowBytes];
+ m_tempBuffer.reset(new unsigned char[ly * rowBytes]);
}
}
}
@@ -270,8 +277,7 @@ public:
readLineInterlace(&buffer[0], x0, x1, shrink);
m_y++;
if (m_tempBuffer && m_y == ly) {
- delete[] m_tempBuffer;
- m_tempBuffer = 0;
+ m_tempBuffer.reset();
}
return;
}
@@ -281,14 +287,13 @@ public:
return;
m_y++;
- png_bytep row_pointer = m_rowBuffer;
+ png_bytep row_pointer = m_rowBuffer.get();
png_read_row(m_png_ptr, row_pointer, NULL);
writeRow(buffer);
if (m_tempBuffer && m_y == ly) {
- delete[] m_tempBuffer;
- m_tempBuffer = 0;
+ m_tempBuffer.reset();
}
}
@@ -303,7 +308,7 @@ public:
free(lineBuffer);
} else {
m_y++;
- png_bytep row_pointer = m_rowBuffer;
+ png_bytep row_pointer = m_rowBuffer.get();
png_read_row(m_png_ptr, row_pointer, NULL);
}
}
@@ -468,43 +473,43 @@ public:
if ((channels == 4 || channels == 3) && m_bit_depth == 16) {
for (int i = 0; i < count; i += 2) {
for (int j = 0; j < channels * 2; j++) {
- (m_tempBuffer + (dstY * rowBytes))[(i * dstDx + dstX) * channels + j] = m_rowBuffer[i * channels + j];
+ (m_tempBuffer.get() + (dstY * rowBytes))[(i * dstDx + dstX) * channels + j] = m_rowBuffer[i * channels + j];
}
}
} else if (channels == 2 && m_bit_depth == 16) {
for (int i = 0; i < count; i += 2) {
for (int j = 0; j < 4 * 2; j++) {
- (m_tempBuffer + (dstY * rowBytes * 4))[(i * dstDx + dstX) * 4 + j] = m_rowBuffer[i * 4 + j];
+ (m_tempBuffer.get() + (dstY * rowBytes * 4))[(i * dstDx + dstX) * 4 + j] = m_rowBuffer[i * 4 + j];
}
}
} else if (channels == 1 && m_bit_depth == 16) {
for (int i = 0; i < count; i += 2) {
for (int j = 0; j < 3 * 2; j++) {
- (m_tempBuffer + (dstY * rowBytes * 4))[(i * dstDx + dstX) * 3 + j] = m_rowBuffer[i * 3 + j];
+ (m_tempBuffer.get() + (dstY * rowBytes * 4))[(i * dstDx + dstX) * 3 + j] = m_rowBuffer[i * 3 + j];
}
}
} else if (channels == 1 && m_bit_depth == 8) {
for (int i = 0; i < count; i++) {
for (int j = 0; j < 3; j++) {
- (m_tempBuffer + (dstY * rowBytes * 4))[(i * dstDx + dstX) * 3 + j] = m_rowBuffer[i * 3 + j];
+ (m_tempBuffer.get() + (dstY * rowBytes * 4))[(i * dstDx + dstX) * 3 + j] = m_rowBuffer[i * 3 + j];
}
}
} else if (channels == 2 && m_bit_depth == 8) {
for (int i = 0; i < count; i++) {
for (int j = 0; j < 4; j++) {
- (m_tempBuffer + (dstY * rowBytes * 4))[(i * dstDx + dstX) * 4 + j] = m_rowBuffer[i * 4 + j];
+ (m_tempBuffer.get() + (dstY * rowBytes * 4))[(i * dstDx + dstX) * 4 + j] = m_rowBuffer[i * 4 + j];
}
}
} else if ((channels == 1 || channels == 2) && m_bit_depth < 8) {
for (int i = 0; i < count; i++) {
for (int j = 0; j < 3; j++) {
- (m_tempBuffer + (dstY * lx * 3))[(i * dstDx + dstX) * 3 + j] = m_rowBuffer[i * 3 + j];
+ (m_tempBuffer.get() + (dstY * lx * 3))[(i * dstDx + dstX) * 3 + j] = m_rowBuffer[i * 3 + j];
}
}
} else {
for (int i = 0; i < count; i++) {
for (int j = 0; j < channels; j++) {
- (m_tempBuffer + (dstY * rowBytes))[(i * dstDx + dstX) * channels + j] = m_rowBuffer[i * channels + j];
+ (m_tempBuffer.get() + (dstY * rowBytes))[(i * dstDx + dstX) * channels + j] = m_rowBuffer[i * channels + j];
}
}
}
@@ -524,7 +529,7 @@ public:
int channels = png_get_channels(m_png_ptr, m_info_ptr);
int rowBytes = png_get_rowbytes(m_png_ptr, m_info_ptr);
- png_bytep row_pointer = m_rowBuffer;
+ png_bytep row_pointer = m_rowBuffer.get();
int lx = m_info.m_lx;
@@ -581,11 +586,11 @@ public:
// fase di copia
if (channels == 1 || channels == 2) {
if (m_bit_depth < 8)
- memcpy(m_rowBuffer, m_tempBuffer + ((m_y)*lx * 3), lx * 3);
+ memcpy(m_rowBuffer.get(), m_tempBuffer.get() + ((m_y)*lx * 3), lx * 3);
else
- memcpy(m_rowBuffer, m_tempBuffer + ((m_y)*rowBytes * 4), rowBytes * 4);
+ memcpy(m_rowBuffer.get(), m_tempBuffer.get() + ((m_y)*rowBytes * 4), rowBytes * 4);
} else {
- memcpy(m_rowBuffer, m_tempBuffer + ((m_y)*rowBytes), rowBytes);
+ memcpy(m_rowBuffer.get(), m_tempBuffer.get() + ((m_y)*rowBytes), rowBytes);
}
// fase di copia vecchia
@@ -611,7 +616,7 @@ public:
int lx = m_info.m_lx;
int rowBytes = png_get_rowbytes(m_png_ptr, m_info_ptr);
- png_bytep row_pointer = m_rowBuffer;
+ png_bytep row_pointer = m_rowBuffer.get();
while (passPng <= passRow && rowNumber < numRows) //finchè il passo d'interlacciamento è minore o uguale
//del passo desiderato effettua tante volte le lettura della riga
@@ -652,9 +657,9 @@ public:
// fase di copia
if (channels == 1 || channels == 2) {
- memcpy(m_rowBuffer, m_tempBuffer + ((m_y)*rowBytes * 4), rowBytes * 4);
+ memcpy(m_rowBuffer.get(), m_tempBuffer.get() + ((m_y)*rowBytes * 4), rowBytes * 4);
} else {
- memcpy(m_rowBuffer, m_tempBuffer + ((m_y)*rowBytes), rowBytes);
+ memcpy(m_rowBuffer.get(), m_tempBuffer.get() + ((m_y)*rowBytes), rowBytes);
}
// fase di copia
diff --git a/toonz/sources/image/tif/tiio_tif.cpp b/toonz/sources/image/tif/tiio_tif.cpp
index 1a7cbf509..1bfa09c3a 100644
--- a/toonz/sources/image/tif/tiio_tif.cpp
+++ b/toonz/sources/image/tif/tiio_tif.cpp
@@ -1,5 +1,3 @@
-
-
#if _MSC_VER >= 1400
#define _CRT_SECURE_NO_DEPRECATE 1
#endif
@@ -11,6 +9,8 @@
#include <unistd.h>
#endif
+#include <memory>
+
#include "tiio.h"
#include "tpixel.h"
#include "tsystem.h"
@@ -448,7 +448,7 @@ void TifReader::readLine(short *buffer, int x0, int x1, int shrink)
// Allocate a sufficient buffer to store a single tile
int tileSize = tileWidth * tileHeight;
- uint64 *tile = new uint64[tileSize];
+ std::unique_ptr<uint64[]> tile(new uint64[tileSize]);
int x = 0;
int y = tileHeight * m_stripIndex;
@@ -458,7 +458,7 @@ void TifReader::readLine(short *buffer, int x0, int x1, int shrink)
// Traverse the tiles row
while (x < m_info.m_lx) {
- int ret = TIFFReadRGBATile_64(m_tiff, x, y, tile);
+ int ret = TIFFReadRGBATile_64(m_tiff, x, y, tile.get());
assert(ret);
int tileRowSize = tmin((int)tileWidth, m_info.m_lx - x) * pixelSize;
@@ -467,14 +467,12 @@ void TifReader::readLine(short *buffer, int x0, int x1, int shrink)
for (int ty = 0; ty < lastTy; ++ty) {
memcpy(
m_stripBuffer + (ty * m_rowLength + x) * pixelSize,
- (UCHAR *)tile + ty * tileWidth * pixelSize,
+ (UCHAR *)tile.get() + ty * tileWidth * pixelSize,
tileRowSize);
}
x += tileWidth;
}
-
- delete[] tile;
} else {
int y = m_rowsPerStrip * m_stripIndex;
int ok = TIFFReadRGBAStrip_64(m_tiff, y, (uint64 *)m_stripBuffer);
@@ -575,7 +573,7 @@ void TifReader::readLine(char *buffer, int x0, int x1, int shrink)
assert(tileWidth > 0 && tileHeight > 0);
int tileSize = tileWidth * tileHeight;
- uint32 *tile = new uint32[tileSize];
+ std::unique_ptr<uint32[]> tile(new uint32[tileSize]);
int x = 0;
int y = tileHeight * m_stripIndex;
@@ -583,7 +581,7 @@ void TifReader::readLine(char *buffer, int x0, int x1, int shrink)
int lastTy = tmin((int)tileHeight, m_info.m_ly - y);
while (x < m_info.m_lx) {
- int ret = TIFFReadRGBATile(m_tiff, x, y, tile);
+ int ret = TIFFReadRGBATile(m_tiff, x, y, tile.get());
assert(ret);
int tileRowSize = tmin((int)tileWidth, (int)(m_info.m_lx - x)) * pixelSize;
@@ -591,14 +589,12 @@ void TifReader::readLine(char *buffer, int x0, int x1, int shrink)
for (int ty = 0; ty < lastTy; ++ty) {
memcpy(
m_stripBuffer + (ty * m_rowLength + x) * pixelSize,
- (UCHAR *)tile + ty * tileWidth * pixelSize,
+ (UCHAR *)tile.get() + ty * tileWidth * pixelSize,
tileRowSize);
}
x += tileWidth;
}
-
- delete[] tile;
} else {
int y = m_rowsPerStrip * m_stripIndex;
int ok = TIFFReadRGBAStrip(m_tiff, y, (uint32 *)m_stripBuffer);
diff --git a/toonz/sources/include/tvectorimage.h b/toonz/sources/include/tvectorimage.h
index 669ecbabd..586e66df2 100644
--- a/toonz/sources/include/tvectorimage.h
+++ b/toonz/sources/include/tvectorimage.h
@@ -272,8 +272,8 @@ public:
//! Call the following method after stroke modification
void notifyChangedStrokes(int strokeIndex, TStroke *oldStroke = 0, bool isFlipped = false);
- UINT getFillData(IntersectionBranch *&v);
- void setFillData(IntersectionBranch *v, UINT size, bool doComputeRegions = true);
+ UINT getFillData(std::unique_ptr<IntersectionBranch[]>& v);
+ void setFillData(std::unique_ptr<IntersectionBranch[]> const& v, UINT size, bool doComputeRegions = true);
void drawAutocloses(const TVectorRenderData &rd) const; //debug method
diff --git a/toonz/sources/toonz/ObjectTracker.cpp b/toonz/sources/toonz/ObjectTracker.cpp
index 2f0d2f845..265588b83 100644
--- a/toonz/sources/toonz/ObjectTracker.cpp
+++ b/toonz/sources/toonz/ObjectTracker.cpp
@@ -10,6 +10,12 @@ Compiler: Microsoft Visual Studio.net
Luigi Sgaglione
**********************************************************************/
+#ifdef _WIN32
+#define NOMINMAX
+#endif
+
+#include <memory>
+
#include "ObjectTracker.h"
#include <math.h>
#include <stdio.h>
@@ -17,12 +23,10 @@ Luigi Sgaglione
#include <fstream>
#include <iostream>
#include <ios>
+#include <algorithm>
using namespace std;
-#define min(a, b) (((a) < (b)) ? (a) : (b))
-
-#define max(a, b) (((a) > (b)) ? (a) : (b))
#define MEANSHIFT_ITERATION_NO 15
#define ALPHA 0.98
@@ -56,11 +60,11 @@ CObjectTracker::CObjectTracker(int imW, int imH, bool _colorimage, bool _att_bac
else
HISTOGRAM_LENGTH = 8192;
- m_sTrackingObject.initHistogram = new float[HISTOGRAM_LENGTH];
+ m_sTrackingObject.initHistogram.reset(new float[HISTOGRAM_LENGTH]);
if (att_background)
- m_sTrackingObject.weights_background = new float[HISTOGRAM_LENGTH];
+ m_sTrackingObject.weights_background.reset(new float[HISTOGRAM_LENGTH]);
else
- m_sTrackingObject.weights_background = 0;
+ m_sTrackingObject.weights_background.reset();
m_sTrackingObject.Status = false;
for (short j = 0; j < HISTOGRAM_LENGTH; j++)
@@ -71,8 +75,6 @@ CObjectTracker::CObjectTracker(int imW, int imH, bool _colorimage, bool _att_bac
//Distructor
CObjectTracker::~CObjectTracker()
{
- delete[] m_sTrackingObject.initHistogram;
- delete[] m_sTrackingObject.weights_background;
}
//--------------------------------------------------------------------------------------------------------
@@ -158,7 +160,7 @@ void CObjectTracker::ObjeckTrackerHandlerByUser(TRaster32P *frame)
if (m_sTrackingObject.Status) {
if (!m_sTrackingObject.assignedAnObject) {
- FindHistogram(frame, m_sTrackingObject.initHistogram, 1);
+ FindHistogram(frame, m_sTrackingObject.initHistogram.get(), 1);
m_sTrackingObject.assignedAnObject = true;
/*
ofstream output;
@@ -218,10 +220,10 @@ void CObjectTracker::FindHistogram(TRaster32P *frame, float(*histogram), float h
normx = short(m_sTrackingObject.X + m_sTrackingObject.W / 2);
normy = short(m_sTrackingObject.Y + m_sTrackingObject.H / 2);
- for (y = max(m_sTrackingObject.Y - m_sTrackingObject.H / 2, 0);
- y <= min(m_sTrackingObject.Y + m_sTrackingObject.H / 2, m_nImageHeight - 1); y++)
- for (x = max(m_sTrackingObject.X - m_sTrackingObject.W / 2, 0);
- x <= min(m_sTrackingObject.X + m_sTrackingObject.W / 2, m_nImageWidth - 1); x++) {
+ for (y = std::max(m_sTrackingObject.Y - m_sTrackingObject.H / 2, 0);
+ y <= std::min(m_sTrackingObject.Y + m_sTrackingObject.H / 2, m_nImageHeight - 1); y++)
+ for (x = std::max(m_sTrackingObject.X - m_sTrackingObject.W / 2, 0);
+ x <= std::min(m_sTrackingObject.X + m_sTrackingObject.W / 2, m_nImageWidth - 1); x++) {
E = CheckEdgeExistance(frame, x, y);
pixelValues = GetPixelValues(frame, x, y);
@@ -278,10 +280,10 @@ void CObjectTracker::FindHistogramBackground(TRaster32P *frame, float(*backgroun
for (i = 0; i < HISTOGRAM_LENGTH; i++)
background[i] = 0.0;
- for (y = max(m_sTrackingObject.Y - (m_sTrackingObject.H * 1.73) / 2, 0);
- y <= min(m_sTrackingObject.Y + (m_sTrackingObject.H * 1.73) / 2, m_nImageHeight - 1); y++)
- for (x = max(m_sTrackingObject.X - (m_sTrackingObject.W * 1.73) / 2, 0);
- x <= min(m_sTrackingObject.X + (m_sTrackingObject.W * 1.73) / 2, m_nImageWidth - 1); x++) {
+ for (y = std::max(m_sTrackingObject.Y - (m_sTrackingObject.H * 1.73) / 2, 0.0);
+ y <= std::min(m_sTrackingObject.Y + (m_sTrackingObject.H * 1.73) / 2, m_nImageHeight - 1.0); y++)
+ for (x = std::max(m_sTrackingObject.X - (m_sTrackingObject.W * 1.73) / 2, 0.0);
+ x <= std::min(m_sTrackingObject.X + (m_sTrackingObject.W * 1.73) / 2, m_nImageWidth - 1.0); x++) {
if (((m_sTrackingObject.Y - m_sTrackingObject.H / 2) <= y) && (y <= (m_sTrackingObject.Y + m_sTrackingObject.H / 2)) && ((m_sTrackingObject.X - m_sTrackingObject.W / 2) <= x) && (x <= (m_sTrackingObject.X + m_sTrackingObject.W / 2)))
continue;
@@ -307,13 +309,13 @@ void CObjectTracker::FindHistogramBackground(TRaster32P *frame, float(*backgroun
void CObjectTracker::FindWeightsBackground(TRaster32P *frame)
{
float small1;
- float *background = new float[HISTOGRAM_LENGTH];
+ std::unique_ptr<float[]> background(new float[HISTOGRAM_LENGTH]);
short i;
for (i = 0; i < HISTOGRAM_LENGTH; i++)
m_sTrackingObject.weights_background[i] = 0.0;
//Histogram background
- FindHistogramBackground(frame, background);
+ FindHistogramBackground(frame, background.get());
//searce min != 0.0
for (i = 0; background[i] == 0.0; i++)
@@ -330,8 +332,6 @@ void CObjectTracker::FindWeightsBackground(TRaster32P *frame)
else
m_sTrackingObject.weights_background[i] = small1 / background[i];
}
-
- delete[] background;
}
//--------------------------------------------------------------------------------------------------------
@@ -349,7 +349,7 @@ void CObjectTracker::FindWightsAndCOM(TRaster32P *frame, float(*histogram))
float newY = 0.0;
ValuePixel pixelValues;
- float *weights = new float[HISTOGRAM_LENGTH];
+ std::unique_ptr<float[]> weights(new float[HISTOGRAM_LENGTH]);
//weigths
for (i = 0; i < HISTOGRAM_LENGTH; i++) {
@@ -360,10 +360,10 @@ void CObjectTracker::FindWightsAndCOM(TRaster32P *frame, float(*histogram))
}
//new location
- for (y = max(m_sTrackingObject.Y - m_sTrackingObject.H / 2, 0);
- y <= min(m_sTrackingObject.Y + m_sTrackingObject.H / 2, m_nImageHeight - 1); y++)
- for (x = max(m_sTrackingObject.X - m_sTrackingObject.W / 2, 0);
- x <= min(m_sTrackingObject.X + m_sTrackingObject.W / 2, m_nImageWidth - 1); x++) {
+ for (y = std::max(m_sTrackingObject.Y - m_sTrackingObject.H / 2, 0);
+ y <= std::min(m_sTrackingObject.Y + m_sTrackingObject.H / 2, m_nImageHeight - 1); y++)
+ for (x = std::max(m_sTrackingObject.X - m_sTrackingObject.W / 2, 0);
+ x <= std::min(m_sTrackingObject.X + m_sTrackingObject.W / 2, m_nImageWidth - 1); x++) {
E = CheckEdgeExistance(frame, x, y);
pixelValues = GetPixelValues(frame, x, y);
@@ -388,8 +388,6 @@ void CObjectTracker::FindWightsAndCOM(TRaster32P *frame, float(*histogram))
m_sTrackingObject.X = short((newX / sumOfWeights) + 0.5);
m_sTrackingObject.Y = short((newY / sumOfWeights) + 0.5);
}
-
- delete[] weights, weights = 0;
}
//--------------------------------------------------------------------------------------------------------
@@ -461,7 +459,7 @@ void CObjectTracker::FindNextLocation(TRaster32P *frame)
float DELTA;
double rho, rho1, rho2;
- float *currentHistogram = new float[HISTOGRAM_LENGTH];
+ std::unique_ptr<float[]> currentHistogram(new float[HISTOGRAM_LENGTH]);
Height = m_sTrackingObject.H;
Width = m_sTrackingObject.W;
@@ -485,13 +483,13 @@ void CObjectTracker::FindNextLocation(TRaster32P *frame)
yold = m_sTrackingObject.Y;
//Histogram with bandwidth h
- FindHistogram(frame, currentHistogram, h);
+ FindHistogram(frame, currentHistogram.get(), h);
//New location
- FindWightsAndCOM(frame, currentHistogram);
+ FindWightsAndCOM(frame, currentHistogram.get());
//Histogram with new location
- FindHistogram(frame, currentHistogram, h);
+ FindHistogram(frame, currentHistogram.get(), h);
//Battacharyya coefficient
for (i = 0; i < HISTOGRAM_LENGTH; i++)
@@ -504,13 +502,13 @@ void CObjectTracker::FindNextLocation(TRaster32P *frame)
//Histogram with bandwidth h-DELTA
m_sTrackingObject.H = Height - m_sTrackingObject.var_dim;
m_sTrackingObject.W = Width - m_sTrackingObject.var_dim;
- FindHistogram(frame, currentHistogram, h - DELTA);
+ FindHistogram(frame, currentHistogram.get(), h - DELTA);
//New location
- FindWightsAndCOM(frame, currentHistogram);
+ FindWightsAndCOM(frame, currentHistogram.get());
//Histogram with new location
- FindHistogram(frame, currentHistogram, h - DELTA);
+ FindHistogram(frame, currentHistogram.get(), h - DELTA);
//Battacharyya coefficient
for (i = 0; i < HISTOGRAM_LENGTH; i++)
@@ -523,13 +521,13 @@ void CObjectTracker::FindNextLocation(TRaster32P *frame)
//Histogram with bandwidth h+DELTA
m_sTrackingObject.H = Height + m_sTrackingObject.var_dim;
m_sTrackingObject.W = Width + m_sTrackingObject.var_dim;
- FindHistogram(frame, currentHistogram, h + DELTA);
+ FindHistogram(frame, currentHistogram.get(), h + DELTA);
//New location
- FindWightsAndCOM(frame, currentHistogram);
+ FindWightsAndCOM(frame, currentHistogram.get());
//Histogram with new location
- FindHistogram(frame, currentHistogram, h + DELTA);
+ FindHistogram(frame, currentHistogram.get(), h + DELTA);
//Battacharyya coefficient
for (i = 0; i < HISTOGRAM_LENGTH; i++)
@@ -561,10 +559,10 @@ void CObjectTracker::FindNextLocation(TRaster32P *frame)
m_sTrackingObject.Y = yold;
//Current Histogram
- FindHistogram(frame, currentHistogram, h);
+ FindHistogram(frame, currentHistogram.get(), h);
//Definitive new location
- FindWightsAndCOM(frame, currentHistogram);
+ FindWightsAndCOM(frame, currentHistogram.get());
//threshold
distanza = sqrt(float((xold - m_sTrackingObject.X) * (xold - m_sTrackingObject.X) + (yold - m_sTrackingObject.Y) * (yold - m_sTrackingObject.Y)));
@@ -573,11 +571,9 @@ void CObjectTracker::FindNextLocation(TRaster32P *frame)
break;
}
//New Histogram
- FindHistogram(frame, currentHistogram, h);
+ FindHistogram(frame, currentHistogram.get(), h);
//Update
- UpdateInitialHistogram(currentHistogram);
-
- delete[] currentHistogram, currentHistogram = 0;
+ UpdateInitialHistogram(currentHistogram.get());
}
//--------------------------------------------------------------------------------------------------------
@@ -598,17 +594,12 @@ float CObjectTracker::Matching(TRaster32P *frame, TRaster32P *frame_temp)
float dist = 0.0;
float min_dist = MAX_FLOAT;
- ValuePixel *pixel_temp;
- ValuePixel *area_ricerca;
-
short u, v, x, y;
short u_sup, v_sup;
short x_min, y_min;
short x_max, y_max;
short dimx, dimy;
short dimx_int, dimy_int;
- short *u_att;
- short *v_att;
short ok_u = 0;
short ok_v = 0;
@@ -622,14 +613,14 @@ float CObjectTracker::Matching(TRaster32P *frame, TRaster32P *frame_temp)
}
}
- u_att = new short[2 * m_sTrackingObject.dim_temp + 1];
- v_att = new short[2 * m_sTrackingObject.dim_temp + 1];
+ std::unique_ptr<short[]> u_att(new short[2 * m_sTrackingObject.dim_temp + 1]);
+ std::unique_ptr<short[]> v_att(new short[2 * m_sTrackingObject.dim_temp + 1]);
- x_min = max(m_sTrackingObject.X_temp - m_sTrackingObject.W_temp / 2, 0);
- y_min = max(m_sTrackingObject.Y_temp - m_sTrackingObject.H_temp / 2, 0);
+ x_min = std::max(m_sTrackingObject.X_temp - m_sTrackingObject.W_temp / 2, 0);
+ y_min = std::max(m_sTrackingObject.Y_temp - m_sTrackingObject.H_temp / 2, 0);
- x_max = min(m_sTrackingObject.X_temp + m_sTrackingObject.W_temp / 2, m_nImageWidth - 1);
- y_max = min(m_sTrackingObject.Y_temp + m_sTrackingObject.H_temp / 2, m_nImageHeight - 1);
+ x_max = std::min(m_sTrackingObject.X_temp + m_sTrackingObject.W_temp / 2, m_nImageWidth - 1);
+ y_max = std::min(m_sTrackingObject.Y_temp + m_sTrackingObject.H_temp / 2, m_nImageHeight - 1);
//dimension template
dimx = x_max - x_min + 1;
@@ -667,7 +658,7 @@ float CObjectTracker::Matching(TRaster32P *frame, TRaster32P *frame_temp)
if ((ok_u > 0) && (ok_v > 0)) {
//Interpolate template
- pixel_temp = new ValuePixel[dimx_int * dimy_int];
+ std::unique_ptr<ValuePixel[]> pixel_temp(new ValuePixel[dimx_int * dimy_int]);
//original value
for (int i = 0; i <= (dimx - 1); i++)
@@ -737,7 +728,7 @@ float CObjectTracker::Matching(TRaster32P *frame, TRaster32P *frame_temp)
dimx_int_ric = ((dimx + ok_u - 1) * 2 - 1);
dimy_int_ric = ((dimy + ok_v - 1) * 2 - 1);
- area_ricerca = new ValuePixel[dimx_int_ric * dimy_int_ric];
+ std::unique_ptr<ValuePixel[]> area_ricerca(new ValuePixel[dimx_int_ric * dimy_int_ric]);
//Original value
for (int i = 0; i <= ((dimx + ok_u - 1) - 1); i++)
@@ -797,7 +788,7 @@ float CObjectTracker::Matching(TRaster32P *frame, TRaster32P *frame_temp)
unsigned long indt, indc;
- float *mat_dist = new float[(2 * ok_u - 1) * (2 * ok_v - 1)];
+ std::unique_ptr<float[]> mat_dist(new float[(2 * ok_u - 1) * (2 * ok_v - 1)]);
float att_dist_cent = MAX_FLOAT;
float dist_cent;
@@ -953,12 +944,6 @@ float CObjectTracker::Matching(TRaster32P *frame, TRaster32P *frame_temp)
m_sTrackingObject.X += u_sup / 2;
m_sTrackingObject.Y += v_sup / 2;
}
-
- delete[] area_ricerca;
- delete[] mat_dist;
- delete[] pixel_temp;
- delete[] u_att;
- delete[] v_att;
}
return min_dist;
diff --git a/toonz/sources/toonz/ObjectTracker.h b/toonz/sources/toonz/ObjectTracker.h
index 640c5c0b5..b9adb41f8 100644
--- a/toonz/sources/toonz/ObjectTracker.h
+++ b/toonz/sources/toonz/ObjectTracker.h
@@ -1,8 +1,8 @@
-
-
#if !defined(OBEJCTTRACKER_H_INCLUDED_)
#define OBEJCTTRACKER_H_INCLUDED_
+#include <memory>
+
#include "traster.h"
#include "predict3d.h"
@@ -55,8 +55,8 @@ private:
short H_old;
//histogram
- float *initHistogram;
- float *weights_background;
+ std::unique_ptr<float[]> initHistogram;
+ std::unique_ptr<float[]> weights_background;
//template characterize
short X_temp;
diff --git a/toonz/sources/toonz/cellselectioncommand.cpp b/toonz/sources/toonz/cellselectioncommand.cpp
index 9444448eb..21b564266 100644
--- a/toonz/sources/toonz/cellselectioncommand.cpp
+++ b/toonz/sources/toonz/cellselectioncommand.cpp
@@ -1,4 +1,4 @@
-
+#include <memory>
#include "cellselection.h"
@@ -598,7 +598,7 @@ class ReframeUndo : public TUndo
int m_r0, m_r1;
int m_type;
int m_nr;
- TXshCell *m_cells;
+ std::unique_ptr<TXshCell[]> m_cells;
public:
std::vector<int> m_newRows;
@@ -629,11 +629,11 @@ public:
//-----------------------------------------------------------------------------
ReframeUndo::ReframeUndo(int r0, int r1, std::vector<int> columnIndeces, int type)
- : m_r0(r0), m_r1(r1), m_type(type), m_nr(0), m_cells(0), m_columnIndeces(columnIndeces)
+ : m_r0(r0), m_r1(r1), m_type(type), m_nr(0), m_columnIndeces(columnIndeces)
{
m_nr = m_r1 - m_r0 + 1;
assert(m_nr > 0);
- m_cells = new TXshCell[m_nr * (int)m_columnIndeces.size()];
+ m_cells.reset(new TXshCell[m_nr * (int)m_columnIndeces.size()]);
assert(m_cells);
int k = 0;
for (int r = r0; r <= r1; r++)
@@ -647,8 +647,6 @@ ReframeUndo::ReframeUndo(int r0, int r1, std::vector<int> columnIndeces, int typ
ReframeUndo::~ReframeUndo()
{
- delete[] m_cells;
- m_cells = 0;
}
//-----------------------------------------------------------------------------
diff --git a/toonz/sources/toonz/predict3d.cpp b/toonz/sources/toonz/predict3d.cpp
index 80bd339b9..f5c5f5979 100644
--- a/toonz/sources/toonz/predict3d.cpp
+++ b/toonz/sources/toonz/predict3d.cpp
@@ -25,6 +25,7 @@
* - i punti di cui e' nota la posizione corrente non sono
* allineati, ovvero non giacciono su un'unica retta
---------------------------------------------------------------------*/
+#include <memory>
#include "predict3d.h"
#include "metnum.h"
@@ -59,8 +60,6 @@ bool Predict3D::Predict(int k, Point initial[], Point current[], bool visible[])
/* Definizione e allocazione delle variabili */
int n, m, kvis;
double **x;
- double *y;
- double *c;
int i, ii, j, l;
kvis = 0;
for (i = 0; i < k; i++)
@@ -74,8 +73,8 @@ bool Predict3D::Predict(int k, Point initial[], Point current[], bool visible[])
x = AllocMatrix(m, n);
if (x == 0)
return false;
- y = new double[n];
- c = new double[m];
+ std::unique_ptr<double[]> y(new double[n]);
+ std::unique_ptr<double[]> c(new double[m]);
/* Costruzione dei coefficienti del sistema */
@@ -108,11 +107,9 @@ bool Predict3D::Predict(int k, Point initial[], Point current[], bool visible[])
/* Soluzione del sistema */
- int status = Approx(n, m, x, y, c);
+ int status = Approx(n, m, x, y.get(), c.get());
if (status != 0) {
FreeMatrix(m, x);
- delete[] y;
- delete[] c;
return false;
}
@@ -130,8 +127,6 @@ bool Predict3D::Predict(int k, Point initial[], Point current[], bool visible[])
}
FreeMatrix(m, x);
- delete[] y;
- delete[] c;
return true;
}
diff --git a/toonz/sources/toonz/timestretchpopup.cpp b/toonz/sources/toonz/timestretchpopup.cpp
index 13ea0e3db..68e360fd0 100644
--- a/toonz/sources/toonz/timestretchpopup.cpp
+++ b/toonz/sources/toonz/timestretchpopup.cpp
@@ -1,4 +1,4 @@
-
+#include <memory>
#include "timestretchpopup.h"
@@ -44,7 +44,7 @@ class TimeStretchUndo : public TUndo
int m_r0, m_r1;
int m_c0, m_c1;
int m_newRange;
- TXshCell *m_cells;
+ std::unique_ptr<TXshCell[]> m_cells;
//servono per modificare la selezione
TimeStretchPopup::STRETCH_TYPE m_type;
@@ -53,12 +53,12 @@ class TimeStretchUndo : public TUndo
public:
TimeStretchUndo(int r0, int c0, int r1, int c1, int newRange, TimeStretchPopup::STRETCH_TYPE type)
- : m_r0(r0), m_c0(c0), m_r1(r1), m_c1(c1), m_newRange(newRange), m_cells(0), m_type(type), m_c0Old(0), m_c1Old(0)
+ : m_r0(r0), m_c0(c0), m_r1(r1), m_c1(c1), m_newRange(newRange), m_type(type), m_c0Old(0), m_c1Old(0)
{
int nr = m_r1 - m_r0 + 1;
int nc = m_c1 - m_c0 + 1;
assert(nr > 0 && nc > 0);
- m_cells = new TXshCell[nr * nc];
+ m_cells.reset(new TXshCell[nr * nc]);
assert(m_cells);
int k = 0;
for (int c = c0; c <= c1; c++)
@@ -68,8 +68,6 @@ public:
~TimeStretchUndo()
{
- delete[] m_cells;
- m_cells = 0;
}
void setOldColumnRange(int c0, int c1)
diff --git a/toonz/sources/toonz/trackerpopup.cpp b/toonz/sources/toonz/trackerpopup.cpp
index d046a81fb..c5d2abac4 100644
--- a/toonz/sources/toonz/trackerpopup.cpp
+++ b/toonz/sources/toonz/trackerpopup.cpp
@@ -402,40 +402,40 @@ bool Tracker::setup()
}
//ID object
- short *id = new short[m_trackerCount];
+ std::unique_ptr<short[]> id(new short[m_trackerCount]);
if (!id) {
m_lastErrorCode = 1;
return false;
}
//(x,y) coordinate object
- short *x = new short[m_trackerCount];
+ std::unique_ptr<short[]> x(new short[m_trackerCount]);
if (!x) {
m_lastErrorCode = 1;
return false;
}
- short *y = new short[m_trackerCount];
+ std::unique_ptr<short[]> y(new short[m_trackerCount]);
if (!y) {
m_lastErrorCode = 1;
return false;
}
//Width and Height of object box
- short *Width = new short[m_trackerCount];
+ std::unique_ptr<short[]> Width(new short[m_trackerCount]);
if (!Width) {
m_lastErrorCode = 1;
return false;
}
- short *Height = new short[m_trackerCount];
+ std::unique_ptr<short[]> Height(new short[m_trackerCount]);
if (!Height) {
m_lastErrorCode = 1;
return false;
}
//# start frame
- m_numstart = new int[m_trackerCount];
+ std::unique_ptr<int[]> m_numstart(new int[m_trackerCount]);
if (!m_numstart) {
m_lastErrorCode = 1;
return false;
@@ -628,11 +628,6 @@ bool Tracker::setup()
m_trackerRegionIndex = 0;
m_oldObjectId = 0;
- delete[] x;
- delete[] y;
- delete[] Width;
- delete[] Height;
- delete[] id;
return true;
}
diff --git a/toonz/sources/toonzlib/sandor_fxs/CallCircle.cpp b/toonz/sources/toonzlib/sandor_fxs/CallCircle.cpp
index 491d90f5d..015db2717 100644
--- a/toonz/sources/toonzlib/sandor_fxs/CallCircle.cpp
+++ b/toonz/sources/toonzlib/sandor_fxs/CallCircle.cpp
@@ -27,7 +27,7 @@ int callcircle_xydwCompare(const void *a, const void *b)
return 0;
}
-CCallCircle::CCallCircle(const double r) : m_r(r), m_nb(0), m_c(0)
+CCallCircle::CCallCircle(const double r) : m_r(r), m_nb(0)
{
int rr = (int)r + 1;
rr *= 2;
@@ -39,7 +39,7 @@ CCallCircle::CCallCircle(const double r) : m_r(r), m_nb(0), m_c(0)
return;
}
- m_c = new SXYDW[dd2];
+ m_c.reset(new SXYDW[dd2]);
if (!m_c)
throw SMemAllocError("in callCircle");
for (int y = -rr; y <= rr; y++)
@@ -52,17 +52,14 @@ CCallCircle::CCallCircle(const double r) : m_r(r), m_nb(0), m_c(0)
m_nb++;
}
}
- qsort(m_c, m_nb, sizeof(SXYDW), callcircle_xydwCompare);
+ qsort(m_c.get(), m_nb, sizeof(SXYDW), callcircle_xydwCompare);
}
void CCallCircle::null()
{
m_nb = 0;
m_r = 0.0;
- if (m_c) {
- delete[] m_c;
- m_c = 0;
- }
+ m_c.reset();
}
CCallCircle::~CCallCircle()
diff --git a/toonz/sources/toonzlib/sandor_fxs/CallCircle.h b/toonz/sources/toonzlib/sandor_fxs/CallCircle.h
index cfbe6e6d1..1ccca9087 100644
--- a/toonz/sources/toonzlib/sandor_fxs/CallCircle.h
+++ b/toonz/sources/toonzlib/sandor_fxs/CallCircle.h
@@ -22,14 +22,14 @@ class CCallCircle
{
double m_r;
int m_nb;
- SXYDW *m_c;
+ std::unique_ptr<SXYDW[]> m_c;
void draw(UCHAR *drawB, const int lX, const int lY,
const int xx, const int yy, const double r);
void null();
public:
- CCallCircle() : m_r(0.0), m_nb(0), m_c(0){};
+ CCallCircle() : m_r(0.0), m_nb(0) {}
CCallCircle(const double r);
virtual ~CCallCircle();
void print();
diff --git a/toonz/sources/toonzlib/sandor_fxs/Pattern.cpp b/toonz/sources/toonzlib/sandor_fxs/Pattern.cpp
index 905d0fb13..3d98a54eb 100644
--- a/toonz/sources/toonzlib/sandor_fxs/Pattern.cpp
+++ b/toonz/sources/toonzlib/sandor_fxs/Pattern.cpp
@@ -30,7 +30,7 @@
//#define P(a) tmsg_warning("-- %d --",a)
-CPattern::CPattern(RASTER *imgContour) : m_lX(0), m_lY(0), m_pat(0)
+CPattern::CPattern(RASTER *imgContour) : m_lX(0), m_lY(0)
{
if (!readPattern(imgContour)) {
throw SFileReadError();
@@ -50,10 +50,7 @@ CPattern::~CPattern()
void CPattern::null()
{
m_lX = m_lY = 0;
- if (m_pat) {
- delete[] m_pat;
- m_pat = 0;
- }
+ m_pat.reset();
m_fn[0] = '\0';
}
@@ -130,7 +127,7 @@ bool CPattern::readPattern(RASTER *imgContour)
if (lpic.m_lX > 0 && lpic.m_lY > 0 && lpic.m_pic) {
m_lX = lpic.m_lX;
m_lY = lpic.m_lY;
- m_pat = new UC_PIXEL[m_lX * m_lY];
+ m_pat.reset(new UC_PIXEL[m_lX * m_lY]);
if (!m_pat) {
m_lX = m_lY = 0;
lpic.null();
@@ -140,7 +137,7 @@ bool CPattern::readPattern(RASTER *imgContour)
for (int y = 0; y < m_lY; y++)
for (int x = 0; x < m_lX; x++) {
UC_PIXEL *plp = lpic.m_pic + y * lpic.m_lX + x;
- UC_PIXEL *ucp = m_pat + y * m_lX + x;
+ UC_PIXEL *ucp = m_pat.get() + y * m_lX + x;
ucp->r = plp->r;
ucp->g = plp->g;
ucp->b = plp->b;
@@ -169,7 +166,7 @@ void CPattern::getMapPixel(const int xx, const int yy, const double invScale,
int x = I_ROUND(d2xx);
int y = I_ROUND(d2yy);
if (x >= 0 && x < m_lX && y >= 0 && y < m_lY) {
- pucp = m_pat + y * m_lX + x;
+ pucp = m_pat.get() + y * m_lX + x;
pucp = (pucp->m) == (UCHAR)0 ? 0 : pucp;
}
}
@@ -183,7 +180,7 @@ void CPattern::getMapPixel(const int xx, const int yy, const double invScale,
int x = I_ROUND(dxx);
int y = I_ROUND(dyy);
if (x >= 0 && x < m_lX && y >= 0 && y < m_lY) {
- pucp = m_pat + y * m_lX + x;
+ pucp = m_pat.get() + y * m_lX + x;
pucp = (pucp->m) == (UCHAR)0 ? 0 : pucp;
}
}
@@ -194,7 +191,7 @@ void CPattern::getBBox(SRECT &bb)
bb.y0 = m_lY;
bb.x1 = -1;
bb.y1 = -1;
- UC_PIXEL *pPic = m_pat;
+ UC_PIXEL *pPic = m_pat.get();
for (int y = 0; y < m_lY; y++)
for (int x = 0; x < m_lX; x++, pPic++)
if (pPic->m > (UCHAR)0) {
@@ -213,7 +210,7 @@ void CPattern::optimalizeSize()
if (bb.x0 <= bb.x1 && bb.y0 <= bb.y1) {
int nLX = bb.x1 - bb.x0 + 1;
int nLY = bb.y1 - bb.y0 + 1;
- UC_PIXEL *nPat = new UC_PIXEL[nLX * nLY];
+ std::unique_ptr<UC_PIXEL[]> nPat(new UC_PIXEL[nLX * nLY]);
if (!nPat) {
char s[200];
sprintf(s, "in Pattern Optimalization \n");
@@ -221,8 +218,8 @@ void CPattern::optimalizeSize()
}
for (int y = bb.y0; y <= bb.y1; y++)
for (int x = bb.x0; x <= bb.x1; x++) {
- UC_PIXEL *pPat = m_pat + y * m_lX + x;
- UC_PIXEL *pNPat = nPat + (y - bb.y0) * nLX + x - bb.x0;
+ UC_PIXEL *pPat = m_pat.get() + y * m_lX + x;
+ UC_PIXEL *pNPat = nPat.get() + (y - bb.y0) * nLX + x - bb.x0;
pNPat->r = pPat->r;
pNPat->g = pPat->g;
pNPat->b = pPat->b;
@@ -230,8 +227,7 @@ void CPattern::optimalizeSize()
}
m_lX = nLX;
m_lY = nLY;
- delete[] m_pat;
- m_pat = nPat;
+ m_pat = std::move(nPat);
}
}
@@ -255,15 +251,15 @@ void CPattern::rotate(const double angle)
double co = cos(-DEG2RAD(angle));
double si = sin(-DEG2RAD(angle));
- UC_PIXEL *nPat = new UC_PIXEL[nLXY * nLXY];
+ std::unique_ptr<UC_PIXEL[]> nPat(new UC_PIXEL[nLXY * nLXY]);
if (!nPat) {
char s[200];
sprintf(s, "in Pattern Rotation \n");
throw SMemAllocError(s);
}
- eraseBuffer(nLXY, nLXY, nPat);
+ eraseBuffer(nLXY, nLXY, nPat.get());
- UC_PIXEL *pNPat = nPat;
+ UC_PIXEL *pNPat = nPat.get();
for (int y = 0; y < nLXY; y++)
for (int x = 0; x < nLXY; x++, pNPat++) {
UC_PIXEL *pucp = 0;
@@ -276,8 +272,7 @@ void CPattern::rotate(const double angle)
}
}
m_lX = m_lY = nLXY;
- delete[] m_pat;
- m_pat = nPat;
+ m_pat = std::move(nPat);
try {
optimalizeSize();
diff --git a/toonz/sources/toonzlib/sandor_fxs/Pattern.h b/toonz/sources/toonzlib/sandor_fxs/Pattern.h
index dd76666c8..c09793a6e 100644
--- a/toonz/sources/toonzlib/sandor_fxs/Pattern.h
+++ b/toonz/sources/toonzlib/sandor_fxs/Pattern.h
@@ -11,6 +11,7 @@
#pragma once
#endif // _MSC_VER > 1000
+#include <memory>
#include "STColSelPic.h"
#include "SDef.h"
#include "toonz4.6/pixel.h"
@@ -18,7 +19,7 @@
class CPattern
{
int m_lX, m_lY;
- UC_PIXEL *m_pat;
+ std::unique_ptr<UC_PIXEL[]> m_pat;
char m_fn[1024];
void null();
@@ -37,7 +38,7 @@ class CPattern
void eraseBuffer(const int lX, const int lY, UC_PIXEL *buffer);
public:
- CPattern() : m_lX(0), m_lY(0), m_pat(0) { m_fn[0] = '\0'; };
+ CPattern() : m_lX(0), m_lY(0) { m_fn[0] = '\0'; };
CPattern(RASTER *imgContour);
virtual ~CPattern();
void rotate(const double angle);
@@ -132,7 +133,7 @@ public:
int x1 = I_ROUND(d2xx);
int y1 = I_ROUND(d2yy);
if (x1 >= 0 && x1 < m_lX && y1 >= 0 && y1 < m_lY) {
- pucp = m_pat + y1 * m_lX + x1;
+ pucp = m_pat.get() + y1 * m_lX + x1;
pucp = (pucp->m) == (UCHAR)0 ? 0 : pucp;
}
// ----------------------------------------------------
diff --git a/toonz/sources/toonzlib/sandor_fxs/PatternPosition.cpp b/toonz/sources/toonzlib/sandor_fxs/PatternPosition.cpp
index fa158a3c1..62879b584 100644
--- a/toonz/sources/toonzlib/sandor_fxs/PatternPosition.cpp
+++ b/toonz/sources/toonzlib/sandor_fxs/PatternPosition.cpp
@@ -8,6 +8,8 @@
#pragma warning(disable : 4996)
#endif
+#include <memory>
+
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
@@ -180,7 +182,6 @@ void CPatternPosition::makeDDPositions(const int lX, const int lY, UCHAR *sel,
{
const int maxNbDDC = 20;
vector<SPOINT> ddc[maxNbDDC];
- UCHAR *lSel = 0;
// Checking parameters
if (lX <= 0 || lY <= 0 || !sel)
@@ -202,33 +203,29 @@ void CPatternPosition::makeDDPositions(const int lX, const int lY, UCHAR *sel,
throw;
}
// Preparing local selection
- lSel = new UCHAR[lX * lY];
+ std::unique_ptr<UCHAR[]> lSel(new UCHAR[lX * lY]);
if (!lSel) {
char s[50];
sprintf(s, "in Pattern Position Generation");
throw SMemAllocError(s);
}
- memcpy(lSel, sel, lX * lY * sizeof(UCHAR));
+ memcpy(lSel.get(), sel, lX * lY * sizeof(UCHAR));
SRECT bb;
- sel0255To01(lX, lY, lSel, bb);
+ sel0255To01(lX, lY, lSel.get(), bb);
if (bb.x0 > bb.x1 || bb.y0 > bb.y1) {
- delete[] lSel;
return;
}
try {
int x = 0, y = 0;
- while (findEmptyPos(lX, lY, lSel, x, y, bb)) {
+ while (findEmptyPos(lX, lY, lSel.get(), x, y, bb)) {
SPOINT sp = {x, y};
m_pos.push_back(sp);
int iddc = nbDDC == 1 ? 0 : rand() % nbDDC;
- eraseCurrentArea(lX, lY, lSel, ddc[iddc], sp.x, sp.y);
+ eraseCurrentArea(lX, lY, lSel.get(), ddc[iddc], sp.x, sp.y);
}
- delete[] lSel;
-
} catch (exception) {
- delete[] lSel;
char s[50];
sprintf(s, "in Pattern Position Generation");
throw SMemAllocError(s);
diff --git a/toonz/sources/toonzlib/sandor_fxs/SDirection.cpp b/toonz/sources/toonzlib/sandor_fxs/SDirection.cpp
index 88b333642..3b24878a1 100644
--- a/toonz/sources/toonzlib/sandor_fxs/SDirection.cpp
+++ b/toonz/sources/toonzlib/sandor_fxs/SDirection.cpp
@@ -1,4 +1,4 @@
-
+#include <memory>
// SDirection.cpp: implementation of the CSDirection class.
//
@@ -12,7 +12,7 @@
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
-CSDirection::CSDirection() : m_lX(0), m_lY(0), m_dir(0), m_lDf(0)
+CSDirection::CSDirection() : m_lX(0), m_lY(0), m_lDf(0)
{
for (int i = 0; i < NBDIR; i++)
m_df[i] = 0;
@@ -20,19 +20,19 @@ CSDirection::CSDirection() : m_lX(0), m_lY(0), m_dir(0), m_lDf(0)
CSDirection::CSDirection(const int lX, const int lY, const UCHAR *sel,
const int sens)
- : m_lX(lX), m_lY(lY), m_dir(0), m_lDf(0)
+ : m_lX(lX), m_lY(lY), m_lDf(0)
{
for (int i = 0; i < NBDIR; i++)
m_df[i] = 0;
try {
if (m_lX > 0 && m_lY > 0) {
- m_dir = new UCHAR[m_lX * m_lY];
+ m_dir.reset(new UCHAR[m_lX * m_lY]);
if (!m_dir) {
null();
throw SMemAllocError("in directionMap");
}
- memcpy(m_dir, sel, sizeof(UCHAR) * m_lX * m_lY);
+ memcpy(m_dir.get(), sel, sizeof(UCHAR) * m_lX * m_lY);
setDir01();
// For optimalization purpose.
// The quality is better, if it is removed.
@@ -46,19 +46,19 @@ CSDirection::CSDirection(const int lX, const int lY, const UCHAR *sel,
CSDirection::CSDirection(const int lX, const int lY, const UCHAR *sel,
const int sens, const int border)
- : m_lX(lX), m_lY(lY), m_dir(0), m_lDf(0)
+ : m_lX(lX), m_lY(lY), m_lDf(0)
{
for (int i = 0; i < NBDIR; i++)
m_df[i] = 0;
try {
if (m_lX > 0 && m_lY > 0) {
- m_dir = new UCHAR[m_lX * m_lY];
+ m_dir.reset(new UCHAR[m_lX * m_lY]);
if (!m_dir) {
null();
throw SMemAllocError("in directionMap");
}
- memcpy(m_dir, sel, sizeof(UCHAR) * m_lX * m_lY);
+ memcpy(m_dir.get(), sel, sizeof(UCHAR) * m_lX * m_lY);
setDir01();
if (border > 0)
setContourBorder(border);
@@ -75,14 +75,14 @@ bool CSDirection::isContourBorder(const int xx, const int yy,
for (int y = yy - border; y <= (yy + border); y++)
for (int x = xx - border; x <= (xx + border); x++)
if (x >= 0 && y >= 0 && x < m_lX && y < m_lY)
- if (*(m_dir + y * m_lX + x) == (UCHAR)0)
+ if (*(m_dir.get() + y * m_lX + x) == (UCHAR)0)
return true;
return false;
}
void CSDirection::setContourBorder(const int border)
{
- UCHAR *pDir = m_dir;
+ UCHAR *pDir = m_dir.get();
int y = 0;
for (y = 0; y < m_lY; y++)
for (int x = 0; x < m_lX; x++, pDir++)
@@ -91,22 +91,17 @@ void CSDirection::setContourBorder(const int border)
*pDir = (UCHAR)2;
int xy = m_lX * m_lY;
- pDir = m_dir;
+ pDir = m_dir.get();
for (y = 0; y < xy; y++, pDir++)
*pDir = *pDir == (UCHAR)2 ? (UCHAR)0 : *pDir;
}
void CSDirection::null()
{
- if (m_dir) {
- delete[] m_dir;
- m_dir = 0;
+ m_dir.reset();
+ for (auto&& df : m_df) {
+ df.reset();
}
- for (int i = 0; i < NBDIR; i++)
- if (m_df[i]) {
- delete[] m_df[i];
- m_df[i] = 0;
- }
m_lX = m_lY = 0;
m_lDf = 0;
}
@@ -203,7 +198,7 @@ UCHAR CSDirection::getDir(const int xx, const int yy, UCHAR *sel)
void CSDirection::makeDir(UCHAR *sel)
{
UCHAR *pSel = sel;
- UCHAR *pDir = m_dir;
+ UCHAR *pDir = m_dir.get();
for (int y = 0; y < m_lY; y++)
for (int x = 0; x < m_lX; x++, pSel++, pDir++) {
*pDir = 0;
@@ -281,7 +276,7 @@ UCHAR CSDirection::equalizeDir_LT50(UCHAR *sel,
void CSDirection::equalizeDir(UCHAR *sel, const int d)
{
UCHAR *pSel = sel;
- UCHAR *pDir = m_dir;
+ UCHAR *pDir = m_dir.get();
for (int y = 0; y < m_lY; y++)
for (int x = 0; x < m_lX; x++, pSel++) {
if (*pSel > (UCHAR)0) {
@@ -321,7 +316,7 @@ void CSDirection::makeDirFilter(const int sens)
m_lDf = size * size;
for (int i = 0; i < NBDIR; i++) {
- m_df[i] = new SXYW[m_lDf];
+ m_df[i].reset(new SXYW[m_lDf]);
if (!m_df[i]) {
null();
throw SMemAllocError("in directionMap");
@@ -378,41 +373,38 @@ UCHAR CSDirection::blurRadius(UCHAR *sel, const int xx, const int yy, const int
void CSDirection::blurRadius(const int dBlur)
{
if (m_lX > 0 && m_lY > 0 && m_dir) {
- UCHAR *sel = new UCHAR[m_lX * m_lY];
+ std::unique_ptr<UCHAR[]> sel(new UCHAR[m_lX * m_lY]);
if (!sel)
throw SMemAllocError("in directionMap");
- memcpy(sel, m_dir, m_lX * m_lY * sizeof(UCHAR));
- UCHAR *pSel = sel;
- UCHAR *pDir = m_dir;
+ memcpy(sel.get(), m_dir.get(), m_lX * m_lY * sizeof(UCHAR));
+ UCHAR *pSel = sel.get();
+ UCHAR *pDir = m_dir.get();
for (int y = 0; y < m_lY; y++)
for (int x = 0; x < m_lX; x++, pSel++, pDir++)
if (*pSel > (UCHAR)0)
- *pDir = blurRadius(sel, x, y, dBlur);
- delete[] sel;
+ *pDir = blurRadius(sel.get(), x, y, dBlur);
}
}
void CSDirection::setDir01()
{
int xy = m_lX * m_lY;
- UCHAR *pDir = m_dir;
+ UCHAR *pDir = m_dir.get();
for (int i = 0; i < xy; i++, pDir++)
*pDir = *pDir > (UCHAR)0 ? (UCHAR)1 : (UCHAR)0;
}
void CSDirection::doDir()
{
- UCHAR *sel = 0;
if (m_lX > 0 && m_lY > 0 && m_dir) {
- sel = new UCHAR[m_lX * m_lY];
+ std::unique_ptr<UCHAR[]> sel(new UCHAR[m_lX * m_lY]);
if (!sel)
throw SMemAllocError("in directionMap");
size_t length = (size_t)(m_lX * m_lY * sizeof(UCHAR));
- memcpy(sel, m_dir, length);
- makeDir(sel);
- memcpy(sel, m_dir, length);
- equalizeDir(sel, 3);
- delete[] sel;
+ memcpy(sel.get(), m_dir.get(), length);
+ makeDir(sel.get());
+ memcpy(sel.get(), m_dir.get(), length);
+ equalizeDir(sel.get(), 3);
}
}
@@ -421,7 +413,7 @@ void CSDirection::doRadius(const double rH, const double rLR,
{
try {
int xy = m_lX * m_lY;
- UCHAR *pDir = m_dir;
+ UCHAR *pDir = m_dir.get();
double r[4] = {D_CUT_0_1(rH), D_CUT_0_1(rLR), D_CUT_0_1(rV), D_CUT_0_1(rRL)};
for (int i = 0; i < xy; i++, pDir++)
@@ -439,5 +431,5 @@ void CSDirection::doRadius(const double rH, const double rLR,
void CSDirection::getResult(UCHAR *sel)
{
- memcpy(sel, m_dir, (size_t)(m_lX * m_lY * sizeof(UCHAR)));
+ memcpy(sel, m_dir.get(), (size_t)(m_lX * m_lY * sizeof(UCHAR)));
}
diff --git a/toonz/sources/toonzlib/sandor_fxs/SDirection.h b/toonz/sources/toonzlib/sandor_fxs/SDirection.h
index 9e03f8072..3da23b261 100644
--- a/toonz/sources/toonzlib/sandor_fxs/SDirection.h
+++ b/toonz/sources/toonzlib/sandor_fxs/SDirection.h
@@ -13,6 +13,8 @@
#include "SDef.h"
+#include <memory>
+#include <array>
#include <vector>
using namespace std;
@@ -29,8 +31,8 @@ typedef struct {
class CSDirection
{
int m_lX, m_lY;
- UCHAR *m_dir;
- SXYW *m_df[NBDIR];
+ std::unique_ptr<UCHAR[]> m_dir;
+ std::array<std::unique_ptr<SXYW[]>, NBDIR> m_df;
int m_lDf;
void null();
diff --git a/toonz/sources/toonzlib/sandor_fxs/blend.cpp b/toonz/sources/toonzlib/sandor_fxs/blend.cpp
index 5c57d12e4..ad4be7754 100644
--- a/toonz/sources/toonzlib/sandor_fxs/blend.cpp
+++ b/toonz/sources/toonzlib/sandor_fxs/blend.cpp
@@ -100,31 +100,28 @@ struct SelectionData {
// using raw bits and bitwise operators, and use just the double of the space required with bit arrays.
class SelectionArrayPtr
{
- SelectionData *m_buffer;
+ std::unique_ptr<SelectionData[]> m_buffer;
public:
- SelectionArrayPtr() : m_buffer(0) {}
-
inline void allocate(unsigned int count)
{
- m_buffer = new SelectionData[count];
- memset(m_buffer, 0, count * sizeof(SelectionData));
+ m_buffer.reset(new SelectionData[count]);
+ memset(m_buffer.get(), 0, count * sizeof(SelectionData));
}
inline void destroy()
{
- delete[] m_buffer;
- m_buffer = 0;
+ m_buffer.reset();
}
inline SelectionData *data() const
{
- return m_buffer;
+ return m_buffer.get();
}
inline SelectionData *data()
{
- return m_buffer;
+ return m_buffer.get();
}
};
diff --git a/toonz/sources/toonzlib/tcenterlinepolygonizer.cpp b/toonz/sources/toonzlib/tcenterlinepolygonizer.cpp
index 4e81016c0..028f0fe95 100644
--- a/toonz/sources/toonzlib/tcenterlinepolygonizer.cpp
+++ b/toonz/sources/toonzlib/tcenterlinepolygonizer.cpp
@@ -166,13 +166,12 @@ inline unsigned char PixelEvaluator<TPixelCM32>::getBlackOrWhite(int x, int y)
class Signaturemap
{
- unsigned char *m_array;
+ std::unique_ptr<unsigned char[]> m_array;
int m_rowSize;
int m_colSize;
public:
Signaturemap(const TRasterP &ras, int threshold);
- ~Signaturemap() { delete[] m_array; }
template <typename T>
void readRasterData(const TRasterPT<T> &ras, int threshold);
@@ -238,11 +237,11 @@ void Signaturemap::readRasterData(const TRasterPT<T> &ras, int threshold)
m_rowSize = ras->getLx() + 2;
m_colSize = ras->getLy() + 2;
- m_array = new unsigned char[m_rowSize * m_colSize];
+ m_array.reset(new unsigned char[m_rowSize * m_colSize]);
- memset(m_array, none << 1, m_rowSize);
+ memset(m_array.get(), none << 1, m_rowSize);
- currByte = m_array + m_rowSize;
+ currByte = m_array.get() + m_rowSize;
for (y = 0; y < ras->getLy(); ++y) {
*currByte = none << 1;
currByte++;
@@ -512,14 +511,13 @@ inline bool isCircular(int a, int b, int c)
//--------------------------------------------------------------------------
//Extracts a 'next corner' array - helps improving overall speed
-inline int *findNextCorners(RawBorder &path)
+inline std::unique_ptr<int[]> findNextCorners(RawBorder &path)
{
- int i, currentCorner;
- int *corners = new int[path.size()];
+ std::unique_ptr<int[]> corners(new int[path.size()]);
//NOTE: 0 is a corner, due to the path extraction procedure.
- currentCorner = 0;
- for (i = path.size() - 1; i >= 0; --i) {
+ int currentCorner = 0;
+ for (int i = path.size() - 1; i >= 0; --i) {
if (path[currentCorner].x() != path[i].x() &&
path[currentCorner].y() != path[i].y())
currentCorner = i + 1;
@@ -532,11 +530,11 @@ inline int *findNextCorners(RawBorder &path)
//--------------------------------------------------------------------------
//Calculate furthest k satisfying 1) for all fixed i.
-inline int *furthestKs(RawBorder &path, int *&nextCorners)
+inline std::unique_ptr<int[]> furthestKs(RawBorder &path, std::unique_ptr<int[]>& nextCorners)
{
int n = path.size();
- int *kVector = new int[n];
+ std::unique_ptr<int[]> kVector(new int[n]);
enum { left,
up,
@@ -650,17 +648,18 @@ inline int *furthestKs(RawBorder &path, int *&nextCorners)
// arcs approximating the given raw border:
// for every a in [i,res[i]], the arc connecting border[i] and
// border[a] will be a possible one.
-inline int *calculateForwardArcs(RawBorder &border, bool ambiguitiesCheck)
+inline std::unique_ptr<int[]> calculateForwardArcs(RawBorder &border, bool ambiguitiesCheck)
{
- int i, j, n = (int)border.size();
+ int const n = (int)border.size();
- int *nextCorners;
- int *k = furthestKs(border, nextCorners);
- int *K = new int[n];
- int *res = new int[n];
+ std::unique_ptr<int[]> nextCorners;
+ std::unique_ptr<int[]> k = furthestKs(border, nextCorners);
+ std::unique_ptr<int[]> K(new int[n]);
+ std::unique_ptr<int[]> res(new int[n]);
//find K[i]= min {k[j]}, j=i..n-1.
- for (i = 0; i < n; ++i) {
+ for (int i = 0; i < n; ++i) {
+ int j;
for (j = i, K[i] = k[i]; isCircular(i, j, K[i]); j = (j + 1) % n)
if (isCircular(j, k[j], K[i]))
K[i] = k[j];
@@ -672,7 +671,7 @@ inline int *calculateForwardArcs(RawBorder &border, bool ambiguitiesCheck)
// square);
// second, arcs of the kind [i,j] with j<i, become [i,n].
- for (i = n - 1, j = 0; j < n; i = j, ++j) {
+ for (int i = n - 1, j = 0; j < n; i = j, ++j) {
res[j] = K[i] < j ? (K[i] == 0 ? n - 1 : n) : K[i] - 1;
}
@@ -680,14 +679,14 @@ inline int *calculateForwardArcs(RawBorder &border, bool ambiguitiesCheck)
//straight-skeleton thinning process.
if (ambiguitiesCheck) {
- for (i = 1; nextCorners[i] > 0; i = nextCorners[i]) {
+ for (int i = 1; nextCorners[i] > 0; i = nextCorners[i]) {
if (border[i].getAmbiguous() == RawBorderPoint::right) {
//Check vertices from i (excluded) to res[res[i]]; if in it there exists vertex k so that pos(k)==pos(i)...
//This prevents the existence of 0 degree angles in the optimal polygon.
int rrPlus1 = (res[res[i] % n] + 1) % n;
- for (j = nextCorners[i];
+ for (int j = nextCorners[i];
isCircular(i, j, rrPlus1) && j != i; //remember that isCircular(a,a,b) == 1 ...
j = nextCorners[j]) {
if (border[j].getAmbiguous() && (border[j].pos() == border[i].pos())) {
@@ -707,10 +706,6 @@ inline int *calculateForwardArcs(RawBorder &border, bool ambiguitiesCheck)
}
}
- delete[] k;
- delete[] K;
- delete[] nextCorners;
-
return res;
}
@@ -772,16 +767,15 @@ inline double penalty(RawBorder &path, int a, int b)
inline void reduceBorder(RawBorder &border, Contour &res, bool ambiguitiesCheck)
{
- int i, j, k, a, *b, n = border.size(), m;
- double newPenalty;
+ int n = border.size();
int minPenaltyNext;
- int *minPenaltyNextArray = new int[n];
+ std::unique_ptr<int[]> minPenaltyNextArray(new int[n]);
//Calculate preliminary infos
- int *longestArcFrom = calculateForwardArcs(border, ambiguitiesCheck);
+ std::unique_ptr<int[]> longestArcFrom = calculateForwardArcs(border, ambiguitiesCheck);
calculateSums(border);
- double *penaltyToEnd = new double[n + 1];
+ std::unique_ptr<double[]> penaltyToEnd(new double[n + 1]);
//EXPLANATION:
//The fastest way to extract the optimal reduced border is based on the
@@ -793,24 +787,26 @@ inline void reduceBorder(RawBorder &border, Contour &res, bool ambiguitiesCheck)
//longestArc[a[i-1]-1]<a[i], and a[m]=n.
//Calculate m
- for (i = 0, m = 0; i < n; i = longestArcFrom[i])
+ int m = 0;
+ for (int i = 0; i < n; i = longestArcFrom[i])
++m;
//Calculate b[]
- b = new int[m + 1];
+ std::unique_ptr<int[]> b(new int[m + 1]);
b[m] = n;
- for (i = 0, j = 0; j < m; i = longestArcFrom[i], ++j)
+ for (int i = 0, j = 0; j < m; i = longestArcFrom[i], ++j)
b[j] = i;
//NOTE: a[] need not be completely found - we just remember the
//a=a[j+1] currently needed.
//Now, build the optimal polygon
- for (j = m - 1, a = n; j >= 0; --j) {
+ for (int j = m - 1, a = n; j >= 0; --j) {
+ int k;
for (k = b[j]; k >= 0 && longestArcFrom[k] >= a; --k) {
penaltyToEnd[k] = infinity;
- for (i = a; i <= longestArcFrom[k]; ++i) {
- newPenalty = penaltyToEnd[i] + penalty(border, k, i);
+ for (int i = a; i <= longestArcFrom[k]; ++i) {
+ double newPenalty = penaltyToEnd[i] + penalty(border, k, i);
if (newPenalty < penaltyToEnd[k])
penaltyToEnd[k] = newPenalty;
minPenaltyNext = i;
@@ -823,7 +819,7 @@ inline void reduceBorder(RawBorder &border, Contour &res, bool ambiguitiesCheck)
//Finally, read off the optimal polygon
res.resize(m);
- for (i = j = 0; i < n; i = minPenaltyNextArray[i], ++j) {
+ for (int i = 0, j = 0; i < n; i = minPenaltyNextArray[i], ++j) {
res[j] = ContourNode(border[i].x(), border[i].y());
//Ambiguities are still remembered in the output polygon.
@@ -833,13 +829,9 @@ inline void reduceBorder(RawBorder &border, Contour &res, bool ambiguitiesCheck)
res[j].setAttribute(ContourNode::AMBIGUOUS_RIGHT);
}
- delete[] longestArcFrom;
- delete[] minPenaltyNextArray;
delete[] border.sums();
delete[] border.sums2();
delete[] border.sumsMix();
- delete[] penaltyToEnd;
- delete[] b;
}
//--------------------------------------------------------------------------
diff --git a/toonz/sources/toonzlib/tdistort.cpp b/toonz/sources/toonzlib/tdistort.cpp
index 66efdf133..b3921e3d4 100644
--- a/toonz/sources/toonzlib/tdistort.cpp
+++ b/toonz/sources/toonzlib/tdistort.cpp
@@ -1,4 +1,5 @@
-
+#include <memory>
+#include <array>
#include "toonz/tdistort.h"
#include "traster.h"
@@ -115,7 +116,7 @@ void resample(const TRasterCM32P &rasIn, TRasterCM32P &rasOut, const TDistorter
if (rasOut->getLx() < 1 || rasOut->getLy() < 1 || rasIn->getLx() < 1 || rasIn->getLy() < 1)
return;
- TPointD *preImages = new TPointD[distorter.maxInvCount()];
+ std::unique_ptr<TPointD[]> preImages(new TPointD[distorter.maxInvCount()]);
int x, y;
int i;
@@ -126,7 +127,7 @@ void resample(const TRasterCM32P &rasIn, TRasterCM32P &rasOut, const TDistorter
for (x = 0; pix != endPix; pix++, x++) {
TPixelCM32 pixDown;
- int count = distorter.invMap(convert(p) + TPointD(x + 0.5, y + 0.5), preImages);
+ int count = distorter.invMap(convert(p) + TPointD(x + 0.5, y + 0.5), preImages.get());
for (i = count - 1; i >= 0; --i) {
TPixelCM32 pixUp;
TPointD preImage(preImages[i].x - 0.5, preImages[i].y - 0.5);
@@ -141,8 +142,6 @@ void resample(const TRasterCM32P &rasIn, TRasterCM32P &rasOut, const TDistorter
*pix = pixDown;
}
}
-
- delete[] preImages;
}
//---------------------------------------------------------------------------------
@@ -165,7 +164,7 @@ void resampleClosestPixel(const TRasterPT<T> &rasIn, TRasterPT<T> &rasOut,
if (rasOut->getLx() < 1 || rasOut->getLy() < 1 || rasIn->getLx() < 1 || rasIn->getLy() < 1)
return;
- TPointD *preImages = new TPointD[distorter.maxInvCount()];
+ std::unique_ptr<TPointD[]> preImages(new TPointD[distorter.maxInvCount()]);
int x, y;
int i;
@@ -178,7 +177,7 @@ void resampleClosestPixel(const TRasterPT<T> &rasIn, TRasterPT<T> &rasOut,
T pixDown(0, 0, 0, 0);
//preImages.clear();
- int count = distorter.invMap(convert(p) + TPointD(x + 0.5, y + 0.5), preImages);
+ int count = distorter.invMap(convert(p) + TPointD(x + 0.5, y + 0.5), preImages.get());
for (i = count - 1; i >= 0; --i) {
T pixUp(0, 0, 0, 0);
TPointD preImage(preImages[i].x - 0.5, preImages[i].y - 0.5);
@@ -191,8 +190,6 @@ void resampleClosestPixel(const TRasterPT<T> &rasIn, TRasterPT<T> &rasOut,
*pix = pixDown;
}
}
-
- delete[] preImages;
}
//---------------------------------------------------------------------------------
@@ -213,7 +210,7 @@ void resampleClosestPixel(const TRasterCM32P &rasIn, TRasterCM32P &rasOut,
if (rasOut->getLx() < 1 || rasOut->getLy() < 1 || rasIn->getLx() < 1 || rasIn->getLy() < 1)
return;
- TPointD *preImages = new TPointD[distorter.maxInvCount()];
+ std::unique_ptr<TPointD[]> preImages(new TPointD[distorter.maxInvCount()]);
int x, y;
int i;
@@ -225,7 +222,7 @@ void resampleClosestPixel(const TRasterCM32P &rasIn, TRasterCM32P &rasOut,
for (; pix != endPix; pix++, x++) {
TPixelCM32 pixDown(0, 0, 255);
- int count = distorter.invMap(convert(p) + TPointD(x + 0.5, y + 0.5), preImages);
+ int count = distorter.invMap(convert(p) + TPointD(x + 0.5, y + 0.5), preImages.get());
for (i = count - 1; i >= 0; --i) {
TPixelCM32 pixUp(0, 0, 255);
TPointD preImage(preImages[i].x - 0.5, preImages[i].y - 0.5);
@@ -238,8 +235,6 @@ void resampleClosestPixel(const TRasterCM32P &rasIn, TRasterCM32P &rasOut,
*pix = pixDown;
}
}
-
- delete[] preImages;
}
//=================================================================================
@@ -359,51 +354,55 @@ void resample(const TRasterPT<T> &rasIn, TRasterPT<T> &rasOut, const TDistorter
int invsCount = distorter.maxInvCount();
//Allocate buffers
- TPointD *invs[2];
- invs[0] = new TPointD[invsCount * (rasOut->getLx() + 1)];
- invs[1] = new TPointD[invsCount * (rasOut->getLx() + 1)];
- int *counts[2];
- counts[0] = new int[rasOut->getLx() + 1];
- counts[1] = new int[rasOut->getLx() + 1];
- T *temp = new T[rasIn->getLx()];
- TPointD *newInvs, *oldInvs, *currOldInv, *currNewInv;
- int x, y, i, *newCounts, *oldCounts;
+ std::array<std::unique_ptr<TPointD[]>, 2> invs = {
+ std::unique_ptr<TPointD[]>(new TPointD[invsCount * (rasOut->getLx() + 1)]),
+ std::unique_ptr<TPointD[]>(new TPointD[invsCount * (rasOut->getLx() + 1)]),
+ };
+ std::array<std::unique_ptr<int[]>, 2> counts = {
+ std::unique_ptr<int[]>(new int[rasOut->getLx() + 1]),
+ std::unique_ptr<int[]>(new int[rasOut->getLx() + 1]),
+ };
+ std::unique_ptr<T[]> temp(new T[rasIn->getLx()]);
TPointD shift(convert(p) + TPointD(0.5, 0.5));
//Fill in the first inverses (lower edge of output image)
- currOldInv = invs[0];
- oldCounts = counts[0];
- for (x = 0; x <= rasOut->getLx(); currOldInv += invsCount, ++x)
- oldCounts[x] = distorter.invMap(shift + TPointD(x, 0.0), currOldInv);
+ {
+ TPointD* currOldInv = invs[0].get();
+ int* oldCounts = counts[0].get();
+ for (int x = 0; x <= rasOut->getLx(); currOldInv += invsCount, ++x)
+ oldCounts[x] = distorter.invMap(shift + TPointD(x, 0.0), currOldInv);
+ }
//For each output row
- for (y = 0; y < rasOut->getLy(); ++y) {
+ for (int y = 0; y < rasOut->getLy(); ++y) {
//Alternate inverse buffers
- oldInvs = invs[y % 2];
- newInvs = invs[(y + 1) % 2];
- oldCounts = counts[y % 2];
- newCounts = counts[(y + 1) % 2];
+ TPointD* oldInvs = invs[y % 2].get();
+ TPointD* newInvs = invs[(y + 1) % 2].get();
+ int* oldCounts = counts[y % 2].get();
+ int* newCounts = counts[(y + 1) % 2].get();
//Build the new inverses
- currNewInv = newInvs;
- for (x = 0; x <= rasOut->getLx(); currNewInv += invsCount, ++x)
- newCounts[x] = distorter.invMap(shift + TPointD(x, y + 1.0), currNewInv);
+ {
+ TPointD* currNewInv = newInvs;
+ for (int x = 0; x <= rasOut->getLx(); currNewInv += invsCount, ++x)
+ newCounts[x] = distorter.invMap(shift + TPointD(x, y + 1.0), currNewInv);
+ }
//Filter each pixel in the row
T *pix = rasOut->pixels(y);
- currOldInv = oldInvs;
- currNewInv = newInvs;
- for (x = 0; x < rasOut->getLx(); currOldInv += invsCount, currNewInv += invsCount, ++x, ++pix) {
+ TPointD* currOldInv = oldInvs;
+ TPointD* currNewInv = newInvs;
+ for (int x = 0; x < rasOut->getLx(); currOldInv += invsCount, currNewInv += invsCount, ++x, ++pix) {
T pixDown(0, 0, 0, 0);
int count = tmin(oldCounts[x], oldCounts[x + 1], newCounts[x]);
- for (i = 0; i < count; ++i) {
+ for (int i = 0; i < count; ++i) {
T pixUp(0, 0, 0, 0);
pixUp = filterPixel<T, CHANNEL_TYPE>(
currOldInv[i].x - 0.5, (currOldInv + invsCount)[i].x - 0.5,
currOldInv[i].y - 0.5, currNewInv[i].y - 0.5,
- rasIn, temp);
+ rasIn, temp.get());
pixDown = overPix(pixDown, pixUp);
}
@@ -411,12 +410,6 @@ void resample(const TRasterPT<T> &rasIn, TRasterPT<T> &rasOut, const TDistorter
*pix = pixDown;
}
}
-
- delete[] invs[0];
- delete[] invs[1];
- delete[] counts[0];
- delete[] counts[1];
- delete[] temp;
}
} // namespace
diff --git a/toonz/sources/toonzlib/txsheet.cpp b/toonz/sources/toonzlib/txsheet.cpp
index afb869241..8fe7fb370 100644
--- a/toonz/sources/toonzlib/txsheet.cpp
+++ b/toonz/sources/toonzlib/txsheet.cpp
@@ -761,7 +761,7 @@ void TXsheet::stepCells(int r0, int c0, int r1, int c1, int type)
if (nr < 1 || nc <= 0)
return;
int size = nr * nc;
- TXshCell *cells = new TXshCell[size];
+ std::unique_ptr<TXshCell[]> cells(new TXshCell[size]);
if (!cells)
return;
//salvo il contenuto delle celle in cells
@@ -788,10 +788,6 @@ void TXsheet::stepCells(int r0, int c0, int r1, int c1, int type)
i += type; //dipende dal tipo di step (2 o 3 per ora)
}
}
-
- if (cells)
- delete[] cells;
- cells = 0;
}
//-----------------------------------------------------------------------------
@@ -877,7 +873,7 @@ void TXsheet::eachCells(int r0, int c0, int r1, int c1, int type)
int size = newRows * nc;
assert(size > 0);
- TXshCell *cells = new TXshCell[size];
+ std::unique_ptr<TXshCell[]> cells(new TXshCell[size]);
assert(cells);
int i, j, k;
@@ -900,10 +896,6 @@ void TXsheet::eachCells(int r0, int c0, int r1, int c1, int type)
setCell(i, j, cells[k]);
k++;
}
-
- if (cells)
- delete[] cells;
- cells = 0;
}
//-----------------------------------------------------------------------------
@@ -989,7 +981,7 @@ void TXsheet::rollupCells(int r0, int c0, int r1, int c1)
int nc = c1 - c0 + 1;
int size = 1 * nc;
assert(size > 0);
- TXshCell *cells = new TXshCell[size];
+ std::unique_ptr<TXshCell[]> cells(new TXshCell[size]);
assert(cells);
//in cells copio il contenuto delle celle che mi interessano
@@ -1004,10 +996,6 @@ void TXsheet::rollupCells(int r0, int c0, int r1, int c1)
insertCells(r1, k, 1);
setCell(r1, k, cells[k - c0]); //setto le celle
}
-
- if (cells)
- delete[] cells;
- cells = 0;
}
//-----------------------------------------------------------------------------
@@ -1018,7 +1006,7 @@ void TXsheet::rolldownCells(int r0, int c0, int r1, int c1)
int nc = c1 - c0 + 1;
int size = 1 * nc;
assert(size > 0);
- TXshCell *cells = new TXshCell[size];
+ std::unique_ptr<TXshCell[]> cells(new TXshCell[size]);
assert(cells);
//in cells copio il contenuto delle celle che mi interessano
@@ -1033,10 +1021,6 @@ void TXsheet::rolldownCells(int r0, int c0, int r1, int c1)
insertCells(r0, k, 1);
setCell(r0, k, cells[k - c0]); //setto le celle
}
-
- if (cells)
- delete[] cells;
- cells = 0;
}
//-----------------------------------------------------------------------------
@@ -1051,9 +1035,9 @@ void TXsheet::timeStretch(int r0, int c0, int r1, int c1, int nr)
for (c = c0; c <= c1; c++) {
int dn = nr - oldNr;
assert(oldNr > 0);
- TXshCell *cells = new TXshCell[oldNr];
+ std::unique_ptr<TXshCell[]> cells(new TXshCell[oldNr]);
assert(cells);
- getCells(r0, c, oldNr, cells);
+ getCells(r0, c, oldNr, cells.get());
insertCells(r0 + 1, c, dn);
int i;
for (i = nr - 1; i >= 0; i--) {
@@ -1061,18 +1045,15 @@ void TXsheet::timeStretch(int r0, int c0, int r1, int c1, int nr)
if (j < i)
setCell(i + r0, c, cells[j]);
}
- if (cells)
- delete[] cells;
- cells = 0;
}
} else /* rimpicciolisce */
{
int c;
for (c = c0; c <= c1; c++) {
int dn = oldNr - nr;
- TXshCell *cells = new TXshCell[oldNr];
+ std::unique_ptr<TXshCell[]> cells(new TXshCell[oldNr]);
assert(cells);
- getCells(r0, c, oldNr, cells);
+ getCells(r0, c, oldNr, cells.get());
int i;
for (i = 0; i < nr; i++) {
int j = i * double(oldNr) / double(nr);
@@ -1080,9 +1061,6 @@ void TXsheet::timeStretch(int r0, int c0, int r1, int c1, int nr)
setCell(i + r0, c, cells[j]);
}
removeCells(r1 - dn + 1, c, dn);
- if (cells)
- delete[] cells;
- cells = 0;
}
}
}
diff --git a/toonz/sources/toonzqt/pluginhost.cpp b/toonz/sources/toonzqt/pluginhost.cpp
index 714d8df2f..4e5d401b0 100644
--- a/toonz/sources/toonzqt/pluginhost.cpp
+++ b/toonz/sources/toonzqt/pluginhost.cpp
@@ -132,7 +132,6 @@ PluginInformation::~PluginInformation()
fin_();
}
}
- delete[] param_pages_;
}
void PluginInformation::add_ref()
@@ -818,7 +817,7 @@ bool RasterFxPluginHost::setParamStructure(int n, toonz_param_page_t *p, int &er
param_resources.clear();
- toonz_param_page_t *origin_pages = new toonz_param_page_t[n];
+ std::unique_ptr<toonz_param_page_t[]> origin_pages(new toonz_param_page_t[n]);
for (int i = 0; i < n; i++) {
toonz_param_page_t &dst_page = origin_pages[i];
const toonz_param_page_t &src_page = p[i];
@@ -876,7 +875,7 @@ bool RasterFxPluginHost::setParamStructure(int n, toonz_param_page_t *p, int &er
}
pi_->param_page_num_ = n;
- pi_->param_pages_ = origin_pages;
+ pi_->param_pages_ = std::move(origin_pages);
return true;
}
return false;
diff --git a/toonz/sources/toonzqt/pluginhost.h b/toonz/sources/toonzqt/pluginhost.h
index ccbdab9be..d3dfd28fd 100644
--- a/toonz/sources/toonzqt/pluginhost.h
+++ b/toonz/sources/toonzqt/pluginhost.h
@@ -86,7 +86,7 @@ public:
void (*fin_)(void);
int ref_count_;
int param_page_num_;
- toonz_param_page_t *param_pages_;
+ std::unique_ptr<toonz_param_page_t[]> param_pages_;
std::vector<UIPage *> ui_pages_;
std::vector<ParamView *> param_views_;
@@ -96,7 +96,7 @@ public:
std::vector<std::shared_ptr<std::string>> param_string_tbl_; /* shared_ptr< void > では non-virtual destructor が呼ばれないので */
public:
- PluginInformation() : desc_(NULL), library_(NULL), handler_(NULL), host_(NULL), ini_(NULL), fin_(NULL), ref_count_(1), param_page_num_(0), param_pages_(NULL)
+ PluginInformation() : desc_(NULL), library_(NULL), handler_(NULL), host_(NULL), ini_(NULL), fin_(NULL), ref_count_(1), param_page_num_(0)
{
}