1
0
Fork 0

source/Graphics/Image.cpp: in setPixels() do proper conversion.

This commit is contained in:
Henrik Hautakoski 2020-10-22 16:52:54 +02:00
parent 4f04a8e7c9
commit 02912b857b

View file

@ -165,16 +165,36 @@ void Image::flipY()
void Image::setPixels(const void *pixels, PixelFormat format)
{
if (format == PixelFormat::PF_RGB) {
switch(format) {
case PixelFormat::PF_RGB :
case PixelFormat::PF_32BGR :
m_channels = RGB;
} else if (format == PixelFormat::PF_RGBA) {
break;
case PixelFormat::PF_RGBA :
case PixelFormat::PF_32BGRA :
m_channels = RGBA;
} else if (format == PixelFormat::PF_Alpha) {
break;
default :
m_channels = Alpha;
}
m_pixels.resize(m_size.y * getStride());
memcpy(&m_pixels[0], pixels, m_pixels.size());
if (format == PixelFormat::PF_32BGR || format == PixelFormat::PF_32BGRA) {
const uint8_t *ptr = (const uint8_t *) pixels;
for(int i = 0; i < m_pixels.size(); i += 4) {
m_pixels[i+0] = ptr[2];
m_pixels[i+1] = ptr[1];
m_pixels[i+2] = ptr[0];
if (format == PixelFormat::PF_32BGRA) {
m_pixels[i+3] = ptr[3];
}
ptr += 4;
}
} else {
memcpy(&m_pixels[0], pixels, m_pixels.size());
}
}
const unsigned char* Image::getPixels() const