source/Graphics/Image.cpp: in setPixels() do proper conversion.
This commit is contained in:
parent
4f04a8e7c9
commit
02912b857b
1 changed files with 24 additions and 4 deletions
|
|
@ -165,16 +165,36 @@ void Image::flipY()
|
||||||
|
|
||||||
void Image::setPixels(const void *pixels, PixelFormat format)
|
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;
|
m_channels = RGB;
|
||||||
} else if (format == PixelFormat::PF_RGBA) {
|
break;
|
||||||
|
case PixelFormat::PF_RGBA :
|
||||||
|
case PixelFormat::PF_32BGRA :
|
||||||
m_channels = RGBA;
|
m_channels = RGBA;
|
||||||
} else if (format == PixelFormat::PF_Alpha) {
|
break;
|
||||||
|
default :
|
||||||
m_channels = Alpha;
|
m_channels = Alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pixels.resize(m_size.y * getStride());
|
m_pixels.resize(m_size.y * getStride());
|
||||||
|
|
||||||
|
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());
|
memcpy(&m_pixels[0], pixels, m_pixels.size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned char* Image::getPixels() const
|
const unsigned char* Image::getPixels() const
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue