MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / get

Function get

TheForceEngine/TFE_Asset/imageAsset.cpp:89–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87 }
88
89 SDL_Surface* get(const char* imagePath)
90 {
91 ImageMap::iterator iImage = s_images.find(imagePath);
92 if (iImage != s_images.end())
93 {
94 return iImage->second;
95 }
96
97 SDL_Surface* sdlimg = IMG_Load(imagePath);
98 if (!sdlimg)
99 {
100 TFE_System::logWrite(LOG_ERROR, "Image", "Cannot load image from '%s', error: '%s'", imagePath, SDL_GetError());
101 return nullptr;
102 }
103
104 if (sdlimg->format->BitsPerPixel != 32)
105 {
106 sdlimg = convertToRGBA(sdlimg);
107 }
108 if (!sdlimg)
109 {
110 TFE_System::logWrite(LOG_ERROR, "Image", "Cannot convert image '%s' to 32-bits, error: '%s'", imagePath, SDL_GetError());
111 return nullptr;
112 }
113
114 s_images[imagePath] = sdlimg;
115 return sdlimg;
116 }
117
118 void free(SDL_Surface* image)
119 {

Callers

nothing calls this directly

Calls 3

logWriteFunction · 0.85
convertToRGBAFunction · 0.70
endMethod · 0.45

Tested by

no test coverage detected