mirror of
https://github.com/InvisibleUp/uvmac.git
synced 2025-01-18 11:30:04 +00:00
Add custom B&W palette support
This commit is contained in:
parent
5c6bbec87a
commit
24eeabe9a5
@ -24,6 +24,7 @@
|
||||
Macintosh port of vMac, by Philip Cummins.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include "SYSDEPNS.h"
|
||||
#include "UI/MYOSGLUE.h"
|
||||
#include "UTIL/ENDIANAC.h"
|
||||
@ -51,9 +52,12 @@ uint32_t vMacScreenByteWidth;
|
||||
uint32_t vMacScreenMonoNumBytes;
|
||||
uint32_t vMacScreenMonoByteWidth;
|
||||
bool UseLargeScreenHack;
|
||||
char *ScreenColorBlack = NULL;
|
||||
char *ScreenColorWhite = NULL;
|
||||
|
||||
bool Screen_Init(void)
|
||||
{
|
||||
// enable a palette because heck it
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -74,6 +78,10 @@ bool Screen_LoadCfg()
|
||||
vMacScreenDepth = temp;
|
||||
okay = Config_GetBool(CONFIG_VIDEO_USEHACK, &UseLargeScreenHack, false);
|
||||
if (!okay) { return false; }
|
||||
okay = Config_GetString(CONFIG_VIDEO_BLACK, &ScreenColorBlack, "#000000");
|
||||
if (!okay) { return false; }
|
||||
okay = Config_GetString(CONFIG_VIDEO_WHITE, &ScreenColorWhite, "#FFFFFF");
|
||||
if (!okay) { return false; }
|
||||
|
||||
// Compute the other sorts of things
|
||||
vMacScreenNumPixels = vMacScreenHeight * vMacScreenWidth;
|
||||
|
@ -33,5 +33,7 @@ extern uint32_t vMacScreenByteWidth;
|
||||
extern uint32_t vMacScreenMonoNumBytes;
|
||||
extern uint32_t vMacScreenMonoByteWidth;
|
||||
bool UseLargeScreenHack;
|
||||
char *ScreenColorBlack;
|
||||
char *ScreenColorWhite;
|
||||
|
||||
#endif
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_pixels.h>
|
||||
#include "CNFGRAPI.h"
|
||||
@ -32,12 +33,33 @@ SDL_PixelFormat *format = NULL;
|
||||
uint8_t * ScalingBuff = nullpr;
|
||||
uint8_t * CLUT_final;
|
||||
|
||||
SDL_Color bwpalette[2];
|
||||
bool bwpalette_loaded = false;
|
||||
|
||||
// Set the display palette from the Macintosh's memory or w/e
|
||||
static int SetPalette(SDL_Palette *palette, const SDL_Color *macColors, int ncolors)
|
||||
{
|
||||
return SDL_SetPaletteColors(palette, macColors, 0, ncolors);
|
||||
}
|
||||
|
||||
static SDL_Color HexToColor(const char *hexIn, SDL_Color fallback) {
|
||||
unsigned int r, g, b;
|
||||
assert(hexIn != NULL);
|
||||
int numRead = sscanf(hexIn, "#%02x%02x%02x", &r, &g, &b);
|
||||
if (numRead != 3) { return fallback; }
|
||||
SDL_Color result = {.r = r, .g = g, .b = b};
|
||||
return result;
|
||||
}
|
||||
|
||||
void LoadCustomPalette()
|
||||
{
|
||||
if (bwpalette_loaded) { return; }
|
||||
SDL_Color fallbacks[] = { {.r=255,.g=255,.b=255}, {.r=0,.b=0,.g=0} };
|
||||
bwpalette[0] = HexToColor(ScreenColorWhite, fallbacks[0]);
|
||||
bwpalette[1] = HexToColor(ScreenColorBlack, fallbacks[1]);
|
||||
bwpalette_loaded = true;
|
||||
}
|
||||
|
||||
// Get pixel format for a given screen depth
|
||||
// Note: this is complete and total guesswork right now. Lol.
|
||||
uint32_t GetPixFormatFromDepth(int depth)
|
||||
@ -80,6 +102,8 @@ GLOBALOSGLUPROC Screen_OutputFrame(uint8_t * src_ptr)
|
||||
vMacScreenByteWidth,
|
||||
src_format
|
||||
);
|
||||
LoadCustomPalette();
|
||||
SetPalette(src->format->palette, bwpalette, 2);
|
||||
|
||||
// Setup dst surface
|
||||
SDL_LockTexture(texture, NULL, &pixels, &pitch);
|
||||
|
Loading…
x
Reference in New Issue
Block a user