few polish of png functions

Signed-off-by: Sergey Isakov <isakov-sl@bk.ru>
This commit is contained in:
Sergey Isakov 2020-02-26 09:13:03 +03:00
parent 1946bf5838
commit f4457dc741

View File

@ -116,24 +116,32 @@ void XImage::FlipRB(bool WantAlpha)
} }
} }
/*
* The function converted plain array into XImage object
*/
unsigned XImage::FromPNG(const uint8_t * Data, UINTN Length, bool WantAlpha) unsigned XImage::FromPNG(const uint8_t * Data, UINTN Length, bool WantAlpha)
{ {
unsigned Error = 0;
uint8_t * PixelPtr = (uint8_t *)&PixelData[0]; uint8_t * PixelPtr = (uint8_t *)&PixelData[0];
Error = eglodepng_decode(&PixelPtr, &Width, &Height, Data, Length); unsigned Error = eglodepng_decode(&PixelPtr, &Width, &Height, Data, Length);
FlipRB(WantAlpha); FlipRB(WantAlpha);
return Error; return Error;
} }
/*
* The function creates new array Data and inform about it size to be saved
* as a file.
* The caller is responsible to free the array.
*/
unsigned XImage::ToPNG(uint8_t** Data, UINTN& OutSize) unsigned XImage::ToPNG(uint8_t** Data, UINTN& OutSize)
{ {
size_t FileDataLength = 0; size_t FileDataLength = 0;
FlipRB(false); FlipRB(false);
uint8_t * PixelPtr = (uint8_t *)&PixelData[0]; uint8_t * PixelPtr = (uint8_t *)&PixelData[0];
unsigned lode_return = eglodepng_encode(Data, &FileDataLength, PixelPtr, Width, Height); unsigned Error = eglodepng_encode(Data, &FileDataLength, PixelPtr, Width, Height);
OutSize = FileDataLength; OutSize = FileDataLength;
return lode_return; return Error;
} }