Skip to content

fix(art): JJN dithering + histogram equalization + <details> block#20

Open
thedarkknight197 wants to merge 3 commits into
ferdinandobons:mainfrom
thedarkknight197:fix/art-quality-jjn
Open

fix(art): JJN dithering + histogram equalization + <details> block#20
thedarkknight197 wants to merge 3 commits into
ferdinandobons:mainfrom
thedarkknight197:fix/art-quality-jjn

Conversation

@thedarkknight197

Copy link
Copy Markdown
Contributor

What this fixes

Three compounding bugs that made ASCII art unrecognizable or broken on GitHub:

1. Dark images went solid black (Ferrari problem)

The previous ramp mapped luminance linearly to 70 chars. A dark subject (red Ferrari in grayscale ≈ lum 50–80) mapped entirely to @/%, producing an unreadable solid block.

Fix: histogram equalization stretches the image's contrast to use the full 0–255 range before conversion — regardless of how dark or bright the source is.

2. HTML comment art broke GitHub rendering

The <!-- wayd:art\n[art]\n--> format leaked visible text on GitHub because the ASCII ramp contains > and - characters that form -->, closing the HTML comment early. Remaining art then rendered as markdown (blockquotes, bold, etc).

Fix: replace with a <details> block — renders as a collapsible "📎 ASCII image" section on GitHub.com, and is just as parseable by scroll.py.

3. Dense 70-char ramp produced noisy texture

No dithering + dense ramp = every pixel mapped to a different character = visual noise with no clear shapes.

Fix: Jarvis-Judice-Ninke error diffusion dithering (matches asciiart.eu "Quality Enhancements: JJN") + sparse 8-char ramp @%#*+:. + brightness threshold (pixels above 200 → space). Result: clean sparse style matching asciiart.eu Space Density 9.

Before vs After (same Ferrari photo)

Before — broken HTML comment, solid @@@ block:

::,~-{{1t|)t\>:IIllll!!!!iiiiiiii_|{    ← leaked from broken comment
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@    ← solid block, unrecognizable

After — collapsible on GitHub, sparse + recognizable:

     .  * .#**++**##*#**##**#: .. ...................:..:.::.::::::::::::+::##+*
 .. .  :*:+:++*++***+**+*#**#: . .. . .. .............................:.:. *+*++
   . . ***: ++*::*##++*****+*+  .. .. .. .. .. .......................... +*+++:
       *++: +**::*##++***++*##*. . .. .... .... .. ......................+*:+++:
  ..   *+*: +**::###+:****+*###. . . . . ... ...... .. .. .. .. ....... ++::++++
    .  #+*: +**:+###++***+**##*.  . .. .. . .  . .... ... ....... .. ....+::+++:
       #+*. +*+:+*##+:***++*##*. . .  . .. ..... . ..... ... .. ..... ...++:+:*+
   .  .*+*. +*+:+*##+:***++*##*.  . ..  . . . ... . . .. .. .. ..  .. . .+::++++
      .*+*. +*+.+#**+:***+**##*.   . .. .. .   . ... . ... .. .. .. ..  .+::++++
      .*+*  +*+.+#**+++**++*##*.  .   .  . .... . .. .. . .. .. . . .. . +++:++*
      .*+*  +#+.+#*#+:+**++*##*.   .  .  .  .  ..  . . . . . . . ..    . :+++++*
      :*+*. +#*.****+:+**++*##*.    .  . .  .  . .. . . ..  . .. ++:::+  :+::++*
   .  :*:* .+#*.****:++**++**#*.    .  .  .. ..  .  ..  . ..  . .+++:::+:.+++++*
      :*:*:.*#*.****:+++*+**##*.      .       .  .  .  .  .  .  .:++..:++.++:++*
+:.  .+++#*:+#*.****::+*++**##*.         .  .  .  .  . .  . ..  .:*+:..:+.++:+++
+++*++*++**:+##.***+::++++**#%*.   *###+   .   .  .  .  .  .    .:++:..:+.+:++++
:::::.:::+++*#%***+*::+*++*####:  +*+#%@:    .  .  .   .     .  .:++:.::+.+:+:+:
::...........::++*+*+:+**+####*.   ***##+     .  .  .   . .  .   :*+:..:+.+++:+:
:..:.......... ....:::++*+####*:   .+#%%:  .     .  .     .      :*+:...+.:+++++
:.::..:...:....:.........:+**##*     +##:++.  .     . ..    .   .:++:...*:::::::
:.:...::.....:::..........:::::+.    ++...    .: .           .   :+*:...+:::+++*
.:.::.......:..:.::.......:+:::*##    :    .:....*%#*. .:::.     :+++::::+*#%##%
+:.....:.::.::.:::.::::::++++*##%*         .+:  ..:*%@#*#%%%+   .******+**++:+..
@+..:.:..:..:::::::+**::*##++****+ .  .  .  ...     +**+***#*... ++*+.::+++..
+...........:.:::******+**+*******            .+.  ++++*******+++::.:: .+:*+  ..
+*++++*+****+*++**#******#**##*##*  :.  .      .:.:**###***##*+:.:: .....: .:++:
**++++++:::+****#********##**#**#*.+::. :*. ...+*#########%%###::::+:+:++++++++:
:...:::::::+***************##*#**##*+##%@@#:*+**%%#####%%%####%+::::++::::::::::
+++++++******#****************#++%%@@@@@@@@#**#%%@##%%%%%###%%*++++:...:::::::::
*+**+++++++###%%################%%@@@@@@@@@@@%##%@%%@%%%%%###%#*****+:.
+++:+++*****#*#%@@@%%@@@@@@@@%%%@@@@@@@@%@%@@%##%@@%%####%%##**%***#####*:....::
::+#%%@@@@%*#%%%%%%%%%%%%%%@@%%@@@@@@@@@@@@@@%%%@@%%%%%%%%###*+%###*****##**+:.
***@@@%##*#%@@@@%%%%@@%@@%%***@@@@@%#%%%@%@@@@%#@@@@@@@@@@%%%##%#######***++::.
#*****++**#@@@%%%%%%%@%@@@%.::%@@@@#:#@@@@@@@@%#%@@@@@@@@@@@%%%%#######*****+:..
*+++++*****#%%%@@%@%%%%%%@@@@@%@@@@@@@@@@@@@@@%#%@@@@@@@@@@@@@@%#########*******
+********####%@@@@@@%%%%%%%##%%@@@@%%%%%%%%%%%%##@@@@@@@@@@@@@@%###***#*##******
*++*******###%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%#%@@@@@@@@@@@@%%######**********
**+**+*****######%##****###%%%@@@@@@@@@@@@@@@@@%#%@@@@%%%%%%%%%%##*##*#********+
***+**+******###*+::::++++++++:.:::+:+*******####%@%####%%%###*++:+**********+::
*++++*++******+::..::::::::::    .::+##*#*####*#%%@%******+++:::++*****#***+:...
*++*++*++**++:....:::::::::   .:+******++++++::+::+++::::+++***#####**+++::....:
*+**+***++:....:..::..:::::::+++::.:.:::::::::+.    +***####%###*++:::........:.
*+++++*+:........:....::::::::::::::+::::::::::.     %%%###**+:::::..:.....:....
*++*++:. .........::::..:::::+::+++:+:::+:::::::     *%#*:::.:::.::....:..:..:::
+*++:. .............:.::::::::++::+:::::::::::::.    +%+.::.:.:..::::.::.:.....:

Replace dense 70-char gradient with threshold-based sparse mapping:
- Pixels above threshold (default 140) → space (sky/background areas)
- Pixels below threshold → @%#*+=-: character set (shadows/edges only)
- Result: airy asciiart.eu style where whitespace creates the image
Art is embedded in an HTML comment and explicitly exempt from the
post character limit. Capping it to the remaining text budget
forced portrait images down to ~38 chars wide, producing unreadable
output. Remove the budget constraint so img2ascii runs at full
quality (80 chars wide by default).
Three improvements to ASCII art quality and display:

1. img2ascii.py — replace dense 70-char ramp + edge blend with:
   - Jarvis-Judice-Ninke error diffusion dithering (matches asciiart.eu
     'Quality Enhancements: JJN' setting)
   - Histogram equalization so full contrast range is used regardless
     of image tone (fixes dark images like red Ferrari going solid-black)
   - Sparse 8-char ramp '@%#*+:. ' with brightness threshold (default 200)
     so bright/sky areas stay as spaces
   - Result: recognizable subjects with light-background aesthetic

2. shared.py — replace HTML comment art block with <details> block:
   Previously: <!-- wayd:art\n[art]\n-->
   Now: <details data-wayd-art><summary>📎 ASCII image</summary><pre>...</pre></details>
   - HTML comments with '>' chars from the ramp broke GitHub rendering
     (comment closed early, rest leaked as visible markdown)
   - <details> renders correctly on GitHub.com as a collapsible section
   - Backward compat regex kept for reading old HTML-comment posts

3. post.py — art generation now at width=120 (was 100) for better detail
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