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:
1 parent
aafd541b0f
commit
53e4e457ca
36 files changed
+2366
-150
No files matched your search
@@ -970,15 +970,17 @@ class ImageCodecService extends ChangeNotifier implements ImageSendCodec {
|
||||
|
||||
/// [ImageSendCodec] entry point used by `ImageSendPreviewSheet`.
|
||||
///
|
||||
/// Takes the raw picked file (JPEG/PNG/HEIC/…), centre-crops and scales it to
|
||||
/// [kImageCodecSquareSize] square, then encodes. Throws on failure so the
|
||||
/// Takes the raw picked file (JPEG/PNG/HEIC/…), stretches the part of it
|
||||
/// that [variant] selects (see [rerollSourceRect]; 0 is the whole photo) to
|
||||
/// a [kImageCodecSquareSize] square, then encodes. Throws on failure so the
|
||||
/// sheet can surface it — unlike the nullable service-level methods below,
|
||||
/// whose contract is "null means not available".
|
||||
@override
|
||||
Future<Uint8List> encode(
|
||||
Uint8List imageBytes,
|
||||
ImageCodecRatePoint rate,
|
||||
) async {
|
||||
ImageCodecRatePoint rate, {
|
||||
int variant = 0,
|
||||
}) async {
|
||||
if (!kImageCodecBitstreamPathAvailable) {
|
||||
// Fail here rather than after a 512x512 raster and a session load, and
|
||||
// fail with the specific exception so the sheet can say why.
|
||||
@@ -990,7 +992,7 @@ class ImageCodecService extends ChangeNotifier implements ImageSendCodec {
|
||||
throw const ImageCodecBundleIncomplete();
|
||||
}
|
||||
final result = await encodeImage(
|
||||
rgbBytes: await _toSquareRgb(imageBytes),
|
||||
rgbBytes: await _toSquareRgb(imageBytes, variant: variant),
|
||||
ratePoint: aeicRatePointForUi(rate),
|
||||
);
|
||||
final bitstream = result?.bitstream;
|
||||
@@ -1300,14 +1302,18 @@ class ImageCodecService extends ChangeNotifier implements ImageSendCodec {
|
||||
|
||||
static const int _bytesPerPixel = 3;
|
||||
|
||||
/// Centre-crops [imageBytes] to a square and scales it to
|
||||
/// [kImageCodecSquareSize], returning packed 8-bit RGB.
|
||||
/// Stretches the [variant] region of [imageBytes] (see [rerollSourceRect];
|
||||
/// 0 is the whole frame) to a [kImageCodecSquareSize] square, returning
|
||||
/// packed 8-bit RGB.
|
||||
///
|
||||
/// Uses `dart:ui` rather than a decode package so this adds no dependency.
|
||||
/// It runs on the root isolate, which is acceptable: it is a single 512x512
|
||||
/// raster, three orders of magnitude cheaper than the 1385 GFLOP inference
|
||||
/// that follows in the worker.
|
||||
Future<Uint8List> _toSquareRgb(Uint8List imageBytes) async {
|
||||
Future<Uint8List> _toSquareRgb(
|
||||
Uint8List imageBytes, {
|
||||
int variant = 0,
|
||||
}) async {
|
||||
final codec = await ui.instantiateImageCodec(imageBytes);
|
||||
final frame = await codec.getNextFrame();
|
||||
final source = frame.image;
|
||||
@@ -1317,16 +1323,11 @@ class ImageCodecService extends ChangeNotifier implements ImageSendCodec {
|
||||
// Aspect ratio is deliberately not preserved: the codec's graph is
|
||||
// statically 512x512, so something has to give, and losing 25% of a 4:3
|
||||
// photo (44% of 16:9, or the subject's head in a portrait) is worse than
|
||||
// distorting it. Nothing outside the frame is discarded this way.
|
||||
// NOTE: the aspect ratio is NOT transmitted, so the receiver cannot undo
|
||||
// the stretch — see the note in image_chunk_transport.dart on the
|
||||
// metadata byte.
|
||||
final src = ui.Rect.fromLTWH(
|
||||
0,
|
||||
0,
|
||||
source.width.toDouble(),
|
||||
source.height.toDouble(),
|
||||
);
|
||||
// distorting it. The source shape travels in the metadata byte's aspect
|
||||
// nibble, so the receiver un-stretches it. Re-roll variants trim at most
|
||||
// ~2% at an edge, so they keep the same shape and aspect code.
|
||||
final r = rerollSourceRect(source.width, source.height, variant);
|
||||
final src = ui.Rect.fromLTWH(r.left, r.top, r.width, r.height);
|
||||
final dstSize = kImageCodecSquareSize.toDouble();
|
||||
final recorder = ui.PictureRecorder();
|
||||
ui.Canvas(recorder).drawImageRect(
|
||||
|
||||
Reference in new issue
Block a user