Splitting mac_pal and mac_gamma to always allow SDL gamma changes

This commit is contained in:
Seth Polsley 2020-09-13 03:41:23 -05:00
parent 21c16f991e
commit 6de9a5032d
3 changed files with 70 additions and 49 deletions

View File

@ -341,8 +341,10 @@ public:
virtual void switch_to_current_mode(void) = 0;
// Called by the video driver to set the color palette (in indexed modes)
// or the gamma table (in direct modes)
virtual void set_palette(uint8 *pal, int num) = 0;
// Called by the video driver to set the gamma table (in direct modes)
virtual void set_gamma(uint8 *gamma, int num) = 0;
};
// Vector of pointers to available monitor descriptions, filled by VideoInit()
@ -387,6 +389,7 @@ public:
virtual void switch_to_current_mode(void);
virtual void set_palette(uint8 *pal, int num);
virtual void set_gamma(uint8 *gamma, int num);
bool video_open(void);
void video_close(void);
@ -1778,53 +1781,26 @@ void video_set_palette(void)
}
monitor->set_palette(pal, n_colors);
}
void video_set_gamma(void)
{
monitor_desc * monitor = VideoMonitors[0];
int n_colors = palette_size(monitor->get_current_mode().viAppleMode);
uint8 gamma[256 * 3];
for (int c = 0; c < n_colors; c++) {
gamma[c*3 + 0] = mac_gamma[c].red;
gamma[c*3 + 1] = mac_gamma[c].green;
gamma[c*3 + 2] = mac_gamma[c].blue;
}
monitor->set_gamma(gamma, n_colors);
}
#endif
void SDL_monitor_desc::set_palette(uint8 *pal, int num_in)
{
const VIDEO_MODE &mode = get_current_mode();
if ((int)VIDEO_MODE_DEPTH > VIDEO_DEPTH_8BIT) {
// handle the gamma ramp
if (pal[0] == 127 && pal[num_in*3-1] == 127) // solid grey
return; // ignore
uint16 red[256];
uint16 green[256];
uint16 blue[256];
int repeats = 256 / num_in;
for (int i = 0; i < num_in; i++) {
for (int j = 0; j < repeats; j++) {
red[i*repeats + j] = pal[i*3 + 0] << 8;
green[i*repeats + j] = pal[i*3 + 1] << 8;
blue[i*repeats + j] = pal[i*3 + 2] << 8;
}
}
// fill remaining entries (if any) with last value
for (int i = num_in * repeats; i < 256; i++) {
red[i] = pal[(num_in - 1) * 3] << 8;
green[i] = pal[(num_in - 1) * 3 + 1] << 8;
blue[i] = pal[(num_in - 1) * 3 + 2] << 8;
}
bool changed = (memcmp(red, last_gamma_red, 512) != 0 ||
memcmp(green, last_gamma_green, 512) != 0 ||
memcmp(blue, last_gamma_blue, 512) != 0);
if (changed) {
memcpy(last_gamma_red, red, 512);
memcpy(last_gamma_green, green, 512);
memcpy(last_gamma_blue, blue, 512);
ApplyGammaRamp();
}
return;
}
LOCK_PALETTE;
// Convert colors to XColor array
@ -1867,6 +1843,48 @@ void SDL_monitor_desc::set_palette(uint8 *pal, int num_in)
UNLOCK_PALETTE;
}
void SDL_monitor_desc::set_gamma(uint8 *gamma, int num_in)
{
// handle the gamma ramp
if (gamma[0] == 127 && gamma[num_in*3-1] == 127) // solid grey
return; // ignore
uint16 red[256];
uint16 green[256];
uint16 blue[256];
int repeats = 256 / num_in;
for (int i = 0; i < num_in; i++) {
for (int j = 0; j < repeats; j++) {
red[i*repeats + j] = gamma[i*3 + 0] << 8;
green[i*repeats + j] = gamma[i*3 + 1] << 8;
blue[i*repeats + j] = gamma[i*3 + 2] << 8;
}
}
// fill remaining entries (if any) with last value
for (int i = num_in * repeats; i < 256; i++) {
red[i] = gamma[(num_in - 1) * 3] << 8;
green[i] = gamma[(num_in - 1) * 3 + 1] << 8;
blue[i] = gamma[(num_in - 1) * 3 + 2] << 8;
}
bool changed = (memcmp(red, last_gamma_red, 512) != 0 ||
memcmp(green, last_gamma_green, 512) != 0 ||
memcmp(blue, last_gamma_blue, 512) != 0);
if (changed) {
memcpy(last_gamma_red, red, 512);
memcpy(last_gamma_green, green, 512);
memcpy(last_gamma_blue, blue, 512);
ApplyGammaRamp();
}
}
/*

View File

@ -106,6 +106,7 @@ extern uint32 screen_base; // Frame buffer base address
extern int cur_mode; // Number of current video mode (index in VModes array)
extern int display_type; // Current display type (see above)
extern rgb_color mac_pal[256];
extern rgb_color mac_gamma[256];
extern uint8 remap_mac_be[256];
extern uint8 MacCursor[68];
@ -140,6 +141,7 @@ extern void VideoInstallAccel(void);
extern void VideoQuitFullScreen(void);
extern void video_set_palette(void);
extern void video_set_gamma(void);
extern void video_set_cursor(void);
extern bool video_can_change_cursor(void);
extern int16 video_mode_change(VidLocals *csSave, uint32 ParamPtr);

View File

@ -46,6 +46,7 @@ uint32 screen_base = 0; // Frame buffer base address
int cur_mode; // Number of current video mode (index in VModes array)
int display_type = DIS_INVALID; // Current display type
rgb_color mac_pal[256];
rgb_color mac_gamma[256];
uint8 remap_mac_be[256];
uint8 MacCursor[68] = {16, 1}; // Mac cursor image
@ -236,7 +237,7 @@ static int16 set_gamma(VidLocals *csSave, uint32 gamma)
for (int i=0; i<256; i++) {
WriteMacInt8(p + i, i);
mac_pal[i].red = mac_pal[i].green = mac_pal[i].blue = i;
mac_gamma[i].red = mac_gamma[i].green = mac_gamma[i].blue = i;
}
} else { // User-supplied gamma table
@ -290,14 +291,14 @@ static int16 set_gamma(VidLocals *csSave, uint32 gamma)
max_red = max(max_red, ReadMacInt8(p_red++));
max_green = max(max_green, ReadMacInt8(p_green++));
max_blue = max(max_blue, ReadMacInt8(p_blue++));
mac_pal[i].red = max_red;
mac_pal[i].green = max_green;
mac_pal[i].blue = max_blue;
mac_gamma[i].red = max_red;
mac_gamma[i].green = max_green;
mac_gamma[i].blue = max_blue;
}
}
}
video_set_palette();
video_set_gamma();
return noErr;
}