Browse Source

Fix function order [palette.cpp]

pull/481/head
galaxyhaxz 7 years ago committed by Anders Jenbo
parent
commit
5f941e862e
  1. 128
      Source/palette.cpp
  2. 5
      Source/palette.h

128
Source/palette.cpp

@ -12,38 +12,45 @@ int gamma_correction = 100;
BOOL color_cycling_enabled = TRUE; BOOL color_cycling_enabled = TRUE;
BOOLEAN sgbFadedIn = TRUE; BOOLEAN sgbFadedIn = TRUE;
void SaveGamma() static void palette_update()
{ {
SRegSaveValue("Diablo", "Gamma Correction", 0, gamma_correction); int nentries;
SRegSaveValue("Diablo", "Color Cycling", FALSE, color_cycling_enabled); int max_entries;
if (lpDDPalette) {
nentries = 0;
max_entries = 256;
if (!fullscreen) {
nentries = gdwPalEntries;
max_entries = 2 * (128 - gdwPalEntries);
}
SDrawUpdatePalette(nentries, max_entries, &system_palette[nentries], 0);
}
} }
void palette_init() static void ApplyGamma(PALETTEENTRY *dst, PALETTEENTRY *src, int n)
{ {
DWORD error_code; int i;
double g;
LoadGamma(); g = gamma_correction / 100.0;
memcpy(system_palette, orig_palette, sizeof(orig_palette));
LoadSysPal(); for (i = 0; i < n; i++) {
#ifdef __cplusplus dst->peRed = pow(src->peRed / 256.0, g) * 256.0;
error_code = lpDDInterface->CreatePalette(DDPCAPS_ALLOW256 | DDPCAPS_8BIT, system_palette, &lpDDPalette, NULL); dst->peGreen = pow(src->peGreen / 256.0, g) * 256.0;
#else dst->peBlue = pow(src->peBlue / 256.0, g) * 256.0;
error_code = lpDDInterface->lpVtbl->CreatePalette(lpDDInterface, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, system_palette, &lpDDPalette, NULL); dst++;
#endif src++;
if (error_code) }
ErrDlg(IDD_DIALOG8, error_code, "C:\\Src\\Diablo\\Source\\PALETTE.CPP", 143); }
#ifdef __cplusplus
error_code = lpDDSPrimary->SetPalette(lpDDPalette); void SaveGamma()
#else {
error_code = lpDDSPrimary->lpVtbl->SetPalette(lpDDSPrimary, lpDDPalette); SRegSaveValue("Diablo", "Gamma Correction", 0, gamma_correction);
#endif SRegSaveValue("Diablo", "Color Cycling", FALSE, color_cycling_enabled);
#ifndef RGBMODE
if (error_code)
ErrDlg(IDD_DIALOG8, error_code, "C:\\Src\\Diablo\\Source\\PALETTE.CPP", 146);
#endif
} }
void LoadGamma() static void LoadGamma()
{ {
int gamma_value; int gamma_value;
int value; int value;
@ -63,7 +70,7 @@ void LoadGamma()
color_cycling_enabled = value; color_cycling_enabled = value;
} }
void LoadSysPal() static void LoadSysPal()
{ {
HDC hDC; HDC hDC;
int i, iStartIndex; int i, iStartIndex;
@ -90,6 +97,31 @@ void LoadSysPal()
} }
} }
void palette_init()
{
DWORD error_code;
LoadGamma();
memcpy(system_palette, orig_palette, sizeof(orig_palette));
LoadSysPal();
#ifdef __cplusplus
error_code = lpDDInterface->CreatePalette(DDPCAPS_ALLOW256 | DDPCAPS_8BIT, system_palette, &lpDDPalette, NULL);
#else
error_code = lpDDInterface->lpVtbl->CreatePalette(lpDDInterface, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, system_palette, &lpDDPalette, NULL);
#endif
if (error_code)
ErrDlg(IDD_DIALOG8, error_code, "C:\\Src\\Diablo\\Source\\PALETTE.CPP", 143);
#ifdef __cplusplus
error_code = lpDDSPrimary->SetPalette(lpDDPalette);
#else
error_code = lpDDSPrimary->lpVtbl->SetPalette(lpDDSPrimary, lpDDPalette);
#endif
#ifndef RGBMODE
if (error_code)
ErrDlg(IDD_DIALOG8, error_code, "C:\\Src\\Diablo\\Source\\PALETTE.CPP", 146);
#endif
}
void LoadPalette(char *pszFileName) void LoadPalette(char *pszFileName)
{ {
int i; int i;
@ -149,38 +181,6 @@ void IncreaseGamma()
} }
} }
void palette_update()
{
int nentries;
int max_entries;
if (lpDDPalette) {
nentries = 0;
max_entries = 256;
if (!fullscreen) {
nentries = gdwPalEntries;
max_entries = 2 * (128 - gdwPalEntries);
}
SDrawUpdatePalette(nentries, max_entries, &system_palette[nentries], 0);
}
}
void ApplyGamma(PALETTEENTRY *dst, PALETTEENTRY *src, int n)
{
int i;
double g;
g = gamma_correction / 100.0;
for (i = 0; i < n; i++) {
dst->peRed = pow(src->peRed / 256.0, g) * 256.0;
dst->peGreen = pow(src->peGreen / 256.0, g) * 256.0;
dst->peBlue = pow(src->peBlue / 256.0, g) * 256.0;
dst++;
src++;
}
}
void DecreaseGamma() void DecreaseGamma()
{ {
if (gamma_correction > 30) { if (gamma_correction > 30) {
@ -202,12 +202,7 @@ int UpdateGamma(int gamma)
return 130 - gamma_correction; return 130 - gamma_correction;
} }
void BlackPalette() static void SetFadeLevel(DWORD fadeval)
{
SetFadeLevel(0);
}
void SetFadeLevel(DWORD fadeval)
{ {
int i; int i;
@ -227,6 +222,11 @@ void SetFadeLevel(DWORD fadeval)
} }
} }
void BlackPalette()
{
SetFadeLevel(0);
}
void PaletteFadeIn(int fr) void PaletteFadeIn(int fr)
{ {
int i; int i;

5
Source/palette.h

@ -9,18 +9,13 @@ extern int gdwPalEntries;
void SaveGamma(); void SaveGamma();
void palette_init(); void palette_init();
void LoadGamma();
void LoadSysPal();
void LoadPalette(char *pszFileName); void LoadPalette(char *pszFileName);
void LoadRndLvlPal(int l); void LoadRndLvlPal(int l);
void ResetPal(); void ResetPal();
void IncreaseGamma(); void IncreaseGamma();
void palette_update();
void ApplyGamma(PALETTEENTRY *dst, PALETTEENTRY *src, int n);
void DecreaseGamma(); void DecreaseGamma();
int UpdateGamma(int gamma); int UpdateGamma(int gamma);
void BlackPalette(); void BlackPalette();
void SetFadeLevel(DWORD fadeval);
void PaletteFadeIn(int fr); void PaletteFadeIn(int fr);
void PaletteFadeOut(int fr); void PaletteFadeOut(int fr);
void palette_update_caves(); void palette_update_caves();

Loading…
Cancel
Save