#ifndef SWIFT_IMAGE_CODEC_H
#define SWIFT_IMAGE_CODEC_H

#include <swift/io.h>
#include <swift/stdlib.h>

#include <swift/image/image.h>

typedef struct swift_image_codec_t swift_image_codec_t;

typedef swift_image_t *(* swift_read_image_fn_t)(swift_stream_t *stream);
typedef bool (* swift_write_image_fn_t)(swift_stream_t *stream,
	swift_image_t *image);

struct swift_image_codec_t {
	swift_read_image_fn_t read_image;
	swift_write_image_fn_t write_image;
	char *name, *full_name;
	size_t index;
};

SWIFT_IMAGE_API bool swift_init_image_codecs(const char *path);
SWIFT_IMAGE_API void swift_term_image_codecs(void);

SWIFT_IMAGE_API size_t swift_get_image_codec_count(void);
SWIFT_IMAGE_API swift_image_codec_t *swift_get_image_codec(size_t index);
SWIFT_IMAGE_API swift_image_codec_t *swift_search_image_codec(const char *name);
SWIFT_IMAGE_API bool swift_add_image_codec(const char *name,
	const char *full_name, swift_read_image_fn_t read_image,
	swift_write_image_fn_t write_image);
SWIFT_IMAGE_API void swift_remove_image_codec(const char *name);

SWIFT_IMAGE_API swift_image_t *swift_try_read_image(swift_stream_t *stream);
SWIFT_IMAGE_API swift_image_t *swift_try_read_image_from_file(const char *path);

SWIFT_IMAGE_API swift_image_t *swift_read_image(swift_image_codec_t *codec,
	swift_stream_t *stream);
SWIFT_IMAGE_API swift_image_t *swift_read_image_from_file(
	swift_image_codec_t *codec, const char *path);

SWIFT_IMAGE_API bool swift_write_image(swift_image_codec_t *codec,
	swift_stream_t *stream, swift_image_t *image);
SWIFT_IMAGE_API bool swift_write_image_to_file(swift_image_codec_t *codec,
	const char *path, swift_image_t *image);

#endif /* SWIFT_IMAGE_CODEC_H */
