Skip to content

feat: Add SIMD pixel swizzling with tests and fuzzers#9

Merged
JacobBorden merged 5 commits intodevelopmentfrom
feat/simd-swizzle-tests
May 30, 2025
Merged

feat: Add SIMD pixel swizzling with tests and fuzzers#9
JacobBorden merged 5 commits intodevelopmentfrom
feat/simd-swizzle-tests

Conversation

@JacobBorden
Copy link
Owner

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.

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
@JacobBorden JacobBorden merged commit fe0ad63 into development May 30, 2025
2 checks passed
@JacobBorden JacobBorden deleted the feat/simd-swizzle-tests branch May 31, 2025 00:45
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.

1 participant