The MCOimg pixel decoder loads at the first image, not with the chat

The decoder moves from core/mcoimg.py to core/mcoimg_decode.py, unchanged.
mcoimg.py keeps recognition (the caption needs only the header) and is
what the chat imports; pixelart imports the decoder inside decoded().
On the PicoCalc the decoder cost about 50 ms on every chat import.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5.5 committed 2026-11-20 00:47:53 -05:00
1 parent 2f2225b8bb
commit e84c902a80
5 files changed
+1270 -1241

No files matched your search

+7 -1234
View File
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+2 -1
View File
@@ -68,6 +68,7 @@ from .widgets import (
if TYPE_CHECKING:
from ..context import AppContext
from ..core.mcoimg_decode import Picture
from ..services.message_paths import TraceWalk
from .map_render import MapMarker
from .map_screen import Locator
@@ -1355,7 +1356,7 @@ class ChatScreen(Screen):
message = self._messages[max(0, min(self._selected, len(self._messages) - 1))]
return links.urls(self._sender_and_body(message)[1])
def _picked_picture(self) -> mcoimg.Picture | None:
def _picked_picture(self) -> Picture | None:
"""The pixel image of the selected message, or ``None`` (no selection, or no image)."""
if self._selected is None or not self._messages:
return None
+6 -4
View File
@@ -25,12 +25,11 @@ from rich.console import Group
from rich.style import Style
from rich.text import Text
from ..core import mcoimg
from ..platforms import Platform, on_platform
from .tui.screen import ScrollScreen
if TYPE_CHECKING:
from ..core.mcoimg import Picture
from ..core.mcoimg_decode import Picture
RGB = tuple[int, int, int]
@@ -57,9 +56,12 @@ def decoded(body: str) -> Picture | None:
"""The image of a message body, or ``None``. It keeps the last results.
A transcript paints many times while a message is visible. Each paint asks again, and
the cache answers without a second decode.
the cache answers without a second decode. The decoder is large, so it loads here, at
the first image, and not when the chat opens.
"""
return mcoimg.decode(body)
from ..core.mcoimg_decode import decode
return decode(body)
def fit(
+3 -2
View File
@@ -17,7 +17,8 @@ from pathlib import Path
import pytest
from meshterm.core import mcoimg, mcoimg_palettes
from meshterm.core.mcoimg import PixelImage, _decode_refs, base91_decode, decode, recognize
from meshterm.core.mcoimg import PixelImage, base91_decode, recognize
from meshterm.core.mcoimg_decode import Picture, _decode_refs, decode
#: (text, width, height, colours) from the version 3 vectors: one case for each mode of
#: the dimensions and for each palette profile that the vectors use.
@@ -298,7 +299,7 @@ def test_a_picture_draws_two_pixels_in_each_cell() -> None:
from meshterm.ui.pixelart import picture_text
red, blue = (255, 0, 0), (0, 0, 255)
picture = mcoimg.Picture(2, 3, (red, None, blue, red, red, None))
picture = Picture(2, 3, (red, None, blue, red, red, None))
lines = picture_text(picture, 10, indent=2).plain.split("\n")
# Row 0 over row 1: red over blue, nothing over red. Row 2 alone: red, nothing.
assert lines == [" ▀▄", " ▀ "]