Preview image versions before sending, and repair unheard chunks

Send sheet: opens on what recipients will see (the encoded photo decoded
on this device) instead of the original. "Try another version" encodes
the whole photo again with a near-invisible zoom/shift; the generative
decoder reconstructs each version differently, and on Kodak the best of
three raised CLIP agreement from 0.828 to 0.853. The user picks the
version to send; packet count and airtime follow the selection. Version 1
is byte-identical to the previous encode, so the wire format is
unchanged. The sender's bubble shows the chosen version and carries the
AI-reconstructed label.

Repeater echoes: the raw RX log handler now decrypts GRP_DATA as well as
GRP_TXT and counts repeaters re-flooding each chunk of our own images.
The bubble shows the repeat count like channel text, and Packet info
lists each packet. About 15 s after sending, chunks no repeater echoed
are resent once, but only when another chunk of the same image was
echoed, so senders with no repeater in earshot do not double their
airtime. Outgoing entries now record their payload size.
This commit is contained in:
zjs81 committed 2026-11-14 20:58:43 -07:00
1 parent aafd541b0f
commit 53e4e457ca
36 files changed
+2366 -150

No files matched your search

+62 -17
View File
@@ -1892,9 +1892,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
final connector = context.read<MeshCoreConnector>();
// The picked bytes are kept past the preview on purpose: the sender's own
// bubble renders from them (see [_registerOutgoingImage]). The bitstream
// cannot serve — turning it back into pixels is a ~2.16 GiB, ~1 s decode
// of an image the sender is already holding.
// bubble falls back to them (see [_registerOutgoingImage]) when the sheet
// could not decode the chosen version on this device.
final XFile? picked;
try {
picked = await ImagePicker().pickImage(
@@ -2070,8 +2069,11 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
/// GRP_DATA is not echoed back to the sender and an image is not a
/// [ChannelMessage], so without this the sender sees a "sent" snack bar and
/// an otherwise empty conversation. The entry lands in `decoded` directly —
/// an outgoing image is never queued for inference, so showing your own
/// photo costs no model memory.
/// an outgoing image is never queued for inference.
///
/// The bubble shows the version the user picked, decoded as recipients see
/// it ([ImageSendPreviewResult.previewPng]). Only when this device could not decode does it fall back
/// to the stretched original.
///
/// Best effort throughout: a failure here has already been preceded by a
/// successful transmission, so it must not turn into an error the user sees.
@@ -2087,7 +2089,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
} on ProviderNotFoundException {
return; // screen test without the store
}
final previewPng = await _squarePreviewPng(sourceBytes);
final previewPng =
result.previewPng ?? await _squarePreviewPng(sourceBytes);
if (previewPng == null) return;
try {
await store.registerOutgoing(
@@ -2101,6 +2104,18 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
rate: aeicRatePointForUi(result.rate),
chunkCount: chunkSet.dataChunkCount,
aspectCode: await _aspectCodeOf(sourceBytes),
// The decoded version is model output and carries the AI label; the
// stretched-original fallback is the sender's own pixels.
synthesized: result.previewPng != null,
payloadBytes: result.payload.length,
// Repeaters may already have echoed the first chunks while the rest
// were still going out.
chunkEchoes: mounted
? context.read<MeshCoreConnector>().ownImageEchoes(
widget.channel.index,
chunkSet.imgId,
)
: null,
);
} on Exception catch (error) {
debugPrint('outgoing image registration failed: $error');
@@ -2128,11 +2143,9 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
/// [imageBytes] stretched to 512x512, as PNG.
///
/// This is what the preview sheet showed (`BoxFit.fill` on a 1:1 box is
/// exactly the stretch the codec applies) and what the codec actually
/// encoded, so the sender's bubble matches both. Deliberately not a decode of the
/// bitstream: that would cost ~2.16 GiB and ~1 s to reproduce, less well, an
/// image this device is already holding in memory.
/// Fallback for the sender's bubble when the preview sheet had no decoded
/// version to hand over (a device that cannot decode). It is the input the
/// codec stretched, not what recipients see, so it is only a stand-in.
///
/// Returns null rather than throwing on an undecodable source — the send has
/// already happened by the time this runs.
@@ -2375,12 +2388,35 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
right: 8,
bottom: 4,
),
child: Text(
formatChatTime(context, entry.firstSeen),
style: MeshTheme.mono(
fontSize: 12 * textScale,
color: metaColor,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
formatChatTime(context, entry.firstSeen),
style: MeshTheme.mono(
fontSize: 12 * textScale,
color: metaColor,
),
),
if (isOutgoing) ...[
const SizedBox(width: 4),
// Same status as channel text: repeats heard, here
// for the least-heard data chunk.
MessageStatusIcon(
size: 16 * textScale,
isAcked: false,
isChannel: true,
repeatCount: entry.minDataChunkEchoes ?? 0,
resendProgress: context
.watch<MeshCoreConnector>()
.imageResendProgress(
entry.channelIndex,
entry.imgId,
),
onColor: metaColor,
),
],
],
),
),
],
@@ -2513,6 +2549,15 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
if (entry.recoveredWithParity)
Text(l10n.receivedImage_parityRecovered),
if (decodeMs != null) Text(l10n.receivedImage_decodeTime(decodeMs)),
if (entry.chunkEchoes case final echoes?) ...[
const SizedBox(height: 8),
for (var i = 0; i < echoes.length; i++)
Text(
i < entry.totalChunks
? l10n.receivedImage_packetEchoes(i + 1, echoes[i])
: l10n.receivedImage_recoveryPacketEchoes(echoes[i]),
),
],
],
),
actions: [