diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-03-16 14:08:31 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-03-17 22:09:10 +0000 |
commit | f65a4c931b0b849c6118a872948e9eb74dc4e011 (patch) | |
tree | 4dd487babca8a7618de58f681abed4fe04e7b7bd | |
parent | f88cf324a0bef2db4419c867ab97cb0741d366d1 (diff) |
Replace malloc'ed tables with QVarLengthArray
Basic cleanup using proper Qt classes instead of malloc.
Change-Id: I532b47aac7cfe15a5963371224288bec08135f25
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/plugins/imageformats/tiff/qtiffhandler.cpp | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/src/plugins/imageformats/tiff/qtiffhandler.cpp b/src/plugins/imageformats/tiff/qtiffhandler.cpp index 675e6c3..9697f45 100644 --- a/src/plugins/imageformats/tiff/qtiffhandler.cpp +++ b/src/plugins/imageformats/tiff/qtiffhandler.cpp @@ -494,20 +494,13 @@ bool QTiffHandler::write(const QImage &image) } //// write the color table // allocate the color tables - uint16 *redTable = static_cast<uint16 *>(malloc(256 * sizeof(uint16))); - uint16 *greenTable = static_cast<uint16 *>(malloc(256 * sizeof(uint16))); - uint16 *blueTable = static_cast<uint16 *>(malloc(256 * sizeof(uint16))); - if (!redTable || !greenTable || !blueTable) { - free(redTable); - free(greenTable); - free(blueTable); - TIFFClose(tiff); - return false; - } - - // set the color table const int tableSize = colorTable.size(); Q_ASSERT(tableSize <= 256); + QVarLengthArray<uint16> redTable(tableSize); + QVarLengthArray<uint16> greenTable(tableSize); + QVarLengthArray<uint16> blueTable(tableSize); + + // set the color table for (int i = 0; i<tableSize; ++i) { const QRgb color = colorTable.at(i); redTable[i] = qRed(color) * 257; @@ -515,11 +508,7 @@ bool QTiffHandler::write(const QImage &image) blueTable[i] = qBlue(color) * 257; } - const bool setColorTableSuccess = TIFFSetField(tiff, TIFFTAG_COLORMAP, redTable, greenTable, blueTable); - - free(redTable); - free(greenTable); - free(blueTable); + const bool setColorTableSuccess = TIFFSetField(tiff, TIFFTAG_COLORMAP, redTable.data(), greenTable.data(), blueTable.data()); if (!setColorTableSuccess) { TIFFClose(tiff); |