Skip to content

Fix: ASCII renderer inverted by default#692

Closed
MJenius wants to merge 2 commits intoShane32:masterfrom
MJenius:fix/issue-646
Closed

Fix: ASCII renderer inverted by default#692
MJenius wants to merge 2 commits intoShane32:masterfrom
MJenius:fix/issue-646

Conversation

@MJenius
Copy link
Copy Markdown

@MJenius MJenius commented Mar 9, 2026

Fixes #646

Summary by CodeRabbit

  • Bug Fixes
    • Refined ASCII QR code rendering by updating character mapping to improve visual appearance of color transitions in the generated output.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 9, 2026

📝 Walkthrough

Walkthrough

This change corrects the inverted rendering in the ASCII 'small' renderer by reassigning the palette character mappings in the GetGraphicSmall method. The Unicode block characters and space are swapped to properly represent white and black module color combinations.

Changes

Cohort / File(s) Summary
Palette Mapping Fix
QRCoder/ASCIIQRCode.cs
Reassigned character values for WHITE_ALL, WHITE_BLACK, BLACK_WHITE, and BLACK_ALL palette entries to correct the inverted rendering of ASCII QR codes without altering control flow.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • gfoidl
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the primary fix: correcting the inverted ASCII renderer output by default.
Linked Issues check ✅ Passed The PR changes directly address issue #646's requirements by reassigning palette character mappings to correct the inverted rendering behavior.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the ASCII 'small' renderer's inverted palette mapping as specified in issue #646, with no unrelated modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@QRCoder/ASCIIQRCode.cs`:
- Around line 112-115: Tests still expect the old palette ordering so update the
small-renderer fixtures in AsciiQRCodeRendererTests to match the new constants
(WHITE_ALL, WHITE_BLACK, BLACK_WHITE, BLACK_ALL) by swapping/rewriting the
expected outputs: swap the default-case expected output with the invert: true
case (or otherwise invert the fixtures) so the filled quiet zone and
inverted-render expectations align with the new palette mapping; modify the
assertions in QRCoderTests/AsciiQRCodeRendererTests.cs (the test method(s)
around AsciiQRCodeRendererTests) to use the corrected expected strings for the
default and invert:true cases and keep the test names/structure unchanged.
- Around line 112-115: Default inversion for the public helper
AsciiQRCodeHelper.GetQRCode(..., bool invert = true) must be flipped to false to
match the palette change; locate the GetQRCode method declaration and change its
default parameter to invert = false (and update any other overloads or callers
that rely on the old default), ensuring the new default aligns with the ASCII
palette constants (WHITE_ALL, WHITE_BLACK, BLACK_WHITE, BLACK_ALL) so
GetGraphicSmall(invert: false) and the helper's default behavior produce the
same non-inverted output.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2e7c979e-f6dd-4ff0-ae03-ba20d59403fb

📥 Commits

Reviewing files that changed from the base of the PR and between 4973174 and 5527610.

⛔ Files ignored due to path filters (15)
  • QRCoderDemoUWP/Assets/LockScreenLogo.scale-200.png is excluded by !**/*.png
  • QRCoderDemoUWP/Assets/SplashScreen.scale-200.png is excluded by !**/*.png
  • QRCoderDemoUWP/Assets/Square150x150Logo.scale-200.png is excluded by !**/*.png
  • QRCoderDemoUWP/Assets/Square44x44Logo.scale-200.png is excluded by !**/*.png
  • QRCoderDemoUWP/Assets/Square44x44Logo.targetsize-24_altform-unplated.png is excluded by !**/*.png
  • QRCoderDemoUWP/Assets/StoreLogo.png is excluded by !**/*.png
  • QRCoderDemoUWP/Assets/Wide310x150Logo.scale-200.png is excluded by !**/*.png
  • QRCoderTests/PdfByteQRCodeRendererTests.can_render_pdfbyte_qrcode_blackwhite.approved.pdf is excluded by !**/*.pdf
  • QRCoderTests/PdfByteQRCodeRendererTests.can_render_pdfbyte_qrcode_color.approved.pdf is excluded by !**/*.pdf
  • QRCoderTests/PdfByteQRCodeRendererTests.can_render_pdfbyte_qrcode_custom_dpi.approved.pdf is excluded by !**/*.pdf
  • QRCoderTests/PdfByteQRCodeRendererTests.can_render_pdfbyte_qrcode_from_helper.approved.pdf is excluded by !**/*.pdf
  • QRCoderTests/PdfByteQRCodeRendererTests.can_render_pdfbyte_qrcode_from_helper_2.approved.pdf is excluded by !**/*.pdf
  • QRCoderTests/TransposeVerificationTests.pdf_renderer.approved.pdf is excluded by !**/*.pdf
  • QRCoderTests/assets/noun_software engineer_2909346.png is excluded by !**/*.png
  • nuget-icon.png is excluded by !**/*.png
📒 Files selected for processing (1)
  • QRCoder/ASCIIQRCode.cs

Comment on lines +112 to +115
WHITE_ALL = " ",
WHITE_BLACK = "\u2584",
BLACK_WHITE = "\u2580",
BLACK_ALL = "\u2588",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Update the small-renderer fixtures in AsciiQRCodeRendererTests.

QRCoderTests/AsciiQRCodeRendererTests.cs:38-75 still hardcodes the pre-fix output: the default case expects the filled quiet zone, and the invert: true case expects the non-inverted one. After this palette swap, those expectations need to be swapped/rewritten as well, otherwise the corrected behavior is either untested or the existing tests will fail.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@QRCoder/ASCIIQRCode.cs` around lines 112 - 115, Tests still expect the old
palette ordering so update the small-renderer fixtures in
AsciiQRCodeRendererTests to match the new constants (WHITE_ALL, WHITE_BLACK,
BLACK_WHITE, BLACK_ALL) by swapping/rewriting the expected outputs: swap the
default-case expected output with the invert: true case (or otherwise invert the
fixtures) so the filled quiet zone and inverted-render expectations align with
the new palette mapping; modify the assertions in
QRCoderTests/AsciiQRCodeRendererTests.cs (the test method(s) around
AsciiQRCodeRendererTests) to use the corrected expected strings for the default
and invert:true cases and keep the test names/structure unchanged.

⚠️ Potential issue | 🟠 Major

Flip the helper overload default to false too.

This palette swap corrects GetGraphicSmall(invert: false), but Line 197 still declares AsciiQRCodeHelper.GetQRCode(..., bool invert = true). Calls through that public helper will therefore keep returning the inverted output by default, so the bug remains on one entry point.

Suggested follow-up
-    public static string GetQRCode(string plainText, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, string endOfLine = "\n", bool drawQuietZones = true, bool invert = true)
+    public static string GetQRCode(string plainText, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, string endOfLine = "\n", bool drawQuietZones = true, bool invert = false)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@QRCoder/ASCIIQRCode.cs` around lines 112 - 115, Default inversion for the
public helper AsciiQRCodeHelper.GetQRCode(..., bool invert = true) must be
flipped to false to match the palette change; locate the GetQRCode method
declaration and change its default parameter to invert = false (and update any
other overloads or callers that rely on the old default), ensuring the new
default aligns with the ASCII palette constants (WHITE_ALL, WHITE_BLACK,
BLACK_WHITE, BLACK_ALL) so GetGraphicSmall(invert: false) and the helper's
default behavior produce the same non-inverted output.

@MJenius MJenius closed this by deleting the head repository Mar 12, 2026
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.

ASCII 'small' renderer prints inverted by default

1 participant