diff --git a/toonz/sources/common/tapptools/tcli.cpp b/toonz/sources/common/tapptools/tcli.cpp index baac4c5..a632e9e 100644 --- a/toonz/sources/common/tapptools/tcli.cpp +++ b/toonz/sources/common/tapptools/tcli.cpp @@ -205,7 +205,7 @@ void MultiArgument::fetch(int index, int &argc, char *argv[]) //--------------------------------------------------------- UsageLine::UsageLine() - : m_elements(0), m_count(0) + : m_count(0) { } @@ -213,9 +213,6 @@ UsageLine::UsageLine() UsageLine::~UsageLine() { - if (m_elements) { - delete[] m_elements; - } } //--------------------------------------------------------- @@ -223,8 +220,8 @@ UsageLine::~UsageLine() UsageLine::UsageLine(const UsageLine &src) { m_count = src.m_count; - m_elements = new UsageElementPtr[m_count]; - ::memcpy(m_elements, src.m_elements, m_count * sizeof(m_elements[0])); + m_elements.reset(new UsageElementPtr[m_count]); + ::memcpy(m_elements.get(), src.m_elements.get(), m_count * sizeof(m_elements[0])); } //--------------------------------------------------------- @@ -232,9 +229,8 @@ UsageLine::UsageLine(const UsageLine &src) UsageLine &UsageLine::operator=(const UsageLine &src) { if (src.m_elements != m_elements) { - delete[] m_elements; - m_elements = new UsageElementPtr[src.m_count]; - ::memcpy(m_elements, src.m_elements, src.m_count * sizeof(m_elements[0])); + m_elements.reset(new UsageElementPtr[src.m_count]); + ::memcpy(m_elements.get(), src.m_elements.get(), src.m_count * sizeof(m_elements[0])); } m_count = src.m_count; return *this; @@ -245,8 +241,8 @@ UsageLine &UsageLine::operator=(const UsageLine &src) UsageLine::UsageLine(const UsageLine &src, UsageElement &elem) { m_count = src.m_count; - m_elements = new UsageElementPtr[m_count + 1]; - ::memcpy(m_elements, src.m_elements, m_count * sizeof(m_elements[0])); + m_elements.reset(new UsageElementPtr[m_count + 1]); + ::memcpy(m_elements.get(), src.m_elements.get(), m_count * sizeof(m_elements[0])); m_elements[m_count++] = &elem; } @@ -255,8 +251,8 @@ UsageLine::UsageLine(const UsageLine &src, UsageElement &elem) UsageLine::UsageLine(int count) { m_count = count; - m_elements = new UsageElementPtr[m_count]; - ::memset(m_elements, 0, m_count * sizeof(m_elements[0])); + m_elements.reset(new UsageElementPtr[m_count]); + ::memset(m_elements.get(), 0, m_count * sizeof(m_elements[0])); } //--------------------------------------------------------- @@ -264,7 +260,7 @@ UsageLine::UsageLine(int count) UsageLine::UsageLine(UsageElement &elem) { m_count = 1; - m_elements = new UsageElementPtr[m_count]; + m_elements.reset(new UsageElementPtr[m_count]); m_elements[0] = &elem; } @@ -273,7 +269,7 @@ UsageLine::UsageLine(UsageElement &elem) UsageLine::UsageLine(UsageElement &a, UsageElement &b) { m_count = 2; - m_elements = new UsageElementPtr[m_count]; + m_elements.reset(new UsageElementPtr[m_count]); m_elements[0] = &a; m_elements[1] = &b; } diff --git a/toonz/sources/common/tgl/tgl.cpp b/toonz/sources/common/tgl/tgl.cpp index e4bfeeb..9b04bb7 100644 --- a/toonz/sources/common/tgl/tgl.cpp +++ b/toonz/sources/common/tgl/tgl.cpp @@ -435,8 +435,7 @@ void tglDraw(const TCubic &cubic, int precision, GLenum pointOrLine) { CHECK_ERRORS_BY_GL; assert(pointOrLine == GL_POINT || pointOrLine == GL_LINE); - float(*ctrlPts)[3]; - ctrlPts = new float[4][3]; + float ctrlPts[4][3]; ctrlPts[0][0] = cubic.getP0().x; ctrlPts[0][1] = cubic.getP0().y; @@ -463,8 +462,6 @@ void tglDraw(const TCubic &cubic, int precision, GLenum pointOrLine) CHECK_ERRORS_BY_GL; glEvalMesh1(pointOrLine, 0, precision); CHECK_ERRORS_BY_GL; - - delete[] ctrlPts; } //----------------------------------------------------------------------------- diff --git a/toonz/sources/common/tiio/tiio_bmp.cpp b/toonz/sources/common/tiio/tiio_bmp.cpp index d33948b..3ceb903 100644 --- a/toonz/sources/common/tiio/tiio_bmp.cpp +++ b/toonz/sources/common/tiio/tiio_bmp.cpp @@ -1,9 +1,9 @@ - - #ifdef _WIN32 #pragma warning(disable : 4996) #endif +#include + #include "tiio_bmp.h" // #include "bmp/filebmp.h" #include "tpixel.h" @@ -109,7 +109,7 @@ class BmpReader : public Tiio::Reader BMP_HEADER m_header; char *m_line; int m_lineSize; - TPixel *m_cmap; + std::unique_ptr m_cmap; bool m_corrupted; typedef int (BmpReader::*ReadLineMethod)(char *buffer, int x0, int x1, int shrink); ReadLineMethod m_readLineMethod; @@ -155,7 +155,9 @@ private: //--------------------------------------------------------- BmpReader::BmpReader() - : m_chan(0), m_cmap(0), m_corrupted(false), m_readLineMethod(&BmpReader::readNoLine) + : m_chan(0) + , m_corrupted(false) + , m_readLineMethod(&BmpReader::readNoLine) { memset(&m_header, 0, sizeof m_header); } @@ -164,7 +166,6 @@ BmpReader::BmpReader() BmpReader::~BmpReader() { - delete[] m_cmap; } //--------------------------------------------------------- @@ -261,8 +262,8 @@ void BmpReader::readHeader() ? m_header.biClrUsed : 1 << m_header.biBitCount; assert(cmaplen <= 256); - m_cmap = new TPixel[256]; - TPixel32 *pix = m_cmap; + m_cmap.reset(new TPixel[256]); + TPixel32 *pix = m_cmap.get(); for (int i = 0; i < cmaplen; i++) { pix->b = getc(m_chan); pix->g = getc(m_chan); diff --git a/toonz/sources/common/traster/traster.cpp b/toonz/sources/common/traster/traster.cpp index aaf5624..9e978a0 100644 --- a/toonz/sources/common/traster/traster.cpp +++ b/toonz/sources/common/traster/traster.cpp @@ -296,19 +296,18 @@ void TRaster::yMirror() { const int rowSize = m_lx * m_pixelSize; const int wrapSize = m_wrap * m_pixelSize; - UCHAR *auxBuf = new UCHAR[rowSize]; + std::unique_ptr auxBuf(new UCHAR[rowSize]); lock(); UCHAR *buff1 = getRawData(); UCHAR *buff2 = getRawData(0, (m_ly - 1)); while (buff1 < buff2) { - ::memcpy(auxBuf, buff1, rowSize); + ::memcpy(auxBuf.get(), buff1, rowSize); ::memcpy(buff1, buff2, rowSize); - ::memcpy(buff2, auxBuf, rowSize); + ::memcpy(buff2, auxBuf.get(), rowSize); buff1 += wrapSize; buff2 -= wrapSize; } unlock(); - delete[] auxBuf; } //------------------------------------------------------------ @@ -317,22 +316,21 @@ void TRaster::xMirror() { const int wrapSize = m_wrap * m_pixelSize; const int lastPixelOffset = (m_lx - 1) * m_pixelSize; - UCHAR *auxBuf = new UCHAR[m_pixelSize]; + std::unique_ptr auxBuf(new UCHAR[m_pixelSize]); lock(); UCHAR *row = getRawData(); for (int i = 0; i < m_ly; i++) { UCHAR *a = row, *b = row + lastPixelOffset; while (a < b) { - ::memcpy(auxBuf, a, m_pixelSize); + ::memcpy(auxBuf.get(), a, m_pixelSize); ::memcpy(a, b, m_pixelSize); - ::memcpy(b, auxBuf, m_pixelSize); + ::memcpy(b, auxBuf.get(), m_pixelSize); a += m_pixelSize; b -= m_pixelSize; } row += wrapSize; } unlock(); - delete[] auxBuf; } //------------------------------------------------------------ @@ -341,15 +339,15 @@ void TRaster::rotate180() { //const int rowSize = m_lx * m_pixelSize; const int wrapSize = m_wrap * m_pixelSize; - UCHAR *auxBuf = new UCHAR[m_pixelSize]; + std::unique_ptr auxBuf(new UCHAR[m_pixelSize]); lock(); UCHAR *buff1 = getRawData(); UCHAR *buff2 = buff1 + wrapSize * (m_ly - 1) + m_pixelSize * (m_lx - 1); if (m_wrap == m_lx) { while (buff1 < buff2) { - ::memcpy(auxBuf, buff1, m_pixelSize); + ::memcpy(auxBuf.get(), buff1, m_pixelSize); ::memcpy(buff1, buff2, m_pixelSize); - ::memcpy(buff2, auxBuf, m_pixelSize); + ::memcpy(buff2, auxBuf.get(), m_pixelSize); buff1 += m_pixelSize; buff2 -= m_pixelSize; } @@ -357,9 +355,9 @@ void TRaster::rotate180() for (int y = 0; y < m_ly / 2; y++) { UCHAR *a = buff1, *b = buff2; for (int x = 0; x < m_lx; x++) { - ::memcpy(auxBuf, a, m_pixelSize); + ::memcpy(auxBuf.get(), a, m_pixelSize); ::memcpy(a, b, m_pixelSize); - ::memcpy(b, auxBuf, m_pixelSize); + ::memcpy(b, auxBuf.get(), m_pixelSize); a += m_pixelSize; b -= m_pixelSize; } @@ -368,7 +366,6 @@ void TRaster::rotate180() } } unlock(); - delete[] auxBuf; } //------------------------------------------------------------ diff --git a/toonz/sources/common/trop/brush.cpp b/toonz/sources/common/trop/brush.cpp index eb335db..f716657 100644 --- a/toonz/sources/common/trop/brush.cpp +++ b/toonz/sources/common/trop/brush.cpp @@ -1,3 +1,4 @@ +#include #include #include "trop.h" @@ -6,16 +7,16 @@ class HalfCord { - int *m_array; + std::unique_ptr m_array; int m_radius; public: HalfCord(int radius) + : m_radius(radius) + , m_array(new int[radius + 1]) { assert(radius >= 0); - m_radius = radius; - m_array = new int[m_radius + 1]; - memset(m_array, 0, (m_radius + 1) * sizeof(int)); + memset(m_array.get(), 0, (m_radius + 1) * sizeof(int)); float dCircle = 1.25f - m_radius; // inizializza decision variable int y = m_radius; // inizializzazione indice scanline @@ -34,10 +35,6 @@ public: } while (y >= x); } - ~HalfCord() - { - delete[] m_array; - } inline int getCord(int x) { assert(0 <= x && x <= m_radius); diff --git a/toonz/sources/common/trop/tblur.cpp b/toonz/sources/common/trop/tblur.cpp index b4b8715..e256d76 100644 --- a/toonz/sources/common/trop/tblur.cpp +++ b/toonz/sources/common/trop/tblur.cpp @@ -866,7 +866,6 @@ void doBlurRgb(TRasterPT &dstRas, TRasterPT &srcRas, double blur, int dx, delete[] col1; delete[] row1; r1->unlock(); - //delete[]fbuffer; } } diff --git a/toonz/sources/common/trop/tresample.cpp b/toonz/sources/common/trop/tresample.cpp index c570ea2..78d7498 100644 --- a/toonz/sources/common/trop/tresample.cpp +++ b/toonz/sources/common/trop/tresample.cpp @@ -861,7 +861,7 @@ wrap_in = wrap UINT calc_value; UCHAR *calc_byte = 0; int goodcols; - int *col_height = new int[lu]; + std::unique_ptr col_height(new int[lu]); int ref_u, ref_v; int filter_diam_u = max_pix_ref_u - min_pix_ref_u + 1; int filter_diam_v = max_pix_ref_v - min_pix_ref_v + 1; @@ -873,7 +873,7 @@ wrap_in = wrap assert(col_height); CALC_VALUE_INIT - ch = col_height; + ch = col_height.get(); ch_end = ch + lu; while (ch < ch_end) { @@ -985,9 +985,6 @@ wrap_in = wrap } } assert(!calc_byte || calc_byte == calc + calc_bytesize); - - if (col_height) - delete[] col_height; } /*---------------------------------------------------------------------------*/ diff --git a/toonz/sources/common/tvrender/tfont_nt.cpp b/toonz/sources/common/tvrender/tfont_nt.cpp index 44af3e1..7cbf774 100644 --- a/toonz/sources/common/tvrender/tfont_nt.cpp +++ b/toonz/sources/common/tvrender/tfont_nt.cpp @@ -72,13 +72,12 @@ TFont::Impl::Impl(const LOGFONTW &logfont, HDC hdc) DWORD pairsCount = GetKerningPairsW(hdc, 0, 0); if (pairsCount) { m_hasKerning = true; - KERNINGPAIR *tempKernPairs = new KERNINGPAIR[pairsCount]; - GetKerningPairsW(hdc, pairsCount, tempKernPairs); + std::unique_ptr tempKernPairs(new KERNINGPAIR[pairsCount]); + GetKerningPairsW(hdc, pairsCount, tempKernPairs.get()); for (UINT i = 0; i < pairsCount; i++) { pair key = make_pair(tempKernPairs[i].wFirst, tempKernPairs[i].wSecond); m_kerningPairs[key] = tempKernPairs[i].iKernAmount; } - delete[] tempKernPairs; } else m_hasKerning = false; @@ -132,17 +131,17 @@ TPoint TFont::drawChar(TVectorImageP &image, wchar_t charcode, wchar_t nextCharC return TPoint(); } - LPVOID lpvBuffer = new char[charMemorySize]; + std::unique_ptr lpvBuffer(new char[charMemorySize]); - charMemorySize = GetGlyphOutlineW(m_pimpl->m_hdc, charcode, GGO_NATIVE, &gm, charMemorySize, lpvBuffer, &mat2); + charMemorySize = GetGlyphOutlineW(m_pimpl->m_hdc, charcode, GGO_NATIVE, &gm, charMemorySize, lpvBuffer.get(), &mat2); if (charMemorySize == GDI_ERROR) { assert(0); return TPoint(); } - TTPOLYGONHEADER *header = (TTPOLYGONHEADER *)lpvBuffer; + TTPOLYGONHEADER *header = (TTPOLYGONHEADER *)lpvBuffer.get(); - while ((char *)header < (char *)lpvBuffer + charMemorySize) { + while ((char *)header < (char *)lpvBuffer.get() + charMemorySize) { points.clear(); TThickPoint startPoint = toThickPoint(header->pfxStart); points.push_back(startPoint); @@ -204,8 +203,6 @@ TPoint TFont::drawChar(TVectorImageP &image, wchar_t charcode, wchar_t nextCharC header = (TTPOLYGONHEADER *)curve; } - delete[] lpvBuffer; - image->group(0, image->getStrokeCount()); return getDistance(charcode, nextCharCode); diff --git a/toonz/sources/include/tcli.h b/toonz/sources/include/tcli.h index 5aa2f59..e46fcf8 100644 --- a/toonz/sources/include/tcli.h +++ b/toonz/sources/include/tcli.h @@ -242,16 +242,11 @@ public: template class MultiArgumentT : public MultiArgument { - T *m_values; + std::unique_ptr m_values; public: MultiArgumentT(string name, string help) - : MultiArgument(name, help), m_values(0){}; - ~MultiArgumentT() - { - if (m_values) - delete[] m_values; - }; + : MultiArgument(name, help) {} T operator[](int index) { assert(0 <= index && index < m_count); @@ -273,17 +268,13 @@ public: void resetValue() { - if (m_values) - delete[] m_values; - m_values = 0; + m_values.reset(); m_count = m_index = 0; }; void allocate(int count) { - if (m_values) - delete[] m_values; - m_values = count ? new T[count] : 0; + m_values.reset((count > 0) ? new T[count] : nullptr); m_count = count; m_index = 0; }; @@ -298,7 +289,7 @@ typedef UsageElement *UsageElementPtr; class DVAPI UsageLine { protected: - UsageElementPtr *m_elements; + std::unique_ptr m_elements; int m_count; public: diff --git a/toonz/sources/include/toonz/Naa2TlvConverter.h b/toonz/sources/include/toonz/Naa2TlvConverter.h index ca368b3..807f505 100644 --- a/toonz/sources/include/toonz/Naa2TlvConverter.h +++ b/toonz/sources/include/toonz/Naa2TlvConverter.h @@ -30,14 +30,13 @@ class WorkRaster public: typedef T Pixel; WorkRaster(int lx, int ly) : m_lx(lx), m_ly(ly), m_buffer(new Pixel[lx * ly]) {} - ~WorkRaster() { delete[] m_buffer; } inline int getLx() const { return m_lx; } inline int getLy() const { return m_ly; } - inline Pixel *pixels(int y = 0) const { return m_buffer + m_lx * y; } + inline Pixel *pixels(int y = 0) const { return m_buffer.get() + m_lx * y; } private: - Pixel *m_buffer; + std::unique_ptr m_buffer; int m_lx, m_ly; }; diff --git a/toonz/sources/sound/aiff/tsio_aiff.cpp b/toonz/sources/sound/aiff/tsio_aiff.cpp index b1d5bcb..0151547 100644 --- a/toonz/sources/sound/aiff/tsio_aiff.cpp +++ b/toonz/sources/sound/aiff/tsio_aiff.cpp @@ -169,17 +169,11 @@ class TSSNDChunk : public TAIFFChunk public: TUINT32 m_offset; //dall'inizio dei sample frames tra i wavedata TUINT32 m_blockSize; - UCHAR *m_waveData; + std::unique_ptr m_waveData; TSSNDChunk(string name, TINT32 length) : TAIFFChunk(name, length) {} - ~TSSNDChunk() - { - if (m_waveData) - delete[] m_waveData; - } - bool read(ifstream &is) { @@ -192,10 +186,10 @@ public: } // alloca il buffer dei campioni - m_waveData = new UCHAR[m_length - OFFSETBLOCSIZE_NBYTE]; + m_waveData.reset(new UCHAR[m_length - OFFSETBLOCSIZE_NBYTE]); if (!m_waveData) cout << " ERRORE " << endl; - is.read((char *)m_waveData, m_length - OFFSETBLOCSIZE_NBYTE); + is.read((char *)m_waveData.get(), m_length - OFFSETBLOCSIZE_NBYTE); return true; } @@ -215,7 +209,7 @@ public: os.write((char *)&length, sizeof(TINT32)); os.write((char *)&offset, sizeof(TINT32)); os.write((char *)&blockSize, sizeof(TINT32)); - os.write((char *)m_waveData, m_length - OFFSETBLOCSIZE_NBYTE); + os.write((char *)m_waveData.get(), m_length - OFFSETBLOCSIZE_NBYTE); return true; } }; @@ -427,7 +421,7 @@ TSoundTrackP TSoundTrackReaderAiff::load() memcpy( (void *)track->getRawData(), - (void *)(ssndChunk->m_waveData + ssndChunk->m_offset), + (void *)(ssndChunk->m_waveData.get() + ssndChunk->m_offset), commChunk->m_frames * commChunk->m_chans); break; @@ -444,11 +438,11 @@ TSoundTrackP TSoundTrackReaderAiff::load() if (!TNZ_LITTLE_ENDIAN) memcpy( (void *)track->getRawData(), - (void *)(ssndChunk->m_waveData + ssndChunk->m_offset), + (void *)(ssndChunk->m_waveData.get() + ssndChunk->m_offset), commChunk->m_frames * track->getSampleSize()); else swapAndCopySamples( - (short *)(ssndChunk->m_waveData + ssndChunk->m_offset), + (short *)(ssndChunk->m_waveData.get() + ssndChunk->m_offset), (short *)track->getRawData(), (TINT32)(commChunk->m_frames * commChunk->m_chans)); break; @@ -468,21 +462,21 @@ TSoundTrackP TSoundTrackReaderAiff::load() for (int i = 0; i < (int)(commChunk->m_frames * commChunk->m_chans); ++i) { //dovrebbe andare bene anche adesso *(begin + 4 * i) = 0; *(begin + 4 * i + 1) = - *(ssndChunk->m_waveData + ssndChunk->m_offset + 3 * i); + *(ssndChunk->m_waveData.get() + ssndChunk->m_offset + 3 * i); *(begin + 4 * i + 2) = - *(ssndChunk->m_waveData + ssndChunk->m_offset + 3 * i + 1); + *(ssndChunk->m_waveData.get() + ssndChunk->m_offset + 3 * i + 1); *(begin + 4 * i + 3) = - *(ssndChunk->m_waveData + ssndChunk->m_offset + 3 * i + 2); + *(ssndChunk->m_waveData.get() + ssndChunk->m_offset + 3 * i + 2); } } else { UCHAR *begin = (UCHAR *)track->getRawData(); for (int i = 0; i < (int)(commChunk->m_frames * commChunk->m_chans); ++i) { *(begin + 4 * i) = - *(ssndChunk->m_waveData + ssndChunk->m_offset + 3 * i + 2); + *(ssndChunk->m_waveData.get() + ssndChunk->m_offset + 3 * i + 2); *(begin + 4 * i + 1) = - *(ssndChunk->m_waveData + ssndChunk->m_offset + 3 * i + 1); + *(ssndChunk->m_waveData.get() + ssndChunk->m_offset + 3 * i + 1); *(begin + 4 * i + 2) = - *(ssndChunk->m_waveData + ssndChunk->m_offset + 3 * i); + *(ssndChunk->m_waveData.get() + ssndChunk->m_offset + 3 * i); *(begin + 4 * i + 3) = 0; /* @@ -551,7 +545,7 @@ bool TSoundTrackWriterAiff::save(const TSoundTrackP &st) ssndChunk.m_offset = DEFAULT_OFFSET; ssndChunk.m_blockSize = DEFAULT_BLOCKSIZE; - UCHAR *waveData = new UCHAR[soundDataCount]; + std::unique_ptr waveData(new UCHAR[soundDataCount]); if (TNZ_LITTLE_ENDIAN) { postHeadData = swapTINT32(postHeadData); @@ -559,14 +553,14 @@ bool TSoundTrackWriterAiff::save(const TSoundTrackP &st) if (commChunk.m_bitPerSample == 16) { swapAndCopySamples( (short *)sndtrack->getRawData(), - (short *)waveData, + (short *)waveData.get(), (TINT32)(commChunk.m_frames * commChunk.m_chans)); } else if (commChunk.m_bitPerSample == 24) { UCHAR *begin = (UCHAR *)sndtrack->getRawData(); for (int i = 0; i < (int)commChunk.m_frames * commChunk.m_chans; ++i) { - *(waveData + 3 * i) = *(begin + 4 * i + 2); - *(waveData + 3 * i + 1) = *(begin + 4 * i + 1); - *(waveData + 3 * i + 2) = *(begin + 4 * i); + *(waveData.get() + 3 * i) = *(begin + 4 * i + 2); + *(waveData.get() + 3 * i + 1) = *(begin + 4 * i + 1); + *(waveData.get() + 3 * i + 2) = *(begin + 4 * i); /* *(waveData + 3*i + 2) = *(begin + 4*i + 3); @@ -578,26 +572,26 @@ bool TSoundTrackWriterAiff::save(const TSoundTrackP &st) } } else memcpy( - (void *)waveData, + (void *)waveData.get(), (void *)sndtrack->getRawData(), soundDataCount); } else { if (commChunk.m_bitPerSample != 24) memcpy( - (void *)waveData, + (void *)waveData.get(), (void *)sndtrack->getRawData(), soundDataCount); else { UCHAR *begin = (UCHAR *)sndtrack->getRawData(); for (int i = 0; i < (int)commChunk.m_frames * commChunk.m_chans; ++i) { - *(waveData + 3 * i) = *(begin + 4 * i + 1); - *(waveData + 3 * i + 1) = *(begin + 4 * i + 2); - *(waveData + 3 * i + 2) = *(begin + 4 * i + 3); + *(waveData.get() + 3 * i) = *(begin + 4 * i + 1); + *(waveData.get() + 3 * i + 1) = *(begin + 4 * i + 2); + *(waveData.get() + 3 * i + 2) = *(begin + 4 * i + 3); } } } - ssndChunk.m_waveData = waveData; + ssndChunk.m_waveData = std::move(waveData); os.write("FORM", 4); os.write((char *)&postHeadData, sizeof(TINT32)); diff --git a/toonz/sources/sound/wav/tsio_wav.cpp b/toonz/sources/sound/wav/tsio_wav.cpp index e4afb57..28814a8 100644 --- a/toonz/sources/sound/wav/tsio_wav.cpp +++ b/toonz/sources/sound/wav/tsio_wav.cpp @@ -1,4 +1,4 @@ - +#include #include "tmachine.h" #include "tsio_wav.h" @@ -163,25 +163,19 @@ class TDATAChunk : public TWAVChunk { public: - UCHAR *m_samples; + std::unique_ptr m_samples; TDATAChunk(TINT32 length) : TWAVChunk("data", length) {} - ~TDATAChunk() - { - if (m_samples) - delete[] m_samples; - } - bool read(Tifstream &is) { // alloca il buffer dei campioni - m_samples = new UCHAR[m_length]; + m_samples.reset(new UCHAR[m_length]); if (!m_samples) return false; - is.read((char *)m_samples, m_length); + is.read((char *)m_samples.get(), m_length); return true; } @@ -196,7 +190,7 @@ public: os.write((char *)"data", 4); os.write((char *)&length, sizeof(length)); - os.write((char *)m_samples, m_length); + os.write((char *)m_samples.get(), m_length); return true; } }; @@ -300,19 +294,19 @@ TSoundTrackP TSoundTrackReaderWav::load() case 8: memcpy( (void *)track->getRawData(), - (void *)(dataChunk->m_samples), + (void *)(dataChunk->m_samples.get()), sampleCount * fmtChunk->m_bytesPerSample); break; case 16: if (!TNZ_LITTLE_ENDIAN) swapAndCopySamples( - (short *)dataChunk->m_samples, + (short *)dataChunk->m_samples.get(), (short *)track->getRawData(), sampleCount * fmtChunk->m_chans); else memcpy( (void *)track->getRawData(), - (void *)(dataChunk->m_samples), + (void *)(dataChunk->m_samples.get()), sampleCount * fmtChunk->m_bytesPerSample); //#endif break; @@ -322,18 +316,18 @@ TSoundTrackP TSoundTrackReaderWav::load() for (int i = 0; i < (int)(sampleCount * fmtChunk->m_chans); ++i) { *(begin + 4 * i) = 0; *(begin + 4 * i + 1) = - *(dataChunk->m_samples + 3 * i + 2); + *(dataChunk->m_samples.get() + 3 * i + 2); *(begin + 4 * i + 2) = - *(dataChunk->m_samples + 3 * i + 1); + *(dataChunk->m_samples.get() + 3 * i + 1); *(begin + 4 * i + 3) = - *(dataChunk->m_samples + 3 * i); + *(dataChunk->m_samples.get() + 3 * i); } } else { UCHAR *begin = (UCHAR *)track->getRawData(); for (int i = 0; i < (int)(sampleCount * fmtChunk->m_chans); ++i) { memcpy( (void *)(begin + 4 * i), - (void *)(dataChunk->m_samples + 3 * i), 3); + (void *)(dataChunk->m_samples.get() + 3 * i), 3); *(begin + 4 * i + 3) = 0; } } @@ -413,7 +407,7 @@ bool TSoundTrackWriterWav::save(const TSoundTrackP &sndtrack) TDATAChunk dataChunk(soundDataLenght); - UCHAR *waveData = new UCHAR[soundDataLenght]; + std::unique_ptr waveData(new UCHAR[soundDataLenght]); if (!TNZ_LITTLE_ENDIAN) RIFFChunkLength = swapTINT32(RIFFChunkLength); @@ -444,20 +438,20 @@ bool TSoundTrackWriterWav::save(const TSoundTrackP &sndtrack) { if (fmtChunk.m_bitPerSample != 24) memcpy( - (void *)waveData, + (void *)waveData.get(), (void *)sndtrack->getRawData(), soundDataLenght); else { //togliere quarto byte UCHAR *begin = (UCHAR *)sndtrack->getRawData(); for (int i = 0; i < (int)sndtrack->getSampleCount() * fmtChunk.m_chans; ++i) { - *(waveData + 3 * i) = *(begin + 4 * i); - *(waveData + 3 * i + 1) = *(begin + 4 * i + 1); - *(waveData + 3 * i + 2) = *(begin + 4 * i + 2); + *(waveData.get() + 3 * i) = *(begin + 4 * i); + *(waveData.get() + 3 * i + 1) = *(begin + 4 * i + 1); + *(waveData.get() + 3 * i + 2) = *(begin + 4 * i + 2); } } } #endif - dataChunk.m_samples = waveData; + dataChunk.m_samples = std::move(waveData); os.write("RIFF", 4); os.write((char *)&RIFFChunkLength, sizeof(TINT32)); diff --git a/toonz/sources/stdfx/localblurfx.cpp b/toonz/sources/stdfx/localblurfx.cpp index 5a3d599..78040dc 100644 --- a/toonz/sources/stdfx/localblurfx.cpp +++ b/toonz/sources/stdfx/localblurfx.cpp @@ -32,40 +32,25 @@ namespace { struct Sums { - TUINT64 *m_sumsIX_r; //!< m_sumsIX1[i+1] = m_sumsIX1[i] + i * pix.r - TUINT64 *m_sumsIX_g; - TUINT64 *m_sumsIX_b; - TUINT64 *m_sumsIX_m; - TUINT64 *m_sumsX_r; //!< m_sumsX[i+1] = m_sumsX[i] + pix.r - TUINT64 *m_sumsX_g; - TUINT64 *m_sumsX_b; - TUINT64 *m_sumsX_m; + std::unique_ptr m_sumsIX_r; //!< m_sumsIX1[i+1] = m_sumsIX1[i] + i * pix.r + std::unique_ptr m_sumsIX_g; + std::unique_ptr m_sumsIX_b; + std::unique_ptr m_sumsIX_m; + std::unique_ptr m_sumsX_r; //!< m_sumsX[i+1] = m_sumsX[i] + pix.r + std::unique_ptr m_sumsX_g; + std::unique_ptr m_sumsX_b; + std::unique_ptr m_sumsX_m; Sums(int length) + : m_sumsIX_r(new TUINT64[length + 1]) + , m_sumsIX_g(new TUINT64[length + 1]) + , m_sumsIX_b(new TUINT64[length + 1]) + , m_sumsIX_m(new TUINT64[length + 1]) + , m_sumsX_r(new TUINT64[length + 1]) + , m_sumsX_g(new TUINT64[length + 1]) + , m_sumsX_b(new TUINT64[length + 1]) + , m_sumsX_m(new TUINT64[length + 1]) { - ++length; - m_sumsIX_r = new TUINT64[length]; - m_sumsIX_g = new TUINT64[length]; - m_sumsIX_b = new TUINT64[length]; - m_sumsIX_m = new TUINT64[length]; - - m_sumsX_r = new TUINT64[length]; - m_sumsX_g = new TUINT64[length]; - m_sumsX_b = new TUINT64[length]; - m_sumsX_m = new TUINT64[length]; - } - - ~Sums() - { - delete[] m_sumsIX_r; - delete[] m_sumsIX_g; - delete[] m_sumsIX_b; - delete[] m_sumsIX_m; - - delete[] m_sumsX_r; - delete[] m_sumsX_g; - delete[] m_sumsX_b; - delete[] m_sumsX_m; } template diff --git a/toonz/sources/tnzbase/tscanner/tscannerepson.cpp b/toonz/sources/tnzbase/tscanner/tscannerepson.cpp index 9c8d0ef..bb2dda1 100644 --- a/toonz/sources/tnzbase/tscanner/tscannerepson.cpp +++ b/toonz/sources/tnzbase/tscanner/tscannerepson.cpp @@ -327,7 +327,7 @@ void TScannerEpson::acquire(const TScannerParameters ¶ms, int paperCount) throw TException(os.str()); } unsigned long reqBytes = bytes_to_read; - unsigned char *readBuffer = ESCI_read_data2(reqBytes); + std::unique_ptr readBuffer = ESCI_read_data2(reqBytes); if (!readBuffer) throw TException("Error reading image data"); @@ -339,8 +339,7 @@ void TScannerEpson::acquire(const TScannerParameters ¶ms, int paperCount) readBuffer[i] = ~readBuffer[i]; } */ - memcpy(buffer + bytes_read, readBuffer, reqBytes); - delete[] readBuffer; + memcpy(buffer + bytes_read, readBuffer.get(), reqBytes); bytes_read += reqBytes; nTimes++; if (bytes_read == bytes) @@ -625,7 +624,6 @@ void TScannerEpson::collectInformation(char *lev0, char *lev1, unsigned short *l { log("collectInformation"); unsigned char stx; - unsigned char *buffer; int pos = 0; unsigned short counter; unsigned char status; @@ -638,11 +636,11 @@ if (!resetScanner()) throw TException("Unable to get scanner info. Is it off ?"); unsigned long s = 4; // 4 bytes cfr Identity Data Block on ESCI Manual!!! - unsigned char *buffer2 = ESCI_read_data2(s); + std::unique_ptr buffer2 = ESCI_read_data2(s); if (!buffer2 || (s != 4)) throw TException("Error reading scanner info"); - memcpy(&stx, buffer2, 1); + memcpy(&stx, buffer2.get(), 1); memcpy(&counter, &(buffer2[2]), 2); #ifdef SWAPIT @@ -656,12 +654,9 @@ if (!resetScanner()) os << "stx = " << stx << " status = " << status << " counter=" << counter << '\n' << '\0'; #endif - delete[] buffer2; - buffer2 = 0; - s = counter; - buffer = ESCI_read_data2(s); - int len = strlen((const char *)buffer); + std::unique_ptr buffer = ESCI_read_data2(s); + int len = strlen((const char *)buffer.get()); /*printf("Level %c%c", buffer[0], buffer[1]);*/ if (len > 1) { @@ -677,7 +672,6 @@ if (!resetScanner()) *hiRes = 0; *vMax = 0; *hMax = 0; - delete[] buffer; throw TException("unable to get information from scanner"); } @@ -697,15 +691,12 @@ if (!resetScanner()) *hiRes = 0; *vMax = 0; *hMax = 0; - delete[] buffer; throw TException("unable to get information from scanner"); } *hMax = (buffer[pos + 2] * 256) + buffer[pos + 1]; *vMax = (buffer[pos + 4] * 256) + buffer[pos + 3]; - delete[] buffer; - ESCI_command('f', false); ESCI_readLineData2(stx, status, counter); @@ -715,7 +706,7 @@ if (!resetScanner()) s = counter; buffer = ESCI_read_data2(s); //name buffer+1A - const char *name = (const char *)(buffer + 0x1A); + const char *name = (const char *)(buffer.get() + 0x1A); if (strncmp(name, "Perfection1640", strlen("Perfection1640"))) { m_settingsMode = NEW_STYLE; } else { @@ -738,7 +729,6 @@ scsi_b77(1, "adf_installed",0); /**/ #endif m_hasADF = !!(buffer[1] & 0x80); - delete[] buffer; log("collectInformation:OK"); } @@ -883,12 +873,12 @@ bool TScannerEpson::ESCI_command_4w(char cmd, unsigned short p0, unsigned short return status; } -unsigned char *TScannerEpson::ESCI_read_data2(unsigned long &size) +std::unique_ptr TScannerEpson::ESCI_read_data2(unsigned long &size) { - unsigned char *buffer = new unsigned char[size]; - memset(buffer, 0, size); + std::unique_ptr buffer(new unsigned char[size]); + memset(buffer.get(), 0, size); unsigned long bytesToRead = size; - size = receive(buffer, bytesToRead); + size = receive(buffer.get(), bytesToRead); return buffer; } @@ -929,27 +919,27 @@ void TScannerEpson::scanArea2pix(const TScannerParameters ¶ms, unsigned shor void TScannerEpson::ESCI_readLineData(unsigned char &stx, unsigned char &status, unsigned short &counter, unsigned short &lines, bool &areaEnd) { unsigned long s = 6; - unsigned char *buffer = ESCI_read_data2(s); + std::unique_ptr buffer = ESCI_read_data2(s); if (!buffer) throw TException("Error reading scanner info"); /* PACKET DATA LEN = 6 - type offs descr - byte 0 STX - b77 1 fatal_error - b66 1 not_ready - b55 1 area_end - b44 1 option_unit - b33 1 col_attrib_bit_3 - b22 1 col_attrib_bit_2 - b11 1 extended_commands - drow 2, counter - drow 4 lines -*/ + type offs descr + byte 0 STX + b77 1 fatal_error + b66 1 not_ready + b55 1 area_end + b44 1 option_unit + b33 1 col_attrib_bit_3 + b22 1 col_attrib_bit_2 + b11 1 extended_commands + drow 2, counter + drow 4 lines + */ bool fatalError = !!(buffer[1] & 0x80); bool notReady = !!(buffer[1] & 0x40); areaEnd = !!(buffer[1] & 0x20); - memcpy(&stx, buffer, 1); + memcpy(&stx, buffer.get(), 1); memcpy(&counter, &(buffer[2]), 2); #ifdef SWAPIT @@ -977,20 +967,18 @@ void TScannerEpson::ESCI_readLineData(unsigned char &stx, unsigned char &status, TSystem::outputDebug(os.str()); #endif - - delete[] buffer; } void TScannerEpson::ESCI_readLineData2(unsigned char &stx, unsigned char &status, unsigned short &counter) { unsigned long s = 4; - unsigned char *buffer = ESCI_read_data2(s); + std::unique_ptr buffer = ESCI_read_data2(s); if (!buffer) throw TException("Error reading scanner info"); bool fatalError = !!(buffer[1] & 0x80); bool notReady = !!(buffer[1] & 0x40); - memcpy(&stx, buffer, 1); + memcpy(&stx, buffer.get(), 1); memcpy(&counter, &(buffer[2]), 2); #ifdef SWAPIT counter = swapUshort(counter); @@ -1011,6 +999,5 @@ void TScannerEpson::ESCI_readLineData2(unsigned char &stx, unsigned char &status TSystem::outputDebug(os.str()); #endif - - delete[] buffer; } + diff --git a/toonz/sources/tnzbase/tscanner/tscannerepson.h b/toonz/sources/tnzbase/tscanner/tscannerepson.h index 6721db6..dce9e55 100644 --- a/toonz/sources/tnzbase/tscanner/tscannerepson.h +++ b/toonz/sources/tnzbase/tscanner/tscannerepson.h @@ -49,7 +49,7 @@ private: bool ESCI_command_2w(char cmd, unsigned short p0, unsigned short p1, bool checkACK); bool ESCI_command_4w(char cmd, unsigned short p0, unsigned short p1, unsigned short p2, unsigned short p3, bool checkACK); - unsigned char *ESCI_read_data2(unsigned long &size); + std::unique_ptr ESCI_read_data2(unsigned long &size); void ESCI_readLineData(unsigned char &stx, unsigned char &status, unsigned short &counter, unsigned short &lines, bool &areaEnd); void ESCI_readLineData2(unsigned char &stx, unsigned char &status, unsigned short &counter); diff --git a/toonz/sources/toonzlib/sandor_fxs/CallCircle.h b/toonz/sources/toonzlib/sandor_fxs/CallCircle.h index 1ccca90..66cd369 100644 --- a/toonz/sources/toonzlib/sandor_fxs/CallCircle.h +++ b/toonz/sources/toonzlib/sandor_fxs/CallCircle.h @@ -38,7 +38,7 @@ public: void getCC(CSTColSelPic

&pic, P &col) { int xy = pic.m_lX * pic.m_lY; - UCHAR *pSel = pic.m_sel; + UCHAR *pSel = pic.m_sel.get(); for (int i = 0; i < xy; i++, pSel++) if (*pSel > (UCHAR)0) { P *pPic = pic.m_pic + i; @@ -57,7 +57,7 @@ public: int x = xx + m_c[i].x; int y = yy + m_c[i].y; if (x >= 0 && y >= 0 && x < pic.m_lX && y < pic.m_lY) { - UCHAR *pSel = pic.m_sel + y * pic.m_lX + x; + UCHAR *pSel = pic.m_sel.get() + y * pic.m_lX + x; if (*pSel > (UCHAR)0) { P *pPic = pic.m_pic + y * pic.m_lX + x; col.r = pPic->r; @@ -128,15 +128,14 @@ public: return; try { - UCHAR *drawB = 0; CSTColSelPic

picOri; picOri = pic; if (pic.m_lX > 0 && pic.m_lY > 0) { - drawB = new UCHAR[pic.m_lX * pic.m_lY]; + std::unique_ptr drawB(new UCHAR[pic.m_lX * pic.m_lY]); if (!drawB) throw SMemAllocError("in callCircle"); - memset(drawB, 0, pic.m_lX * pic.m_lY); - UCHAR *pSel = pic.m_sel; + memset(drawB.get(), 0, pic.m_lX * pic.m_lY); + UCHAR *pSel = pic.m_sel.get(); for (int y = 0; y < pic.m_lY; y++) for (int x = 0; x < pic.m_lX; x++, pSel++) if (*pSel > (UCHAR)0) { @@ -144,10 +143,9 @@ public: int rani = I_ROUND(random); int ranii = rani > 0 ? rand() % (2 * rani) - 15 * rani / 8 : 0; q = q * (1.0 + (double)ranii / 100.0); - draw(drawB, pic.m_lX, pic.m_lY, x, y, q); + draw(drawB.get(), pic.m_lX, pic.m_lY, x, y, q); } - setNewContour(picOri, pic, drawB, isOneCC); - delete[] drawB; + setNewContour(picOri, pic, drawB.get(), isOneCC); } } catch (SMemAllocError) { throw; diff --git a/toonz/sources/toonzlib/sandor_fxs/EraseContour.cpp b/toonz/sources/toonzlib/sandor_fxs/EraseContour.cpp index 0dad41b..6378301 100644 --- a/toonz/sources/toonzlib/sandor_fxs/EraseContour.cpp +++ b/toonz/sources/toonzlib/sandor_fxs/EraseContour.cpp @@ -25,14 +25,14 @@ void CEraseContour::null() m_lX = m_lY = 0; m_picUC = 0; m_picUS = 0; - m_sel = 0; + m_sel.reset(); m_ras = 0; m_cil.m_nb = 0; } int CEraseContour::makeSelectionCMAP32() { - UCHAR *pSel = m_sel; + UCHAR *pSel = m_sel.get(); int xy = 0, nbSel = 0; for (int y = 0; y < m_lY; y++) @@ -74,7 +74,7 @@ int CEraseContour::makeSelection(const CCIL &iil) return 0; if (m_lX <= 0 || m_lY <= 0 || !m_sel || !m_ras || !(m_picUC || m_picUS)) return 0; - memset(m_sel, 0, m_lX * m_lY); + memset(m_sel.get(), 0, m_lX * m_lY); if (m_ras->type == RAS_CM32) nb = makeSelectionCMAP32(); if (nb > 0) @@ -90,7 +90,7 @@ int CEraseContour::makeSelection(const CCIL &iil) // 3 - paint color int CEraseContour::makeSelection() { - memset(m_sel, 0, m_lX * m_lY); + memset(m_sel.get(), 0, m_lX * m_lY); if (m_ras->type == RAS_CM32) return makeSelectionCMAP32(); return 0; @@ -116,14 +116,14 @@ int CEraseContour::doIt(const CCIL &iil) void CEraseContour::sel0123To01() { int xy = m_lX * m_lY; - UCHAR *pSel = m_sel; + UCHAR *pSel = m_sel.get(); for (int i = 0; i < xy; i++, pSel++) *pSel = *(pSel) == (UCHAR)1 ? (UCHAR)1 : (UCHAR)0; } void CEraseContour::eraseInkColors() { - UCHAR *pSel = m_sel; + UCHAR *pSel = m_sel.get(); prepareNeighbours(); for (int y = 0; y < m_lY; y++) for (int x = 0; x < m_lX; x++, pSel++) @@ -170,7 +170,7 @@ void CEraseContour::prepareNeighbours() m_neighbours[m_nbNeighbours].w = sqrt((double)(x * x + y * y)); m_nbNeighbours++; } - qsort(m_neighbours, m_nbNeighbours, sizeof(SXYDW), erasecontour_xydwCompare); + qsort(m_neighbours.data(), m_nbNeighbours, sizeof(SXYDW), erasecontour_xydwCompare); } bool CEraseContour::findClosestPaint(const int xx, const int yy, I_PIXEL &ip) @@ -180,7 +180,7 @@ bool CEraseContour::findClosestPaint(const int xx, const int yy, I_PIXEL &ip) int x = xx + m_neighbours[i].x; int y = yy + m_neighbours[i].y; if (x >= 0 && y >= 0 && x < m_lX && y < m_lY) - if (*(m_sel + y * m_lX + x) == (UCHAR)3) { + if (*(m_sel.get() + y * m_lX + x) == (UCHAR)3) { if (m_picUC) { UC_PIXEL *uc = m_picUC + y * m_lX + x; ip.r = (int)uc->r; diff --git a/toonz/sources/toonzlib/sandor_fxs/EraseContour.h b/toonz/sources/toonzlib/sandor_fxs/EraseContour.h index 8d2e26c..61cc816 100644 --- a/toonz/sources/toonzlib/sandor_fxs/EraseContour.h +++ b/toonz/sources/toonzlib/sandor_fxs/EraseContour.h @@ -11,6 +11,9 @@ #pragma once #endif // _MSC_VER > 1000 +#include +#include + #include "STColSelPic.h" #include "toonz4.6/raster.h" #include "SDef.h" @@ -22,10 +25,10 @@ class CEraseContour UC_PIXEL *m_picUC; US_PIXEL *m_picUS; const RASTER *m_ras; - UCHAR *m_sel; + std::shared_ptr m_sel; int m_lX, m_lY; CCIL m_cil; - SXYDW m_neighbours[MAXNB_NEIGHBOURS]; + std::array m_neighbours; int m_nbNeighbours; void null(); @@ -37,8 +40,15 @@ class CEraseContour void sel0123To01(); public: - CEraseContour() : m_picUC(0), m_picUS(0), m_ras(0), m_sel(0), - m_lX(0), m_lY(0), m_cil(){}; + CEraseContour() + : m_picUC(0) + , m_picUS(0) + , m_ras(0) + , m_lX(0) + , m_lY(0) + , m_cil() + { + } virtual ~CEraseContour(); int makeSelection(const CCIL &iil); int doIt(const CCIL &iil); diff --git a/toonz/sources/toonzlib/sandor_fxs/PatternPosition.h b/toonz/sources/toonzlib/sandor_fxs/PatternPosition.h index 77a62a0..3e75b90 100644 --- a/toonz/sources/toonzlib/sandor_fxs/PatternPosition.h +++ b/toonz/sources/toonzlib/sandor_fxs/PatternPosition.h @@ -55,10 +55,10 @@ public: // nbPat= nbPat>(int)(0.9*nbPixel) ? (int)(0.9*nbPixel) : nbPat; nbPat = nbPat > nbPixel ? nbPixel : nbPat; if (nbPat > 0) - makeRandomPositions(nbPat, nbPixel, p.m_lX, p.m_lY, p.m_sel); + makeRandomPositions(nbPat, nbPixel, p.m_lX, p.m_lY, p.m_sel.get()); } else { // Distance-driven position - makeDDPositions(p.m_lX, p.m_lY, p.m_sel, minD, maxD); + makeDDPositions(p.m_lX, p.m_lY, p.m_sel.get(), minD, maxD); } } catch (SMemAllocError) { throw; diff --git a/toonz/sources/toonzlib/sandor_fxs/STColSelPic.h b/toonz/sources/toonzlib/sandor_fxs/STColSelPic.h index a2a6ea8..124322a 100644 --- a/toonz/sources/toonzlib/sandor_fxs/STColSelPic.h +++ b/toonz/sources/toonzlib/sandor_fxs/STColSelPic.h @@ -20,6 +20,7 @@ #endif #include #include +#include #include #include @@ -35,29 +36,23 @@ template class CSTColSelPic : public CSTPic

{ public: - UCHAR *m_sel; + std::shared_ptr m_sel; - CSTColSelPic() : CSTPic

(), m_sel(0){}; + CSTColSelPic() : CSTPic

() {} virtual ~CSTColSelPic() { - if (m_sel) { - delete[] m_sel, m_sel = 0; - } }; void nullSel() { - if (m_sel) { - delete[] m_sel; - m_sel = 0; - } + m_sel.reset(); } void initSel() //throw(SMemAllocError) { nullSel(); if (CSTPic

::m_lX > 0 && CSTPic

::m_lY > 0) { - m_sel = new UCHAR[CSTPic

::m_lX * CSTPic

::m_lY]; + m_sel.reset(new UCHAR[CSTPic

::m_lX * CSTPic

::m_lY], std::default_delete()); if (!m_sel) throw SMemAllocError(" in initColorSelection"); } else { @@ -69,29 +64,17 @@ public: void copySel(const UCHAR *sel) { - memcpy(m_sel, sel, CSTPic

::m_lX * CSTPic

::m_lY * sizeof(UCHAR)); + memcpy(m_sel.get(), sel, CSTPic

::m_lX * CSTPic

::m_lY * sizeof(UCHAR)); } void copySel(const UCHAR sel) { - memset(m_sel, sel, CSTPic

::m_lX * CSTPic

::m_lY * sizeof(UCHAR)); + memset(m_sel.get(), sel, CSTPic

::m_lX * CSTPic

::m_lY * sizeof(UCHAR)); } CSTColSelPic(const CSTColSelPic &csp) /*throw(SMemAllocError) */ : CSTPic

(csp) - /* , m_sel(0) */ { - /* - try { - if ( csp.m_sel && m_lX>0 m_lY>0) { - initSel(); - copySel(csp.m_sel); - } - } - catch (SMemAllocError) { - throw; - } -*/ } const CSTColSelPic

&operator=(const CSTColSelPic

&sp) // throw(SMemAllocError) @@ -106,7 +89,7 @@ public: *dpp = *spp; if (sp.m_sel && CSTPic

::m_lX > 0 && CSTPic

::m_lY > 0) { initSel(); - copySel(sp.m_sel); + copySel(sp.m_sel.get()); } } catch (SMemAllocError) { throw; @@ -125,7 +108,7 @@ public: int makeSelectionCMAP32(const COLOR_INDEX_LIST &ink, const COLOR_INDEX_LIST &paint) { - UCHAR *pSel = m_sel; + UCHAR *pSel = m_sel.get(); P *pic = CSTPic

::m_pic; int xy = 0, nbSel = 0; diff --git a/toonz/sources/toonzlib/sandor_fxs/calligraph.cpp b/toonz/sources/toonzlib/sandor_fxs/calligraph.cpp index b2a2084..fde6a67 100644 --- a/toonz/sources/toonzlib/sandor_fxs/calligraph.cpp +++ b/toonz/sources/toonzlib/sandor_fxs/calligraph.cpp @@ -56,7 +56,7 @@ void calligraphUC(const RASTER *inr, RASTER *outr, CCallParam &par, fSize = D_CUT(fSize, 1.0, 20.0); // CSDirection dir(ipUC.m_lX,ipUC.m_lY,ipUC.m_sel,I_ROUND(fSize)); // Only on border (thickness of border is 3 ) - CSDirection dir(ipUC.m_lX, ipUC.m_lY, ipUC.m_sel, I_ROUND(fSize), 3); + CSDirection dir(ipUC.m_lX, ipUC.m_lY, ipUC.m_sel.get(), I_ROUND(fSize), 3); dir.doDir(); // Calculation of 'RADIUS MAP' based on the 'DIRECTION MAP' @@ -65,7 +65,7 @@ void calligraphUC(const RASTER *inr, RASTER *outr, CCallParam &par, fSize = D_CUT(fSize, 1.0, 10.0); ; dir.doRadius(par.m_rH, par.m_rLR, par.m_rV, par.m_rRL, I_ROUND(fSize)); - dir.getResult(ipUC.m_sel); + dir.getResult(ipUC.m_sel.get()); // Draws the circles CCallCircle cc(par.m_thickness); @@ -105,7 +105,7 @@ void calligraphUS(const RASTER *inr, RASTER *outr, CCallParam &par, fSize = D_CUT(fSize, 1.0, 20.0); // CSDirection dir(ipUS.m_lX,ipUS.m_lY,ipUS.m_sel,I_ROUND(fSize)); // Only on border (thickness of border is 3 ) - CSDirection dir(ipUS.m_lX, ipUS.m_lY, ipUS.m_sel, I_ROUND(fSize), 3); + CSDirection dir(ipUS.m_lX, ipUS.m_lY, ipUS.m_sel.get(), I_ROUND(fSize), 3); dir.doDir(); // Calculation of 'RADIUS MAP' based on the 'DIRECTION MAP' @@ -114,7 +114,7 @@ void calligraphUS(const RASTER *inr, RASTER *outr, CCallParam &par, fSize = D_CUT(fSize, 1.0, 10.0); ; dir.doRadius(par.m_rH, par.m_rLR, par.m_rV, par.m_rRL, I_ROUND(fSize)); - dir.getResult(ipUS.m_sel); + dir.getResult(ipUS.m_sel.get()); // Draws the circles CCallCircle cc(par.m_thickness); diff --git a/toonz/sources/toonzlib/sandor_fxs/patternmap.cpp b/toonz/sources/toonzlib/sandor_fxs/patternmap.cpp index 9ef7c5d..bc18f18 100644 --- a/toonz/sources/toonzlib/sandor_fxs/patternmap.cpp +++ b/toonz/sources/toonzlib/sandor_fxs/patternmap.cpp @@ -66,9 +66,9 @@ void patternmapUC(const RASTER *iras, RASTER *oras, CPatternMapParam &pmP, } if (nbContourPixel > 0) { if (!pmP.m_isRandomDir) { - CSDirection dir(ipUC.m_lX, ipUC.m_lY, ipUC.m_sel, DIRACCURACY); + CSDirection dir(ipUC.m_lX, ipUC.m_lY, ipUC.m_sel.get(), DIRACCURACY); dir.doDir(); - dir.getResult(ipUC.m_sel); + dir.getResult(ipUC.m_sel.get()); } CPatternPosition pPos(ipUC, nbContourPixel, pmP.m_density, pmP.m_minDist, pmP.m_maxDist); // Reads the pattern @@ -84,7 +84,7 @@ void patternmapUC(const RASTER *iras, RASTER *oras, CPatternMapParam &pmP, angle = pmP.m_minDirAngle + (double)(rand() % 1001) * 0.001 * (pmP.m_maxDirAngle - pmP.m_minDirAngle); else { if (pp->x >= 0 && pp->y >= 0 && pp->x < ipUC.m_lX && pp->y < ipUC.m_lY) { - UCHAR *sel = ipUC.m_sel + pp->y * ipUC.m_lX + pp->x; + UCHAR *sel = ipUC.m_sel.get() + pp->y * ipUC.m_lX + pp->x; if (*sel > (UCHAR)0) angle = (double)(*sel) - 50.0; } @@ -139,9 +139,9 @@ void patternmapUS(const RASTER *iras, RASTER *oras, CPatternMapParam &pmP, } if (nbContourPixel > 0) { if (!pmP.m_isRandomDir) { - CSDirection dir(ipUS.m_lX, ipUS.m_lY, ipUS.m_sel, DIRACCURACY); + CSDirection dir(ipUS.m_lX, ipUS.m_lY, ipUS.m_sel.get(), DIRACCURACY); dir.doDir(); - dir.getResult(ipUS.m_sel); + dir.getResult(ipUS.m_sel.get()); } CPatternPosition pPos(ipUS, nbContourPixel, pmP.m_density, pmP.m_minDist, pmP.m_maxDist); // Reads the pattern @@ -157,7 +157,7 @@ void patternmapUS(const RASTER *iras, RASTER *oras, CPatternMapParam &pmP, angle = pmP.m_minDirAngle + (double)(rand() % 1001) * 0.001 * (pmP.m_maxDirAngle - pmP.m_minDirAngle); else { if (pp->x >= 0 && pp->y >= 0 && pp->x < ipUS.m_lX && pp->y < ipUS.m_lY) { - UCHAR *sel = ipUS.m_sel + pp->y * ipUS.m_lX + pp->x; + UCHAR *sel = ipUS.m_sel.get() + pp->y * ipUS.m_lX + pp->x; if (*sel > (UCHAR)0) angle = (double)(*sel) - 50.0; }