diff --git a/tests/g2chromatic2.cpp b/tests/g2chromatic2.cpp index be1ccc7..3d21b60 100644 --- a/tests/g2chromatic2.cpp +++ b/tests/g2chromatic2.cpp @@ -9,12 +9,10 @@ #include "../util/output/aviwriter.hpp" #include "../util/output/bmpwriter.hpp" #include "../util/timing_decorator.cpp" -#include "../util/output/frame.hpp" -#include "../util/output/video.hpp" struct AnimationConfig { - int width = 1024; - int height = 1024; + int width = 256; + int height = 256; int totalFrames = 480; float fps = 30.0f; int numSeeds = 8; @@ -72,6 +70,7 @@ void expandPixel(Grid2& grid, AnimationConfig config, std::vector> newseeds; + std::unordered_set visitedThisFrame; for (const auto& seed : seeds) { visitedThisFrame.insert(std::get<0>(seed)); @@ -89,6 +88,7 @@ void expandPixel(Grid2& grid, AnimationConfig config, std::vector> frames, AnimationConfig config) { + TIME_FUNCTION; + std::string filename = "output/chromatic_transformation.avi"; - Grid2 grid = setup(config); - Preview(grid); - std::vector> seeds = pickSeeds(grid,config); + std::cout << "Frame count: " << frames.size() << std::endl; + std::cout << "Frame size: " << (frames.empty() ? 0 : frames[0].size()) << std::endl; + std::cout << "Width: " << config.width << ", Height: " << config.height << std::endl; - // Create video object with BGR channels and configured FPS - video vid(config.width+1, config.height+1, {'B', 'G', 'R'}, config.fps, true); - - for (int i = 0; i < config.totalFrames; ++i){ - std::cout << "Processing frame " << i + 1 << "/" << config.totalFrames << std::endl; - expandPixel(grid,config,seeds); - - frame outputFrame; - grid.getGridAsFrame(outputFrame, {'B', 'G', 'R'}); - - // Add frame to video (this will compress it using RLE + differential encoding) - vid.add_frame(outputFrame); - - // Optional: Print compression stats every 50 frames - // if ((i + 1) % 50 == 0) { - // auto stats = vid.get_compression_stats(); - // std::cout << "Frame " << (i + 1) << " - Compression ratio: " << stats.overall_ratio - // << ", Total compressed: " << stats.total_compressed_bytes << " bytes" << std::endl; - // } + std::filesystem::path dir = "output"; + if (!std::filesystem::exists(dir)) { + if (!std::filesystem::create_directories(dir)) { + std::cout << "Failed to create output directory!" << std::endl; + return false; + } } - // Use the video-based AVIWriter overload - bool success = AVIWriter::saveAVI("output/chromatic_transformation.avi", vid, config.fps); + bool success = AVIWriter::saveAVI(filename, frames, config.width+1, config.height+1, config.fps); if (success) { - // Print final compression statistics - auto final_stats = vid.get_compression_stats(); - std::cout << "Successfully saved AVI with " << vid.frame_count() << " frames" << std::endl; - std::cout << "Final compression statistics:" << std::endl; - std::cout << " Total frames: " << final_stats.total_frames << std::endl; - std::cout << " Video duration: " << final_stats.video_duration << " seconds" << std::endl; - std::cout << " Uncompressed size: " << final_stats.total_uncompressed_bytes << " bytes" << std::endl; - std::cout << " Compressed size: " << final_stats.total_compressed_bytes << " bytes" << std::endl; - std::cout << " Overall compression ratio: " << final_stats.overall_ratio << std::endl; - std::cout << " Average frame compression ratio: " << final_stats.average_frame_ratio << std::endl; - - // Optional: Save compressed video data for later use - auto serialized_data = vid.serialize(); - std::cout << "Serialized video data size: " << serialized_data.size() << " bytes" << std::endl; + // Check if file actually exists + if (std::filesystem::exists(filename)) { + auto file_size = std::filesystem::file_size(filename); + } } else { std::cout << "Failed to save AVI file!" << std::endl; } + return success; +} + +int main() { + AnimationConfig config; + + Grid2 grid = setup(config); + //grid.updateNeighborMap(); + Preview(grid); + std::vector> seeds = pickSeeds(grid,config); + std::vector> frames; + + for (int i = 0; i < config.totalFrames; ++i){ + std::cout << "Processing frame " << i + 1 << "/" << config.totalFrames << std::endl; + expandPixel(grid,config,seeds); + int width; + int height; + std::vector frame; + grid.getGridAsBGR(width,height,frame); + frames.push_back(frame); + } + + exportavi(frames,config); FunctionTimer::printStats(FunctionTimer::Mode::ENHANCED); return 0; } \ No newline at end of file