/*
 * Photos: decoding and encoding without a window, for the app and its
 * tile provider alike. Both go through glycin, every decoder and encoder
 * in a sandbox.
 */
#ifndef PHOTOS_ENCODE_H
#define PHOTOS_ENCODE_H

#include <stdbool.h>
#include <cairo.h>
#include <gio/gio.h>

/* The first frame of a picture (a path or a URI), turned as its EXIF
 * says, as a cairo image; NULL with err set. Blocks: a thread's. */
cairo_surface_t *ph_decode(const char *file, GError **err);
/* A copy whose longer side is at most max_side (a new reference to s
 * when it is already that small) */
cairo_surface_t *ph_shrink(cairo_surface_t *s, int max_side);
/* s encoded as mime (JPEG at quality 92); NULL with err set. Blocks. */
GBytes *ph_encode(cairo_surface_t *s, const char *mime, GError **err);
/* Whether glycin can write mime */
bool ph_can_encode(const char *mime);

/* Writes the part (x, y, w, h) of s to path as mime, its longer side at
 * most max_side (0: as it is), by rename, on a thread; the pixels are
 * copied first, so s may go. done runs on the main loop with the error
 * to show, or NULL. */
typedef void (*ph_saved_fn)(const char *error, void *data);
void ph_save(cairo_surface_t *s, int x, int y, int w, int h, int max_side,
	const char *mime, const char *path, ph_saved_fn done, void *data);

#endif
