-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathimage.cpp
More file actions
38 lines (30 loc) · 702 Bytes
/
image.cpp
File metadata and controls
38 lines (30 loc) · 702 Bytes
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
#include "headers/image.h"
Image::Image(const string& s, bool transparent)
{
SDL_Surface* tmpImg = IMG_Load(s.c_str());
if (!tmpImg)
throw ImageNotLoaded(s);
// Optimize image for depth of screen
img = SDL_DisplayFormat(tmpImg);
SDL_FreeSurface(tmpImg);
if (!img)
throw ImageNotLoaded(s);
// Enable transparency
if (transparent)
{
Uint32 colorkey = SDL_MapRGB(img->format, 255, 255, 255);
SDL_SetColorKey(img, SDL_SRCCOLORKEY, colorkey);
}
}
SDL_Surface* Image::surface()
{
return img;
}
Image::~Image()
{
SDL_FreeSurface(img);
}
ostream& operator<<(ostream& os, const ImageNotLoaded& o)
{
return os << o.s;
}