diff --git a/.gitignore b/.gitignore index 0ff488affbfb0b34a14622c4654924aed019d78b..b945a25e72b4904e1e69a673f56e7db6c30687bd 100644 --- a/.gitignore +++ b/.gitignore @@ -45,4 +45,5 @@ vscode/ # Project-specific ignores go below here. ## input/ +input_backup/ output/ diff --git a/documents/references.md b/documents/references.md index dd34e5e015dcfd221a802c74a470d388bfb26d49..47ce71c7f87fd2927f361fb94b4f68b441436c9e 100644 --- a/documents/references.md +++ b/documents/references.md @@ -47,6 +47,9 @@ Various references used in project. * <https://stackoverflow.com/a/59553786> * <https://stackoverflow.com/a/5420568> +#### Memory Management +* <https://www.geeksforgeeks.org/delete-in-c/> + ## CUDA References diff --git a/part_1/image.cu b/part_1/image.cu index 06952d2e1f0250740d73a44175c5a7cbf3fc8259..ee9c2b13561eb8713eb82c7f80c3be87c72986f6 100644 --- a/part_1/image.cu +++ b/part_1/image.cu @@ -79,6 +79,9 @@ void Image::import_image_file() { logger.debug("Image::import_image_file():"); logger.debug(""); + logger.info("Attempting to import image data..."); + logger.info("Data from: \"" + input_path + "\""); + // Open input file. std::ifstream input_file; input_file.open(input_path, std::ios::binary | std::ios::in); @@ -90,9 +93,13 @@ void Image::import_image_file() { // File opened. Grab data. std::string header; input_file >> header; - if (strcmp(header.c_str(), "P6") != 0) { - throw("Can't read input file"); - } + // if (strcmp(header.c_str(), "P6") != 0) { + // // throw("Can't read input file"); + // logger.error("Wrong file type, oops: "); + // logger.error(header); + // logger.error(input_path); + // logger.error(""); + // } // Save image values to class. input_file >> width >> height >> bit_depth; @@ -144,6 +151,7 @@ Image::Image() { } } + /** * Constructor that takes input path to image file. * Output path is determined based on parsing input path. @@ -153,7 +161,9 @@ Image::Image(std::string user_path) { logger.debug(" user_path: " + user_path); logger.debug(""); - // Re-validate path for saving to class.. + logger.info("Constructing image class."); + + // Re-validate path for saving to class. path_validator_struct* return_struct = validate_path(user_path); int path_type = return_struct->file_type; if (return_struct->err_code) { @@ -166,9 +176,22 @@ Image::Image(std::string user_path) { calculate_paths(user_path); import_image_file(); } else { - logger.error("Provided path is not to image file. Class initialization failed."); + logger.error("Provided path is not an image file. Class initialization failed."); return; } + + logger.info("Image class created."); +} + + +/** + * Deconstructor. + */ +Image::~Image() { + logger.debug("Deconstructing image class"); + + // Deallocate memory objects. + delete[] pixel_arr; } //endregion Constructors. @@ -186,9 +209,9 @@ void Image::display_properties() { logger.info(""); logger.info("input file path: " + input_path); logger.info("output file path: " + output_path); - logger.info("width: " + width); - logger.info("height: " + height); - logger.info("bit depth: " + bit_depth); + logger.info("width: " + std::to_string(width)); + logger.info("height: " + std::to_string(height)); + logger.info("bit depth: " + std::to_string(bit_depth)); logger.info(""); } diff --git a/part_1/image.h b/part_1/image.h index 4d9eb465148621e72b133250da4310c6e9bba770..65b5ba10724a12f51a51a77ae0969d23e2738f19 100644 --- a/part_1/image.h +++ b/part_1/image.h @@ -4,9 +4,9 @@ // System Import Headers. +#include <cctype> #include <cstdio> #include <cstdlib> -#include <cctype> #include <filesystem> #include <fstream> #include <iostream> @@ -86,6 +86,11 @@ class Image { */ Image(std::string user_path); + /** + * Deconstructor. + */ + ~Image(); + //endregion Constructors. diff --git a/part_1/logging.cu b/part_1/logging.cu index 5fb3771f7cbb3a9eeef3df3ed9157c0cabcae9b3..e281960f4b1507035b7c9b69767432c8d5eeef79 100644 --- a/part_1/logging.cu +++ b/part_1/logging.cu @@ -17,7 +17,7 @@ */ Logging::Logging() { std::filesystem::path cwd = std::filesystem::current_path(); - core_logging_folder = cwd.string() + "/log/"; + core_logging_folder = cwd.string() + "/logs/"; // Check if logging directory exists. struct stat info; diff --git a/part_1/main.cu b/part_1/main.cu index 5710a71bc3c0e8245b861e94e368f4b8712af91a..d1094ee0d6ec56b2a193d07833690bbbbb00df11 100644 --- a/part_1/main.cu +++ b/part_1/main.cu @@ -4,9 +4,9 @@ // System Import Headers. +#include <cctype> #include <cstdio> #include <cstdlib> -#include <cctype> #include <filesystem> #include <fstream> #include <iostream> @@ -98,6 +98,10 @@ void process_dir(std::string path_str) { logger.debug(" path_str: " + path_str); logger.debug(""); + logger.info(""); + logger.info(""); + logger.info(""); + logger.info(""); logger.info("Handling dir."); // Process all files in directory. @@ -122,9 +126,6 @@ void process_dir(std::string path_str) { // Process file. process_file(file_path_str); } - - // Send individual file path for processing. - process_file(entry.path()); } } @@ -137,6 +138,10 @@ void process_file(std::string path_str) { logger.debug(" path_str: " + path_str); logger.debug(""); + logger.info(""); + logger.info(""); + logger.info(""); + logger.info(""); logger.info("Handling file."); Image image(path_str); diff --git a/part_1/makefile b/part_1/makefile index 75402366ac21a022af2d41221c745883076acc04..85404c9c0a3d11d73de90e8331493db25fbbac65 100644 --- a/part_1/makefile +++ b/part_1/makefile @@ -31,5 +31,6 @@ run: $(TARGET) # Compile target if dependencies update. Then run. valgrind: $(TARGET) - @rm ./logs/vg/* - valgrind --leak-check=full --suppressions=valgrind_supression.txt --log-file=./logs/vg/vg.%p ./$(TARGET) $(ARGS) +# @rm ./logs/vg/* +# valgrind --leak-check=full --log-file=./logs/vg/vg.%p ./$(TARGET) $(ARGS) + valgrind --leak-check=full ./$(TARGET) $(ARGS) diff --git a/part_1/utility.h b/part_1/utility.h index d20726d61bf547b8eced74f998a578f7184af8ba..fea1b97f3423ee1aa6f6ef5e15b1678d65577628 100644 --- a/part_1/utility.h +++ b/part_1/utility.h @@ -4,9 +4,9 @@ // System Import Headers. +#include <cctype> #include <cstdio> #include <cstdlib> -#include <cctype> #include <filesystem> #include <fstream> #include <iostream>