diff --git a/.gitignore b/.gitignore index 65aee5e083..4535b8077a 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ build/ build-win/ build-nuget/ *~ +.vscode \ No newline at end of file diff --git a/src/lib/OpenEXR/ImfDwaCompressor.cpp b/src/lib/OpenEXR/ImfDwaCompressor.cpp index 214e1c5dc7..822d2545ec 100644 --- a/src/lib/OpenEXR/ImfDwaCompressor.cpp +++ b/src/lib/OpenEXR/ImfDwaCompressor.cpp @@ -119,7 +119,6 @@ #include "ImathFun.h" #include "ImathVec.h" #include "half.h" -#include "halfLimits.h" #include #include @@ -2074,13 +2073,13 @@ DwaCompressor::compress ( if (*unknownUncompressedSize > 0) { - uLongf inSize = (uLongf) (*unknownUncompressedSize); - uLongf outSize = compressBound (inSize); + uLong inSize = static_cast (*unknownUncompressedSize); + uLong outSize = compressBound (inSize); if (Z_OK != ::compress2 ( - (Bytef*) outDataPtr, + reinterpret_cast (outDataPtr), &outSize, - (const Bytef*) _planarUncBuffer[UNKNOWN], + reinterpret_cast (_planarUncBuffer[UNKNOWN]), inSize, 9)) { @@ -2114,15 +2113,15 @@ DwaCompressor::compress ( case DEFLATE: { - uLongf destLen = compressBound ( - (*totalAcUncompressedCount) * sizeof (unsigned short)); + uLong sourceLen = static_cast (*totalAcUncompressedCount * sizeof (unsigned short)); + uLong destLen = compressBound (sourceLen); if (Z_OK != ::compress2 ( - (Bytef*) outDataPtr, + reinterpret_cast (outDataPtr), &destLen, - (Bytef*) _packedAcBuffer, - (uLong) (*totalAcUncompressedCount * sizeof (unsigned short)), + reinterpret_cast (_packedAcBuffer), + sourceLen, 9)) { throw IEX_NAMESPACE::InputExc ( @@ -2166,13 +2165,14 @@ DwaCompressor::compress ( _planarUncBuffer[RLE], (signed char*) _rleBuffer); - uLongf dstLen = compressBound ((uLongf) *rleUncompressedSize); + uLong srcLen = static_cast (*rleUncompressedSize); + uLong dstLen = compressBound (srcLen); if (Z_OK != ::compress2 ( - (Bytef*) outDataPtr, + reinterpret_cast (outDataPtr), &dstLen, - (Bytef*) _rleBuffer, - (uLong) (*rleUncompressedSize), + reinterpret_cast (_rleBuffer), + srcLen, 9)) { throw IEX_NAMESPACE::BaseExc ("Error compressing RLE'd data."); @@ -2402,13 +2402,14 @@ DwaCompressor::uncompress ( "(corrupt header)."); } - uLongf outSize = (uLongf) unknownUncompressedSize; + uLong inSize = static_cast (unknownCompressedSize); + uLong outSize = static_cast (unknownUncompressedSize); if (Z_OK != ::uncompress ( - (Bytef*) _planarUncBuffer[UNKNOWN], + reinterpret_cast (_planarUncBuffer[UNKNOWN]), &outSize, - (Bytef*) compressedUnknownBuf, - (uLong) unknownCompressedSize)) + reinterpret_cast (compressedUnknownBuf), + inSize)) { throw IEX_NAMESPACE::BaseExc ("Error uncompressing UNKNOWN data."); } @@ -2445,14 +2446,14 @@ DwaCompressor::uncompress ( break; case DEFLATE: { - uLongf destLen = - (int) (totalAcUncompressedCount) * sizeof (unsigned short); + uLong destLen = static_cast (totalAcUncompressedCount * sizeof (unsigned short)); + uLong sourceLen = static_cast (acCompressedSize); if (Z_OK != ::uncompress ( - (Bytef*) _packedAcBuffer, + reinterpret_cast (_packedAcBuffer), &destLen, - (Bytef*) compressedAcBuf, - (uLong) acCompressedSize)) + reinterpret_cast (compressedAcBuf), + sourceLen)) { throw IEX_NAMESPACE::InputExc ( "Data decompression (zlib) failed."); @@ -2516,13 +2517,14 @@ DwaCompressor::uncompress ( "(corrupt header)."); } - uLongf dstLen = (uLongf) rleUncompressedSize; + uLong dstLen = static_cast (rleUncompressedSize); + uLong srcLen = static_cast (rleCompressedSize); if (Z_OK != ::uncompress ( - (Bytef*) _rleBuffer, + reinterpret_cast (_rleBuffer), &dstLen, - (Bytef*) compressedRleBuf, - (uLong) rleCompressedSize)) + reinterpret_cast (compressedRleBuf), + srcLen)) { throw IEX_NAMESPACE::BaseExc ("Error uncompressing RLE data."); } @@ -2870,7 +2872,7 @@ DwaCompressor::initializeBuffers (size_t& outBufferSize) maxOutBufferSize += std::max ( 2lu * maxLossyDctAcSize + 65536lu, - static_cast (compressBound (maxLossyDctAcSize))); + static_cast (compressBound (static_cast (maxLossyDctAcSize)))); numLossyDctChans++; break; @@ -2910,14 +2912,14 @@ DwaCompressor::initializeBuffers (size_t& outBufferSize) // which could take slightly more space // - maxOutBufferSize += static_cast (compressBound (rleBufferSize)); + maxOutBufferSize += static_cast (compressBound (static_cast (rleBufferSize))); // // And the same goes for the UNKNOWN data // maxOutBufferSize += - static_cast (compressBound (unknownBufferSize)); + static_cast (compressBound (static_cast (unknownBufferSize))); // // Allocate a zip/deflate compressor big enought to hold the DC data @@ -3036,7 +3038,7 @@ DwaCompressor::initializeBuffers (size_t& outBufferSize) if (planarUncBufferSize[UNKNOWN] > 0) { planarUncBufferSize[UNKNOWN] = static_cast ( - compressBound (planarUncBufferSize[UNKNOWN])); + compressBound (static_cast (planarUncBufferSize[UNKNOWN]))); } for (int i = 0; i < NUM_COMPRESSOR_SCHEMES; ++i) diff --git a/src/lib/OpenEXR/ImfIDManifest.cpp b/src/lib/OpenEXR/ImfIDManifest.cpp index 4c9911ce7f..3a5a73ac89 100644 --- a/src/lib/OpenEXR/ImfIDManifest.cpp +++ b/src/lib/OpenEXR/ImfIDManifest.cpp @@ -537,12 +537,13 @@ IDManifest::IDManifest (const CompressedIDManifest& compressed) // vector uncomp (compressed._uncompressedDataSize); - uLongf outSize = compressed._uncompressedDataSize; + uLong outSize = static_cast (compressed._uncompressedDataSize); + uLong inSize = static_cast (compressed._compressedDataSize); if (Z_OK != ::uncompress ( - &uncomp[0], + uncomp.data(), &outSize, - (const Bytef*) compressed._data, - compressed._compressedDataSize)) + reinterpret_cast (compressed._data), + inSize)) { throw IEX_NAMESPACE::InputExc ( "IDManifest decompression (zlib) failed."); @@ -1061,16 +1062,16 @@ CompressedIDManifest::CompressedIDManifest (const IDManifest& manifest) manifest.serialize (serial); - uLong outputSize = serial.size (); + uLong outputSize = static_cast (serial.size ()); // // allocate a buffer which is guaranteed to be big enough for compression // - uLongf compressedDataSize = compressBound (outputSize); + uLong compressedDataSize = compressBound (outputSize); _data = (unsigned char*) malloc (compressedDataSize); if (Z_OK != ::compress ( - _data, &compressedDataSize, (Bytef*) &serial[0], outputSize)) + _data, &compressedDataSize, reinterpret_cast (serial.data ()), outputSize)) { throw IEX_NAMESPACE::InputExc ("ID manifest compression failed"); } diff --git a/src/lib/OpenEXR/ImfPxr24Compressor.cpp b/src/lib/OpenEXR/ImfPxr24Compressor.cpp index acae0dc546..e576395c28 100644 --- a/src/lib/OpenEXR/ImfPxr24Compressor.cpp +++ b/src/lib/OpenEXR/ImfPxr24Compressor.cpp @@ -341,13 +341,14 @@ Pxr24Compressor::compress ( } } - uLongf outSize = int (ceil ((tmpBufferEnd - _tmpBuffer) * 1.01)) + 100; + uLong inBufferSize = static_cast (tmpBufferEnd - _tmpBuffer); + uLong outSize = compressBound (inBufferSize); if (Z_OK != ::compress ( - (Bytef*) _outBuffer, + reinterpret_cast (_outBuffer), &outSize, - (const Bytef*) _tmpBuffer, - tmpBufferEnd - _tmpBuffer)) + reinterpret_cast (_tmpBuffer), + inBufferSize)) { throw IEX_NAMESPACE::BaseExc ("Data compression (zlib) failed."); } @@ -366,11 +367,14 @@ Pxr24Compressor::uncompress ( return 0; } - uLongf tmpSize = _maxScanLineSize * _numScanLines; + uLong tmpSize = static_cast (_maxScanLineSize * _numScanLines); if (Z_OK != ::uncompress ( - (Bytef*) _tmpBuffer, &tmpSize, (const Bytef*) inPtr, inSize)) + reinterpret_cast (_tmpBuffer), + &tmpSize, + reinterpret_cast (inPtr), + inSize)) { throw IEX_NAMESPACE::InputExc ("Data decompression (zlib) failed."); } @@ -408,7 +412,7 @@ Pxr24Compressor::uncompress ( ptr[3] = ptr[2] + n; tmpBufferEnd = ptr[3] + n; - if ((uLongf) (tmpBufferEnd - _tmpBuffer) > tmpSize) + if (static_cast (tmpBufferEnd - _tmpBuffer) > tmpSize) notEnoughData (); for (int j = 0; j < n; ++j) @@ -433,7 +437,7 @@ Pxr24Compressor::uncompress ( ptr[1] = ptr[0] + n; tmpBufferEnd = ptr[1] + n; - if ((uLongf) (tmpBufferEnd - _tmpBuffer) > tmpSize) + if (static_cast (tmpBufferEnd - _tmpBuffer) > tmpSize) notEnoughData (); for (int j = 0; j < n; ++j) @@ -456,7 +460,7 @@ Pxr24Compressor::uncompress ( ptr[2] = ptr[1] + n; tmpBufferEnd = ptr[2] + n; - if ((uLongf) (tmpBufferEnd - _tmpBuffer) > tmpSize) + if (static_cast (tmpBufferEnd - _tmpBuffer) > tmpSize) notEnoughData (); for (int j = 0; j < n; ++j) @@ -479,7 +483,7 @@ Pxr24Compressor::uncompress ( } } - if ((uLongf) (tmpBufferEnd - _tmpBuffer) < tmpSize) tooMuchData (); + if (static_cast (tmpBufferEnd - _tmpBuffer) < tmpSize) tooMuchData (); outPtr = _outBuffer; return writePtr - _outBuffer; diff --git a/src/lib/OpenEXR/ImfZip.cpp b/src/lib/OpenEXR/ImfZip.cpp index 78c270877d..b0824a496f 100644 --- a/src/lib/OpenEXR/ImfZip.cpp +++ b/src/lib/OpenEXR/ImfZip.cpp @@ -93,13 +93,14 @@ Zip::compress (const char* raw, int rawSize, char* compressed) // Compress the data using zlib // - uLongf outSize = int (ceil (rawSize * 1.01)) + 100; + uLong inSize = static_cast (rawSize); + uLong outSize = compressBound (inSize); if (Z_OK != ::compress2 ( - (Bytef*) compressed, + reinterpret_cast (compressed), &outSize, - (const Bytef*) _tmpBuffer, - rawSize, + reinterpret_cast (_tmpBuffer), + inSize, _zipLevel)) { throw IEX_NAMESPACE::BaseExc ("Data compression (zlib) failed."); @@ -240,13 +241,14 @@ Zip::uncompress (const char* compressed, int compressedSize, char* raw) // Decompress the data using zlib // - uLongf outSize = _maxRawSize; + uLong outSize = static_cast (_maxRawSize); + uLong inSize = static_cast (compressedSize); if (Z_OK != ::uncompress ( - (Bytef*) _tmpBuffer, + reinterpret_cast (_tmpBuffer), &outSize, - (const Bytef*) compressed, - compressedSize)) + reinterpret_cast (compressed), + inSize)) { throw IEX_NAMESPACE::InputExc ("Data decompression (zlib) failed."); } diff --git a/src/lib/OpenEXRCore/internal_pxr24.c b/src/lib/OpenEXRCore/internal_pxr24.c index 96f2f66e5f..f1928ad3b4 100644 --- a/src/lib/OpenEXRCore/internal_pxr24.c +++ b/src/lib/OpenEXRCore/internal_pxr24.c @@ -92,7 +92,7 @@ apply_pxr24_impl (exr_encode_pipeline_t* encode) uint8_t* out = encode->scratch_buffer_1; uint64_t nOut = 0; const uint8_t* lastIn = encode->packed_buffer; - uLongf compbufsz = encode->compressed_alloc_size; + uLong compbufsz = (uLong) encode->compressed_alloc_size; for (int y = 0; y < encode->chunk.height; ++y) { @@ -219,7 +219,7 @@ apply_pxr24_impl (exr_encode_pipeline_t* encode) (Bytef*) encode->compressed_buffer, &compbufsz, (const Bytef*) encode->scratch_buffer_1, - nOut)) + (uLong) nOut)) { return EXR_ERR_CORRUPT_CHUNK; } @@ -229,7 +229,7 @@ apply_pxr24_impl (exr_encode_pipeline_t* encode) encode->compressed_buffer, encode->packed_buffer, encode->packed_bytes); - compbufsz = encode->packed_bytes; + compbufsz = (uLong) encode->packed_bytes; } encode->compressed_bytes = compbufsz; return EXR_ERR_SUCCESS; @@ -262,7 +262,7 @@ undo_pxr24_impl ( void* scratch_data, uint64_t scratch_size) { - uLongf outSize = (uLongf) uncompressed_size; + uLong outSize = (uLong) uncompressed_size; int rstat; uint8_t* out = uncompressed_data; uint64_t nOut = 0; diff --git a/src/lib/OpenEXRCore/internal_zip.c b/src/lib/OpenEXRCore/internal_zip.c index 62e9ebe992..7a1b4dc05b 100644 --- a/src/lib/OpenEXRCore/internal_zip.c +++ b/src/lib/OpenEXRCore/internal_zip.c @@ -158,7 +158,7 @@ undo_zip_impl ( void* scratch_data, uint64_t scratch_size) { - uLongf outSize = (uLongf) uncompressed_size; + uLong outSize = (uLong) uncompressed_size; int rstat; if (scratch_size < uncompressed_size) return EXR_ERR_INVALID_ARGUMENT; @@ -226,7 +226,7 @@ apply_zip_impl (exr_encode_pipeline_t* encode) const uint8_t* raw = encode->packed_buffer; const uint8_t* stop = raw + encode->packed_bytes; int p, level; - uLongf compbufsz = encode->compressed_alloc_size; + uLong compbufsz = (uLong) encode->compressed_alloc_size; exr_result_t rv = EXR_ERR_SUCCESS; rv = exr_get_zip_compression_level ( @@ -257,7 +257,7 @@ apply_zip_impl (exr_encode_pipeline_t* encode) (Bytef*) encode->compressed_buffer, &compbufsz, (const Bytef*) encode->scratch_buffer_1, - encode->packed_bytes, + (uLong) encode->packed_bytes, level)) { return EXR_ERR_CORRUPT_CHUNK; diff --git a/src/test/OpenEXRTest/testIDManifest.cpp b/src/test/OpenEXRTest/testIDManifest.cpp index a8278eddd3..11f42b521a 100644 --- a/src/test/OpenEXRTest/testIDManifest.cpp +++ b/src/test/OpenEXRTest/testIDManifest.cpp @@ -136,14 +136,15 @@ doReadWriteManifest (const IDManifest& mfst, const string& fn, bool dump) // // allocate a buffer which is guaranteed to be big enough for compression // - uLongf compressedDataSize = compressBound (str.str ().size ()); + uLong sourceDataSize = static_cast (str.str ().size ()); + uLong compressedDataSize = compressBound (sourceDataSize); vector compressed (compressedDataSize); ::compress ( - (Bytef*) &compressed[0], + reinterpret_cast (compressed.data ()), &compressedDataSize, - (const Bytef*) str.str ().c_str (), - str.str ().size ()); + reinterpret_cast (str.str ().c_str ()), + sourceDataSize); cerr << "simple zip size: " << compressedDataSize << ' '; #endif