aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2019-01-17 01:04:15 +0000
committerHarry Jeffery <harry@exec64.co.uk>2019-01-29 22:25:04 +0000
commit68435c2aa880d15575e4eccbe7670439c23f97d0 (patch)
tree641100586a0a7afa8b0dff58ab7d76fbc12a26b1
parent4cf06693f5b8c7910c354ba5715ed4446bda799c (diff)
downloadimv-68435c2aa880d15575e4eccbe7670439c23f97d0.tar.gz
Define sources & backends
-rw-r--r--src/backend.h30
-rw-r--r--src/source.h49
2 files changed, 79 insertions, 0 deletions
diff --git a/src/backend.h b/src/backend.h
new file mode 100644
index 0000000..0da2244
--- /dev/null
+++ b/src/backend.h
@@ -0,0 +1,30 @@
+#ifndef IMV_BACKEND_H
+#define IMV_BACKEND_H
+
+struct imv_source;
+
+enum backend_result {
+ BACKEND_SUCCESS = 0, /* successful load */
+ BACKEND_BAD_PATH = 1, /* no such file, bad permissions, etc. */
+ BACKEND_UNSUPPORTED = 2, /* unsupported file format */
+};
+
+/* A backend is responsible for taking a path, or a raw data pointer, and
+ * converting that into a source that imv can handle. Each backend
+ * may be powered by a different image library and support different
+ * image formats.
+ */
+struct imv_backend {
+ /* Name of the backend, for debug and user informational purposes */
+ const char *name;
+
+ /* Input: path to open
+ * Output: initialises the imv_source instance passed in
+ */
+ enum backend_result (*open_path)(const char *path, struct imv_source **src);
+
+ /* Clean up this backend */
+ void (*free)(struct imv_backend *backend);
+};
+
+#endif
diff --git a/src/source.h b/src/source.h
new file mode 100644
index 0000000..6f051e3
--- /dev/null
+++ b/src/source.h
@@ -0,0 +1,49 @@
+#ifndef IMV_SOURCE_H
+#define IMV_SOURCE_H
+
+#include <stdbool.h>
+#include "bitmap.h"
+
+/* Generic source of one or more bitmaps. Essentially a single image file */
+struct imv_source {
+ /* usually the path of the image this is the source of */
+ char *name;
+
+ /* source's image dimensions */
+ int width;
+ int height;
+
+ /* Usually 1, more if animated */
+ int num_frames;
+
+ /* Frames are returned using SDL events. These two fields must be
+ * populated by callers before calling any frame loading functionality
+ * on the source.
+ */
+ unsigned int image_event_id;
+ unsigned int error_event_id;
+
+ /* Trigger loading of the first frame. */
+ void (*load_first_frame)(struct imv_source *src);
+
+ /* Trigger loading of next frame. */
+ void (*load_next_frame)(struct imv_source *src);
+
+ /* Notify source of time passing, automatically triggers loading of
+ * the next frame when due. */
+ void (*time_passed)(struct imv_source *src, double dt);
+
+ /* Asks the source how long we can sleep for before the next frame is due */
+ double (*time_left)(struct imv_source *src);
+
+ /* 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);
+
+ /* Implementation private data */
+ void *private;
+};
+
+
+#endif