Show images from a conversation
A screen can receive thumbnails of images the agent places in a conversation. Start with a single image encoded as RGB565 rows. Add gallery navigation and JPEG only if the device has the storage and decoder for them. A general image display works independently of downloadable faces.
On this page
Choose a profile
| Your receiver | Image feature bits | Required behavior |
|---|---|---|
| Single image | Bit 5, mask 0x20 | Support row-based RLE, cumulative acknowledgments and explicit presentation. |
| Browsable gallery | Bits 5–6, mask 0x60 | Also understand message token, image index and count. Request or pin an index. |
| Browsable gallery with JPEG | Bits 5–7, mask 0xE0 | Also receive baseline JPEG chunks, verify compressed bytes and decode within bounds. Accept RLE fallback. |
Expose the writable Media characteristic 1004 for the image bytes. IMAGE_BEGIN, END and PRESENT arrive on Control. Send every ACK and gallery request on Status. Working from complete logical messages keeps transfers independent of the negotiated ATT packet size. Frame a message.
Receive two red pixels
This synthetic single-image exchange fits a 2 × 1 thumbnail into one row. Assume the current nonzero context is 42 and the message token is 23. Without gallery support, the same token identifies the transfer and presentation. All fields use little-endian encoding. The ID and sequence below are decimal header fields.
| Message | ID / sequence | Payload (hex) | Expected effect |
|---|---|---|---|
| App → device IMAGE_BEGIN (17), flags 0 | 42 / 23 | 02 00 01 00 5a 87 f5 29 | Reserve staging for width 2, height 1, expected CRC32 0x29F5875A. Keep the current image displayed. |
| Device → app IMAGE_ACK (20), flags 0 | 23 / 0 | Empty | Ready for row zero. BEGIN acknowledges setup only. |
| App → device IMAGE_ROW (18), flags 0 | 23 / 0 | 81 00 f8 | Expand to two copies of RGB565 red (0xF800). Feed the uncompressed bytes 00 f8 00 f8 to CRC32. |
| Device → app IMAGE_ACK (20), flags 0 | 23 / 1 | Empty | All rows received. The image remains staged. |
| App → device IMAGE_END (19), flags 0 | 42 / 23 | Empty | Verify the row count, dimensions and checksum. Commit only valid pixels. |
| Device → app IMAGE_ACK (20), flags 1 | 23 / 1 | Empty | Commit receipt. The user can now view this image. A duplicate END for the same completed transfer can repeat this ACK. |
| App → device IMAGE_PRESENT (21), flags 0 | 42 / 23 | a0 0f | Request that the committed image appear for 4,000 ms. Match the current message and respect a user interaction already in progress. |
Rows are independent. Each command’s low seven bits encode the pixel count minus one. A set high bit repeats the following u16 color. Otherwise copy the given number of literal u16 colors. Check input length before reading, cap expansion to the declared width and require exactly that many pixels when the row ends. RGB565 uses red bits 15–11, green bits 10–5 and blue bits 4–0.
Reproduce the integrity check locally with python3 -c "import zlib; print(hex(zlib.crc32(bytes.fromhex('00 f8 00 f8'))))". The expected result is 0x29f5875a. Change the RLE color to 01 f8 but retain the original BEGIN. On END the receiver should issue IMAGE_ACK with flags 2 and preserve the previously committed image. The packet fixtures include the intact IMAGE_ROW with its wire header.
Receive a JPEG
Check width 1–192, height 1–152 and encoded length 1–16,384 bytes before reserving memory. A JPEG BEGIN has flag 1, with a 20-byte payload containing width, height, CRC32, gallery message token, index, count and compressed byte length. CRC covers the exact JPEG file bytes. Bound both memory use and decoded dimensions, and require successful baseline JPEG decoding before issuing a committed ACK.
For example, take gallery 31, index 0 of 2, a fresh transfer token 70 and 900 JPEG bytes. Once BEGIN is accepted, ACK ID 70 at offset 0. If media capacity allows 300-byte chunks, expect ROW seq 0, 300 and 600 with flag 1. ACK the contiguous byte offset 300, 600, then 900. END has ID 42 and seq 70. After validation, the successful ACK has ID 70, seq 900 and flag 1. To show it, PRESENT uses ID 42 and seq 31, the gallery message token. The transfer token is scoped to this attempt.
The sender can have up to four RLE rows or twelve JPEG chunks in flight. A JPEG chunk is ≤512 bytes and sized for the media characteristic. An ACK represents the next contiguous offset or row. If a chunk arrives twice, report the same progress and keep the original bytes. If it arrives ahead of a gap, report your current contiguous position. Allow speaker traffic between complete image messages. The reference sender retries after two seconds without progress, with at most three retries before reporting failure.
Navigate a gallery
Only advertise gallery support with the base image profile. A gallery BEGIN adds an opaque message token, a zero-based index and a positive count. Reject an out-of-range index. Keep the conversation and gallery token with all stored images.
| User or host event | Protocol action |
|---|---|
| User opens index 1 of gallery 31 | Send IMAGE_REQUEST (23), ID 42, seq 31, flags 0, payload 01 00. Accept the selected image under a new transfer token. |
| User selects an image already decoded locally | Use the local pixels and send the same request with flags 2 to pin the selection. Avoid another download. |
| A newer reply arrives while viewing an older gallery | Keep the user’s pinned gallery and index. Receiving bytes or an unread indicator does not itself request a popup. |
| Host prefetches a sibling JPEG | BEGIN has flags 5 (JPEG + cache-only). Accept a sibling of the selected gallery when capacity permits. Verify and ACK it without changing the displayed selection. |
| User dismisses the gallery | Send IMAGE_REQUEST, ID 42, seq 31, flags 1 and an empty payload to release the selection. |
| An attachment cannot be obtained | The app can send IMAGE_BEGIN with flags 2, ID 42, seq 31 and an empty payload. Offer a fresh request if the user retries. |
On disconnect, clear partial staging and ACK state. Across a conversation change, invalidate gallery tokens and pending presentation requests. Bound any compressed cache and use the host for evicted entries. A cache fill, a committed image, and an explicit request to bring it onscreen have separate meanings. Image and gallery wire reference.
Images and galleries reference
Packet fields and receiver rules
| Kind | Direction | ID / seq | Payload and flags |
|---|---|---|---|
| 17 IMAGE_BEGIN | App → device | context / transfer token | u16 width, u16 height, u32 CRC. Gallery adds u32 message token, u16 index, u16 count. JPEG adds u32 compressed byte length. Flag 1 JPEG, flag 4 cache-only JPEG. Flag 2 alone carries an empty payload with gallery token as seq to report unavailability. |
| 18 IMAGE_ROW | App → device on 1004 | transfer token / row or byte offset | RLE row with flags 0, or compressed file bytes with flag 1. |
| 19 IMAGE_END | App → device | context / transfer token | Empty. Flag 0 RLE or 1 JPEG. Verify the complete object before committing. |
| 20 IMAGE_ACK | Device → app | transfer token / next expected row or byte offset | Empty. Flags 0 cumulative progress, 1 verified commit, 2 failed. |
| 21 IMAGE_PRESENT | App → device | context / message token | u16 duration in milliseconds, 1,000–15,000. Explicit request to show the matching committed image. |
| 23 IMAGE_REQUEST | Device → app | context / gallery message token | Flags 0 request index (u16), 2 pin an already rendered index (u16), 1 release (empty). |
Fit within 192 × 152, validate nonzero dimensions and gallery count, and require index < count. Each RLE command covers (low seven bits + 1) RGB565 pixels. If bit 7 is set, repeat the following little-endian color, otherwise copy that many little-endian colors. A row must expand exactly to width. CRC-32/IEEE covers all uncompressed row-major RGB565 bytes. For JPEG validate a baseline file of ≤16 KiB, integrity over the compressed file bytes, and agreement with declared dimensions. The absence of gallery capability uses the 8-byte BEGIN form and the transfer token as message token.
ACK 0 offset at BEGIN. The sender allows four RLE rows or twelve JPEG chunks in flight (JPEG chunks ≤512 bytes). Accept duplicates idempotently, ACK only contiguous complete data, and only commit after decoding and CRC validation. The reference sender retries after two seconds without progress up to three times. Keep the last displayed image on corruption or interruption. A cache-only BEGIN must never replace the user’s displayed image. The host can preload history on reconnect. Only explicit IMAGE_PRESENT requests a popup. Gallery navigation is scoped to its conversation and reply. A face asset and a chat attachment use different contracts.