1
0
Fork 0

Spectre/Graphics/PixelFormat: Rework

source/Graphics/Image/IcoFormat.cpp: use new PixelFormat.
source/Graphics/Image.cpp: update to confirm with new PixelFormat
Spectre/Graphics/PixelFormat: add PF_getNumChannels()
Spectre/Graphics/PixelFormat: Rework the enum with proper naming convention and documentation.
This commit is contained in:
Henrik Hautakoski 2020-11-03 14:20:36 +01:00
parent 82add50157
commit c731cda1a2
5 changed files with 73 additions and 16 deletions

View file

@ -165,29 +165,28 @@ void Image::flipY()
void Image::setPixels(const void *pixels, PixelFormat format)
{
switch(format) {
case PixelFormat::PF_RGB :
case PixelFormat::PF_32BGR :
m_channels = RGB;
break;
case PixelFormat::PF_RGBA :
case PixelFormat::PF_32BGRA :
switch(PF_getNumChannels(format)) {
case 4:
m_channels = RGBA;
break;
case 3:
m_channels = RGB;
break;
default :
m_channels = Alpha;
}
m_pixels.resize(m_size.y * getStride());
if (format == PixelFormat::PF_32BGR || format == PixelFormat::PF_32BGRA) {
// TODO: Move pixel format convertion to it's own function(s)
if (format == PixelFormat::PF_BGR || format == PixelFormat::PF_BGRA) {
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) {
if (format == PixelFormat::PF_BGRA) {
m_pixels[i+3] = ptr[3];
}
ptr += 4;

View file

@ -61,9 +61,9 @@ bool IcoFormat::decode(Image& img, const unsigned char *data, unsigned size)
largest = findLargestImage(ent, num_ent);
if (largest->bpp == 32) {
format = PixelFormat::PF_32BGRA;
format = PixelFormat::PF_BGRA;
} else {
format = PixelFormat::PF_32BGR;
format = PixelFormat::PF_BGR;
}
// NOTE: plus 40 bytes here to skip over the DIB header.

View file

@ -0,0 +1,26 @@
#include <Spectre/Graphics/PixelFormat.h>
namespace sp {
uint8_t PF_getNumChannels(enum PixelFormat format)
{
switch(format) {
case PixelFormat::PF_RGBA :
case PixelFormat::PF_RGBA32 :
case PixelFormat::PF_BGRA :
case PixelFormat::PF_BGRA32 :
return 4;
case PixelFormat::PF_RGB :
case PixelFormat::PF_RGBX :
case PixelFormat::PF_RGBX32 :
case PixelFormat::PF_BGR :
case PixelFormat::PF_BGRX :
case PixelFormat::PF_BGRX32 :
return 3;
default :
return 1;
}
}
} // namespace sp