Some minor code cleanup.

This commit is contained in:
Leon Styhre 2021-01-15 18:47:01 +01:00
parent a99d32f596
commit ee8e0a0c89
3 changed files with 16 additions and 17 deletions

View file

@ -19,20 +19,20 @@ std::vector<unsigned char> ImageIO::loadFromMemoryRGBA32(const unsigned char* da
std::vector<unsigned char> rawData;
width = 0;
height = 0;
FIMEMORY * fiMemory = FreeImage_OpenMemory((BYTE *)data, (DWORD)size);
FIMEMORY* fiMemory = FreeImage_OpenMemory(const_cast<BYTE*>(data), static_cast<DWORD>(size));
if (fiMemory != nullptr) {
// Detect the filetype from data.
FREE_IMAGE_FORMAT format = FreeImage_GetFileTypeFromMemory(fiMemory);
if (format != FIF_UNKNOWN && FreeImage_FIFSupportsReading(format)) {
// File type is supported. load image,
// File type is supported, load image.
FIBITMAP* fiBitmap = FreeImage_LoadFromMemory(format, fiMemory);
if (fiBitmap != nullptr) {
// Loaded. convert to 32bit if necessary.
// Loaded. convert to 32-bit if necessary.
if (FreeImage_GetBPP(fiBitmap) != 32) {
FIBITMAP* fiConverted = FreeImage_ConvertTo32Bits(fiBitmap);
if (fiConverted != nullptr) {
//free original bitmap data
// Free original bitmap data.
FreeImage_Unload(fiBitmap);
fiBitmap = fiConverted;
}
@ -44,8 +44,8 @@ std::vector<unsigned char> ImageIO::loadFromMemoryRGBA32(const unsigned char* da
// This is necessary, because width*height*bpp might not be == pitch.
unsigned char* tempData = new unsigned char[width * height * 4];
for (size_t i = 0; i < height; i++) {
const BYTE * scanLine = FreeImage_GetScanLine(fiBitmap,
static_cast<int>(i));
const BYTE* scanLine =
FreeImage_GetScanLine(fiBitmap, static_cast<int>(i));
memcpy(tempData + (i * width * 4), scanLine, width * 4);
}
// Convert from BGRA to RGBA.
@ -65,15 +65,14 @@ std::vector<unsigned char> ImageIO::loadFromMemoryRGBA32(const unsigned char* da
}
}
else {
LOG(LogError) << "Failed to load image from memory!";
LOG(LogError) << "Failed to load image from memory";
}
}
else {
LOG(LogError) << "Couldn't load image, file is missing or the file type is " <<
// it's not existing or the file type " <<
(format == FIF_UNKNOWN ? "unknown" : "unsupported") << "!";
(format == FIF_UNKNOWN ? "unknown" : "unsupported");
}
// Free fiMemory again
// Free fiMemory again.
FreeImage_CloseMemory(fiMemory);
}
return rawData;

View file

@ -52,7 +52,7 @@ void NinePatchComponent::buildVertices()
if (mVertices != nullptr)
delete[] mVertices;
// Scale the corner size according to the screen resolution.
// Scale the corner size relative to the screen resolution.
mTexture = TextureResource::get(mPath, false, false, true, Renderer::getScreenWidthModifier());
if (mTexture->getSize() == Vector2i::Zero()) {

View file

@ -335,7 +335,7 @@ namespace Renderer
void popClipRect()
{
if (clipStack.empty()) {
LOG(LogError) << "Tried to popClipRect while the stack was empty!";
LOG(LogError) << "Tried to popClipRect while the stack was empty";
return;
}