mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-04-10 19:15:13 +00:00
Convert image data only when necessary
Convert images only when they're not already 32bit
This commit is contained in:
parent
6d499d4e3a
commit
fa6fdd7cce
|
@ -20,19 +20,29 @@ std::vector<unsigned char> ImageIO::loadFromMemoryRGBA32(const unsigned char * d
|
||||||
FIBITMAP * fiBitmap = FreeImage_LoadFromMemory(format, fiMemory);
|
FIBITMAP * fiBitmap = FreeImage_LoadFromMemory(format, fiMemory);
|
||||||
if (fiBitmap != nullptr)
|
if (fiBitmap != nullptr)
|
||||||
{
|
{
|
||||||
//loaded. convert to 32bit
|
//loaded. convert to 32bit if necessary
|
||||||
FIBITMAP * fiConverted = FreeImage_ConvertTo32Bits(fiBitmap);
|
FIBITMAP * fiConverted = nullptr;
|
||||||
if (fiConverted != nullptr)
|
if (FreeImage_GetBPP(fiBitmap) != 32)
|
||||||
{
|
{
|
||||||
width = FreeImage_GetWidth(fiConverted);
|
FIBITMAP * fiConverted = FreeImage_ConvertTo32Bits(fiBitmap);
|
||||||
height = FreeImage_GetHeight(fiConverted);
|
if (fiConverted != nullptr)
|
||||||
unsigned int pitch = FreeImage_GetPitch(fiConverted);
|
{
|
||||||
|
//free original bitmap data
|
||||||
|
FreeImage_Unload(fiBitmap);
|
||||||
|
fiBitmap = fiConverted;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fiBitmap != nullptr)
|
||||||
|
{
|
||||||
|
width = FreeImage_GetWidth(fiBitmap);
|
||||||
|
height = FreeImage_GetHeight(fiBitmap);
|
||||||
|
unsigned int pitch = FreeImage_GetPitch(fiBitmap);
|
||||||
//loop through scanlines and add all pixel data to the return vector
|
//loop through scanlines and add all pixel data to the return vector
|
||||||
//this is necessary, because width*height*bpp might not be == pitch
|
//this is necessary, because width*height*bpp might not be == pitch
|
||||||
unsigned char * tempData = new unsigned char[width * height * 4];
|
unsigned char * tempData = new unsigned char[width * height * 4];
|
||||||
for (size_t i = 0; i < height; i++)
|
for (size_t i = 0; i < height; i++)
|
||||||
{
|
{
|
||||||
const BYTE * scanLine = FreeImage_GetScanLine(fiConverted, i);
|
const BYTE * scanLine = FreeImage_GetScanLine(fiBitmap, i);
|
||||||
memcpy(tempData + (i * width * 4), scanLine, width * 4);
|
memcpy(tempData + (i * width * 4), scanLine, width * 4);
|
||||||
}
|
}
|
||||||
//convert from BGRA to RGBA
|
//convert from BGRA to RGBA
|
||||||
|
@ -47,11 +57,13 @@ std::vector<unsigned char> ImageIO::loadFromMemoryRGBA32(const unsigned char * d
|
||||||
((RGBQUAD *)tempData)[i] = rgba;
|
((RGBQUAD *)tempData)[i] = rgba;
|
||||||
}
|
}
|
||||||
rawData = std::vector<unsigned char>(tempData, tempData + width * height * 4);
|
rawData = std::vector<unsigned char>(tempData, tempData + width * height * 4);
|
||||||
//free converted data
|
//free bitmap data
|
||||||
FreeImage_Unload(fiConverted);
|
FreeImage_Unload(fiBitmap);
|
||||||
}
|
}
|
||||||
//free bitmap data
|
}
|
||||||
FreeImage_Unload(fiBitmap);
|
else
|
||||||
|
{
|
||||||
|
LOG(LogError) << "Error - Failed to load image from memory!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue