diff options
Diffstat (limited to 'src/source.h')
-rw-r--r-- | src/source.h | 79 |
1 files changed, 27 insertions, 52 deletions
diff --git a/src/source.h b/src/source.h index d55e560..f843d85 100644 --- a/src/source.h +++ b/src/source.h @@ -1,72 +1,47 @@ #ifndef IMV_SOURCE_H #define IMV_SOURCE_H -#include <pthread.h> -#include <stdbool.h> -#include "image.h" - -struct imv_source_message { - /* Pointer to sender of message */ - struct imv_source *source; - - /* User-supplied pointer */ - void *user_data; - - /* Receiver is responsible for destroying image */ - struct imv_image *image; - - /* If an animated gif, the frame's duration in milliseconds, else 0 */ - int frametime; - - /* Error message if image was NULL */ - const char *error; -}; - /* While imv_image represents a single frame of an image, be it a bitmap or * vector image, imv_source represents an open handle to an image file, which * can emit one or more imv_images. */ -struct imv_source { - /* usually the path of the image this is the source of */ - char *name; +struct imv_source; - /* source's image dimensions */ - int width; - int height; +struct imv_source_message; +struct imv_image; - /* Usually 1, more if animated */ - int num_frames; +/* Clean up a source. Blocks if the source is active in the background. Async + * version does not block, performing cleanup in another thread */ +void imv_source_async_free(struct imv_source *src); +void imv_source_free(struct imv_source *src); - /* Next frame to be loaded, 0-indexed */ - int next_frame; +/* Load the first frame. Silently aborts if source is already loading. Async + * version performs loading in background. */ +void imv_source_async_load_first_frame(struct imv_source *src); +void imv_source_load_first_frame(struct imv_source *src); - /* Attempted to be locked by load_first_frame or load_next_frame. - * If the mutex can't be locked, the call is aborted. - * Used to prevent the source from having multiple worker threads at once. - * Released by the source before calling the message callback with a result. - */ - pthread_mutex_t busy; +/* Load the next frame. Silently aborts if source is already loading. Async + * version performs loading in background. */ +void imv_source_async_load_next_frame(struct imv_source *src); +void imv_source_load_next_frame(struct imv_source *src); - /* Trigger loading of the first frame. Returns 0 on success. */ - void *(*load_first_frame)(struct imv_source *src); +typedef void (*imv_source_callback)(struct imv_source_message *message); - /* Trigger loading of next frame. Returns 0 on success. */ - void *(*load_next_frame)(struct imv_source *src); +/* Sets the callback function to be called when frame loading completes */ +void imv_source_set_callback(struct imv_source *src, imv_source_callback callback, void *data); - /* Safely free contents of this source. After this returns - * it is safe to dealocate/overwrite the imv_source instance. - */ - void (*free)(struct imv_source *src); - - /* User-specified callback for returning messages */ - void (*callback)(struct imv_source_message *message); +struct imv_source_message { + /* Pointer to sender of message */ + struct imv_source *source; - /* User-specified pointer, included in returned messages */ + /* User-supplied pointer */ void *user_data; - /* Implementation private data */ - void *private; -}; + /* Receiver is responsible for destroying image */ + struct imv_image *image; + /* If an animated gif, the frame's duration in milliseconds, else 0 */ + int frametime; +}; #endif |