summaryrefslogtreecommitdiff
path: root/src/image.hh
blob: b9644b7eef1ce8c6b6c6b10051c3f1be9b42ff5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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