]> git.tdb.fi Git - libs/gui.git/blob - source/graphics/image.cpp
a0e6e380ad24d54b20c5144c6001208147f9dbc5
[libs/gui.git] / source / graphics / image.cpp
1 #include <msp/core/refptr.h>
2 #include <msp/fs/utils.h>
3 #include <msp/io/file.h>
4 #include <msp/io/memory.h>
5 #include "image.h"
6 #include "imageloader.h"
7
8 using namespace std;
9
10 namespace Msp {
11 namespace Graphics {
12
13 Image::Data::Data():
14         fmt(RGB),
15         width(0),
16         height(0),
17         data(0)
18 { }
19
20 Image::Data::Data(const Data &other):
21         fmt(other.fmt),
22         width(other.width),
23         height(other.height),
24         stride(other.stride),
25         data(other.data ? new char[stride*height] : 0)
26 {
27         if(data)
28                 copy(other.data, other.data+stride*height, data);
29 }
30
31 Image::Data &Image::Data::operator=(const Data &other)
32 {
33         delete[] data;
34         data = 0;
35
36         fmt = other.fmt;
37         width = other.width;
38         height = other.height;
39         stride = other.stride;
40
41         if(other.data)
42         {
43                 data = new char[stride*height];
44                 copy(other.data, other.data+stride*height, data);
45         }
46
47         return *this;
48 }
49
50 Image::Data::~Data()
51 {
52         delete[] data;
53 }
54
55
56 void Image::load_file(const string &fn)
57 {
58         RefPtr<ImageLoader> loader = ImageLoader::open_file(fn);
59         load(*loader);
60 }
61
62 void Image::load_io(IO::Seekable &io)
63 {
64         RefPtr<ImageLoader> loader = ImageLoader::open_io(io);
65         load(*loader);
66 }
67
68 void Image::load(ImageLoader &loader)
69 {
70         loader.load(data);
71 }
72
73 } // namespace Graphics
74 } // namespace Msp