think I fixed the reported memory usage bug
This commit is contained in:
@@ -125,29 +125,24 @@ bool exportavi(std::vector<frame> frames, AnimationConfig config) {
|
|||||||
std::cout << "\n=== Frame Compression Statistics ===" << std::endl;
|
std::cout << "\n=== Frame Compression Statistics ===" << std::endl;
|
||||||
size_t totalOriginalSize = 0;
|
size_t totalOriginalSize = 0;
|
||||||
size_t totalCompressedSize = 0;
|
size_t totalCompressedSize = 0;
|
||||||
int compressedFrameCount = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < frames.size(); ++i) {
|
for (int i = 0; i < frames.size(); ++i) {
|
||||||
totalOriginalSize += frames[i].getSourceSize();
|
totalOriginalSize += frames[i].getSourceSize();
|
||||||
totalCompressedSize += frames[i].getCompressedSize();
|
totalCompressedSize += frames[i].getTotalCompressedSize();
|
||||||
compressedFrameCount++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print summary
|
double overallRatio = static_cast<double>(totalOriginalSize) / totalCompressedSize;
|
||||||
//if (compressedFrameCount > 0) {
|
double overallSavings = (1.0 - 1.0/overallRatio) * 100.0;
|
||||||
double overallRatio = static_cast<double>(totalOriginalSize) / totalCompressedSize;
|
|
||||||
double overallSavings = (1.0 - 1.0/overallRatio) * 100.0;
|
std::cout << "\n=== Overall Compression Summary ===" << std::endl;
|
||||||
|
std::cout << "Total frames: " << frames.size() << std::endl;
|
||||||
std::cout << "\n=== Overall Compression Summary ===" << std::endl;
|
std::cout << "Compressed frames: " << frames.size() << std::endl;
|
||||||
std::cout << "Total frames: " << frames.size() << std::endl;
|
std::cout << "Total original size: " << totalOriginalSize << " bytes ("
|
||||||
std::cout << "Compressed frames: " << compressedFrameCount << std::endl;
|
<< std::fixed << std::setprecision(2) << (totalOriginalSize / (1024.0 * 1024.0)) << " MB)" << std::endl;
|
||||||
std::cout << "Total original size: " << totalOriginalSize << " bytes ("
|
std::cout << "Total compressed size: " << totalCompressedSize << " bytes ("
|
||||||
<< std::fixed << std::setprecision(2) << (totalOriginalSize / (1024.0 * 1024.0)) << " MB)" << std::endl;
|
<< std::fixed << std::setprecision(2) << (totalCompressedSize / (1024.0 * 1024.0)) << " MB)" << std::endl;
|
||||||
std::cout << "Total compressed size: " << totalCompressedSize << " bytes ("
|
std::cout << "Overall compression ratio: " << std::fixed << std::setprecision(2) << overallRatio << ":1" << std::endl;
|
||||||
<< std::fixed << std::setprecision(2) << (totalCompressedSize / (1024.0 * 1024.0)) << " MB)" << std::endl;
|
std::cout << "Overall space savings: " << std::fixed << std::setprecision(1) << overallSavings << "%" << std::endl;
|
||||||
std::cout << "Overall compression ratio: " << std::fixed << std::setprecision(2) << overallRatio << ":1" << std::endl;
|
|
||||||
std::cout << "Overall space savings: " << std::fixed << std::setprecision(1) << overallSavings << "%" << std::endl;
|
|
||||||
//}
|
|
||||||
|
|
||||||
std::filesystem::path dir = "output";
|
std::filesystem::path dir = "output";
|
||||||
if (!std::filesystem::exists(dir)) {
|
if (!std::filesystem::exists(dir)) {
|
||||||
@@ -183,12 +178,12 @@ int main() {
|
|||||||
std::vector<frame> frames;
|
std::vector<frame> frames;
|
||||||
|
|
||||||
for (int i = 0; i < config.totalFrames; ++i){
|
for (int i = 0; i < config.totalFrames; ++i){
|
||||||
std::cout << "Processing frame " << i + 1 << "/" << config.totalFrames << std::endl;
|
|
||||||
expandPixel(grid,config,seeds);
|
expandPixel(grid,config,seeds);
|
||||||
frame bgrframe;
|
|
||||||
|
|
||||||
// Print compression info for this frame
|
// Print compression info for this frame
|
||||||
if (i % 10 == 0 ) {
|
if (i % 10 == 0 ) {
|
||||||
|
frame bgrframe;
|
||||||
|
std::cout << "Processing frame " << i + 1 << "/" << config.totalFrames << std::endl;
|
||||||
bgrframe = grid.getGridAsFrame(frame::colormap::BGR);
|
bgrframe = grid.getGridAsFrame(frame::colormap::BGR);
|
||||||
bgrframe.printCompressionStats();
|
bgrframe.printCompressionStats();
|
||||||
//(bgrframe, i + 1);
|
//(bgrframe, i + 1);
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ public:
|
|||||||
cformat = compresstype::RAW;
|
cformat = compresstype::RAW;
|
||||||
_compressedData.clear();
|
_compressedData.clear();
|
||||||
_compressedData.shrink_to_fit();
|
_compressedData.shrink_to_fit();
|
||||||
|
overheadmap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<uint8_t>& getData() const {
|
const std::vector<uint8_t>& getData() const {
|
||||||
@@ -151,7 +152,7 @@ public:
|
|||||||
std::mutex mutex;
|
std::mutex mutex;
|
||||||
std::vector<std::vector<uint8_t>> matches128plus;
|
std::vector<std::vector<uint8_t>> matches128plus;
|
||||||
std::vector<std::vector<uint8_t>> matches64plus;
|
std::vector<std::vector<uint8_t>> matches64plus;
|
||||||
std::vector<std::vector<uint8_t>> matches32plus;
|
//std::vector<std::vector<uint8_t>> matches32plus;
|
||||||
std::vector<std::vector<uint8_t>> matchesAll;
|
std::vector<std::vector<uint8_t>> matchesAll;
|
||||||
|
|
||||||
void addMatch(std::vector<uint8_t>&& match, size_t length) {
|
void addMatch(std::vector<uint8_t>&& match, size_t length) {
|
||||||
@@ -160,9 +161,11 @@ public:
|
|||||||
if (matches128plus.size() < 65534) matches128plus.push_back(std::move(match));
|
if (matches128plus.size() < 65534) matches128plus.push_back(std::move(match));
|
||||||
} else if (length >= 64) {
|
} else if (length >= 64) {
|
||||||
if (matches64plus.size() < 65534) matches64plus.push_back(std::move(match));
|
if (matches64plus.size() < 65534) matches64plus.push_back(std::move(match));
|
||||||
} else if (length >= 32) {
|
}
|
||||||
if (matches32plus.size() < 65534) matches32plus.push_back(std::move(match));
|
// else if (length >= 32) {
|
||||||
} else {
|
// if (matches32plus.size() < 65534) matches32plus.push_back(std::move(match));
|
||||||
|
// }
|
||||||
|
else {
|
||||||
if (matchesAll.size() < 65534) matchesAll.push_back(std::move(match));
|
if (matchesAll.size() < 65534) matchesAll.push_back(std::move(match));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -254,15 +257,15 @@ public:
|
|||||||
else break;
|
else break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& match : threadMatches.matches32plus) {
|
// for (const auto& match : threadMatches.matches32plus) {
|
||||||
if (result.size() < 65534) result.push_back(match);
|
// if (result.size() < 65534) result.push_back(match);
|
||||||
else break;
|
// else break;
|
||||||
}
|
// }
|
||||||
|
|
||||||
for (const auto& match : threadMatches.matchesAll) {
|
// for (const auto& match : threadMatches.matchesAll) {
|
||||||
if (result.size() < 65534) result.push_back(match);
|
// if (result.size() < 65534) result.push_back(match);
|
||||||
else break;
|
// else break;
|
||||||
}
|
// }
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -389,6 +392,7 @@ public:
|
|||||||
_data = std::move(decompressedData);
|
_data = std::move(decompressedData);
|
||||||
_compressedData.clear();
|
_compressedData.clear();
|
||||||
_compressedData.shrink_to_fit();
|
_compressedData.shrink_to_fit();
|
||||||
|
overheadmap.clear();
|
||||||
cformat = compresstype::RAW;
|
cformat = compresstype::RAW;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
@@ -449,9 +453,25 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate the size of the dictionary in bytes
|
||||||
|
size_t getDictionarySize() const {
|
||||||
|
size_t dictSize = 0;
|
||||||
|
dictSize = sizeof(overheadmap);
|
||||||
|
return dictSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get compressed size including dictionary overhead
|
||||||
|
size_t getTotalCompressedSize() const {
|
||||||
|
size_t baseSize = getCompressedSize() * 2; // Convert 16-bit words to bytes
|
||||||
|
if (cformat == compresstype::LZ78) {
|
||||||
|
baseSize += getDictionarySize();
|
||||||
|
}
|
||||||
|
return baseSize;
|
||||||
|
}
|
||||||
|
|
||||||
double getCompressionRatio() const {
|
double getCompressionRatio() const {
|
||||||
if (_compressedData.empty() || sourceSize == 0) return 0.0;
|
if (_compressedData.empty() || sourceSize == 0) return 0.0;
|
||||||
return static_cast<double>(sourceSize) / _compressedData.size();
|
return static_cast<double>(sourceSize) / getTotalCompressedSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get source size (uncompressed size)
|
// Get source size (uncompressed size)
|
||||||
@@ -459,8 +479,13 @@ public:
|
|||||||
return sourceSize;
|
return sourceSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get compressed size
|
// Get compressed size (just the compressed data in bytes, excluding dictionary)
|
||||||
size_t getCompressedSize() const {
|
size_t getCompressedSize() const {
|
||||||
|
return _compressedData.size() * 2; // Convert 16-bit words to bytes
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get just the compressed data size in 16-bit words
|
||||||
|
size_t getCompressedDataSize() const {
|
||||||
return _compressedData.size();
|
return _compressedData.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,26 +504,37 @@ public:
|
|||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
std::cout << "Source Size: " << getSourceSize() << " bytes" << std::endl;
|
std::cout << "Source Size: " << getSourceSize() << " bytes" << std::endl;
|
||||||
std::cout << "Compressed Size: " << getCompressedSize() << " 16-bit words" << std::endl;
|
std::cout << "Compressed data Size: " << getCompressedDataSize() << " 16-bit words" << std::endl;
|
||||||
std::cout << "Compressed Size: " << getCompressedSize() * 2 << " bytes" << std::endl;
|
std::cout << "Compressed Size: " << getCompressedSize() << " bytes" << std::endl;
|
||||||
|
|
||||||
|
if (cformat == compresstype::LZ78) {
|
||||||
|
std::cout << "Dictionary Size: " << getDictionarySize() << " bytes" << std::endl;
|
||||||
|
std::cout << "Dictionary Entries: " << overheadmap.size() << std::endl;
|
||||||
|
std::cout << "Total Compressed Size: " << getTotalCompressedSize() << " bytes" << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << "Total Compressed Size: " << getTotalCompressedSize() << " bytes" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << "Compression Ratio: " << getCompressionRatio() << ":1" << std::endl;
|
std::cout << "Compression Ratio: " << getCompressionRatio() << ":1" << std::endl;
|
||||||
|
|
||||||
if (getCompressionRatio() > 1.0) {
|
if (getCompressionRatio() > 1.0) {
|
||||||
double savings = (1.0 - (1.0 / getCompressionRatio())) * 100.0;
|
double savings = (1.0 - (1.0 / getCompressionRatio())) * 100.0;
|
||||||
std::cout << "Space Savings: " << savings << "%" << std::endl;
|
std::cout << "Space Savings: " << savings << "%" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show dictionary size for LZ78
|
|
||||||
if (cformat == compresstype::LZ78) {
|
|
||||||
std::cout << "Dictionary Size: " << overheadmap.size() << " entries" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print compression information in a compact format
|
// Print compression information in a compact format
|
||||||
void printCompressionStats() const {
|
void printCompressionStats() const {
|
||||||
std::cout << "[" << getCompressionTypeString() << "] "
|
if (cformat == compresstype::LZ78) {
|
||||||
<< getSourceSize() << "B -> " << getCompressedSize() * 2 << "B "
|
std::cout << "[" << getCompressionTypeString() << "] "
|
||||||
<< "(ratio: " << getCompressionRatio() << ":1)" << std::endl;
|
<< getSourceSize() << "B -> " << getCompressedSize() << "B + "
|
||||||
|
<< getDictionarySize() << "B dict = " << getTotalCompressedSize() << "B "
|
||||||
|
<< "(ratio: " << getCompressionRatio() << ":1)" << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << "[" << getCompressionTypeString() << "] "
|
||||||
|
<< getSourceSize() << "B -> " << getTotalCompressedSize() << "B "
|
||||||
|
<< "(ratio: " << getCompressionRatio() << ":1)" << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get compression type as string
|
// Get compression type as string
|
||||||
|
|||||||
Reference in New Issue
Block a user