Skip to content

Commit

Permalink
Added converted check and comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskr97 committed Mar 10, 2019
1 parent b6407a0 commit b9b627d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/RageSurface_Save_PNG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ bool RageSurfaceUtils::SavePNG(RageSurface* pImg, RageFile& f, RString& sError)
f.Close(); // The RageFile reference is already opened. Should be closed for following function to succeed.

RageSurface* res;
RageSurfaceUtils::ConvertSurface(pImg, res, pImg->w, pImg->h, 32,
bool converted = RageSurfaceUtils::ConvertSurface(pImg, res, pImg->w, pImg->h, 32,
Swap32BE(0xFF000000),
Swap32BE(0x00FF0000),
Swap32BE(0x0000FF00),
Swap32BE(0x000000FF));

return 0 != stbi_write_png(f.GetRealPath(), pImg->w, pImg->h, 4, res->pixels, pImg->w * 4);
if (!converted) res = pImg;

// stride_in_bytes is image width in bytes
bool success = 0 != stbi_write_png(f.GetRealPath(), res->w, res->h, 4, res->pixels, res->w * 4);
if (converted) delete res; // If we converted then we created a new surface which we need to delete

return success;
}

0 comments on commit b9b627d

Please sign in to comment.