Skip to content

Commit

Permalink
BACKENDS: PSP: Add support for rgba8888 pixelformat
Browse files Browse the repository at this point in the history
  • Loading branch information
rsn8887 committed Nov 4, 2022
1 parent 0a303f4 commit 919a7e0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
2 changes: 1 addition & 1 deletion backends/platform/psp/default_display_client.cpp
Expand Up @@ -111,7 +111,7 @@ void Overlay::setBytesPerPixel(uint32 size) {
_buffer.setPixelFormat(PSPPixelFormat::Type_4444);
break;
case 4:
_buffer.setPixelFormat(PSPPixelFormat::Type_8888);
_buffer.setPixelFormat(PSPPixelFormat::Type_abgr8888);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion backends/platform/psp/display_client.cpp
Expand Up @@ -638,7 +638,7 @@ inline uint32 GuRenderer::convertToGuPixelFormat(PSPPixelFormat::Type format) {
case PSPPixelFormat::Type_5650:
guFormat = GU_PSM_5650;
break;
case PSPPixelFormat::Type_8888:
case PSPPixelFormat::Type_abgr8888:
guFormat = GU_PSM_8888;
break;
case PSPPixelFormat::Type_Palette_8bit:
Expand Down
2 changes: 1 addition & 1 deletion backends/platform/psp/png_loader.cpp
Expand Up @@ -60,7 +60,7 @@ PngLoader::Status PngLoader::allocate() {
}

} else { // 32-bit image
_buffer->setPixelFormat(PSPPixelFormat::Type_8888);
_buffer->setPixelFormat(PSPPixelFormat::Type_abgr8888);
}

if (!_buffer->allocate()) {
Expand Down
22 changes: 19 additions & 3 deletions backends/platform/psp/psppixelformat.cpp
Expand Up @@ -42,7 +42,10 @@ void PSPPixelFormat::set(Type type, bool swap /* = false */) {
case Type_5650:
bitsPerPixel = 16;
break;
case Type_8888:
case Type_abgr8888:
bitsPerPixel = 32;
break;
case Type_rgba8888:
bitsPerPixel = 32;
break;
case Type_Palette_8bit:
Expand Down Expand Up @@ -97,7 +100,9 @@ void PSPPixelFormat::convertFromScummvmPixelFormat(const Graphics::PixelFormat *
} else if (pf->rLoss == 4 && pf->gLoss == 4 && pf->bLoss == 4) {
*target = Type_4444;
} else if (pf->gLoss == 0 && pf->gShift == 8) {
*target = Type_8888;
*target = Type_abgr8888;
} else if (pf->gLoss == 0 && pf->gShift == 16) {
*target = Type_rgba8888;
} else if ((pf->gLoss == 0 && pf->gShift == 0) ||
(pf->gLoss == 8 && pf->gShift == 0)) { // Default CLUT8 can have weird values
*target = Type_5551;
Expand Down Expand Up @@ -153,7 +158,7 @@ Graphics::PixelFormat PSPPixelFormat::convertToScummvmPixelFormat(PSPPixelFormat
pf.gShift = 5;
pf.bShift = 11;
break;
case Type_8888:
case Type_abgr8888:
pf.bytesPerPixel = 4;
pf.aLoss = 0;
pf.rLoss = 0;
Expand All @@ -164,6 +169,17 @@ Graphics::PixelFormat PSPPixelFormat::convertToScummvmPixelFormat(PSPPixelFormat
pf.gShift = 8;
pf.bShift = 16;
break;
case Type_rgba8888:
pf.bytesPerPixel = 4;
pf.aLoss = 0;
pf.rLoss = 0;
pf.gLoss = 0;
pf.bLoss = 0;
pf.aShift = 0;
pf.rShift = 24;
pf.gShift = 16;
pf.bShift = 8;
break;
default:
PSP_ERROR("Unhandled PSPPixelFormat[%u]\n", type);
break;
Expand Down
27 changes: 22 additions & 5 deletions backends/platform/psp/psppixelformat.h
Expand Up @@ -37,7 +37,8 @@ struct PSPPixelFormat {
Type_4444,
Type_5551,
Type_5650,
Type_8888,
Type_abgr8888,
Type_rgba8888,
Type_Palette_8bit,
Type_Palette_4bit,
Type_Unknown
Expand Down Expand Up @@ -69,9 +70,12 @@ struct PSPPixelFormat {
case Type_5650:
color = (((b >> 3) << 11) | ((g >> 2) << 5) | ((r >> 3) << 0));
break;
case Type_8888:
case Type_abgr8888:
color = (((b >> 0) << 16) | ((g >> 0) << 8) | ((r >> 0) << 0) | ((a >> 0) << 24));
break;
case Type_rgba8888:
color = (((b >> 0) << 8) | ((g >> 0) << 16) | ((r >> 0) << 24) | ((a >> 0) << 0));
break;
default:
color = 0;
break;
Expand Down Expand Up @@ -109,12 +113,18 @@ struct PSPPixelFormat {
g = g << 2 | g >> 4;
r = r << 3 | r >> 2;
break;
case Type_8888:
case Type_abgr8888:
a = (color >> 24) & 0xFF;
b = (color >> 16) & 0xFF;
g = (color >> 8) & 0xFF;
r = (color >> 0) & 0xFF;
break;
case Type_rgba8888:
a = (color >> 0) & 0xFF;
b = (color >> 8) & 0xFF;
g = (color >> 16) & 0xFF;
r = (color >> 24) & 0xFF;
break;
default:
a = b = g = r = 0;
break;
Expand All @@ -129,9 +139,12 @@ struct PSPPixelFormat {
case Type_5551:
color = (color & 0x7FFF) | (((uint32)alpha >> 7) << 15);
break;
case Type_8888:
case Type_abgr8888:
color = (color & 0x00FFFFFF) | ((uint32)alpha << 24);
break;
case Type_rgba8888:
color = (color & 0xFFFFFF00) | ((uint32)alpha << 0);
break;
case Type_5650:
default:
break;
Expand Down Expand Up @@ -196,10 +209,14 @@ struct PSPPixelFormat {
output = (color & 0x07e007e0) |
((color & 0x001f001f) << 11) | ((color & 0xf800f800) >> 11);
break;
case Type_8888:
case Type_abgr8888:
output = (color & 0xff00ff00) |
((color & 0x000000ff) << 16) | ((color & 0x00ff0000) >> 16);
break;
case Type_rgba8888:
output = (color & 0x00ff00ff) |
((color & 0x0000ff00) << 16) | ((color & 0xff000000) >> 16);
break;
default:
PSP_ERROR("invalid format[%u] for swapping\n", format);
output = 0;
Expand Down

0 comments on commit 919a7e0

Please sign in to comment.