Screenshots: Create 24-bit PNG files instead of 32-bit files to save some space
This commit is contained in:
parent
7921370937
commit
5336450ebf
1 changed files with 6 additions and 3 deletions
|
@ -7,13 +7,16 @@ bool PNGHelper::WritePNG(std::stringstream &stream, uint32_t* buffer, uint32_t x
|
|||
{
|
||||
size_t pngSize = 0;
|
||||
|
||||
//ARGB -> ABGR
|
||||
//ARGB -> BGR
|
||||
uint32_t size = xSize * ySize * bitsPerPixel / 8 / 4;
|
||||
vector<uint8_t> convertedData(size * 3, 0);
|
||||
for(uint32_t i = 0; i < size; i++) {
|
||||
buffer[i] = (buffer[i] & 0xFF00FF00) | ((buffer[i] & 0xFF0000) >> 16) | ((buffer[i] & 0xFF) << 16);
|
||||
convertedData[i * 3] = (buffer[i] & 0xFF0000) >> 16;
|
||||
convertedData[i * 3 + 1] = (buffer[i] & 0xFF00) >> 8;
|
||||
convertedData[i * 3 + 2] = (buffer[i] & 0xFF);
|
||||
}
|
||||
|
||||
void *pngData = tdefl_write_image_to_png_file_in_memory_ex(buffer, xSize, ySize, bitsPerPixel / 8, &pngSize, MZ_DEFAULT_LEVEL, MZ_FALSE);
|
||||
void* pngData = tdefl_write_image_to_png_file_in_memory_ex(convertedData.data(), xSize, ySize, 3, &pngSize, MZ_DEFAULT_LEVEL, MZ_FALSE);
|
||||
if(!pngData) {
|
||||
std::cout << "tdefl_write_image_to_png_file_in_memory_ex() failed!" << std::endl;
|
||||
return false;
|
||||
|
|
Loading…
Add table
Reference in a new issue