Skip to content

Conversation

@JacobBorden
Copy link
Owner

No description provided.

google-labs-jules bot and others added 30 commits May 23, 2025 23:39
This commit introduces several enhancements to the bitmap image processing library:

Added:
- New image manipulation functions:
    - Invert Colors: Inverts the RGB values of each pixel.
    - Sepia Tone: Applies a classic sepia filter.
    - Box Blur: Applies a configurable box blur effect.
- Comprehensive unit testing framework (`tests/test_bitmap.cpp`) using CMake/CTest.
- Unit tests covering:
    - Pixel-level operations (Greyscale, Invert, Sepia, Brightness, Contrast, Saturation, Luminance, including color-specific variants).
    - Image-level operations (BoxBlur, Shrink, Rotate, and basic validity checks for others).
- `README.md`: Details project features, dependencies, build instructions, and basic usage.
- `CHANGELOG.md`: Tracks changes, starting with this set of enhancements as v0.1.0.

Changed:
- Refined contrast adjustment logic for secondary colors (Magenta, Yellow, Cyan) to apply contrast directly to their constituent primary color channels for more predictable results.
- Significantly improved inline code documentation in `src/bitmap.h` and `src/bitmap.cpp` for all functions, enhancing clarity on purpose, parameters, and logic.
- Standardized clamping of pixel color components to the 0-255 range across various functions.
- Refactored `main.cpp` to serve as a clearer demonstration of library features, including new functions and better error handling for file operations.

Fixed:
- Corrected syntax errors in the original implementations of `ChangePixelContrastMagenta` and `ChangePixelContrastCyan`.
- Addressed incorrect variable usage (e.g., `magenta` vs `cyan`) in `ChangePixelContrastCyan`.
- Corrected `std::min` usage in several saturation and luminance functions.
- Improved GDI resource management in `ScreenShotWindow` by ensuring proper cleanup of device contexts and bitmap handles.
- Corrected minor typos in function parameter names and conditional logic in some pixel manipulation functions.
This commit addresses several issues in the CMake configuration:

- Updated `cmake_minimum_required` in the root `CMakeLists.txt` from VERSION 3.0.0 to VERSION 3.10 to align with modern CMake practices and resolve a deprecation warning.
- Corrected the CPack module inclusion in the root `CMakeLists.txt` from `include(Cpack)` to `include(CPack)`, fixing a case-sensitivity error that prevented CMake from finding the module.

Note: Similar `cmake_minimum_required` deprecation warnings and CPack inclusion errors may still appear from external dependencies (`dependencies/bitmapfile` and `dependencies/matrix`) which are managed via `FetchContent`. These issues reside within the external projects themselves and are not directly modifiable in this repository. The changes in this commit resolve the errors originating from the project's own CMake scripts.
…cements

Feature/image processing enhancements
- Converted custom test functions to Google Test macros (TEST) for better integration and readability.
- Replaced ASSERT_EQUALS with EXPECT_EQ for consistency in assertions.
- Improved test structure for pixel manipulation functions including ApplySepiaToPixel, GreyScalePixel, ApplyBoxBlur, ShrinkImage, RotateImage, and others.
- Enhanced clarity by removing unnecessary output statements and ensuring valid bitmap checks are performed.
- Introduced a comprehensive Matrix library in C++ for matrix creation and manipulation.
- Implemented classes for MatrixRow, Matrix, and their respective iterators (MatrixRowIterator, MatrixColumnIterator, MatrixIterator).
- Added various matrix operations including addition, subtraction, multiplication, and division.
- Included methods for matrix manipulation such as merging, splitting, transposing, and creating identity matrices.
- Implemented exception handling for index bounds and invalid operations.
- Provided detailed documentation covering class descriptions, member functions, and usage examples.
google-labs-jules bot and others added 29 commits May 28, 2025 01:10
Refactors `tests/api_roundtrip.cpp` to use the Google Test framework,
removing its standalone `main` function. This resolves linker errors
caused by multiple `main` function definitions when linking with
`tests_main.cpp` (which provides the main for GTest via `gtest_main`).

- `tests/api_roundtrip.cpp` now uses `TEST()` macro and GTest assertions.
- `tests/CMakeLists.txt` was previously confirmed to correctly include
  `api_roundtrip.cpp` and link against `gtest_main`.
Here's a proposed change to your codebase:
This commit introduces fuzz testing for the `BmpTool::load()` function,
specifically targeting 54-byte BMP headers to ensure graceful failure
without heap interaction when processing malformed headers.

Key changes:
- Integrated libFuzzer into the CMake build system with an
  `ENABLE_FUZZING` option. This uses Clang and AddressSanitizer
  when enabled.
- Created a fuzzing harness (`tests/fuzz/fuzz_bitmap.cpp`) that
  feeds 54-byte data chunks from the fuzzer to `BmpTool::load()`.
- Added a GitHub Actions workflow (`.github/workflows/fuzzing.yml`)
  to automate the fuzzing process on pushes and pull requests.
  The workflow builds with Clang, ASan, and runs the fuzzer for a
  short duration.
- Added a unit test (`tests/test_bitmap.cpp`) to specifically check
  for correct error handling (`BitmapError::NotABmp`) when an
  invalid BMP magic number is encountered.

Manual analysis of `BmpTool::load()` suggests it is designed to
prevent heap allocations if header validation fails for 54-byte inputs.
The primary risks identified (integer overflows in validation,
mishandling of `ih.biSize`) are targets for the automated fuzzing
setup.

A Clang compiler crash was encountered in the development environment
when compiling `src/bitmap/bitmap.cpp` with fuzzing flags. This
prevented direct execution and iteration of the fuzzer during this
development, but the fuzzing infrastructure is provided for environments
where this compilation succeeds (e.g., the GitHub Actions runner).
The method `result.has_error()` was incorrectly used in the
`LoadWithInvalidMagicType` test case in `tests/test_bitmap.cpp`.
This has been changed to the correct method `result.isError()`,
as indicated by build failures in the CI.
Add fuzz testing for BMP header loading
This commit significantly expands the fuzz testing capabilities of the project.

Key changes include:
- Added UndefinedBehaviorSanitizer (UBSan) to the fuzzing configuration alongside AddressSanitizer (ASan) for more comprehensive bug detection.
- Introduced four new fuzz targets:
    - fuzz_bmp_tool_save: Targets the BmpTool::save functionality.
    - fuzz_bitmap_file: Targets Bitmap::File class operations.
    - fuzz_image_operations: Targets various image manipulation functions.
    - fuzz_matrix: Targets Matrix class operations.
- Updated the existing fuzz_bitmap target to use the new sanitizer configuration.
- Modified the CMake build system (tests/CMakeLists.txt) to correctly build all five fuzz targets when ENABLE_FUZZING is ON.
- Enhanced the GitHub Actions fuzzing workflow (.github/workflows/fuzzing.yml):
    - Builds all available fuzz targets.
    - Runs each of the five fuzzers independently.
    - Creates separate corpus directories for each fuzzer.
    - Added -print_pcs=1 libFuzzer option for better call stack information on new coverage.
- Updated README.md with a new "Fuzz Testing" section, detailing the available targets and how to enable/run them.

These changes aim to improve code robustness by systematically testing more parts of the codebase against a wider range of inputs and conditions.
feat: Expand fuzz testing suite and enhance diagnostics
This commit introduces SIMD (AVX2, SSSE3, NEON) optimizations for pixel format conversion and swizzling operations, along with corresponding unit tests and fuzz targets.

Optimizations Implemented:
- BGR (24-bit) to BGRA (32-bit, Alpha=255) conversion in `CreateMatrixFromBitmap`.
- BGRA to RGBA swizzle (e.g., for `BmpTool::load`).
- RGBA to BGRA swizzle (e.g., for `BmpTool::save`).
- Corrected Alpha handling for 24-bit BGR sources to set Alpha to 255 (opaque).

Refactoring:
- The core SIMD and scalar logic for these operations has been refactored into helper functions:
  - `internal_convert_bgr_to_bgra_simd`
  - `internal_swizzle_bgra_to_rgba_simd`
  - `internal_swizzle_rgba_to_bgra_simd`
- These helpers are declared in `src/bitmap/bitmap.h` and `src/format/format_internal_helpers.hpp` for testability.

Testing:
- Added new Google Tests in `tests/test_swizzle.cpp` for all three helper functions, covering various input sizes, edge cases (0 pixels), and content verification.
- Added new fuzz targets in `tests/fuzz/` for each helper function to detect crashes and sanitizer issues with random inputs:
  - `fuzz_convert_bgr_to_bgra.cpp`
  - `fuzz_swizzle_bgra_to_rgba.cpp`
  - `fuzz_swizzle_rgba_to_bgra.cpp`
- Updated `tests/CMakeLists.txt` to integrate the new unit tests and fuzz targets into the build system.
The declaration for `internal_convert_bgr_to_bgra_simd` was missing
from `src/bitmap/bitmap.h`, causing build failures when compiling
the unit tests in `tests/test_swizzle.cpp`.

This commit adds the required declaration.

This also includes the previous work:
feat: Add SIMD pixel swizzling with tests and fuzzers

This commit introduces SIMD (AVX2, SSSE3, NEON) optimizations for pixel format conversion and swizzling operations, along with corresponding unit tests and fuzz targets.

Optimizations Implemented:
- BGR (24-bit) to BGRA (32-bit, Alpha=255) conversion in `CreateMatrixFromBitmap`.
- BGRA to RGBA swizzle (e.g., for `BmpTool::load`).
- RGBA to BGRA swizzle (e.g., for `BmpTool::save`).
- Corrected Alpha handling for 24-bit BGR sources to set Alpha to 255 (opaque).

Refactoring:
- The core SIMD and scalar logic for these operations has been refactored into helper functions:
  - `internal_convert_bgr_to_bgra_simd`
  - `internal_swizzle_bgra_to_rgba_simd`
  - `internal_swizzle_rgba_to_bgra_simd`
- These helpers are declared in `src/bitmap/bitmap.h` and `src/format/format_internal_helpers.hpp` for testability.

Testing:
- Added new Google Tests in `tests/test_swizzle.cpp` for all three helper functions, covering various input sizes, edge cases (0 pixels), and content verification.
- Added new fuzz targets in `tests/fuzz/` for each helper function to detect crashes and sanitizer issues with random inputs:
  - `fuzz_convert_bgr_to_bgra.cpp`
  - `fuzz_swizzle_bgra_to_rgba.cpp`
  - `fuzz_swizzle_rgba_to_bgra.cpp`
- Updated `tests/CMakeLists.txt` to integrate the new unit tests and fuzz targets into the build system.
Corrects "undefined reference" linker errors for SIMD helper functions:
- Added missing declaration for `internal_convert_bgr_to_bgra_simd` to `src/bitmap/bitmap.h`.
- Placed declarations for `internal_swizzle_bgra_to_rgba_simd` and `internal_swizzle_rgba_to_bgra_simd` into the `BmpTool` namespace in `src/format/format_internal_helpers.hpp` to match their definitions.
- Updated calls in `tests/test_swizzle.cpp` to use `BmpTool::` namespace qualifier for these functions.

This also includes the previous work:
feat: Add SIMD pixel swizzling with tests and fuzzers

This commit introduces SIMD (AVX2, SSSE3, NEON) optimizations for pixel format conversion and swizzling operations, along with corresponding unit tests and fuzz targets.

Optimizations Implemented:
- BGR (24-bit) to BGRA (32-bit, Alpha=255) conversion in `CreateMatrixFromBitmap`.
- BGRA to RGBA swizzle (e.g., for `BmpTool::load`).
- RGBA to BGRA swizzle (e.g., for `BmpTool::save`).
- Corrected Alpha handling for 24-bit BGR sources to set Alpha to 255 (opaque).

Refactoring:
- The core SIMD and scalar logic for these operations has been refactored into helper functions:
  - `internal_convert_bgr_to_bgra_simd`
  - `internal_swizzle_bgra_to_rgba_simd`
  - `internal_swizzle_rgba_to_bgra_simd`

Testing:
- Added new Google Tests in `tests/test_swizzle.cpp` for all three helper functions.
- Added new fuzz targets in `tests/fuzz/` for each helper function.
- Updated `tests/CMakeLists.txt` to integrate new tests and fuzzers.
Corrects build errors in fuzz targets by adding the `BmpTool::`
namespace qualifier to calls of:
- `internal_swizzle_bgra_to_rgba_simd` in `fuzz_swizzle_bgra_to_rgba.cpp`
- `internal_swizzle_rgba_to_bgra_simd` in `fuzz_swizzle_rgba_to_bgra.cpp`

This aligns the calls with the function declarations which are
namespaced in `format_internal_helpers.hpp`.

This also includes the previous work:
fix: Resolve linker errors for swizzle helpers
feat: Add SIMD pixel swizzling with tests and fuzzers
Updates `.github/workflows/fuzzing.yml` to create corpus directories
for and execute the three new fuzz targets:
- fuzz_convert_bgr_to_bgra
- fuzz_swizzle_bgra_to_rgba
- fuzz_swizzle_rgba_to_bgra

This ensures these fuzzers are run as part of the CI pipeline.

This also includes the previous work:
fix: Qualify swizzle helper calls in fuzz targets
fix: Resolve linker errors for swizzle helpers
feat: Add SIMD pixel swizzling with tests and fuzzers
feat: Add SIMD pixel swizzling with tests and fuzzers
…unctions.

This commit significantly refactors the BmpTool to act as a true API
layer over the core bitmap processing logic.

Key changes:
- Modified `BmpTool::load` and `BmpTool::save` in `src/format/bitmap.cpp`
  to delegate more responsibility to the core library functions
  (::CreateMatrixFromBitmap, ::CreateBitmapFromMatrix), reducing
  redundant parsing and serialization logic.
- Removed unused internal formatting helpers from `src/format/`.
- Exposed 24 image manipulation functions (shrink, rotate, greyscale,
  color adjustments, blur, etc.) through the `BmpTool` API in
  `include/bitmap.hpp`. These functions now operate on
  `BmpTool::Bitmap` and return `BmpTool::Result`.
- Implemented these API functions in `src/format/bitmap.cpp`, where they
  wrap calls to the core library, handling data conversion (RGBA for API,
  BGRA for internal matrix) and error propagation.
- Updated `main.cpp` to exclusively use the `BmpTool` API for all
  bitmap operations, serving as an example of API usage.
- Created `tests/test_bmptool_api_manipulations.cpp` with unit tests
  for the newly exposed `BmpTool` image manipulation functions.
- Existing tests for core components (`test_bitmap.cpp`,
  `test_bitmap_file.cpp`) and relevant fuzz tests (`fuzz_bitmap.cpp`,
  `fuzz_bmp_tool_save.cpp`) were reviewed and confirmed/kept.

This refactoring provides a cleaner separation of concerns, with BmpTool
now providing a consistent interface for all bitmap operations.
…u'd like me to use, or are you asking me to do something with this information?
Refactor BmpTool into a dedicated API layer and expose manipulation f…
This commit introduces a new GitHub Actions workflow file `analysis.yml`.
This workflow includes three new jobs:

1.  `asan-msan`: Builds the project with Clang and runs tests with AddressSanitizer (ASan) and MemorySanitizer (MSan) enabled. This helps in detecting memory errors. The job runs in a Debug configuration.

2.  `valgrind`: Builds the project in Release mode and runs tests under Valgrind's memcheck tool. This provides an alternative method for memory error detection and leak finding.

3.  `codeql-analysis`: Integrates GitHub's CodeQL static analysis tool to scan the C/C++ codebase for potential security vulnerabilities and other code quality issues.

These jobs are configured to run on pushes and pull requests to the `master` and `development` branches, enhancing the CI process by adding comprehensive code analysis and memory safety checks.
Add GitHub Actions workflow for extended analysis
This commit includes extensive updates to the project's documentation:

1.  **README.md**:
    *   I verified and updated the "Features" section to accurately reflect current library capabilities, distinguishing between the old API and the new `BmpTool` API.
    *   I clarified "Dependencies" and "Core Modules" sections.
    *   I improved the `BmpTool` API explanation and replaced the example with a more comprehensive one from `main.cpp`, demonstrating a full load-process-save cycle.
    *   I updated "Building the Project" with more detailed instructions and clarified test execution.
    *   I added a "Code Documentation" section explaining Doxygen usage for `include/bitmap.hpp` and providing instructions for local documentation generation.
    *   I added a "Contributing" section with basic guidelines.

2.  **src/matrix/Documentation/Matrix.MD**:
    *   I performed a thorough review and update to align with `src/matrix/matrix.h`.
    *   I corrected descriptions for iterator template parameters, operator behaviors, and const-correctness.
    *   I documented previously undocumented constructors, destructors, assignment operators, and member functions for `MatrixRow<T>` and `Matrix<T>`.
    *   I updated function signatures, return types (e.g., for in-place methods and compound assignment operators), and parameter types to match the current implementation.
    *   I clarified differences between `at()` (bounds-checked) and `operator[]` (no bounds-checking).
    *   I revised the "Potential Improvements" section to reflect implemented features and add new suggestions.
    *   I updated usage examples.

3.  **CHANGELOG.md**:
    *   I added entries under version 0.3.0 to record the significant updates made to `README.md` and `src/matrix/Documentation/Matrix.MD`.

These changes ensure that the project documentation is current, accurate, and provides comprehensive guidance for you and contributors.
Docs: Comprehensive project documentation update
This commit introduces automated Doxygen HTML documentation generation.

Key changes:
- Added a `Doxyfile` to the root of the repository, configured to scan `src` and `include` directories and output HTML documentation to `docs/doxygen/html`.
- Modified the `.github/workflows/analysis.yml` workflow:
    - Added a step to install Doxygen using `apt-get`.
    - Added a step to run Doxygen using the `Doxyfile`.
    - Added a step to upload the generated HTML documentation as a build artifact named `doxygen-html-docs`.

This will ensure that documentation is generated automatically with each run of the analysis workflow, providing up-to-date documentation for the project.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants