Skip to content

Conversation

@shreyassanthu77
Copy link
Collaborator

Major Changes

🏗️ Build System Overhaul

  • Complete rewrite of the build system in build.zig
  • Replaced buildOdiff() function with makeOdiff() using new OdiffBuildOptions struct
  • Implemented three-tier module architecture:
    • image_mod - Core image data structure and operations
    • io_mod - Image format handling (imports image_mod)
    • Main module - Core diffing logic (imports both image and io)
  • Removed complex cross-compilation detection logic
  • Consolidated test configuration into single test_files array
  • Changed test command from test-all to test throughout
  • Updated dynamic linking logic with better target detection
  • Added commented-out library building code for future use

📁 Module Structure Reorganization

New directory structure:

src/
├── image/
│   └── image.zig          # NEW: Core Image struct and operations
├── io/
│   ├── io.zig             # SIMPLIFIED: Removed Image struct, now just format handling
│   ├── bmp.zig
│   ├── jpeg.zig
│   ├── png.zig
│   ├── tiff.zig
│   └── webp.zig
├── lib/                   # NEW: Core library modules
│   ├── root.zig           # MOVED: Main library entry point
│   ├── diff.zig           # MOVED: Core diffing algorithm
│   ├── antialiasing.zig   # MOVED: Antialiasing detection
│   ├── color_delta.zig    # MOVED: Color difference calculations
│   ├── rvv.c              # MOVED: RISC-V vector implementation
│   └── vxdiff.asm         # MOVED: AVX assembly implementation
├── cli.zig                # UPDATED: Import changes
├── main.zig               # UPDATED: Import changes
└── test_*.zig             # CONSOLIDATED: See test changes below

🖼️ Image Structure Extraction

Created dedicated image module (src/image/image.zig):

  • Extracted the Image struct from src/io/io.zig into its own module
  • Contains all image manipulation methods:
    • slice(), deinit(), readRawPixelAtOffset(), readRawPixel()
    • setImgColor(), makeSameAsLayout(), makeWithWhiteOverlay()
  • Optimized SIMD-based white overlay generation with vector operations

📥 IO Module Simplification

Simplified src/io/io.zig:

  • Now imports Image from @import("image")
  • Simplified to focus solely on format detection and loading/saving
  • Updated documentation references from loadImageEx to loadImageWithFormat

📚 Library Module Prep

Moved core library files to src/lib/:

  • root.zig - Now serves as main library entry point, exports Image, io, diff, color_delta, antialiasing
  • diff.zig - Updated imports to use new image module
  • antialiasing.zig - Updated imports
  • color_delta.zig - No changes (pure logic)
  • rvv.c - RISC-V vector implementation
  • vxdiff.asm - AVX assembly implementation

🧪 Test Consolidation

Major test file reorganization:

  • DELETED: src/test_io_bmp.zig, src/test_io_jpg.zig, src/test_io_png.zig, src/test_io_tiff.zig, src/test_io_webp.zig (544 lines removed)
  • CREATED: src/test_io.zig - Consolidated all IO tests into single file (277 lines)
  • UPDATED: All remaining test files with new import structure:
    • Changed from @import("root.zig") to @import("odiff")
    • Updated Image type references from io.Image to lib.Image

🔄 Import Updates Across Codebase

Updated import statements:

  • src/cli.zig: Changed from @import("diff.zig") to @import("odiff") and lib.diff
  • src/main.zig: Changed from @import("odiff_lib") to @import("odiff")
  • All IO format files (bmp.zig, jpeg.zig, etc.): Changed Image import from io.zig to image.zig
  • All test files: Updated to use new module structure

🚀 CI/CD Workflow Updates

GitHub Actions changes:

  • .github/workflows/build.yml: Changed test-all to test in two places
  • .github/workflows/riscv-qemu.yml: Updated path trigger from "src/rvv.c" to "src/lib/rvv.c"

📝 Documentation Improvements

Updated docstrings:

  • Fixed references from loadImageEx to loadImageWithFormat
  • Fixed references from saveImageEx to saveImageWithFormat

Statistics

  • Files changed: 28
  • Insertions: 541
  • Deletions: 834
  • Net change: -293 lines (more modular, less duplicated code)

Summary

This refactoring transforms odiff from a monolithic application structure to a modular library-ready architecture. The key benefits are:

  1. Clear separation of concerns - Image data, IO operations, and core algorithms are now in separate modules
  2. Library preparation - The new structure makes it easier to expose odiff as a reusable library
  3. Reduced code duplication - Eliminated duplicate Image struct definitions
  4. Simplified build system - More maintainable and easier to understand
  5. Consolidated testing - All IO tests now in one place, reducing maintenance overhead

The changes maintain full backward compatibility while setting up the foundation for future library usage.

@dmtrKovalenko
Copy link
Owner

dmtrKovalenko commented Oct 29, 2025

Thank you for doing this but somehow these changes lead to 4x performance regression

image

@shreyassanthu77
Copy link
Collaborator Author

Wait what 😅 I will see what's going on

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