srgb textures, cubemap support
[demo] / src / image.cc
1 #include <string.h>
2
3 #include "imago2.h"
4 #include "image.h"
5
6 Image::Image()
7 {
8         w = h = 0;
9         pixels = 0;
10 }
11
12 Image::~Image()
13 {
14         delete [] pixels;
15 }
16
17 Image::Image(const Image &image)
18 {
19         w = image.w;
20         h = image.h;
21
22         pixels = new unsigned char[w * h * 4];
23         memcpy(pixels, image.pixels, w * h * 4);
24 }
25
26 Image &Image::operator =(const Image &image)
27 {
28         if(&image == this)
29                 return *this;
30
31         delete [] pixels;
32
33         w = image.w;
34         h = image.h;
35
36         pixels = new unsigned char[w * h * 4];
37         memcpy(pixels, image.pixels, w * h * 4);
38
39         return *this;
40 }
41
42 Image::Image(Image &&image)
43 {
44         w = image.w;
45         h = image.h;
46
47         pixels = image.pixels;
48         image.pixels = 0;
49 }
50
51 Image &Image::operator =(Image &&image)
52 {
53         if(&image == this)
54                 return *this;
55
56         delete [] pixels;
57
58         w = image.w;
59         h = image.h;
60
61         pixels = image.pixels;
62         image.pixels = 0;
63
64         return *this;
65 }
66
67 bool Image::load(const char *fname)
68 {
69         unsigned char *imago_pixels;
70         if(!(imago_pixels = (unsigned char *)img_load_pixels(fname, &w, &h))) {
71                 fprintf(stderr, "Failed to load pixels from file: %s.\n", fname);
72                 return false;
73         }
74
75         delete [] pixels;
76         pixels = new unsigned char[w * h * 4];
77         memcpy(pixels, imago_pixels, w * h * 4);
78
79         img_free_pixels(imago_pixels);
80
81         return true;
82 }