diff --git a/source/Graphics/Image.cpp b/source/Graphics/Image.cpp index f01c9c5..6228e5f 100644 --- a/source/Graphics/Image.cpp +++ b/source/Graphics/Image.cpp @@ -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