4.4 KiB
4.4 KiB
Here is the phased roadmap to achieve the project objectives while strictly adhering to the single-file and architectural constraints.
1. Phase 1: Test Framework & Baseline Verification
- What will be done: Create an end-to-end integration test suite using a script (e.g.,
test.shortest_runner.py). This will include generating minimal valid (JPEG/PNG) and invalid test images. The script will execute theccolorsbinary and assert against the terminal stdout and the generatedpalette.json. - Why in this order: Because the architecture forces a single-file design without separation of concerns, traditional unit testing is impossible. A black-box integration test suite must be established first to provide a safety net before any internal refactoring or optimizations occur.
- Definition of "Done": The test script is fully executable (ideally integrated into
ctestvia CMake), runs automatically, and successfully validates the "happy path" (successful color extraction) and error paths (file not found, invalid format). - Risk: Extremely low risk as no production code is altered. Rollback: Delete the test script and revert
CMakeLists.txt.
2. Phase 2: Core Debugging & Memory Optimization
- What will be done:
- Debug: Fix the file header check logic. Currently,
file.read(..., 8)assumes the file is at least 8 bytes long. Furthermore, the file is read twice (once manually, once bystbi_load). This will be streamlined. - Optimize: Eliminate the intermediate
std::vector<Pixel> samplesarray. The brightness/saturation filtering and 16x16x16 histogram bucket accumulation will be calculated directly inside thexandydownsampling loops.
- Debug: Fix the file header check logic. Currently,
- Why in this order: Fixing immediate crash risks on tiny/invalid files and removing unnecessary heap allocations (
std::vectoroverhead) provides a robust, highly performant foundation before introducing new features. - Definition of "Done": The
vector<Pixel>is entirely removed from the codebase, the program compiles without warnings, and the Phase 1 integration tests all pass. - Risk: The color quantization or sampling logic might inadvertently change, causing incorrect hex outputs. Rollback:
git checkoutthemain.cppfile to its Phase 1 state.
3. Phase 3: Ease of Use Improvements
- What will be done: Improve error messages and standard output control. Integrate
stbi_failure_reason()to tell the user why an image failed to load (e.g., corrupted file vs. unsupported format). Add a--quiet(-q) CLI flag to suppress standard terminal output, making the tool friendly for automated scripts. - Why in this order: Usability features are best layered on top of a stable, optimized processing core.
- Definition of "Done": Running
ccolors corrupted.jpgprints a highly specific error message. Runningccolors image.jpg -qgenerates the JSON file but prints absolutely nothing to standard output. - Risk: Modifying the
argc/argvparsing loop might accidentally break standard positional arguments. Rollback: Revertmain.cppto its Phase 2 state.
4. Phase 4: New Feature Integration
- What will be done: Add an
--output(-o) flag to allow users to specify a custom filename and path for the generated JSON file, replacing the hardcodedpalette.jsonlimitation. - Why in this order: Adding new command-line routing introduces new code paths and file I/O operations. It relies on the extensible CLI parsing structure created in Phase 3.
- Definition of "Done": Running
ccolors image.jpg -o /tmp/custom_colors.jsonsuccessfully parses the image and writes the JSON output specifically to the requested path. A corresponding test is added to the Phase 1 test suite and passes. - Risk: File stream failures (e.g., specifying a path in a non-existent directory or a read-only location) could crash the app if not handled gracefully. Rollback: Revert
main.cppto its Phase 3 state.
Optional (Speculative / "Nice to Have")
- HTML Visualizer: Add an
--html <file>flag that outputs a standalone.htmlfile with the extracted top 5 colors rendered as CSS colored blocks, providing a visual alternative to the terminal swatches. - Multithreaded Downsampling: Utilize C++17
std::execution::par_unseqor#pragma omp parallel forto parallelize the color extraction loops for massive performance gains on extremely high-resolution images.