diff --git a/tests/g2chromatic.cpp b/tests/g2chromatic.cpp index 43d1f9a..6ff20e9 100644 --- a/tests/g2chromatic.cpp +++ b/tests/g2chromatic.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "../util/grid/grid2.hpp" #include "../util/output/aviwriter.hpp" @@ -36,7 +37,7 @@ int main() { std::uniform_real_distribution<> colorDist(0.2f, 0.8f); // Generate multiple seed points for more interesting patterns - const int numSeeds = 8; + const int numSeeds = 1; std::vector seedPoints; std::vector seedColors; @@ -98,25 +99,40 @@ int main() { std::vector rgbData; grid.getGridAsRGB(frameWidth, frameHeight, rgbData); - // Convert to BGR format for AVI (OpenCV uses BGR) + // Debug output to check frame dimensions + std::cout << "Frame " << frame << ": " << frameWidth << "x" << frameHeight + << ", RGB data size: " << rgbData.size() << std::endl; + + // Convert to BGR format for AVI and ensure proper 8-bit values std::vector bgrFrame(frameWidth * frameHeight * 3); #pragma omp parallel for for (int i = 0; i < frameWidth * frameHeight; ++i) { - bgrFrame[i * 3] = rgbData[i * 3 + 2]; - bgrFrame[i * 3 + 1] = rgbData[i * 3 + 1]; - bgrFrame[i * 3 + 2] = rgbData[i * 3]; + // Ensure values are in 0-255 range and convert RGB to BGR + int r = std::clamp(rgbData[i * 3], 0, 255); + int g = std::clamp(rgbData[i * 3 + 1], 0, 255); + int b = std::clamp(rgbData[i * 3 + 2], 0, 255); + + bgrFrame[i * 3] = static_cast(b); // B + bgrFrame[i * 3 + 1] = static_cast(g); // G + bgrFrame[i * 3 + 2] = static_cast(r); // R + } + + // Verify frame size matches expected + if (bgrFrame.size() != width * height * 3) { + std::cerr << "ERROR: Frame size mismatch! Expected: " << width * height * 3 + << ", Got: " << bgrFrame.size() << std::endl; + return 1; } - // for (int i = 0; i < frameWidth * frameHeight; ++i) { - // bgrFrame[i * 3] = static_cast(rgbData[i * 3 + 2]); // B - // bgrFrame[i * 3 + 1] = static_cast(rgbData[i * 3 + 1]); // G - // bgrFrame[i * 3 + 2] = static_cast(rgbData[i * 3]); // R - // } frames.push_back(bgrFrame); } // Save as AVI std::string filename = "output/chromatic_transformation.avi"; + std::cout << "Attempting to save AVI file: " << filename << std::endl; + std::cout << "Frames to save: " << frames.size() << std::endl; + std::cout << "Frame dimensions: " << width << "x" << height << std::endl; + bool success = AVIWriter::saveAVI(filename, frames, width, height, 30.0f); if (success) { @@ -134,6 +150,16 @@ int main() { } } else { std::cerr << "Failed to save AVI file!" << std::endl; + + // Additional debugging information + std::cerr << "Debug info:" << std::endl; + std::cerr << " - Frames count: " << frames.size() << std::endl; + if (!frames.empty()) { + std::cerr << " - First frame size: " << frames[0].size() << std::endl; + std::cerr << " - Expected frame size: " << width * height * 3 << std::endl; + } + std::cerr << " - Width: " << width << ", Height: " << height << std::endl; + return 1; } diff --git a/util/grid/grid2.hpp b/util/grid/grid2.hpp index 537f5a8..e1125e0 100644 --- a/util/grid/grid2.hpp +++ b/util/grid/grid2.hpp @@ -204,8 +204,8 @@ public: getBoundingBox(minCorner, maxCorner); // Calculate grid dimensions (adding 1 to include both ends) - width = static_cast(std::ceil(maxCorner.x - minCorner.x)) + 1; - height = static_cast(std::ceil(maxCorner.y - minCorner.y)) + 1; + width = static_cast(std::ceil(maxCorner.x - minCorner.x)) ; + height = static_cast(std::ceil(maxCorner.y - minCorner.y)) ; // Initialize with black (0,0,0) rgbData.resize(width * height * 3, 0);