]> git.tdb.fi Git - libs/gui.git/blob - source/graphics/image.h
Make it possible to load an image into an externally allocated buffer
[libs/gui.git] / source / graphics / image.h
1 #ifndef MSP_GRAPHICS_IMAGE_H_
2 #define MSP_GRAPHICS_IMAGE_H_
3
4 #include <stdexcept>
5 #include <string>
6 #include <msp/io/seekable.h>
7 #include "pixelformat.h"
8
9 namespace Msp {
10 namespace Graphics {
11
12 class ImageLoader;
13
14 class Image
15 {
16 public:
17         struct Data
18         {
19                 PixelFormat fmt;
20                 unsigned width;
21                 unsigned height;
22                 unsigned stride;
23                 char *owned_pixels;
24                 char *pixels;
25
26                 Data();
27                 Data(const Data &);
28                 Data &operator=(const Data &);
29                 ~Data();
30         };
31
32 private:
33         Data data;
34
35 public:
36         void load_file(const std::string &);
37         void load_io(IO::Seekable &);
38         void load(ImageLoader &);
39         void load_into(ImageLoader &, void *);
40         void load_headers(ImageLoader &);
41
42         PixelFormat get_format() const { return data.fmt; }
43         unsigned get_width() const { return data.width; }
44         unsigned get_height() const { return data.height; }
45         unsigned get_stride() const { return data.stride; }
46         DEPRECATED const void *get_data() const { return data.pixels; }
47         const void *get_pixels() const { return data.pixels; }
48 };
49
50 } // namespace Graphics
51 } // namespace Msp
52
53 #endif