diff --git a/src/plugins/imageformats/dds/qddshandler.cpp b/src/plugins/imageformats/dds/qddshandler.cpp index 9d44f26460f70e16e143b090d619e6a6db91645f..50ac67cff5f1dc35fc844d743ae0d1c6c27e4fa0 100644 --- a/src/plugins/imageformats/dds/qddshandler.cpp +++ b/src/plugins/imageformats/dds/qddshandler.cpp @@ -103,7 +103,7 @@ struct FormatInfo static const FormatInfo formatInfos[] = { { FormatA8R8G8B8, DDSPixelFormat::FlagRGBA, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, { FormatX8R8G8B8, DDSPixelFormat::FlagRGB, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 }, - { FormatA2B10G10R10, DDSPixelFormat::FlagRGBA, 32, 0x000003ff, 0x0000fc00, 0x3ff00000, 0xc0000000 }, + { FormatA2B10G10R10, DDSPixelFormat::FlagRGBA, 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000 }, { FormatA8B8G8R8, DDSPixelFormat::FlagRGBA, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 }, { FormatX8B8G8R8, DDSPixelFormat::FlagRGB, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000 }, { FormatG16R16, DDSPixelFormat::FlagRGBA, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 }, @@ -325,7 +325,7 @@ static Format getFormat(const DDSHeader &dds) if ((format.flags & info.flags) == info.flags && format.rgbBitCount == info.bitCount && format.rBitMask == info.rBitMask && - format.bBitMask == info.bBitMask && + format.gBitMask == info.gBitMask && format.bBitMask == info.bBitMask && format.aBitMask == info.aBitMask) { return info.format; diff --git a/src/plugins/imageformats/tiff/qtiffhandler.cpp b/src/plugins/imageformats/tiff/qtiffhandler.cpp index f7151f783cd69ac6b64a1bfa91ef50cfe07611cf..71b2cccc83b4a0cd6b00d401cf2f5a50dc8161e6 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);