| 322 | } |
| 323 | |
| 324 | bool cSurface::LoadPng(const std::string& pFile) { |
| 325 | int32 width, height, bytesPerPixel; |
| 326 | void* data = stbi_load(pFile.c_str(), &width, &height, &bytesPerPixel, 0); |
| 327 | |
| 328 | // Calculate pitch |
| 329 | int pitch; |
| 330 | pitch = width * bytesPerPixel; |
| 331 | pitch = (pitch + 3) & ~3; |
| 332 | |
| 333 | // Setup relevance bitmask |
| 334 | uint32 Rmask, Gmask, Bmask, Amask; |
| 335 | #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
| 336 | Rmask = 0x000000FF; |
| 337 | Gmask = 0x0000FF00; |
| 338 | Bmask = 0x00FF0000; |
| 339 | Amask = (bytesPerPixel == 4) ? 0xFF000000 : 0; |
| 340 | #else |
| 341 | int s = (bytesPerPixel == 4) ? 0 : 8; |
| 342 | Rmask = 0xFF000000 >> s; |
| 343 | Gmask = 0x00FF0000 >> s; |
| 344 | Bmask = 0x0000FF00 >> s; |
| 345 | Amask = 0x000000FF >> s; |
| 346 | #endif |
| 347 | auto Surface = SDL_CreateRGBSurfaceFrom(data, width, height, bytesPerPixel*8, pitch, Rmask, Gmask, Bmask, Amask); |
| 348 | if (!Surface) |
| 349 | return false; |
| 350 | SDL_FreeSurface(mSDLSurface); |
| 351 | mSDLSurface = Surface; |
| 352 | |
| 353 | mIsLoadedImage = true; |
| 354 | mWidth = mSDLSurface->w; |
| 355 | mHeight = mSDLSurface->h; |
| 356 | |
| 357 | if (g_Window->GetRenderer()) { |
| 358 | SDL_DestroyTexture(mTexture); |
| 359 | mTexture = SDL_CreateTextureFromSurface((SDL_Renderer*)g_Window->GetRenderer(), mSDLSurface ); |
| 360 | SDL_SetTextureBlendMode(mTexture, SDL_BLENDMODE_ADD); |
| 361 | SDL_SetTextureAlphaMod(mTexture, 0xa0); |
| 362 | SDL_SetTextureColorMod(mTexture, 0xFF, 0xFF, 0xFF); |
| 363 | } |
| 364 | |
| 365 | return mSDLSurface != nullptr; |
| 366 | } |
| 367 | |
| 368 | void cSurface::Save() { |
| 369 |
no test coverage detected