Skip to content

Some cleanup (and minor optimizations) in BitmapByteQRCode - #703

Open
KrisVandermotten wants to merge 1 commit into
Shane32:masterfrom
KrisVandermotten:BitmapByteQRCode
Open

Some cleanup (and minor optimizations) in BitmapByteQRCode#703
KrisVandermotten wants to merge 1 commit into
Shane32:masterfrom
KrisVandermotten:BitmapByteQRCode

Conversation

@KrisVandermotten

@KrisVandermotten KrisVandermotten commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Some cleanup (and minor optimizations) in BitmapByteQRCode. Most important changes:

  • On modern .NET, the header is now a single 32 byte ReadOnlySpan<byte>, avoiding the allocation and initialization of three arrays. This allows the header to be copied into the bitmap as a single 256 bit vector, depending on hardware support. On .NET Framework, a single byte[] is allocated instead of three.
  • The rendering of the actual pixel data now uses normal for loops over the module matrix. Not only is this easier to understand, it also avoids unnecessary bounds checks and other calculations. For clarity, the loop variable over the vertical dimension is now called y and the loop variable over the horizontal dimension is called x, instead of the other way around.
  • The module matrix is now indexed into once per line instead of once per module.
  • For clarity, the posStartFirstPx and lenFirstPx have been renamed to lineStart and lineLength respectively.

Test plan

All changed code is covered by existing unit tests.

Summary by CodeRabbit

  • Bug Fixes

    • Improved bitmap QR code generation for more reliable image output.
    • Updated pixel rendering to preserve the correct row and module layout.
  • Performance

    • Streamlined bitmap creation and pixel writing for more efficient QR code rendering.
  • Compatibility

    • Maintained existing public APIs while improving support across supported runtime configurations.

@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 983a4c08-ad01-4d23-9750-47e97ad2b23b

📥 Commits

Reviewing files that changed from the base of the PR and between faa9fb8 and d9f4a59.

📒 Files selected for processing (1)
  • QRCoder/BitmapByteQRCode.cs

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

BitmapByteQRCode now stores the bitmap header as one buffer, writes header fields at fixed offsets, and generates pixel data with row-major traversal. It also precomputes color-buffer sizes and uses collection expressions for default colors.

Changes

Bitmap rendering

Layer / File(s) Summary
Bitmap header and buffer setup
QRCoder/BitmapByteQRCode.cs
The bitmap header is consolidated into one conditional buffer. Color-buffer sizing uses a precomputed byte width. Default colors use collection expressions.
Bitmap header writing and pixel traversal
QRCoder/BitmapByteQRCode.cs
The complete header is copied at once. File size, width, and height use fixed offsets. Pixel data is generated row by row, with each module row replicated for its pixel height.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to d9f4a

The change keeps the existing bitmap-rendering API and output path while simplifying header creation and pixel traversal; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the cleanup and minor optimizations made in BitmapByteQRCode. It is concise and related to the main changes.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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