#include #include #include #include #include #include #include #include "compressor.h" #include "decompressor.h" #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" #define STB_IMAGE_WRITE_IMPLEMENTATION #include "stb_image_write.h" struct ResultS { int original; int compressed; int64_t compression_time; int64_t decompression_time; }; std::optional run(const char *filepath) { int x, y, n; unsigned char *data = stbi_load(filepath, &x, &y, &n, 1); if (data == NULL) { printf("Error loading image!\n"); return std::nullopt; } std::vector> matrix(x, std::vector(y)); for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { matrix[i][j] = data[i * y + j]; } } delete[] data; Compressor com; auto startCom = std::chrono::high_resolution_clock::now(); com.compress(matrix); auto endCom = std::chrono::high_resolution_clock::now(); Decompressor dec; dec.reader.buffer.copy(com.writer.buffer); auto startDec = std::chrono::high_resolution_clock::now(); std::vector ret = dec.decompress(); auto endDec = std::chrono::high_resolution_clock::now(); stbi_write_bmp("out.bmp", x, y, 1, ret.data()); auto compTime = std::chrono::duration_cast(endCom - startCom); auto decTime = std::chrono::duration_cast(endDec - startDec); ResultS res; res.original = x * y; res.compressed = com.writer.buffer.taken; res.compression_time = compTime.count(); res.decompression_time = decTime.count(); return res; } // ... x = width, y = height // Velikost original, Velikost stisnjena, Razmerje (orig./stisn.), Čas kompresije, Čas dekompresije, int main(int argc, char **argv) { if (false) { std::optional ret = run("slike/Sunrise.bmp"); if (ret.has_value()) { ResultS res = ret.value(); printf("%9d\t", res.original); printf("%9d\t", res.compressed); printf("%9f\t", (float)res.original / (float)res.compressed); printf("%9ld\t", res.compression_time); printf("%9ld\t", res.decompression_time); printf("%s", "slike/Sunrise.bmp"); printf("\n"); } return 0; } printf("%9s\t%9s\t%9s\t%9s\t%9s\t\n", "Original", "Comp.", "Ratio", "Comp. ms", "Dec. ms"); std::string directory_path = "slike/"; std::vector files; // Iterate over the files in the directory for (const auto &entry : std::filesystem::directory_iterator(directory_path)) { // Check if the entry is a regular file if (std::filesystem::is_regular_file(entry.path())) { files.push_back(entry.path().string()); } } std::sort(files.begin(), files.end()); for (auto file : files) { // std::cout << file << std::endl; // if (file == "slike/Sunrise.bmp") continue; std::optional ret = run(file.c_str()); if (ret.has_value()) { ResultS res = ret.value(); printf("%9d\t", res.original); printf("%9d\t", res.compressed); printf("%9f\t", (float)res.original / (float)res.compressed); printf("%9ld\t", res.compression_time); printf("%9ld\t", res.decompression_time); printf("%s", file.c_str()); printf("\n"); } } return 0; }