-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImage.cpp
52 lines (39 loc) · 953 Bytes
/
Image.cpp
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
#include "Image.h"
#include <iostream>
using namespace std;
namespace GameEng {
Image::Image(){}
Image::Image(std::string path){
img = load_image(path);
}
Image::~Image(){
if(img){
SDL_FreeSurface(img);
}
}
Image::Image(const Image& other) : img(other.getSurface()) {
img->refcount++;
}
const Image& Image::operator=(const Image& other){
if (this != &other){
img = other.getSurface();
img->refcount++;
}
return *this;
}
SDL_Surface* Image::getSurface() const { return img; }
SDL_Surface* Image::load_image( std::string path ){
SDL_Surface* loadImg = NULL;
SDL_Surface* opImg = NULL;
loadImg = IMG_Load( path.c_str() );
if(loadImg != NULL){
opImg = SDL_DisplayFormat(loadImg);
SDL_FreeSurface(loadImg);
if(opImg != NULL){
Uint32 transp = *(Uint32*)opImg->pixels;
SDL_SetColorKey( opImg, SDL_SRCCOLORKEY, transp );
}
}
return opImg;
}
}