Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for terminal emulators with less colors #61

Open
7 tasks
AnonymouX47 opened this issue Jun 26, 2022 · 0 comments
Open
7 tasks

Support for terminal emulators with less colors #61

AnonymouX47 opened this issue Jun 26, 2022 · 0 comments
Assignees
Labels
enhancement New feature / Improvement suggestion or request planned Planned feature (should be removed as soon as implementation starts) text Related to the interface common to text-based render styles
Milestone

Comments

@AnonymouX47
Copy link
Owner

AnonymouX47 commented Jun 26, 2022

Requires #62

This will be implemented as render methods (and some style-specific parameters) common to all colored text-based render styles, defined by the [Colored]TextImage (not yet sure if ColoredTextImage will be a thing) class.

Progress:

  • Render methods selection
  • Support detection
  • Integration into existing text-based render styles
  • Style-spcific parameter
  • Style-spcific format spec field
  • CLI integration
  • TUI integration

Initial Idea

NB: These is mostly a raw dump of my thought process at the time I conceived the idea with updates once in a while, so might not be "neat".

[Colored]TextImage:

  • auto, direct, fbterm_256, xterm_256, ansi and no_color render methods for all text-based styles.

    • Determine and store the method equivalent to auto as _AUTO_METHOD
      • The first to be supported in order of quality
    • 256 colors have a slightly different escape sequence that uses a pallete index rather than rgb values.
  • is_supported(): if any(_is_supported(method) for method in _render_methods)

  • ... [See Keep Notes]

  • Style Params:

    • grey: bool = False -> Greyscale (only applies to methods other than none)
    • threshold_8color: int = 128 -> Any band of a pixel with a value less than the given value is taken to be 0. Otherwise, 1.
    • rgb_sep: str = ";" {";", ":"}

Requires updating _get_render_data():

  • Rename rgb -> pixels
  • grey: bool = False
  • threshold_8color: int = 128
  • color: Optional[str] = "rgb" {rgb, 256color, 8color, None}
    • if not color: pixels = None
    • elif grey: convert to "L"
      • rgb: px = (value,) * 3
      • 256:
        • 24-scale excludes black and white.
        • x = round((value - 1) * 25 / 255) # 26-scale includes black and white
        • px = {0: 16, 25: 231}.get(x, 232 - 1 + x) # -1 because the color after black should be index 0
      • 8: px = 7 if value >= threshold else 0
    • else:
      • rgb: px = (r,g,b)
      • 256: 0 <= r, g, b <= 5 -> px = 16 + 36 * round(r * 5 / 255) + 6 * round(g * 5 / 255) + round(b * 5 / 255)
        • Each of r,g,b must be scaled down from 256-scale to 6-scale: x = round(x * 5 / 255)
        • r,g,b in 6-scale are basically the digits of the 216-palette index in base 6
        • Convert to base 10 to get the 216-palette index: x = r * 36 + g * 6 + b
        • offset by +16 to get the 256-palette index: 16 + x
      • 8: 0 <= r, g, b <= 1 -> px = (r >= threshold) << 2 | (g >= threshold) << 1 | (b >= threshold)

Known Issues:

  • For text-based styles, On Kitty, cell BG colors that are equal to the default BG color take the form of the background (I.e might be translucent or blended with a background image).
  • This is overcome in the RGB method by slightly manipulating the pixel color (done in Rendering improvements #54) but can still occur with 265color or 8color method, as fixing it in these modes will require modifying either the pallete entries or the default BG color, which is generally not desired behavior.

Any suggestions are always welcome. 😃

@AnonymouX47 AnonymouX47 added enhancement New feature / Improvement suggestion or request lib Related to the library (Not to be used anymore) cli Related to the image viewer's CLI (Not to be used anymore) tui Related to the image viewer's TUI (Not to be used anymore) text Related to the interface common to text-based render styles planned Planned feature (should be removed as soon as implementation starts) labels Jun 26, 2022
@AnonymouX47 AnonymouX47 added this to the 0.5.0 milestone Jun 26, 2022
@AnonymouX47 AnonymouX47 self-assigned this Jun 26, 2022
@AnonymouX47 AnonymouX47 pinned this issue Jun 27, 2022
@AnonymouX47 AnonymouX47 modified the milestones: 0.5.0, 0.7.0 Feb 23, 2023
@AnonymouX47 AnonymouX47 removed lib Related to the library (Not to be used anymore) cli Related to the image viewer's CLI (Not to be used anymore) tui Related to the image viewer's TUI (Not to be used anymore) labels Apr 16, 2023
@AnonymouX47 AnonymouX47 modified the milestones: 0.7.0, 0.9.0 Jun 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature / Improvement suggestion or request planned Planned feature (should be removed as soon as implementation starts) text Related to the interface common to text-based render styles
Projects
None yet
Development

No branches or pull requests

1 participant