|
PebbleOS
|
Fetches images from the phone. More...
Data Structures | |
| struct | ImagingRequestHeader |
| Image request header, watch to phone. More... | |
| struct | ImagingResponseHeader |
| Image response chunk header, phone to watch. More... | |
Macros | |
| #define | IMAGING_RESPONSE_FLAG_TYPE_MASK (0xf0) |
| Mask of the ImagingImageType a response answers, in bits 4-7 of its flags. | |
| #define | IMAGING_RESPONSE_FLAG_TYPE_SHIFT (4) |
| Shift of the image type in a response's flags. | |
Typedefs | |
| typedef void(* | ImagingReceivedHandler) (uint8_t token, struct GBitmap *bitmap) |
| Called on KernelMain when a requested image has been received. | |
| typedef void(* | ImagingWillReceiveHandler) (uint8_t token) |
| Called before the buffers for an incoming image are allocated. | |
| typedef void(* | ImagingTransferFailedHandler) (uint8_t token) |
| Called when an image transfer is dropped before delivery. | |
Enumerations | |
| enum | ImagingCmdID { ImagingCmdIDRequest = 0x01 , ImagingCmdIDResponse = 0x02 , ImagingCmdIDInvalid = 0xff } |
| Image-fetch endpoint (0x0035) command identifiers. More... | |
| enum | ImagingImageType { ImagingImageTypeAlbumArt = 0x00 , ImagingImageTypeNotification = 0x01 , ImagingImageTypeCount } |
| What an image is for; determines the type-specific parameters of the request. More... | |
| enum | ImagingFormat { ImagingFormat1Bit = 0x00 , ImagingFormat8BitColor = 0x01 , ImagingFormat4BitPalette = 0x02 } |
| Pixel encoding requested by the watch, and used by the response. More... | |
| enum | ImagingResponseFlags { ImagingResponseFlagFirst = (1 << 0) , ImagingResponseFlagLast = (1 << 1) , ImagingResponseFlagNoImage = (1 << 2) , ImagingResponseFlagUnsupported = (1 << 3) } |
| Flags of an image response chunk. More... | |
Functions | |
| void | imaging_register_handler (ImagingImageType image_type, ImagingReceivedHandler handler) |
| Register the handler for an image type. | |
| void | imaging_register_transfer_handlers (ImagingImageType image_type, ImagingWillReceiveHandler will_receive, ImagingTransferFailedHandler transfer_failed) |
| Register the transfer lifecycle handlers for an image type. | |
| bool | imaging_is_type_supported (ImagingImageType image_type) |
| Check whether the connected phone can serve an image type. | |
| bool | imaging_request_album_art (uint8_t token, ImagingFormat format, uint16_t width, uint16_t height, const char *title, const char *artist) |
| Request the album art of a track. | |
| bool | imaging_request_notification_image (uint8_t token, ImagingFormat format, uint16_t width, uint16_t height, const Uuid *item_id) |
| Request the image the phone holds for a timeline item. | |
| void | imaging_protocol_msg_callback (CommSession *session, const uint8_t *msg, size_t length) |
| Handle a message received on the image-fetch endpoint. | |
| void | imaging_handle_comm_session_event (const PebbleCommSessionEvent *event) |
| Handle a comm session event. | |
Fetches images from the phone.
Consumers such as album art ask the phone for an image of a given size and pixel format; the phone streams it back in chunks over the image-fetch endpoint (0x0035) and the reassembled bitmap is passed to the handler registered for the image type. Requests are only sent when the phone advertises image-fetch support.
| struct ImagingRequestHeader |
Image request header, watch to phone.
Type-specific parameters follow:
uint8_t title length, title, uint8_t artist length and artist. The phone returns art for that track, so the request cannot race a track change, or no image.| Data Fields | ||
|---|---|---|
| uint8_t | cmd | ImagingCmdIDRequest. |
| uint8_t | format | Requested ImagingFormat. |
| uint16_t | height | Desired height in pixels. |
| uint8_t | image_type | ImagingImageType. |
| uint8_t | token | Opaque value echoed in the response to match it to the request. |
| uint16_t | width | Desired width in pixels. |
| struct ImagingResponseHeader |
Image response chunk header, phone to watch.
chunk_len pixel bytes follow. On the first chunk they are preceded by an image header: uint16_t width, uint16_t height, uint8_t ImagingFormat, uint8_t palette count (1-16 for palette formats, else 0) and that many GColor8 palette entries.
| Data Fields | ||
|---|---|---|
| uint16_t | chunk_len | Number of pixel bytes in this chunk. |
| uint8_t | cmd | ImagingCmdIDResponse. |
| uint8_t | flags | ImagingResponseFlags and the image type. |
| uint32_t | offset | Byte offset of this chunk's pixels in the pixel stream. |
| uint8_t | token | Token of the request. |
| #define IMAGING_RESPONSE_FLAG_TYPE_MASK (0xf0) |
Mask of the ImagingImageType a response answers, in bits 4-7 of its flags.
Several consumers can have a request outstanding at once, and the token alone does not tell which one a response is for.
| #define IMAGING_RESPONSE_FLAG_TYPE_SHIFT (4) |
Shift of the image type in a response's flags.
| typedef void(* ImagingReceivedHandler) (uint8_t token, struct GBitmap *bitmap) |
Called on KernelMain when a requested image has been received.
| token | Token of the request. |
| bitmap | Received image, or NULL if the phone has none (ImagingResponseFlagNoImage). Ownership of a non-NULL bitmap and its pixel and palette buffers passes to the handler. |
| typedef void(* ImagingTransferFailedHandler) (uint8_t token) |
Called when an image transfer is dropped before delivery.
| token | Token of the request. |
| typedef void(* ImagingWillReceiveHandler) (uint8_t token) |
Called before the buffers for an incoming image are allocated.
| token | Token of the request. |
| enum ImagingCmdID |
| enum ImagingFormat |
| enum ImagingImageType |
| enum ImagingResponseFlags |
Flags of an image response chunk.
| void imaging_handle_comm_session_event | ( | const PebbleCommSessionEvent * | event | ) |
Handle a comm session event.
Called from the shell event loop. When the system session closes, frees a partially received image and forgets the image types the phone reported as unsupported.
| event | Comm session event. |
| bool imaging_is_type_supported | ( | ImagingImageType | image_type | ) |
Check whether the connected phone can serve an image type.
| image_type | Image type. |
| void imaging_protocol_msg_callback | ( | CommSession * | session, |
| const uint8_t * | msg, | ||
| size_t | length | ||
| ) |
Handle a message received on the image-fetch endpoint.
Registered in the protocol endpoints table.
| session | Session the message was received on. |
| msg | Message. |
| length | Length of msg in bytes. |
| void imaging_register_handler | ( | ImagingImageType | image_type, |
| ImagingReceivedHandler | handler | ||
| ) |
Register the handler for an image type.
One handler per type; replaces any previous one. Images without a handler are freed.
| image_type | Image type. |
| handler | Handler, or NULL. |
| void imaging_register_transfer_handlers | ( | ImagingImageType | image_type, |
| ImagingWillReceiveHandler | will_receive, | ||
| ImagingTransferFailedHandler | transfer_failed | ||
| ) |
Register the transfer lifecycle handlers for an image type.
| image_type | Image type. |
| will_receive | Called before buffers are allocated, or NULL. |
| transfer_failed | Called when a transfer is dropped, or NULL. |
| bool imaging_request_album_art | ( | uint8_t | token, |
| ImagingFormat | format, | ||
| uint16_t | width, | ||
| uint16_t | height, | ||
| const char * | title, | ||
| const char * | artist | ||
| ) |
Request the album art of a track.
The handler of ImagingImageTypeAlbumArt is called when the transfer completes.
| token | Opaque value passed back to the handlers. |
| format | Pixel format. |
| width | Width in pixels. |
| height | Height in pixels. |
| title | Track title, truncated to 255 bytes, or NULL. |
| artist | Track artist, truncated to 255 bytes, or NULL. |
| bool imaging_request_notification_image | ( | uint8_t | token, |
| ImagingFormat | format, | ||
| uint16_t | width, | ||
| uint16_t | height, | ||
| const Uuid * | item_id | ||
| ) |
Request the image the phone holds for a timeline item.
The handler of ImagingImageTypeNotification is called when the transfer completes.
| token | Opaque value passed back to the handlers. |
| format | Pixel format. |
| width | Width in pixels. |
| height | Height in pixels. |
| item_id | UUID of the timeline item. |
item_id is NULL or the type is unsupported.