summaryrefslogtreecommitdiff
path: root/src/image.hh
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2021-11-17 22:34:57 +0100
committerJoel Klinghed <the_jk@spawned.biz>2021-11-17 22:34:57 +0100
commit6232d13f5321b87ddf12a1aa36b4545da45f173d (patch)
tree23f3316470a14136debd9d02f9e920ca2b06f4cc /src/image.hh
Travel3: Simple image and video display site
Reads the images and videos from filesystem and builds a site in memroy.
Diffstat (limited to 'src/image.hh')
-rw-r--r--src/image.hh67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/image.hh b/src/image.hh
new file mode 100644
index 0000000..b9644b7
--- /dev/null
+++ b/src/image.hh
@@ -0,0 +1,67 @@
+#ifndef IMAGE_HH
+#define IMAGE_HH
+
+#include "date.hh"
+#include "location.hh"
+#include "rotation.hh"
+
+#include <filesystem>
+#include <memory>
+
+class RoBuffer;
+
+class Image {
+public:
+ virtual ~Image() = default;
+
+ class Thumbnail {
+ public:
+ virtual ~Thumbnail() = default;
+
+ virtual std::string_view mime_type() const = 0;
+ virtual uint64_t size() const = 0;
+
+ protected:
+ Thumbnail() = default;
+ };
+
+ static std::unique_ptr<Image> load(std::filesystem::path const& path);
+
+ virtual uint64_t width() const = 0;
+ virtual uint64_t height() const = 0;
+ virtual Location location() const = 0;
+ virtual Rotation rotation() const = 0;
+ virtual Date date() const = 0;
+
+ virtual Thumbnail* thumbnail() const = 0;
+
+protected:
+ Image() = default;
+ Image(Image const&) = delete;
+ Image& operator=(Image const&) = delete;
+};
+
+class ThumbnailReader {
+public:
+ virtual ~ThumbnailReader() = default;
+
+ static std::unique_ptr<ThumbnailReader> create();
+
+ enum class Return {
+ NEED_MORE, // Call drain() again if you want data.
+ DONE, // Data is available, no need to call drain() again.
+ ERR, // Error, no data will ever be available.
+ };
+
+ virtual Return drain(RoBuffer* in, size_t* bytes = nullptr) = 0;
+
+ // Returns empty until drain() returns Return::DONE.
+ virtual std::string_view data() const = 0;
+
+protected:
+ ThumbnailReader() = default;
+ ThumbnailReader(ThumbnailReader const&) = delete;
+ ThumbnailReader& operator=(ThumbnailReader const&) = delete;
+};
+
+#endif // IMAGE_HH