/* Images as Pi takes them (image.c): which bytes are a supported image,
* the inline size limit, and base64. No database and no I/O here, so tools
* and the provider adapters share one set of rules. */
#ifndef PIC_IMAGE_H
#define PIC_IMAGE_H
#include <stddef.h>
/* Pi's DEFAULT_MAX_BYTES: 4.5MB of base64 payload, under Anthropic's 5MB. */
#define PIC_IMAGE_MAX_BASE64 ((size_t)(4.5 * 1024 * 1024))
/* Pi's notes when an image cannot go inline (image-process.ts). pic does not
* resize or convert, so an image over the limit, or a BMP, gets these. */
#define PIC_IMAGE_TOO_BIG "[Image omitted: could not be resized below the inline image size limit.]"
#define PIC_IMAGE_UNCONVERTIBLE "[Image omitted: could not be converted to a supported inline image format.]"
/* Pi's placeholders for a model without image input (transform-messages.ts). */
#define PIC_IMAGE_USER_PLACEHOLDER "(image omitted: model does not support images)"
#define PIC_IMAGE_TOOL_PLACEHOLDER "(tool image omitted: model does not support images)"
/* An image to attach: its bytes and MIME type. */
typedef struct {
const char *mime;
const unsigned char *data;
size_t len;
} pic_image;
/* Pi's _normalizePromptImages for a message: keeps the images of
* IMAGES[0..*N) that can go inline (moved to the front, *N their count, each
* mime set to its inline type) and returns TEXT followed, after a blank
* line, by a note for each one that cannot (malloc'd; NULL: no memory). */
char *pic_image_prepare(const char *text, pic_image *images, size_t *n);
/* Pi's detectSupportedImageMimeType: image/jpeg, png (not animated), gif,
* webp or bmp from the leading bytes, else NULL. */
const char *pic_image_sniff(const unsigned char *b, size_t n);
/* Pi's normalizeSupportedImageMimeType: the inline type a declared MIME type
* names (image/png, image/jpeg, image/gif, image/webp), else NULL. */
const char *pic_image_inline_mime(const char *declared);
/* Whether N bytes of type MIME can go inline as they are: NULL when they
* can, else the note Pi gives when its conversion or resize fails. */
const char *pic_image_refusal(const char *mime, size_t n);
/* Standard base64 of N bytes into out (4 * ((n + 2) / 3) + 1 bytes, NUL
* terminated); the length written. */
size_t pic_base64_encode(const unsigned char *in, size_t n, char *out);
/* Decodes standard or URL-safe base64 (padding optional, whitespace
* skipped) into out (at least 3 * (n / 4) + 3 bytes). The length, or
* (size_t)-1 when the text is not base64. */
size_t pic_base64_decode(const char *in, size_t n, unsigned char *out);
#endif