From ae3c4a0227436eb78092ce437774cafe4b97a619 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Fri, 14 Apr 2017 20:43:30 +0100 Subject: [PATCH 01/27] Removal of cv_allcaps for console stuff. (cherry picked from commit 95d89078f5bb7a9d8ce52cff129e54a7ec2e4744) --- src/console.c | 20 ++++++++++---------- src/hu_stuff.c | 20 ++++++++++---------- src/m_menu.c | 3 --- src/v_video.c | 2 -- src/v_video.h | 2 +- 5 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/console.c b/src/console.c index 1defa7e82..ec1e892ed 100644 --- a/src/console.c +++ b/src/console.c @@ -1474,32 +1474,32 @@ static void CON_DrawInput(void) if (input_sel < c) V_DrawFill(x, y, charwidth*3, (10 * con_scalefactor), 77 | V_NOSCALESTART); for (i = 0; i < 3; ++i, x += charwidth) - V_DrawCharacter(x, y, '.' | cv_constextsize.value | V_GRAYMAP | V_NOSCALESTART, !cv_allcaps.value); + V_DrawCharacter(x, y, '.' | cv_constextsize.value | V_GRAYMAP | V_NOSCALESTART, true); } else - V_DrawCharacter(x-charwidth, y, CON_PROMPTCHAR | cv_constextsize.value | V_GRAYMAP | V_NOSCALESTART, !cv_allcaps.value); + V_DrawCharacter(x-charwidth, y, CON_PROMPTCHAR | cv_constextsize.value | V_GRAYMAP | V_NOSCALESTART, true); for (cend = c + clen; c < cend; ++c, x += charwidth) { if ((input_sel > c && input_cur <= c) || (input_sel <= c && input_cur > c)) { V_DrawFill(x, y, charwidth, (10 * con_scalefactor), 77 | V_NOSCALESTART); - V_DrawCharacter(x, y, p[c] | cv_constextsize.value | V_YELLOWMAP | V_NOSCALESTART, !cv_allcaps.value); + V_DrawCharacter(x, y, p[c] | cv_constextsize.value | V_YELLOWMAP | V_NOSCALESTART, true); } else - V_DrawCharacter(x, y, p[c] | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); + V_DrawCharacter(x, y, p[c] | cv_constextsize.value | V_NOSCALESTART, true); if (c == input_cur && con_tick >= 4) - V_DrawCharacter(x, y + (con_scalefactor*2), '_' | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); + V_DrawCharacter(x, y + (con_scalefactor*2), '_' | cv_constextsize.value | V_NOSCALESTART, true); } if (cend == input_cur && con_tick >= 4) - V_DrawCharacter(x, y + (con_scalefactor*2), '_' | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); + V_DrawCharacter(x, y + (con_scalefactor*2), '_' | cv_constextsize.value | V_NOSCALESTART, true); if (rellip) { if (input_sel > cend) V_DrawFill(x, y, charwidth*3, (10 * con_scalefactor), 77 | V_NOSCALESTART); for (i = 0; i < 3; ++i, x += charwidth) - V_DrawCharacter(x, y, '.' | cv_constextsize.value | V_GRAYMAP | V_NOSCALESTART, !cv_allcaps.value); + V_DrawCharacter(x, y, '.' | cv_constextsize.value | V_GRAYMAP | V_NOSCALESTART, true); } } @@ -1545,11 +1545,11 @@ static void CON_DrawHudlines(void) else { //charwidth = SHORT(hu_font['A'-HU_FONTSTART]->width) * con_scalefactor; - V_DrawCharacter(x, y, (INT32)(*p) | charflags | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); + V_DrawCharacter(x, y, (INT32)(*p) | charflags | cv_constextsize.value | V_NOSCALESTART, true); } } - //V_DrawCharacter(x, y, (p[c]&0xff) | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); + //V_DrawCharacter(x, y, (p[c]&0xff) | cv_constextsize.value | V_NOSCALESTART, true); y += charheight; } @@ -1620,7 +1620,7 @@ static void CON_DrawConsole(void) charflags = (*p & 0x7f) << V_CHARCOLORSHIFT; p++; } - V_DrawCharacter(x, y, (INT32)(*p) | charflags | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); + V_DrawCharacter(x, y, (INT32)(*p) | charflags | cv_constextsize.value | V_NOSCALESTART, true); } } diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 76b85dd01..a454aaecc 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1583,7 +1583,7 @@ static void HU_drawMiniChat(void) if (cv_chatbacktint.value) // on request of wolfy V_DrawFillConsoleMap(x + dx + 2, y+dy, charwidth, charheight, 159|V_SNAPTOBOTTOM|V_SNAPTOLEFT); - V_DrawChatCharacter(x + dx + 2, y+dy, msg[j++] |V_SNAPTOBOTTOM|V_SNAPTOLEFT|transflag, !cv_allcaps.value, colormap); + V_DrawChatCharacter(x + dx + 2, y+dy, msg[j++] |V_SNAPTOBOTTOM|V_SNAPTOLEFT|transflag, true, colormap); } dx += charwidth; @@ -1677,7 +1677,7 @@ static void HU_drawChatLog(INT32 offset) else { if ((y+dy+2 >= chat_topy) && (y+dy < (chat_bottomy))) - V_DrawChatCharacter(x + dx + 2, y+dy+2, msg[j++] |V_SNAPTOBOTTOM|V_SNAPTOLEFT, !cv_allcaps.value, colormap); + V_DrawChatCharacter(x + dx + 2, y+dy+2, msg[j++] |V_SNAPTOBOTTOM|V_SNAPTOLEFT, true, colormap); else j++; // don't forget to increment this or we'll get stuck in the limbo. } @@ -1778,7 +1778,7 @@ static void HU_DrawChat(void) ++i; else { - V_DrawChatCharacter(chatx + c + 2, y, talk[i] |V_SNAPTOBOTTOM|V_SNAPTOLEFT|cflag, !cv_allcaps.value, V_GetStringColormap(talk[i]|cflag)); + V_DrawChatCharacter(chatx + c + 2, y, talk[i] |V_SNAPTOBOTTOM|V_SNAPTOLEFT|cflag, true, V_GetStringColormap(talk[i]|cflag)); i++; } @@ -1796,7 +1796,7 @@ static void HU_DrawChat(void) typelines = 1; if ((strlen(w_chat) == 0 || c_input == 0) && hu_tick < 4) - V_DrawChatCharacter(chatx + 2 + c, y+1, '_' |V_SNAPTOBOTTOM|V_SNAPTOLEFT|t, !cv_allcaps.value, NULL); + V_DrawChatCharacter(chatx + 2 + c, y+1, '_' |V_SNAPTOBOTTOM|V_SNAPTOLEFT|t, true, NULL); while (w_chat[i]) { @@ -1806,7 +1806,7 @@ static void HU_DrawChat(void) INT32 cursorx = (c+charwidth < boxw-charwidth) ? (chatx + 2 + c+charwidth) : (chatx+1); // we may have to go down. INT32 cursory = (cursorx != chatx+1) ? (y) : (y+charheight); if (hu_tick < 4) - V_DrawChatCharacter(cursorx, cursory+1, '_' |V_SNAPTOBOTTOM|V_SNAPTOLEFT|t, !cv_allcaps.value, NULL); + V_DrawChatCharacter(cursorx, cursory+1, '_' |V_SNAPTOBOTTOM|V_SNAPTOLEFT|t, true, NULL); if (cursorx == chatx+1 && saylen == i) // a weirdo hack { @@ -1819,7 +1819,7 @@ static void HU_DrawChat(void) if (w_chat[i] < HU_FONTSTART) ++i; else - V_DrawChatCharacter(chatx + c + 2, y, w_chat[i++] | V_SNAPTOBOTTOM|V_SNAPTOLEFT | t, !cv_allcaps.value, NULL); + V_DrawChatCharacter(chatx + c + 2, y, w_chat[i++] | V_SNAPTOBOTTOM|V_SNAPTOLEFT | t, true, NULL); c += charwidth; if (c > boxw-(charwidth*2) && !skippedline) @@ -1945,13 +1945,13 @@ static void HU_DrawChat_Old(void) else { //charwidth = SHORT(hu_font[talk[i]-HU_FONTSTART]->width) * con_scalefactor; - V_DrawCharacter(HU_INPUTX + c, y, talk[i++] | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); + V_DrawCharacter(HU_INPUTX + c, y, talk[i++] | cv_constextsize.value | V_NOSCALESTART, true); } c += charwidth; } if ((strlen(w_chat) == 0 || c_input == 0) && hu_tick < 4) - V_DrawCharacter(HU_INPUTX+c, y+2*con_scalefactor, '_' |cv_constextsize.value | V_NOSCALESTART|t, !cv_allcaps.value); + V_DrawCharacter(HU_INPUTX+c, y+2*con_scalefactor, '_' |cv_constextsize.value | V_NOSCALESTART|t, true); i = 0; while (w_chat[i]) @@ -1961,7 +1961,7 @@ static void HU_DrawChat_Old(void) { INT32 cursorx = (HU_INPUTX+c+charwidth < vid.width) ? (HU_INPUTX + c + charwidth) : (HU_INPUTX); // we may have to go down. INT32 cursory = (cursorx != HU_INPUTX) ? (y) : (y+charheight); - V_DrawCharacter(cursorx, cursory+2*con_scalefactor, '_' |cv_constextsize.value | V_NOSCALESTART|t, !cv_allcaps.value); + V_DrawCharacter(cursorx, cursory+2*con_scalefactor, '_' |cv_constextsize.value | V_NOSCALESTART|t, true); } //Hurdler: isn't it better like that? @@ -1973,7 +1973,7 @@ static void HU_DrawChat_Old(void) else { //charwidth = SHORT(hu_font[w_chat[i]-HU_FONTSTART]->width) * con_scalefactor; - V_DrawCharacter(HU_INPUTX + c, y, w_chat[i++] | cv_constextsize.value | V_NOSCALESTART | t, !cv_allcaps.value); + V_DrawCharacter(HU_INPUTX + c, y, w_chat[i++] | cv_constextsize.value | V_NOSCALESTART | t, true); } c += charwidth; diff --git a/src/m_menu.c b/src/m_menu.c index 68aae68eb..6ac2ef5ab 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -3321,9 +3321,6 @@ void M_Init(void) #ifndef NONET CV_RegisterVar(&cv_serversort); #endif - - //todo put this somewhere better... - CV_RegisterVar(&cv_allcaps); } void M_InitCharacterTables(void) diff --git a/src/v_video.c b/src/v_video.c index 297eae9c4..274c14b38 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -44,8 +44,6 @@ static void CV_usegamma_OnChange(void); consvar_t cv_ticrate = {"showfps", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_usegamma = {"gamma", "0", CV_SAVE|CV_CALL, gamma_cons_t, CV_usegamma_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_allcaps = {"allcaps", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; - static CV_PossibleValue_t constextsize_cons_t[] = { {V_NOSCALEPATCH, "Small"}, {V_SMALLSCALEPATCH, "Medium"}, {V_MEDSCALEPATCH, "Large"}, {0, "Huge"}, {0, NULL}}; diff --git a/src/v_video.h b/src/v_video.h index eb60690bd..d229c370f 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -28,7 +28,7 @@ extern UINT8 *screens[5]; extern const UINT8 gammatable[5][256]; -extern consvar_t cv_ticrate, cv_usegamma, cv_allcaps, cv_constextsize; +extern consvar_t cv_ticrate, cv_usegamma, cv_constextsize; // Allocates buffer screens, call before R_Init. void V_Init(void); From f5ecb1b9c90b5eac35b5c7e5f72d21b09d7d884a Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Mon, 23 Mar 2020 16:27:14 -0700 Subject: [PATCH 02/27] Introducing the Colour Cube! https://cdn.discordapp.com/attachments/293238104096112641/304015171385294850/aa.png Basically in preperation of supporting colourblindness modes I implemented the following link when loading palettes. http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter24.html This basically means I can do whatever the hell I want to the colour profile of incoming paletties, and nobody can stop me. Muahahahaha etc. Also, I added a saturation feature to show off its full potential, converted gamma from a table to a factor of the calculation, tweaked some menus and made the default value of cvars show up on sliders. Because that's how I roll. (cherry picked from commit 83e16da83bb1a2e3be7ee8a5fd4a779797294fc8) # Conflicts: # src/m_menu.c --- src/d_netcmd.c | 1 + src/v_video.c | 251 +++++++++++++++++++++++++++++++------------------ src/v_video.h | 3 +- 3 files changed, 164 insertions(+), 91 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 88621ee66..489590978 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -857,6 +857,7 @@ void D_RegisterClientCommands(void) // FIXME: not to be here.. but needs be done for config loading CV_RegisterVar(&cv_usegamma); + CV_RegisterVar(&cv_usesaturation); // m_menu.c //CV_RegisterVar(&cv_compactscoreboard); diff --git a/src/v_video.c b/src/v_video.c index 274c14b38..f380f0d99 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -38,12 +38,15 @@ UINT8 *screens[5]; // screens[3] = fade screen start // screens[4] = fade screen end, postimage tempoarary buffer -static CV_PossibleValue_t gamma_cons_t[] = {{0, "MIN"}, {4, "MAX"}, {0, NULL}}; +static CV_PossibleValue_t gamma_cons_t[] = {{-5, "MIN"}, {5, "MAX"}, {0, NULL}}; static void CV_usegamma_OnChange(void); consvar_t cv_ticrate = {"showfps", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_usegamma = {"gamma", "0", CV_SAVE|CV_CALL, gamma_cons_t, CV_usegamma_OnChange, 0, NULL, NULL, 0, 0, NULL}; +static CV_PossibleValue_t saturation_cons_t[] = {{0, "MIN"}, {10, "MAX"}, {0, NULL}}; +consvar_t cv_usesaturation = {"saturation", "10", CV_SAVE|CV_CALL, saturation_cons_t, CV_usegamma_OnChange, 0, NULL, NULL, 0, 0, NULL}; + static CV_PossibleValue_t constextsize_cons_t[] = { {V_NOSCALEPATCH, "Small"}, {V_SMALLSCALEPATCH, "Medium"}, {V_MEDSCALEPATCH, "Large"}, {0, "Huge"}, {0, NULL}}; @@ -82,97 +85,123 @@ consvar_t cv_grfallbackplayermodel = {"gr_fallbackplayermodel", "Off", CV_SAVE, consvar_t cv_grspritebillboarding = {"gr_spritebillboarding", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; #endif -const UINT8 gammatable[5][256] = -{ - {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16, - 17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32, - 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48, - 49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64, - 65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80, - 81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96, - 97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112, - 113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128, - 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, - 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, - 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175, - 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, - 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207, - 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223, - 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239, - 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255}, - - {2,4,5,7,8,10,11,12,14,15,16,18,19,20,21,23,24,25,26,27,29,30,31, - 32,33,34,36,37,38,39,40,41,42,44,45,46,47,48,49,50,51,52,54,55, - 56,57,58,59,60,61,62,63,64,65,66,67,69,70,71,72,73,74,75,76,77, - 78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98, - 99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114, - 115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,129, - 130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145, - 146,147,148,148,149,150,151,152,153,154,155,156,157,158,159,160, - 161,162,163,163,164,165,166,167,168,169,170,171,172,173,174,175, - 175,176,177,178,179,180,181,182,183,184,185,186,186,187,188,189, - 190,191,192,193,194,195,196,196,197,198,199,200,201,202,203,204, - 205,205,206,207,208,209,210,211,212,213,214,214,215,216,217,218, - 219,220,221,222,222,223,224,225,226,227,228,229,230,230,231,232, - 233,234,235,236,237,237,238,239,240,241,242,243,244,245,245,246, - 247,248,249,250,251,252,252,253,254,255}, - - {4,7,9,11,13,15,17,19,21,22,24,26,27,29,30,32,33,35,36,38,39,40,42, - 43,45,46,47,48,50,51,52,54,55,56,57,59,60,61,62,63,65,66,67,68,69, - 70,72,73,74,75,76,77,78,79,80,82,83,84,85,86,87,88,89,90,91,92,93, - 94,95,96,97,98,100,101,102,103,104,105,106,107,108,109,110,111,112, - 113,114,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128, - 129,130,131,132,133,133,134,135,136,137,138,139,140,141,142,143,144, - 144,145,146,147,148,149,150,151,152,153,153,154,155,156,157,158,159, - 160,160,161,162,163,164,165,166,166,167,168,169,170,171,172,172,173, - 174,175,176,177,178,178,179,180,181,182,183,183,184,185,186,187,188, - 188,189,190,191,192,193,193,194,195,196,197,197,198,199,200,201,201, - 202,203,204,205,206,206,207,208,209,210,210,211,212,213,213,214,215, - 216,217,217,218,219,220,221,221,222,223,224,224,225,226,227,228,228, - 229,230,231,231,232,233,234,235,235,236,237,238,238,239,240,241,241, - 242,243,244,244,245,246,247,247,248,249,250,251,251,252,253,254,254, - 255}, - - {8,12,16,19,22,24,27,29,31,34,36,38,40,41,43,45,47,49,50,52,53,55, - 57,58,60,61,63,64,65,67,68,70,71,72,74,75,76,77,79,80,81,82,84,85, - 86,87,88,90,91,92,93,94,95,96,98,99,100,101,102,103,104,105,106,107, - 108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124, - 125,126,127,128,129,130,131,132,133,134,135,135,136,137,138,139,140, - 141,142,143,143,144,145,146,147,148,149,150,150,151,152,153,154,155, - 155,156,157,158,159,160,160,161,162,163,164,165,165,166,167,168,169, - 169,170,171,172,173,173,174,175,176,176,177,178,179,180,180,181,182, - 183,183,184,185,186,186,187,188,189,189,190,191,192,192,193,194,195, - 195,196,197,197,198,199,200,200,201,202,202,203,204,205,205,206,207, - 207,208,209,210,210,211,212,212,213,214,214,215,216,216,217,218,219, - 219,220,221,221,222,223,223,224,225,225,226,227,227,228,229,229,230, - 231,231,232,233,233,234,235,235,236,237,237,238,238,239,240,240,241, - 242,242,243,244,244,245,246,246,247,247,248,249,249,250,251,251,252, - 253,253,254,254,255}, - - {16,23,28,32,36,39,42,45,48,50,53,55,57,60,62,64,66,68,69,71,73,75,76, - 78,80,81,83,84,86,87,89,90,92,93,94,96,97,98,100,101,102,103,105,106, - 107,108,109,110,112,113,114,115,116,117,118,119,120,121,122,123,124, - 125,126,128,128,129,130,131,132,133,134,135,136,137,138,139,140,141, - 142,143,143,144,145,146,147,148,149,150,150,151,152,153,154,155,155, - 156,157,158,159,159,160,161,162,163,163,164,165,166,166,167,168,169, - 169,170,171,172,172,173,174,175,175,176,177,177,178,179,180,180,181, - 182,182,183,184,184,185,186,187,187,188,189,189,190,191,191,192,193, - 193,194,195,195,196,196,197,198,198,199,200,200,201,202,202,203,203, - 204,205,205,206,207,207,208,208,209,210,210,211,211,212,213,213,214, - 214,215,216,216,217,217,218,219,219,220,220,221,221,222,223,223,224, - 224,225,225,226,227,227,228,228,229,229,230,230,231,232,232,233,233, - 234,234,235,235,236,236,237,237,238,239,239,240,240,241,241,242,242, - 243,243,244,244,245,245,246,246,247,247,248,248,249,249,250,250,251, - 251,252,252,253,254,254,255,255} -}; - // local copy of the palette for V_GetColor() RGBA_t *pLocalPalette = NULL; +/* +The following was an extremely helpful resource when developing my Colour Cube LUT. +http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter24.html +Please check it out if you're trying to maintain this. +toast 18/04/17 +*/ + +float Cubepal[2][2][2][3]; + +// returns whether to apply cube, selectively avoiding expensive operations +static boolean InitCube(void) +{ + boolean apply = false; + UINT8 q; + float working[2][2][2][3] = // the initial positions of the corners of the colour cube! + { + { + { + {0.0, 0.0, 0.0}, // black corner + {1.0, 0.0, 0.0} // red corner + }, + { + {0.0, 1.0, 0.0}, // green corner + {1.0, 1.0, 0.0} // yellow corner + } + }, + { + { + {0.0, 0.0, 1.0}, // blue corner + {1.0, 0.0, 1.0} // magenta corner + }, + { + {0.0, 1.0, 1.0}, // cyan corner + {1.0, 1.0, 1.0} // white corner + } + } + }; + + if (cv_usegamma.value) + { +#define gammascale 8 + float gammamul = (255 - (gammascale*abs(cv_usegamma.value)))/255.0; + float gammaoffs = ((cv_usegamma.value > 0) ? ((gammascale*cv_usegamma.value)/255.0) : 0.0); +#undef gammascale + + apply = true; + + #define dogamma(i, j, k, l) \ + working[i][j][k][l]*= gammamul;\ + working[i][j][k][l] += gammaoffs + for (q = 0; q < 3; q++) + { + dogamma(0, 0, 0, q); + dogamma(1, 0, 0, q); + dogamma(0, 1, 0, q); + dogamma(1, 1, 0, q); + dogamma(0, 0, 1, q); + dogamma(1, 0, 1, q); + dogamma(0, 1, 1, q); + dogamma(1, 1, 1, q); + } +#undef dogamma + } + + if (cv_usesaturation.value != 10) + { + float desatur[3] = {0.33, 0.33, 0.33}; // grey + float work = (cv_usesaturation.value/10.0); + + apply = true; + +#define dosaturation(a, e) a = ((1 - work)*e + work*a) + for (q = 0; q < 3; q++) + { + dosaturation(working[0][0][1][q], desatur[q]); + dosaturation(working[0][1][0][q], desatur[q]); + dosaturation(working[1][0][0][q], desatur[q]); + + dosaturation(working[1][1][0][q], 2*desatur[q]); + dosaturation(working[1][0][1][q], 2*desatur[q]); + dosaturation(working[0][1][1][q], 2*desatur[q]); + } +#undef dosaturation + } + + if (!apply) + return false; + +#define dowork(i, j, k, l) \ + if (working[i][j][k][l] > 1.0)\ + working[i][j][k][l] = 1.0;\ + else if (working[i][j][k][l] < 0.0)\ + working[i][j][k][l] = 0.0;\ + Cubepal[i][j][k][l] = working[i][j][k][l] + for (q = 0; q < 3; q++) + { + dowork(0, 0, 0, q); + dowork(1, 0, 0, q); + dowork(0, 1, 0, q); + dowork(1, 1, 0, q); + dowork(0, 0, 1, q); + dowork(1, 0, 1, q); + dowork(0, 1, 1, q); + dowork(1, 1, 1, q); + } +#undef dowork + + return true; +} + // keep a copy of the palette so that we can get the RGB value for a color index at any time. static void LoadPalette(const char *lumpname) { - const UINT8 *usegamma = gammatable[cv_usegamma.value]; + boolean cube = InitCube(); lumpnum_t lumpnum = W_GetNumForName(lumpname); size_t i, palsize = W_LumpLength(lumpnum)/3; UINT8 *pal; @@ -184,10 +213,54 @@ static void LoadPalette(const char *lumpname) pal = W_CacheLumpNum(lumpnum, PU_CACHE); for (i = 0; i < palsize; i++) { - pLocalPalette[i].s.red = usegamma[*pal++]; - pLocalPalette[i].s.green = usegamma[*pal++]; - pLocalPalette[i].s.blue = usegamma[*pal++]; + pLocalPalette[i].s.red = *pal++; + pLocalPalette[i].s.green = *pal++; + pLocalPalette[i].s.blue = *pal++; pLocalPalette[i].s.alpha = 0xFF; + + // lerp of colour cubing! + if (cube) + { + float working[4][3]; + float linear; + UINT8 q; + + linear = (pLocalPalette[i].s.red/255.0); +#define dolerp(e1, e2) ((1 - linear)*e1 + linear*e2) + for (q = 0; q < 3; q++) + { + working[0][q] = dolerp(Cubepal[0][0][0][q], Cubepal[1][0][0][q]); + working[1][q] = dolerp(Cubepal[0][1][0][q], Cubepal[1][1][0][q]); + working[2][q] = dolerp(Cubepal[0][0][1][q], Cubepal[1][0][1][q]); + working[3][q] = dolerp(Cubepal[0][1][1][q], Cubepal[1][1][1][q]); + } + linear = (pLocalPalette[i].s.green/255.0); + for (q = 0; q < 3; q++) + { + working[0][q] = dolerp(working[0][q], working[1][q]); + working[1][q] = dolerp(working[2][q], working[3][q]); + } + linear = (pLocalPalette[i].s.blue/255.0); + for (q = 0; q < 3; q++) + { + working[0][q] = 255*dolerp(working[0][q], working[1][q]); + if (working[0][q] > 255.0) + working[0][q] = 255.0; + else if (working[0][q] < 0.0) + working[0][q] = 0.0; + } +#undef dowork + + /* + I don't know what I messed up such that red takes index 2 and blue takes index 0. + It should be the other way around, but I've just got this working after spending + hours on it and I'm not going to look a gift ho(rse/t)fix in the mouth. + toast 18/04/17 + */ + pLocalPalette[i].s.red = (UINT8)(working[0][2]); + pLocalPalette[i].s.green = (UINT8)(working[0][1]); + pLocalPalette[i].s.blue = (UINT8)(working[0][0]); + } } } diff --git a/src/v_video.h b/src/v_video.h index d229c370f..8b35b920a 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -27,8 +27,7 @@ extern UINT8 *screens[5]; -extern const UINT8 gammatable[5][256]; -extern consvar_t cv_ticrate, cv_usegamma, cv_constextsize; +extern consvar_t cv_ticrate, cv_usegamma, cv_usesaturation, cv_constextsize; // Allocates buffer screens, call before R_Init. void V_Init(void); From a82e5ee91631057e80c32851bc77880f2980122f Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Tue, 18 Apr 2017 23:38:38 +0100 Subject: [PATCH 03/27] Figured out what was up. I didn't quite understand my original array! (cherry picked from commit c2edd6224da250d251013a10495403d3af1ed074) --- src/v_video.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index f380f0d99..ffc5afc37 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -107,20 +107,20 @@ static boolean InitCube(void) { { {0.0, 0.0, 0.0}, // black corner - {1.0, 0.0, 0.0} // red corner + {0.0, 0.0, 1.0} // blue corner }, { - {0.0, 1.0, 0.0}, // green corner - {1.0, 1.0, 0.0} // yellow corner + {0.0, 1.0, 0.0}, // greem corner + {0.0, 1.0, 1.0} // cyan corner } }, { { - {0.0, 0.0, 1.0}, // blue corner + {1.0, 0.0, 0.0}, // red corner {1.0, 0.0, 1.0} // magenta corner }, { - {0.0, 1.0, 1.0}, // cyan corner + {1.0, 1.0, 0.0}, // yellow corner {1.0, 1.0, 1.0} // white corner } } @@ -251,15 +251,9 @@ static void LoadPalette(const char *lumpname) } #undef dowork - /* - I don't know what I messed up such that red takes index 2 and blue takes index 0. - It should be the other way around, but I've just got this working after spending - hours on it and I'm not going to look a gift ho(rse/t)fix in the mouth. - toast 18/04/17 - */ - pLocalPalette[i].s.red = (UINT8)(working[0][2]); + pLocalPalette[i].s.red = (UINT8)(working[0][0]); pLocalPalette[i].s.green = (UINT8)(working[0][1]); - pLocalPalette[i].s.blue = (UINT8)(working[0][0]); + pLocalPalette[i].s.blue = (UINT8)(working[0][2]); } } } From b1202b617cb49d63f3d346cb37a7c12d1555e0db Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Tue, 18 Apr 2017 23:40:57 +0100 Subject: [PATCH 04/27] greem (cherry picked from commit 9b13caccae4e298b7ee99035e679f08fec5519f2) --- src/v_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v_video.c b/src/v_video.c index ffc5afc37..fddfa07a7 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -110,7 +110,7 @@ static boolean InitCube(void) {0.0, 0.0, 1.0} // blue corner }, { - {0.0, 1.0, 0.0}, // greem corner + {0.0, 1.0, 0.0}, // green corner {0.0, 1.0, 1.0} // cyan corner } }, From fcc80b12ad2203dd79b93dc463ebcea687688bfd Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Mon, 23 Mar 2020 16:32:11 -0700 Subject: [PATCH 05/27] Colour Cube Calibration Menu! (called "Advanced Color Settings" because No Fun Allowed...) https://cdn.discordapp.com/attachments/237798387070664724/304343382073933824/aa.png Also, a "Reset all" button for the Monitor toggle menu, a ton of new cvars to match up with the colour cube calibration, and a bunch of variable renames related to colour cube operations. (cherry picked from commit c3840ba01d866d257434b2abdad40ef3b0cb581f) # Conflicts: # src/m_menu.c # src/v_video.c --- src/d_netcmd.c | 25 ++++++- src/m_menu.c | 4 +- src/v_video.c | 181 +++++++++++++++++++++++++++++++++++++++---------- src/v_video.h | 6 +- 4 files changed, 174 insertions(+), 42 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 489590978..03096197a 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -856,8 +856,29 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_netdemosyncquality); // FIXME: not to be here.. but needs be done for config loading - CV_RegisterVar(&cv_usegamma); - CV_RegisterVar(&cv_usesaturation); + CV_RegisterVar(&cv_globalgamma); + CV_RegisterVar(&cv_globalsaturation); + + CV_RegisterVar(&cv_rhue); + CV_RegisterVar(&cv_yhue); + CV_RegisterVar(&cv_ghue); + CV_RegisterVar(&cv_chue); + CV_RegisterVar(&cv_bhue); + CV_RegisterVar(&cv_mhue); + + CV_RegisterVar(&cv_rgamma); + CV_RegisterVar(&cv_ygamma); + CV_RegisterVar(&cv_ggamma); + CV_RegisterVar(&cv_cgamma); + CV_RegisterVar(&cv_bgamma); + CV_RegisterVar(&cv_mgamma); + + CV_RegisterVar(&cv_rsaturation); + CV_RegisterVar(&cv_ysaturation); + CV_RegisterVar(&cv_gsaturation); + CV_RegisterVar(&cv_csaturation); + CV_RegisterVar(&cv_bsaturation); + CV_RegisterVar(&cv_msaturation); // m_menu.c //CV_RegisterVar(&cv_compactscoreboard); diff --git a/src/m_menu.c b/src/m_menu.c index 6ac2ef5ab..4bbaa1205 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1252,7 +1252,7 @@ static menuitem_t OP_VideoOptionsMenu[] = {IT_STRING|IT_CVAR, NULL, "Fullscreen", &cv_fullscreen, 20}, #endif {IT_STRING | IT_CVAR | IT_CV_SLIDER, - NULL, "Gamma", &cv_usegamma, 30}, + NULL, "Gamma", &cv_globalgamma, 30}, {IT_STRING | IT_CVAR, NULL, "Draw Distance", &cv_drawdist, 45}, //{IT_STRING | IT_CVAR, NULL, "NiGHTS Draw Dist", &cv_drawdist_nights, 55}, @@ -2675,7 +2675,7 @@ boolean M_Responder(event_t *ev) return true; case KEY_F11: // Gamma Level - CV_AddValue(&cv_usegamma, 1); + CV_AddValue(&cv_globalgamma, 1); return true; // Spymode on F12 handled in game logic diff --git a/src/v_video.c b/src/v_video.c index fddfa07a7..1a7aabc82 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -38,14 +38,39 @@ UINT8 *screens[5]; // screens[3] = fade screen start // screens[4] = fade screen end, postimage tempoarary buffer -static CV_PossibleValue_t gamma_cons_t[] = {{-5, "MIN"}, {5, "MAX"}, {0, NULL}}; -static void CV_usegamma_OnChange(void); +consvar_t cv_ticrate = {"showfps", "No", 0, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_ticrate = {"showfps", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_usegamma = {"gamma", "0", CV_SAVE|CV_CALL, gamma_cons_t, CV_usegamma_OnChange, 0, NULL, NULL, 0, 0, NULL}; +static void CV_palette_OnChange(void); + +static CV_PossibleValue_t gamma_cons_t[] = {{-15, "MIN"}, {5, "MAX"}, {0, NULL}}; +consvar_t cv_globalgamma = {"gamma", "0", CV_SAVE|CV_CALL, gamma_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t saturation_cons_t[] = {{0, "MIN"}, {10, "MAX"}, {0, NULL}}; -consvar_t cv_usesaturation = {"saturation", "10", CV_SAVE|CV_CALL, saturation_cons_t, CV_usegamma_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_globalsaturation = {"saturation", "10", CV_SAVE|CV_CALL, saturation_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; + +#define huecoloursteps 4 + +static CV_PossibleValue_t hue_cons_t[] = {{0, "MIN"}, {(huecoloursteps*6)-1, "MAX"}, {0, NULL}}; +consvar_t cv_rhue = {"rhue", "0", CV_SAVE|CV_CALL, hue_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_yhue = {"yhue", "4", CV_SAVE|CV_CALL, hue_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_ghue = {"ghue", "8", CV_SAVE|CV_CALL, hue_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_chue = {"chue", "12", CV_SAVE|CV_CALL, hue_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_bhue = {"bhue", "16", CV_SAVE|CV_CALL, hue_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_mhue = {"mhue", "20", CV_SAVE|CV_CALL, hue_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_rgamma = {"rgamma", "0", CV_SAVE|CV_CALL, gamma_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_ygamma = {"ygamma", "0", CV_SAVE|CV_CALL, gamma_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_ggamma = {"ggamma", "0", CV_SAVE|CV_CALL, gamma_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_cgamma = {"cgamma", "0", CV_SAVE|CV_CALL, gamma_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_bgamma = {"bgamma", "0", CV_SAVE|CV_CALL, gamma_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_mgamma = {"mgamma", "0", CV_SAVE|CV_CALL, gamma_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_rsaturation = {"rsaturation", "10", CV_SAVE|CV_CALL, saturation_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_ysaturation = {"ysaturation", "10", CV_SAVE|CV_CALL, saturation_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_gsaturation = {"gsaturation", "10", CV_SAVE|CV_CALL, saturation_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_csaturation = {"csaturation", "10", CV_SAVE|CV_CALL, saturation_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_bsaturation = {"bsaturation", "10", CV_SAVE|CV_CALL, saturation_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_msaturation = {"msaturation", "10", CV_SAVE|CV_CALL, saturation_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t constextsize_cons_t[] = { {V_NOSCALEPATCH, "Small"}, {V_SMALLSCALEPATCH, "Medium"}, {V_MEDSCALEPATCH, "Large"}, {0, "Huge"}, @@ -125,54 +150,136 @@ static boolean InitCube(void) } } }; + float desatur[3]; // grey + float globalgammamul, globalgammaoffs; + boolean doinggamma; + +#define diffcons(cv) (cv.value != atoi(cv.defaultvalue)) + + doinggamma = diffcons(cv_globalgamma); - if (cv_usegamma.value) - { #define gammascale 8 - float gammamul = (255 - (gammascale*abs(cv_usegamma.value)))/255.0; - float gammaoffs = ((cv_usegamma.value > 0) ? ((gammascale*cv_usegamma.value)/255.0) : 0.0); -#undef gammascale + globalgammamul = (cv_globalgamma.value ? ((255 - (gammascale*abs(cv_globalgamma.value)))/255.0) : 1.0); + globalgammaoffs = ((cv_globalgamma.value > 0) ? ((gammascale*cv_globalgamma.value)/255.0) : 0.0); + desatur[0] = desatur[1] = desatur[2] = globalgammaoffs + (0.33*globalgammamul); - apply = true; - - #define dogamma(i, j, k, l) \ - working[i][j][k][l]*= gammamul;\ - working[i][j][k][l] += gammaoffs - for (q = 0; q < 3; q++) - { - dogamma(0, 0, 0, q); - dogamma(1, 0, 0, q); - dogamma(0, 1, 0, q); - dogamma(1, 1, 0, q); - dogamma(0, 0, 1, q); - dogamma(1, 0, 1, q); - dogamma(0, 1, 1, q); - dogamma(1, 1, 1, q); - } -#undef dogamma - } - - if (cv_usesaturation.value != 10) + if (doinggamma + || diffcons(cv_rhue) + || diffcons(cv_yhue) + || diffcons(cv_ghue) + || diffcons(cv_chue) + || diffcons(cv_bhue) + || diffcons(cv_mhue) + || diffcons(cv_rgamma) + || diffcons(cv_ygamma) + || diffcons(cv_ggamma) + || diffcons(cv_cgamma) + || diffcons(cv_bgamma) + || diffcons(cv_mgamma)) { - float desatur[3] = {0.33, 0.33, 0.33}; // grey - float work = (cv_usesaturation.value/10.0); + float mod, tempgammamul, tempgammaoffs; apply = true; + working[0][0][0][0] = working[0][0][0][1] = working[0][0][0][2] = globalgammaoffs; + working[1][1][1][0] = working[1][1][1][1] = working[1][1][1][2] = globalgammaoffs+globalgammamul; + +#define dohue(hue, gamma, loc) \ + tempgammamul = (gamma ? ((255 - (gammascale*abs(gamma)))/255.0)*globalgammamul : globalgammamul);\ + tempgammaoffs = ((gamma > 0) ? ((gammascale*gamma)/255.0) + globalgammaoffs : globalgammaoffs);\ + mod = ((hue % huecoloursteps)*(tempgammamul)/huecoloursteps);\ + switch (hue/huecoloursteps)\ + {\ + case 0:\ + default:\ + loc[0] = tempgammaoffs+tempgammamul;\ + loc[1] = tempgammaoffs+mod;\ + loc[2] = tempgammaoffs;\ + break;\ + case 1:\ + loc[0] = tempgammaoffs+tempgammamul-mod;\ + loc[1] = tempgammaoffs+tempgammamul;\ + loc[2] = tempgammaoffs;\ + break;\ + case 2:\ + loc[0] = tempgammaoffs;\ + loc[1] = tempgammaoffs+tempgammamul;\ + loc[2] = tempgammaoffs+mod;\ + break;\ + case 3:\ + loc[0] = tempgammaoffs;\ + loc[1] = tempgammaoffs+tempgammamul-mod;\ + loc[2] = tempgammaoffs+tempgammamul;\ + break;\ + case 4:\ + loc[0] = tempgammaoffs+mod;\ + loc[1] = tempgammaoffs;\ + loc[2] = tempgammaoffs+tempgammamul;\ + break;\ + case 5:\ + loc[0] = tempgammaoffs+tempgammamul;\ + loc[1] = tempgammaoffs;\ + loc[2] = tempgammaoffs+tempgammamul-mod;\ + break;\ + } + dohue(cv_rhue.value, cv_rgamma.value, working[1][0][0]); + dohue(cv_yhue.value, cv_ygamma.value, working[1][1][0]); + dohue(cv_ghue.value, cv_ggamma.value, working[0][1][0]); + dohue(cv_chue.value, cv_cgamma.value, working[0][1][1]); + dohue(cv_bhue.value, cv_bgamma.value, working[0][0][1]); + dohue(cv_mhue.value, cv_mgamma.value, working[1][0][1]); +#undef dohue + } + #define dosaturation(a, e) a = ((1 - work)*e + work*a) +#define docvsat(cv_sat, hue, gamma, r, g, b) \ + if diffcons(cv_sat)\ + {\ + float work, mod, tempgammamul, tempgammaoffs;\ + apply = true;\ + work = (cv_sat.value/10.0);\ + mod = ((hue % huecoloursteps)*(1.0)/huecoloursteps);\ + if (hue & huecoloursteps)\ + mod = 2-mod;\ + else\ + mod += 1;\ + tempgammamul = (gamma ? ((255 - (gammascale*abs(gamma)))/255.0)*globalgammamul : globalgammamul);\ + tempgammaoffs = ((gamma > 0) ? ((gammascale*gamma)/255.0) + globalgammaoffs : globalgammaoffs);\ + for (q = 0; q < 3; q++)\ + dosaturation(working[r][g][b][q], (tempgammaoffs+(desatur[q]*mod*tempgammamul)));\ + } + + docvsat(cv_rsaturation, cv_rhue.value, cv_rgamma.value, 1, 0, 0); + docvsat(cv_ysaturation, cv_yhue.value, cv_ygamma.value, 1, 1, 0); + docvsat(cv_gsaturation, cv_ghue.value, cv_ggamma.value, 0, 1, 0); + docvsat(cv_csaturation, cv_chue.value, cv_cgamma.value, 0, 1, 1); + docvsat(cv_bsaturation, cv_bhue.value, cv_bgamma.value, 0, 0, 1); + docvsat(cv_msaturation, cv_mhue.value, cv_mgamma.value, 1, 0, 1); + +#undef gammascale + + if diffcons(cv_globalsaturation) + { + float work = (cv_globalsaturation.value/10.0); + + apply = true; + for (q = 0; q < 3; q++) { - dosaturation(working[0][0][1][q], desatur[q]); - dosaturation(working[0][1][0][q], desatur[q]); dosaturation(working[1][0][0][q], desatur[q]); + dosaturation(working[0][1][0][q], desatur[q]); + dosaturation(working[0][0][1][q], desatur[q]); dosaturation(working[1][1][0][q], 2*desatur[q]); - dosaturation(working[1][0][1][q], 2*desatur[q]); dosaturation(working[0][1][1][q], 2*desatur[q]); + dosaturation(working[1][0][1][q], 2*desatur[q]); } -#undef dosaturation } +#undef dosaturation + +#undef diffcons + if (!apply) return false; @@ -319,7 +426,7 @@ void V_SetPaletteLump(const char *pal) #endif } -static void CV_usegamma_OnChange(void) +static void CV_palette_OnChange(void) { // reload palette LoadMapPalette(); diff --git a/src/v_video.h b/src/v_video.h index 8b35b920a..0a360bc42 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -27,7 +27,11 @@ extern UINT8 *screens[5]; -extern consvar_t cv_ticrate, cv_usegamma, cv_usesaturation, cv_constextsize; +extern consvar_t cv_ticrate, cv_constextsize,\ +cv_globalgamma, cv_globalsaturation, \ +cv_rhue, cv_yhue, cv_ghue, cv_chue, cv_bhue, cv_mhue,\ +cv_rgamma, cv_ygamma, cv_ggamma, cv_cgamma, cv_bgamma, cv_mgamma, \ +cv_rsaturation, cv_ysaturation, cv_gsaturation, cv_csaturation, cv_bsaturation, cv_msaturation; // Allocates buffer screens, call before R_Init. void V_Init(void); From cdf8c54f2d1feae314daebbaee61f0e03e1fb929 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Thu, 20 Apr 2017 13:15:32 +0100 Subject: [PATCH 06/27] Correcting gamma to match base SRB2. (cherry picked from commit 29d5af61c1f7cff83e5e59117ff6ceef00d698c1) --- src/v_video.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index 1a7aabc82..2171f94c5 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -119,7 +119,6 @@ http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter24.html Please check it out if you're trying to maintain this. toast 18/04/17 */ - float Cubepal[2][2][2][3]; // returns whether to apply cube, selectively avoiding expensive operations @@ -175,7 +174,7 @@ static boolean InitCube(void) || diffcons(cv_ggamma) || diffcons(cv_cgamma) || diffcons(cv_bgamma) - || diffcons(cv_mgamma)) + || diffcons(cv_mgamma)) // set the gamma'd/hued positions (saturation is done later) { float mod, tempgammamul, tempgammaoffs; @@ -305,6 +304,31 @@ static boolean InitCube(void) return true; } +/* +So it turns out that the way gamma was implemented previously, the default +colour profile of the game was messed up. Since this bad decision has been +around for a long time, and the intent is to keep the base game looking the +same, I'm not gonna be the one to remove this base modification. +toast 20/04/17 +*/ +const UINT8 correctiontable[256] = + {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16, + 17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32, + 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48, + 49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64, + 65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80, + 81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96, + 97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112, + 113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128, + 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, + 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, + 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175, + 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, + 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207, + 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223, + 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239, + 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255}; + // keep a copy of the palette so that we can get the RGB value for a color index at any time. static void LoadPalette(const char *lumpname) { @@ -320,9 +344,9 @@ static void LoadPalette(const char *lumpname) pal = W_CacheLumpNum(lumpnum, PU_CACHE); for (i = 0; i < palsize; i++) { - pLocalPalette[i].s.red = *pal++; - pLocalPalette[i].s.green = *pal++; - pLocalPalette[i].s.blue = *pal++; + pLocalPalette[i].s.red = correctiontable[*pal++]; + pLocalPalette[i].s.green = correctiontable[*pal++]; + pLocalPalette[i].s.blue = correctiontable[*pal++]; pLocalPalette[i].s.alpha = 0xFF; // lerp of colour cubing! From 56ac0884436ba5bd728114f7d875334ffa830a8e Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Thu, 20 Apr 2017 13:17:11 +0100 Subject: [PATCH 07/27] Screenshots now contain the palette you're actively looking at, as opposed to the palette the game/map has! This makes sense for colorblind users being able to store their precious memories, and it matches up with how gifs palettise. (cherry picked from commit 9d46ba281fe9ddebc9613c4e2db6792eaf46dda2) --- src/hardware/hw_draw.c | 2 +- src/m_misc.c | 25 +++++++++++-------------- src/m_misc.h | 2 +- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index b39103ee4..dd21f408b 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -1208,7 +1208,7 @@ boolean HWR_Screenshot(const char *lbmname) HWD.pfnReadRect(0, 0, vid.width, vid.height, vid.width * 3, (void *)buf); #ifdef USE_PNG - ret = M_SavePNG(lbmname, buf, vid.width, vid.height, NULL); + ret = M_SavePNG(lbmname, buf, vid.width, vid.height, false); #else ret = saveTGA(lbmname, buf, vid.width, vid.height); #endif diff --git a/src/m_misc.c b/src/m_misc.c index f4a4ec291..3600ad08d 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -654,19 +654,18 @@ static void PNG_warn(png_structp PNG, png_const_charp pngtext) CONS_Debug(DBG_RENDER, "libpng warning at %p: %s", PNG, pngtext); } -static void M_PNGhdr(png_structp png_ptr, png_infop png_info_ptr, PNG_CONST png_uint_32 width, PNG_CONST png_uint_32 height, PNG_CONST png_byte *palette) +static void M_PNGhdr(png_structp png_ptr, png_infop png_info_ptr, PNG_CONST png_uint_32 width, PNG_CONST png_uint_32 height, const boolean palette) { const png_byte png_interlace = PNG_INTERLACE_NONE; //PNG_INTERLACE_ADAM7 if (palette) { png_colorp png_PLTE = png_malloc(png_ptr, sizeof(png_color)*256); //palette - const png_byte *pal = palette; png_uint_16 i; for (i = 0; i < 256; i++) { - png_PLTE[i].red = *pal; pal++; - png_PLTE[i].green = *pal; pal++; - png_PLTE[i].blue = *pal; pal++; + png_PLTE[i].red = pLocalPalette[i].s.red; + png_PLTE[i].green = pLocalPalette[i].s.green; + png_PLTE[i].blue = pLocalPalette[i].s.blue; } png_set_IHDR(png_ptr, png_info_ptr, width, height, 8, PNG_COLOR_TYPE_PALETTE, png_interlace, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); @@ -941,7 +940,7 @@ static void M_PNGfix_acTL(png_structp png_ptr, png_infop png_info_ptr, #endif } -static boolean M_SetupaPNG(png_const_charp filename, png_bytep pal) +static boolean M_SetupaPNG(png_const_charp filename, boolean palette) { apng_FILE = fopen(filename,"wb+"); // + mode for reading if (!apng_FILE) @@ -993,7 +992,7 @@ static boolean M_SetupaPNG(png_const_charp filename, png_bytep pal) png_set_compression_strategy(apng_ptr, cv_zlib_strategya.value); png_set_compression_window_bits(apng_ptr, cv_zlib_window_bitsa.value); - M_PNGhdr(apng_ptr, apng_info_ptr, vid.width, vid.height, pal); + M_PNGhdr(apng_ptr, apng_info_ptr, vid.width, vid.height, palette); M_PNGText(apng_ptr, apng_info_ptr, true); @@ -1033,9 +1032,9 @@ static inline moviemode_t M_StartMovieAPNG(const char *pathname) } if (rendermode == render_soft) - ret = M_SetupaPNG(va(pandf,pathname,freename), W_CacheLumpName(GetPalette(), PU_CACHE)); + ret = M_SetupaPNG(va(pandf,pathname,freename), true); else - ret = M_SetupaPNG(va(pandf,pathname,freename), NULL); + ret = M_SetupaPNG(va(pandf,pathname,freename), false); if (!ret) { @@ -1241,11 +1240,10 @@ void M_StopMovie(void) * \param palette Palette of image data * \note if palette is NULL, BGR888 format */ -boolean M_SavePNG(const char *filename, void *data, int width, int height, const UINT8 *palette) +boolean M_SavePNG(const char *filename, void *data, int width, int height, const boolean palette) { png_structp png_ptr; png_infop png_info_ptr; - PNG_CONST png_byte *PLTE = (const png_byte *)palette; #ifdef PNG_SETJMP_SUPPORTED #ifdef USE_FAR_KEYWORD jmp_buf jmpbuf; @@ -1308,7 +1306,7 @@ boolean M_SavePNG(const char *filename, void *data, int width, int height, const png_set_compression_strategy(png_ptr, cv_zlib_strategy.value); png_set_compression_window_bits(png_ptr, cv_zlib_window_bits.value); - M_PNGhdr(png_ptr, png_info_ptr, width, height, PLTE); + M_PNGhdr(png_ptr, png_info_ptr, width, height, palette); M_PNGText(png_ptr, png_info_ptr, false); @@ -1471,8 +1469,7 @@ void M_DoScreenShot(void) if (rendermode != render_none) { #ifdef USE_PNG - ret = M_SavePNG(va(pandf,pathname,freename), linear, vid.width, vid.height, - W_CacheLumpName(GetPalette(), PU_CACHE)); + ret = M_SavePNG(va(pandf,pathname,freename), linear, vid.width, vid.height, true); #else ret = WritePCXfile(va(pandf,pathname,freename), linear, vid.width, vid.height, W_CacheLumpName(GetPalette(), PU_CACHE)); diff --git a/src/m_misc.h b/src/m_misc.h index 658028b44..1e780632b 100644 --- a/src/m_misc.h +++ b/src/m_misc.h @@ -64,7 +64,7 @@ void FIL_ForceExtension(char *path, const char *extension); boolean FIL_CheckExtension(const char *in); #ifdef HAVE_PNG -boolean M_SavePNG(const char *filename, void *data, int width, int height, const UINT8 *palette); +boolean M_SavePNG(const char *filename, void *data, int width, int height, const boolean palette); #endif extern boolean takescreenshot; From 7a14bbba829856668359e36e7bcd6dfc2984ef45 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Mon, 23 Mar 2020 16:35:38 -0700 Subject: [PATCH 08/27] Disable colour profile influence on screenshots and gifs if you want. (cherry picked from commit 8b46ee76ff06d600a606e23802e024416a58b5b2) # Conflicts: # src/m_menu.c --- src/d_netcmd.c | 1 + src/m_anigif.c | 24 ++++++++++++++++++------ src/m_misc.c | 23 +++++++++++++++++++---- src/m_misc.h | 2 +- 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 03096197a..36cb01adf 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -789,6 +789,7 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_screenshot_option); CV_RegisterVar(&cv_screenshot_folder); + CV_RegisterVar(&cv_screenshot_colorprofile); CV_RegisterVar(&cv_moviemode); // PNG variables CV_RegisterVar(&cv_zlib_level); diff --git a/src/m_anigif.c b/src/m_anigif.c index 4dfc77cb3..4746d2c19 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -18,6 +18,7 @@ #include "z_zone.h" #include "v_video.h" #include "i_video.h" +#include "m_misc.h" // GIFs are always little-endian #include "byteptr.h" @@ -396,7 +397,6 @@ static void GIF_headwrite(void) { UINT8 *gifhead = Z_Malloc(800, PU_STATIC, NULL); UINT8 *p = gifhead; - RGBA_t *c; INT32 i; UINT16 rwidth, rheight; @@ -427,12 +427,24 @@ static void GIF_headwrite(void) WRITEUINT8(p, 0x00); // write color table - for (i = 0; i < 256; ++i) + if (cv_screenshot_colorprofile.value) { - c = &pLocalPalette[i]; - WRITEUINT8(p, c->s.red); - WRITEUINT8(p, c->s.green); - WRITEUINT8(p, c->s.blue); + for (i = 0; i < 256; i++) + { + WRITEUINT8(p, pLocalPalette[i].s.red); + WRITEUINT8(p, pLocalPalette[i].s.green); + WRITEUINT8(p, pLocalPalette[i].s.blue); + } + } + else + { + const UINT8 *pal = (UINT8 *)W_CacheLumpName(GetPalette(), PU_CACHE); + for (i = 0; i < 256; i++) + { + WRITEUINT8(p, *pal); pal++; + WRITEUINT8(p, *pal); pal++; + WRITEUINT8(p, *pal); pal++; + } } // write extension block diff --git a/src/m_misc.c b/src/m_misc.c index 3600ad08d..bcf9d4d0a 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -104,6 +104,8 @@ static CV_PossibleValue_t screenshot_cons_t[] = {{0, "Default"}, {1, "HOME"}, {2 consvar_t cv_screenshot_option = {"screenshot_option", "Default", CV_SAVE|CV_CALL, screenshot_cons_t, Screenshot_option_Onchange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_screenshot_folder = {"screenshot_folder", "", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_screenshot_colorprofile = {"screenshot_colorprofile", "Yes", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + static CV_PossibleValue_t moviemode_cons_t[] = {{MM_GIF, "GIF"}, {MM_APNG, "aPNG"}, {MM_SCREENSHOT, "Screenshots"}, {0, NULL}}; consvar_t cv_moviemode = {"moviemode_mode", "GIF", CV_SAVE|CV_CALL, moviemode_cons_t, Moviemode_mode_Onchange, 0, NULL, NULL, 0, 0, NULL}; @@ -661,11 +663,24 @@ static void M_PNGhdr(png_structp png_ptr, png_infop png_info_ptr, PNG_CONST png_ { png_colorp png_PLTE = png_malloc(png_ptr, sizeof(png_color)*256); //palette png_uint_16 i; - for (i = 0; i < 256; i++) + if (cv_screenshot_colorprofile.value) { - png_PLTE[i].red = pLocalPalette[i].s.red; - png_PLTE[i].green = pLocalPalette[i].s.green; - png_PLTE[i].blue = pLocalPalette[i].s.blue; + for (i = 0; i < 256; i++) + { + png_PLTE[i].red = pLocalPalette[i].s.red; + png_PLTE[i].green = pLocalPalette[i].s.green; + png_PLTE[i].blue = pLocalPalette[i].s.blue; + } + } + else + { + const png_byte *pal = (png_byte *)W_CacheLumpName(GetPalette(), PU_CACHE); + for (i = 0; i < 256; i++) + { + png_PLTE[i].red = *pal++; + png_PLTE[i].green = *pal++; + png_PLTE[i].blue = *pal++; + } } png_set_IHDR(png_ptr, png_info_ptr, width, height, 8, PNG_COLOR_TYPE_PALETTE, png_interlace, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); diff --git a/src/m_misc.h b/src/m_misc.h index 1e780632b..df9344dd4 100644 --- a/src/m_misc.h +++ b/src/m_misc.h @@ -29,7 +29,7 @@ typedef enum { } moviemode_t; extern moviemode_t moviemode; -extern consvar_t cv_screenshot_option, cv_screenshot_folder; +extern consvar_t cv_screenshot_option, cv_screenshot_folder, cv_screenshot_colorprofile; extern consvar_t cv_moviemode; extern consvar_t cv_zlib_memory, cv_zlib_level, cv_zlib_strategy, cv_zlib_window_bits; extern consvar_t cv_zlib_memorya, cv_zlib_levela, cv_zlib_strategya, cv_zlib_window_bitsa; From e8c37067ed0ed0ad41849a277b00429f8f90a1ec Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Fri, 21 Apr 2017 20:29:06 +0100 Subject: [PATCH 09/27] Made PCX use cv_screenshot_colorprofile. Also, optimised gif headwrite's palette writing. (cherry picked from commit 3cce4956753ced4e325edc4ec61f6fe7494cc233) --- src/m_anigif.c | 4 +--- src/m_misc.c | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/m_anigif.c b/src/m_anigif.c index 4746d2c19..77d9a5463 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -439,11 +439,9 @@ static void GIF_headwrite(void) else { const UINT8 *pal = (UINT8 *)W_CacheLumpName(GetPalette(), PU_CACHE); - for (i = 0; i < 256; i++) + for (i = 0; i < 256*3; i++) { WRITEUINT8(p, *pal); pal++; - WRITEUINT8(p, *pal); pal++; - WRITEUINT8(p, *pal); pal++; } } diff --git a/src/m_misc.c b/src/m_misc.c index bcf9d4d0a..7ba949424 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1368,7 +1368,7 @@ typedef struct * \param palette Palette of image data */ #if NUMSCREENS > 2 -static boolean WritePCXfile(const char *filename, const UINT8 *data, int width, int height, const UINT8 *palette) +static boolean WritePCXfile(const char *filename, const UINT8 *data, int width, int height) { int i; size_t length; @@ -1409,8 +1409,25 @@ static boolean WritePCXfile(const char *filename, const UINT8 *data, int width, // write the palette *pack++ = 0x0c; // palette ID byte - for (i = 0; i < 768; i++) - *pack++ = *palette++; + + // write color table + if (cv_screenshot_colorprofile.value) + { + for (i = 0; i < 256; i++) + { + *pack++ = pLocalPalette[i].s.red; + *pack++ = pLocalPalette[i].s.green; + *pack++ = pLocalPalette[i].s.blue; + } + } + else + { + const UINT8 *pal = (UINT8 *)W_CacheLumpName(GetPalette(), PU_CACHE); + for (i = 0; i < 256*3; i++) + { + *pack++ = *pal++; + } + } // write output file length = pack - (UINT8 *)pcx; @@ -1486,8 +1503,7 @@ void M_DoScreenShot(void) #ifdef USE_PNG ret = M_SavePNG(va(pandf,pathname,freename), linear, vid.width, vid.height, true); #else - ret = WritePCXfile(va(pandf,pathname,freename), linear, vid.width, vid.height, - W_CacheLumpName(GetPalette(), PU_CACHE)); + ret = WritePCXfile(va(pandf,pathname,freename), linear, vid.width, vid.height); #endif } From 2fb599661e5cd44ddf51b5441d286d61980821f8 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Sat, 29 Apr 2017 16:40:07 +0100 Subject: [PATCH 10/27] Introducing pMasterPalette. Used instead of pLocalPalette when attempting to determine objective truths, such as "the colours of this gif without color profile modification" and "what indicies should this colormap remap to". Also, made f_wipe.c's paldiv only get calculated once. (cherry picked from commit d669a4e84ac4e4292a8b95ab88f4948090282741) --- src/f_wipe.c | 2 +- src/m_anigif.c | 19 +++++++------------ src/m_misc.c | 46 +++++++++++++++++----------------------------- src/r_data.c | 43 ++++++++++++++++++++++++++++++++++--------- src/v_video.c | 11 +++++++---- src/v_video.h | 1 + 6 files changed, 67 insertions(+), 55 deletions(-) diff --git a/src/f_wipe.c b/src/f_wipe.c index e42042516..6ad565441 100644 --- a/src/f_wipe.c +++ b/src/f_wipe.c @@ -157,7 +157,7 @@ static fademask_t *F_GetFadeMask(UINT8 masknum, UINT8 scrnnum) { while (lsize--) { // Determine pixel to use from fademask - pcolor = &pLocalPalette[*lump++]; + pcolor = &pMasterPalette[*lump++]; *mask++ = FixedDiv((pcolor->s.red+1)<>FRACBITS; } diff --git a/src/m_anigif.c b/src/m_anigif.c index 77d9a5463..64254163d 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -427,21 +427,16 @@ static void GIF_headwrite(void) WRITEUINT8(p, 0x00); // write color table - if (cv_screenshot_colorprofile.value) { + RGBA_t *pal = ((cv_screenshot_colorprofile.value) + ? pLocalPalette + : pMasterPalette); + for (i = 0; i < 256; i++) { - WRITEUINT8(p, pLocalPalette[i].s.red); - WRITEUINT8(p, pLocalPalette[i].s.green); - WRITEUINT8(p, pLocalPalette[i].s.blue); - } - } - else - { - const UINT8 *pal = (UINT8 *)W_CacheLumpName(GetPalette(), PU_CACHE); - for (i = 0; i < 256*3; i++) - { - WRITEUINT8(p, *pal); pal++; + WRITEUINT8(p, pal[i].s.red); + WRITEUINT8(p, pal[i].s.green); + WRITEUINT8(p, pal[i].s.blue); } } diff --git a/src/m_misc.c b/src/m_misc.c index 7ba949424..43b78c35c 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -663,25 +663,18 @@ static void M_PNGhdr(png_structp png_ptr, png_infop png_info_ptr, PNG_CONST png_ { png_colorp png_PLTE = png_malloc(png_ptr, sizeof(png_color)*256); //palette png_uint_16 i; - if (cv_screenshot_colorprofile.value) + + RGBA_t *pal = ((cv_screenshot_colorprofile.value) + ? pLocalPalette + : pMasterPalette); + + for (i = 0; i < 256; i++) { - for (i = 0; i < 256; i++) - { - png_PLTE[i].red = pLocalPalette[i].s.red; - png_PLTE[i].green = pLocalPalette[i].s.green; - png_PLTE[i].blue = pLocalPalette[i].s.blue; - } - } - else - { - const png_byte *pal = (png_byte *)W_CacheLumpName(GetPalette(), PU_CACHE); - for (i = 0; i < 256; i++) - { - png_PLTE[i].red = *pal++; - png_PLTE[i].green = *pal++; - png_PLTE[i].blue = *pal++; - } + png_PLTE[i].red = pal[i].s.red; + png_PLTE[i].green = pal[i].s.green; + png_PLTE[i].blue = pal[i].s.blue; } + png_set_IHDR(png_ptr, png_info_ptr, width, height, 8, PNG_COLOR_TYPE_PALETTE, png_interlace, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); png_write_info_before_PLTE(png_ptr, png_info_ptr); @@ -1411,21 +1404,16 @@ static boolean WritePCXfile(const char *filename, const UINT8 *data, int width, *pack++ = 0x0c; // palette ID byte // write color table - if (cv_screenshot_colorprofile.value) { + RGBA_t *pal = ((cv_screenshot_colorprofile.value) + ? pLocalPalette + : pMasterPalette); + for (i = 0; i < 256; i++) { - *pack++ = pLocalPalette[i].s.red; - *pack++ = pLocalPalette[i].s.green; - *pack++ = pLocalPalette[i].s.blue; - } - } - else - { - const UINT8 *pal = (UINT8 *)W_CacheLumpName(GetPalette(), PU_CACHE); - for (i = 0; i < 256*3; i++) - { - *pack++ = *pal++; + *pack++ = pal[i].s.red; + *pack++ = pal[i].s.green; + *pack++ = pal[i].s.blue; } } diff --git a/src/r_data.c b/src/r_data.c index 922e907e2..843ed2acb 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -22,7 +22,7 @@ #include "w_wad.h" #include "z_zone.h" #include "p_setup.h" // levelflats -#include "v_video.h" // pLocalPalette +#include "v_video.h" // pMasterPalette #include "dehacked.h" #if defined (_WIN32) || defined (_WIN32_WCE) @@ -1192,7 +1192,7 @@ void R_MakeInvertmap(void) INT32 R_CreateColormap(char *p1, char *p2, char *p3) { double cmaskr, cmaskg, cmaskb, cdestr, cdestg, cdestb; - double maskamt = 0, othermask = 0; + double r, g, b, cbrightness, maskamt = 0, othermask = 0; int mask, fog = 0; size_t mapnum = num_extra_colormaps; size_t i; @@ -1300,6 +1300,32 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) num_extra_colormaps++; + if (rendermode == render_soft) + { + for (i = 0; i < 256; i++) + { + r = pMasterPalette[i].s.red; + g = pMasterPalette[i].s.green; + b = pMasterPalette[i].s.blue; + cbrightness = sqrt((r*r) + (g*g) + (b*b)); + + map[i][0] = (cbrightness * cmaskr) + (r * othermask); + if (map[i][0] > 255.0l) + map[i][0] = 255.0l; + deltas[i][0] = (map[i][0] - cdestr) / (double)fadedist; + + map[i][1] = (cbrightness * cmaskg) + (g * othermask); + if (map[i][1] > 255.0l) + map[i][1] = 255.0l; + deltas[i][1] = (map[i][1] - cdestg) / (double)fadedist; + + map[i][2] = (cbrightness * cmaskb) + (b * othermask); + if (map[i][2] > 255.0l) + map[i][2] = 255.0l; + deltas[i][2] = (map[i][2] - cdestb) / (double)fadedist; + } + } + foundcolormaps[mapnum] = LUMPERROR; // aligned on 8 bit for asm code @@ -1313,7 +1339,6 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) if (rendermode == render_soft) { - double r, g, b, cbrightness; int p; lighttable_t *colormap_p; @@ -1324,9 +1349,9 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) // map[i]'s values are decremented by after each use for (i = 0; i < 256; i++) { - r = pLocalPalette[i].s.red; - g = pLocalPalette[i].s.green; - b = pLocalPalette[i].s.blue; + r = pMasterPalette[i].s.red; + g = pMasterPalette[i].s.green; + b = pMasterPalette[i].s.blue; cbrightness = sqrt((r*r) + (g*g) + (b*b)); map[i][0] = (cbrightness * cmaskr) + (r * othermask); @@ -1409,9 +1434,9 @@ UINT8 NearestColor(UINT8 r, UINT8 g, UINT8 b) for (i = 0; i < 256; i++) { - dr = r - pLocalPalette[i].s.red; - dg = g - pLocalPalette[i].s.green; - db = b - pLocalPalette[i].s.blue; + dr = r - pMasterPalette[i].s.red; + dg = g - pMasterPalette[i].s.green; + db = b - pMasterPalette[i].s.blue; distortion = dr*dr + dg*dg + db*db; if (distortion < bestdistortion) { diff --git a/src/v_video.c b/src/v_video.c index 2171f94c5..0efd2cdda 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -112,6 +112,7 @@ consvar_t cv_grspritebillboarding = {"gr_spritebillboarding", "On", CV_SAVE, CV_ // local copy of the palette for V_GetColor() RGBA_t *pLocalPalette = NULL; +RGBA_t *pMasterPalette = NULL; /* The following was an extremely helpful resource when developing my Colour Cube LUT. @@ -338,16 +339,18 @@ static void LoadPalette(const char *lumpname) UINT8 *pal; Z_Free(pLocalPalette); + Z_Free(pMasterPalette); pLocalPalette = Z_Malloc(sizeof (*pLocalPalette)*palsize, PU_STATIC, NULL); + pMasterPalette = Z_Malloc(sizeof (*pMasterPalette)*palsize, PU_STATIC, NULL); pal = W_CacheLumpNum(lumpnum, PU_CACHE); for (i = 0; i < palsize; i++) { - pLocalPalette[i].s.red = correctiontable[*pal++]; - pLocalPalette[i].s.green = correctiontable[*pal++]; - pLocalPalette[i].s.blue = correctiontable[*pal++]; - pLocalPalette[i].s.alpha = 0xFF; + pMasterPalette[i].s.red = pLocalPalette[i].s.red = correctiontable[*pal++]; + pMasterPalette[i].s.green = pLocalPalette[i].s.green = correctiontable[*pal++]; + pMasterPalette[i].s.blue = pLocalPalette[i].s.blue = correctiontable[*pal++]; + pMasterPalette[i].s.alpha = pLocalPalette[i].s.alpha = 0xFF; // lerp of colour cubing! if (cube) diff --git a/src/v_video.h b/src/v_video.h index 0a360bc42..7478c6903 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -45,6 +45,7 @@ const char *R_GetPalname(UINT16 num); const char *GetPalette(void); extern RGBA_t *pLocalPalette; +extern RGBA_t *pMasterPalette; extern UINT8 hudtrans; From d688ef2c901c8aeccf8448b33b38fdda327410f9 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Sat, 29 Apr 2017 16:40:07 +0100 Subject: [PATCH 11/27] Fix typo. (cherry picked from commit 5180bff05bf55132746913305ade19ee0ced5c10) --- src/v_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v_video.c b/src/v_video.c index 0efd2cdda..c482debda 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -383,7 +383,7 @@ static void LoadPalette(const char *lumpname) else if (working[0][q] < 0.0) working[0][q] = 0.0; } -#undef dowork +#undef dolerp pLocalPalette[i].s.red = (UINT8)(working[0][0]); pLocalPalette[i].s.green = (UINT8)(working[0][1]); From 60624edc1ae7e5a5f680667a6063e070621dfee9 Mon Sep 17 00:00:00 2001 From: Jimita the Cat Date: Wed, 2 Jan 2019 00:41:52 -0300 Subject: [PATCH 12/27] Add support for flashpals in screenshots (cherry picked from commit e765b9400cf741eb8aaa72768ef677769ee5c12b) --- src/hardware/hw_draw.c | 9 ++++-- src/hardware/hw_main.h | 5 +-- src/m_misc.c | 72 ++++++++++++++++++++++++++---------------- src/m_misc.h | 2 +- src/st_stuff.c | 2 +- src/st_stuff.h | 1 + 6 files changed, 56 insertions(+), 35 deletions(-) diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index dd21f408b..eb1db7d70 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -1196,21 +1196,24 @@ UINT8 *HWR_GetScreenshot(void) return buf; } -boolean HWR_Screenshot(const char *lbmname) +boolean HWR_Screenshot(const char *pathname, char **error) { boolean ret; UINT8 *buf = malloc(vid.width * vid.height * 3 * sizeof (*buf)); if (!buf) + { + *error = "Failed to allocate memory for HWR_Screenshot"; return false; + } // returns 24bit 888 RGB HWD.pfnReadRect(0, 0, vid.width, vid.height, vid.width * 3, (void *)buf); #ifdef USE_PNG - ret = M_SavePNG(lbmname, buf, vid.width, vid.height, false); + ret = M_SavePNG(pathname, buf, vid.width, vid.height, NULL, &*error); // c_irl #else - ret = saveTGA(lbmname, buf, vid.width, vid.height); + ret = saveTGA(pathname, buf, vid.width, vid.height); #endif free(buf); return ret; diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 7bc361d95..109c5cb20 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -38,8 +38,6 @@ void HWR_RenderSkyboxView(INT32 viewnumber, player_t *player); void HWR_RenderPlayerView(INT32 viewnumber, player_t *player); void HWR_DrawViewBorder(INT32 clearlines); void HWR_DrawFlatFill(INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum); -UINT8 *HWR_GetScreenshot(void); -boolean HWR_Screenshot(const char *lbmname); void HWR_InitTextureMapping(void); void HWR_SetViewSize(void); void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option); @@ -54,6 +52,9 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color); void HWR_DrawPic(INT32 x,INT32 y,lumpnum_t lumpnum); +UINT8 *HWR_GetScreenshot(void); +boolean HWR_Screenshot(const char *pathname, char **error); + void HWR_AddCommands(void); void HWR_CorrectSWTricks(void); void transform(float *cx, float *cy, float *cz); diff --git a/src/m_misc.c b/src/m_misc.c index 43b78c35c..40d8c103f 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -30,6 +30,7 @@ #include "g_game.h" #include "m_misc.h" #include "hu_stuff.h" +#include "st_stuff.h" #include "v_video.h" #include "z_zone.h" #include "g_input.h" @@ -588,6 +589,21 @@ void M_SaveConfig(const char *filename) fclose(f); } +// ========================================================================== +// SCREENSHOTS +// ========================================================================== +static UINT8 screenshot_palette[768]; +static void M_CreateScreenShotPalette(void) +{ + size_t i, j; + for (i = 0, j = 0; i < 768; i += 3, j++) + { + RGBA_t locpal = pLocalPalette[(max(st_palette,0)*256)+j]; + screenshot_palette[i] = locpal.s.red; + screenshot_palette[i+1] = locpal.s.green; + screenshot_palette[i+2] = locpal.s.blue; + } +} #if NUMSCREENS > 2 static const char *Newsnapshotfile(const char *pathname, const char *ext) @@ -1024,6 +1040,7 @@ static boolean M_SetupaPNG(png_const_charp filename, boolean palette) static inline moviemode_t M_StartMovieAPNG(const char *pathname) { #ifdef USE_APNG + UINT8 *palette; const char *freename = NULL; boolean ret = false; @@ -1039,10 +1056,8 @@ static inline moviemode_t M_StartMovieAPNG(const char *pathname) return MM_OFF; } - if (rendermode == render_soft) - ret = M_SetupaPNG(va(pandf,pathname,freename), true); - else - ret = M_SetupaPNG(va(pandf,pathname,freename), false); + if (rendermode == render_soft) M_CreateScreenShotPalette(); + ret = M_SetupaPNG(va(pandf,pathname,freename), (palette = screenshot_palette)); if (!ret) { @@ -1245,10 +1260,11 @@ void M_StopMovie(void) * \param data The image data. * \param width Width of the picture. * \param height Height of the picture. - * \param palette Palette of image data + * \param palette Palette of image data. * \note if palette is NULL, BGR888 format + * \param error Error string to return, if screenshot failed. */ -boolean M_SavePNG(const char *filename, void *data, int width, int height, const boolean palette) +boolean M_SavePNG(const char *filename, void *data, int width, int height, const UINT8 *palette, char **error) { png_structp png_ptr; png_infop png_info_ptr; @@ -1262,15 +1278,14 @@ boolean M_SavePNG(const char *filename, void *data, int width, int height, const png_FILE = fopen(filename,"wb"); if (!png_FILE) { - CONS_Debug(DBG_RENDER, "M_SavePNG: Error on opening %s for write\n", filename); + *error = "Failed to open file for write"; return false; } - png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, - PNG_error, PNG_warn); + png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, PNG_error, PNG_warn); if (!png_ptr) { - CONS_Debug(DBG_RENDER, "M_SavePNG: Error on initialize libpng\n"); + *error = "Failed to initialize libpng"; fclose(png_FILE); remove(filename); return false; @@ -1279,7 +1294,7 @@ boolean M_SavePNG(const char *filename, void *data, int width, int height, const png_info_ptr = png_create_info_struct(png_ptr); if (!png_info_ptr) { - CONS_Debug(DBG_RENDER, "M_SavePNG: Error on allocate for libpng\n"); + *error = "Failed to allocate memory for libpng"; png_destroy_write_struct(&png_ptr, NULL); fclose(png_FILE); remove(filename); @@ -1292,7 +1307,7 @@ boolean M_SavePNG(const char *filename, void *data, int width, int height, const if (setjmp(png_jmpbuf(png_ptr))) #endif { - //CONS_Debug(DBG_RENDER, "libpng write error on %s\n", filename); + *error = "libpng write error"; png_destroy_write_struct(&png_ptr, &png_info_ptr); fclose(png_FILE); remove(filename); @@ -1433,9 +1448,8 @@ void M_ScreenShot(void) } /** Takes a screenshot. - * The screenshot is saved as "kartxxxx.pcx" (or "kartxxxx.tga" in hardware - * rendermode) where xxxx is the lowest four-digit number for which a file - * does not already exist. + * The screenshot is saved as "srb2xxxx.png" where xxxx is the lowest + * four-digit number for which a file does not already exist. * * \sa HWR_ScreenShot */ @@ -1444,11 +1458,16 @@ void M_DoScreenShot(void) #if NUMSCREENS > 2 const char *freename = NULL, *pathname = "."; boolean ret = false; + char *error = "Unknown error"; UINT8 *linear = NULL; // Don't take multiple screenshots, obviously takescreenshot = false; + // how does one take a screenshot without a render system? + if (rendermode == render_none) + return; + if (cv_screenshot_option.value == 0) pathname = usehome ? srb2home : srb2path; else if (cv_screenshot_option.value == 1) @@ -1459,16 +1478,13 @@ void M_DoScreenShot(void) pathname = cv_screenshot_folder.string; #ifdef USE_PNG - if (rendermode != render_none) - freename = Newsnapshotfile(pathname,"png"); + freename = Newsnapshotfile(pathname,"png"); #else if (rendermode == render_soft) freename = Newsnapshotfile(pathname,"pcx"); - else if (rendermode != render_none) + else if (rendermode == render_opengl) freename = Newsnapshotfile(pathname,"tga"); #endif - else - I_Error("Can't take a screenshot without a render system"); if (rendermode == render_soft) { @@ -1482,16 +1498,16 @@ void M_DoScreenShot(void) // save the pcx file #ifdef HWRENDER - if (rendermode != render_soft) - ret = HWR_Screenshot(va(pandf,pathname,freename)); + if (rendermode == render_opengl) + ret = HWR_Screenshot(va(pandf,pathname,freename), &error); else #endif - if (rendermode != render_none) { + M_CreateScreenShotPalette(); #ifdef USE_PNG - ret = M_SavePNG(va(pandf,pathname,freename), linear, vid.width, vid.height, true); + ret = M_SavePNG(va(pandf,pathname,freename), linear, vid.width, vid.height, screenshot_palette, &error); #else - ret = WritePCXfile(va(pandf,pathname,freename), linear, vid.width, vid.height); + ret = WritePCXfile(va(pandf,pathname,freename), linear, vid.width, vid.height, screenshot_palette); #endif } @@ -1499,14 +1515,14 @@ failure: if (ret) { if (moviemode != MM_SCREENSHOT) - CONS_Printf(M_GetText("screen shot %s saved in %s\n"), freename, pathname); + CONS_Printf(M_GetText("Screen shot %s saved in %s\n"), freename, pathname); } else { if (freename) - CONS_Printf(M_GetText("Couldn't create screen shot %s in %s\n"), freename, pathname); + CONS_Alert(CONS_ERROR, M_GetText("Couldn't create screen shot %s in %s (%s)\n"), freename, pathname, error); else - CONS_Printf(M_GetText("Couldn't create screen shot (all 10000 slots used!) in %s\n"), pathname); + CONS_Alert(CONS_ERROR, M_GetText("Couldn't create screen shot in %s (all 10000 slots used!)\n"), pathname); if (moviemode == MM_SCREENSHOT) M_StopMovie(); diff --git a/src/m_misc.h b/src/m_misc.h index df9344dd4..990e15b3c 100644 --- a/src/m_misc.h +++ b/src/m_misc.h @@ -64,7 +64,7 @@ void FIL_ForceExtension(char *path, const char *extension); boolean FIL_CheckExtension(const char *in); #ifdef HAVE_PNG -boolean M_SavePNG(const char *filename, void *data, int width, int height, const boolean palette); +boolean M_SavePNG(const char *filename, void *data, int width, int height, const UINT8 *palette, char **error); #endif extern boolean takescreenshot; diff --git a/src/st_stuff.c b/src/st_stuff.c index 2a2ede350..8ac6e89a0 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -203,7 +203,7 @@ void ST_Ticker(void) } // 0 is default, any others are special palettes. -static INT32 st_palette = 0; +INT32 st_palette = 0; void ST_doPaletteStuff(void) { diff --git a/src/st_stuff.h b/src/st_stuff.h index 16f7b8811..5ed5dd1c6 100644 --- a/src/st_stuff.h +++ b/src/st_stuff.h @@ -61,6 +61,7 @@ boolean ST_SameTeam(player_t *a, player_t *b); //-------------------- extern boolean st_overlay; // sb overlay on or off when fullscreen +extern INT32 st_palette; // 0 is default, any others are special palettes. extern lumpnum_t st_borderpatchnum; // patches, also used in intermission From d6493c9101bb29d1a02a577cce3260a75b434886 Mon Sep 17 00:00:00 2001 From: Jimita the Cat Date: Wed, 2 Jan 2019 01:01:57 -0300 Subject: [PATCH 13/27] dumb (cherry picked from commit 892e65071281e1aa2bd6158748120cf4b7cd81c2) --- src/hardware/hw_draw.c | 6 +++--- src/hardware/hw_main.h | 2 +- src/m_misc.c | 18 ++++++++---------- src/m_misc.h | 2 +- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index eb1db7d70..eca6edfc1 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -1196,14 +1196,14 @@ UINT8 *HWR_GetScreenshot(void) return buf; } -boolean HWR_Screenshot(const char *pathname, char **error) +boolean HWR_Screenshot(const char *pathname) { boolean ret; UINT8 *buf = malloc(vid.width * vid.height * 3 * sizeof (*buf)); if (!buf) { - *error = "Failed to allocate memory for HWR_Screenshot"; + CONS_Debug(DBG_RENDER, "HWR_Screenshot: Failed to allocate memory\n"); return false; } @@ -1211,7 +1211,7 @@ boolean HWR_Screenshot(const char *pathname, char **error) HWD.pfnReadRect(0, 0, vid.width, vid.height, vid.width * 3, (void *)buf); #ifdef USE_PNG - ret = M_SavePNG(pathname, buf, vid.width, vid.height, NULL, &*error); // c_irl + ret = M_SavePNG(pathname, buf, vid.width, vid.height, NULL); #else ret = saveTGA(pathname, buf, vid.width, vid.height); #endif diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 109c5cb20..67c2f5430 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -53,7 +53,7 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color); void HWR_DrawPic(INT32 x,INT32 y,lumpnum_t lumpnum); UINT8 *HWR_GetScreenshot(void); -boolean HWR_Screenshot(const char *pathname, char **error); +boolean HWR_Screenshot(const char *pathname); void HWR_AddCommands(void); void HWR_CorrectSWTricks(void); diff --git a/src/m_misc.c b/src/m_misc.c index 40d8c103f..a63c31ce1 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1262,9 +1262,8 @@ void M_StopMovie(void) * \param height Height of the picture. * \param palette Palette of image data. * \note if palette is NULL, BGR888 format - * \param error Error string to return, if screenshot failed. */ -boolean M_SavePNG(const char *filename, void *data, int width, int height, const UINT8 *palette, char **error) +boolean M_SavePNG(const char *filename, void *data, int width, int height, const UINT8 *palette) { png_structp png_ptr; png_infop png_info_ptr; @@ -1278,14 +1277,14 @@ boolean M_SavePNG(const char *filename, void *data, int width, int height, const png_FILE = fopen(filename,"wb"); if (!png_FILE) { - *error = "Failed to open file for write"; + CONS_Debug(DBG_RENDER, "M_SavePNG: Error on opening %s for write\n", filename); return false; } png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, PNG_error, PNG_warn); if (!png_ptr) { - *error = "Failed to initialize libpng"; + CONS_Debug(DBG_RENDER, "M_SavePNG: Error on initialize libpng\n"); fclose(png_FILE); remove(filename); return false; @@ -1294,7 +1293,7 @@ boolean M_SavePNG(const char *filename, void *data, int width, int height, const png_info_ptr = png_create_info_struct(png_ptr); if (!png_info_ptr) { - *error = "Failed to allocate memory for libpng"; + CONS_Debug(DBG_RENDER, "M_SavePNG: Error on allocate for libpng\n"); png_destroy_write_struct(&png_ptr, NULL); fclose(png_FILE); remove(filename); @@ -1307,7 +1306,7 @@ boolean M_SavePNG(const char *filename, void *data, int width, int height, const if (setjmp(png_jmpbuf(png_ptr))) #endif { - *error = "libpng write error"; + //CONS_Debug(DBG_RENDER, "libpng write error on %s\n", filename); png_destroy_write_struct(&png_ptr, &png_info_ptr); fclose(png_FILE); remove(filename); @@ -1458,7 +1457,6 @@ void M_DoScreenShot(void) #if NUMSCREENS > 2 const char *freename = NULL, *pathname = "."; boolean ret = false; - char *error = "Unknown error"; UINT8 *linear = NULL; // Don't take multiple screenshots, obviously @@ -1499,13 +1497,13 @@ void M_DoScreenShot(void) // save the pcx file #ifdef HWRENDER if (rendermode == render_opengl) - ret = HWR_Screenshot(va(pandf,pathname,freename), &error); + ret = HWR_Screenshot(va(pandf,pathname,freename)); else #endif { M_CreateScreenShotPalette(); #ifdef USE_PNG - ret = M_SavePNG(va(pandf,pathname,freename), linear, vid.width, vid.height, screenshot_palette, &error); + ret = M_SavePNG(va(pandf,pathname,freename), linear, vid.width, vid.height, screenshot_palette); #else ret = WritePCXfile(va(pandf,pathname,freename), linear, vid.width, vid.height, screenshot_palette); #endif @@ -1520,7 +1518,7 @@ failure: else { if (freename) - CONS_Alert(CONS_ERROR, M_GetText("Couldn't create screen shot %s in %s (%s)\n"), freename, pathname, error); + CONS_Alert(CONS_ERROR, M_GetText("Couldn't create screen shot %s in %s\n"), freename, pathname); else CONS_Alert(CONS_ERROR, M_GetText("Couldn't create screen shot in %s (all 10000 slots used!)\n"), pathname); diff --git a/src/m_misc.h b/src/m_misc.h index 990e15b3c..3d42b4244 100644 --- a/src/m_misc.h +++ b/src/m_misc.h @@ -64,7 +64,7 @@ void FIL_ForceExtension(char *path, const char *extension); boolean FIL_CheckExtension(const char *in); #ifdef HAVE_PNG -boolean M_SavePNG(const char *filename, void *data, int width, int height, const UINT8 *palette, char **error); +boolean M_SavePNG(const char *filename, void *data, int width, int height, const UINT8 *palette); #endif extern boolean takescreenshot; From a3732678e06c7c4e89276e8f19f3b72f7bb7ca41 Mon Sep 17 00:00:00 2001 From: Jimita the Cat Date: Wed, 2 Jan 2019 00:41:52 -0300 Subject: [PATCH 14/27] Add support for flashpals in screenshots (cherry picked from commit e765b9400cf741eb8aaa72768ef677769ee5c12b) --- src/hardware/hw_draw.c | 6 +++--- src/hardware/hw_main.h | 2 +- src/m_misc.c | 18 ++++++++++-------- src/m_misc.h | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index eca6edfc1..eb1db7d70 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -1196,14 +1196,14 @@ UINT8 *HWR_GetScreenshot(void) return buf; } -boolean HWR_Screenshot(const char *pathname) +boolean HWR_Screenshot(const char *pathname, char **error) { boolean ret; UINT8 *buf = malloc(vid.width * vid.height * 3 * sizeof (*buf)); if (!buf) { - CONS_Debug(DBG_RENDER, "HWR_Screenshot: Failed to allocate memory\n"); + *error = "Failed to allocate memory for HWR_Screenshot"; return false; } @@ -1211,7 +1211,7 @@ boolean HWR_Screenshot(const char *pathname) HWD.pfnReadRect(0, 0, vid.width, vid.height, vid.width * 3, (void *)buf); #ifdef USE_PNG - ret = M_SavePNG(pathname, buf, vid.width, vid.height, NULL); + ret = M_SavePNG(pathname, buf, vid.width, vid.height, NULL, &*error); // c_irl #else ret = saveTGA(pathname, buf, vid.width, vid.height); #endif diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 67c2f5430..109c5cb20 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -53,7 +53,7 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color); void HWR_DrawPic(INT32 x,INT32 y,lumpnum_t lumpnum); UINT8 *HWR_GetScreenshot(void); -boolean HWR_Screenshot(const char *pathname); +boolean HWR_Screenshot(const char *pathname, char **error); void HWR_AddCommands(void); void HWR_CorrectSWTricks(void); diff --git a/src/m_misc.c b/src/m_misc.c index a63c31ce1..40d8c103f 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1262,8 +1262,9 @@ void M_StopMovie(void) * \param height Height of the picture. * \param palette Palette of image data. * \note if palette is NULL, BGR888 format + * \param error Error string to return, if screenshot failed. */ -boolean M_SavePNG(const char *filename, void *data, int width, int height, const UINT8 *palette) +boolean M_SavePNG(const char *filename, void *data, int width, int height, const UINT8 *palette, char **error) { png_structp png_ptr; png_infop png_info_ptr; @@ -1277,14 +1278,14 @@ boolean M_SavePNG(const char *filename, void *data, int width, int height, const png_FILE = fopen(filename,"wb"); if (!png_FILE) { - CONS_Debug(DBG_RENDER, "M_SavePNG: Error on opening %s for write\n", filename); + *error = "Failed to open file for write"; return false; } png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, PNG_error, PNG_warn); if (!png_ptr) { - CONS_Debug(DBG_RENDER, "M_SavePNG: Error on initialize libpng\n"); + *error = "Failed to initialize libpng"; fclose(png_FILE); remove(filename); return false; @@ -1293,7 +1294,7 @@ boolean M_SavePNG(const char *filename, void *data, int width, int height, const png_info_ptr = png_create_info_struct(png_ptr); if (!png_info_ptr) { - CONS_Debug(DBG_RENDER, "M_SavePNG: Error on allocate for libpng\n"); + *error = "Failed to allocate memory for libpng"; png_destroy_write_struct(&png_ptr, NULL); fclose(png_FILE); remove(filename); @@ -1306,7 +1307,7 @@ boolean M_SavePNG(const char *filename, void *data, int width, int height, const if (setjmp(png_jmpbuf(png_ptr))) #endif { - //CONS_Debug(DBG_RENDER, "libpng write error on %s\n", filename); + *error = "libpng write error"; png_destroy_write_struct(&png_ptr, &png_info_ptr); fclose(png_FILE); remove(filename); @@ -1457,6 +1458,7 @@ void M_DoScreenShot(void) #if NUMSCREENS > 2 const char *freename = NULL, *pathname = "."; boolean ret = false; + char *error = "Unknown error"; UINT8 *linear = NULL; // Don't take multiple screenshots, obviously @@ -1497,13 +1499,13 @@ void M_DoScreenShot(void) // save the pcx file #ifdef HWRENDER if (rendermode == render_opengl) - ret = HWR_Screenshot(va(pandf,pathname,freename)); + ret = HWR_Screenshot(va(pandf,pathname,freename), &error); else #endif { M_CreateScreenShotPalette(); #ifdef USE_PNG - ret = M_SavePNG(va(pandf,pathname,freename), linear, vid.width, vid.height, screenshot_palette); + ret = M_SavePNG(va(pandf,pathname,freename), linear, vid.width, vid.height, screenshot_palette, &error); #else ret = WritePCXfile(va(pandf,pathname,freename), linear, vid.width, vid.height, screenshot_palette); #endif @@ -1518,7 +1520,7 @@ failure: else { if (freename) - CONS_Alert(CONS_ERROR, M_GetText("Couldn't create screen shot %s in %s\n"), freename, pathname); + CONS_Alert(CONS_ERROR, M_GetText("Couldn't create screen shot %s in %s (%s)\n"), freename, pathname, error); else CONS_Alert(CONS_ERROR, M_GetText("Couldn't create screen shot in %s (all 10000 slots used!)\n"), pathname); diff --git a/src/m_misc.h b/src/m_misc.h index 3d42b4244..990e15b3c 100644 --- a/src/m_misc.h +++ b/src/m_misc.h @@ -64,7 +64,7 @@ void FIL_ForceExtension(char *path, const char *extension); boolean FIL_CheckExtension(const char *in); #ifdef HAVE_PNG -boolean M_SavePNG(const char *filename, void *data, int width, int height, const UINT8 *palette); +boolean M_SavePNG(const char *filename, void *data, int width, int height, const UINT8 *palette, char **error); #endif extern boolean takescreenshot; From 9ded0d1770c8dd071d1d7fd7ade73504f4db2c6d Mon Sep 17 00:00:00 2001 From: Jimita the Cat Date: Wed, 2 Jan 2019 01:01:57 -0300 Subject: [PATCH 15/27] dumb (cherry picked from commit 892e65071281e1aa2bd6158748120cf4b7cd81c2) --- src/hardware/hw_draw.c | 6 +++--- src/hardware/hw_main.h | 2 +- src/m_misc.c | 18 ++++++++---------- src/m_misc.h | 2 +- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index eb1db7d70..eca6edfc1 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -1196,14 +1196,14 @@ UINT8 *HWR_GetScreenshot(void) return buf; } -boolean HWR_Screenshot(const char *pathname, char **error) +boolean HWR_Screenshot(const char *pathname) { boolean ret; UINT8 *buf = malloc(vid.width * vid.height * 3 * sizeof (*buf)); if (!buf) { - *error = "Failed to allocate memory for HWR_Screenshot"; + CONS_Debug(DBG_RENDER, "HWR_Screenshot: Failed to allocate memory\n"); return false; } @@ -1211,7 +1211,7 @@ boolean HWR_Screenshot(const char *pathname, char **error) HWD.pfnReadRect(0, 0, vid.width, vid.height, vid.width * 3, (void *)buf); #ifdef USE_PNG - ret = M_SavePNG(pathname, buf, vid.width, vid.height, NULL, &*error); // c_irl + ret = M_SavePNG(pathname, buf, vid.width, vid.height, NULL); #else ret = saveTGA(pathname, buf, vid.width, vid.height); #endif diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 109c5cb20..67c2f5430 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -53,7 +53,7 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color); void HWR_DrawPic(INT32 x,INT32 y,lumpnum_t lumpnum); UINT8 *HWR_GetScreenshot(void); -boolean HWR_Screenshot(const char *pathname, char **error); +boolean HWR_Screenshot(const char *pathname); void HWR_AddCommands(void); void HWR_CorrectSWTricks(void); diff --git a/src/m_misc.c b/src/m_misc.c index 40d8c103f..a63c31ce1 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1262,9 +1262,8 @@ void M_StopMovie(void) * \param height Height of the picture. * \param palette Palette of image data. * \note if palette is NULL, BGR888 format - * \param error Error string to return, if screenshot failed. */ -boolean M_SavePNG(const char *filename, void *data, int width, int height, const UINT8 *palette, char **error) +boolean M_SavePNG(const char *filename, void *data, int width, int height, const UINT8 *palette) { png_structp png_ptr; png_infop png_info_ptr; @@ -1278,14 +1277,14 @@ boolean M_SavePNG(const char *filename, void *data, int width, int height, const png_FILE = fopen(filename,"wb"); if (!png_FILE) { - *error = "Failed to open file for write"; + CONS_Debug(DBG_RENDER, "M_SavePNG: Error on opening %s for write\n", filename); return false; } png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, PNG_error, PNG_warn); if (!png_ptr) { - *error = "Failed to initialize libpng"; + CONS_Debug(DBG_RENDER, "M_SavePNG: Error on initialize libpng\n"); fclose(png_FILE); remove(filename); return false; @@ -1294,7 +1293,7 @@ boolean M_SavePNG(const char *filename, void *data, int width, int height, const png_info_ptr = png_create_info_struct(png_ptr); if (!png_info_ptr) { - *error = "Failed to allocate memory for libpng"; + CONS_Debug(DBG_RENDER, "M_SavePNG: Error on allocate for libpng\n"); png_destroy_write_struct(&png_ptr, NULL); fclose(png_FILE); remove(filename); @@ -1307,7 +1306,7 @@ boolean M_SavePNG(const char *filename, void *data, int width, int height, const if (setjmp(png_jmpbuf(png_ptr))) #endif { - *error = "libpng write error"; + //CONS_Debug(DBG_RENDER, "libpng write error on %s\n", filename); png_destroy_write_struct(&png_ptr, &png_info_ptr); fclose(png_FILE); remove(filename); @@ -1458,7 +1457,6 @@ void M_DoScreenShot(void) #if NUMSCREENS > 2 const char *freename = NULL, *pathname = "."; boolean ret = false; - char *error = "Unknown error"; UINT8 *linear = NULL; // Don't take multiple screenshots, obviously @@ -1499,13 +1497,13 @@ void M_DoScreenShot(void) // save the pcx file #ifdef HWRENDER if (rendermode == render_opengl) - ret = HWR_Screenshot(va(pandf,pathname,freename), &error); + ret = HWR_Screenshot(va(pandf,pathname,freename)); else #endif { M_CreateScreenShotPalette(); #ifdef USE_PNG - ret = M_SavePNG(va(pandf,pathname,freename), linear, vid.width, vid.height, screenshot_palette, &error); + ret = M_SavePNG(va(pandf,pathname,freename), linear, vid.width, vid.height, screenshot_palette); #else ret = WritePCXfile(va(pandf,pathname,freename), linear, vid.width, vid.height, screenshot_palette); #endif @@ -1520,7 +1518,7 @@ failure: else { if (freename) - CONS_Alert(CONS_ERROR, M_GetText("Couldn't create screen shot %s in %s (%s)\n"), freename, pathname, error); + CONS_Alert(CONS_ERROR, M_GetText("Couldn't create screen shot %s in %s\n"), freename, pathname); else CONS_Alert(CONS_ERROR, M_GetText("Couldn't create screen shot in %s (all 10000 slots used!)\n"), pathname); diff --git a/src/m_misc.h b/src/m_misc.h index 990e15b3c..3d42b4244 100644 --- a/src/m_misc.h +++ b/src/m_misc.h @@ -64,7 +64,7 @@ void FIL_ForceExtension(char *path, const char *extension); boolean FIL_CheckExtension(const char *in); #ifdef HAVE_PNG -boolean M_SavePNG(const char *filename, void *data, int width, int height, const UINT8 *palette, char **error); +boolean M_SavePNG(const char *filename, void *data, int width, int height, const UINT8 *palette); #endif extern boolean takescreenshot; From 3c2adbb7d187d6a77b2b45762bd29e150ed2bc4c Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 23 Mar 2020 17:08:44 -0700 Subject: [PATCH 16/27] Fix whacky history --- src/m_misc.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/m_misc.c b/src/m_misc.c index a63c31ce1..acd150169 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -672,7 +672,7 @@ static void PNG_warn(png_structp PNG, png_const_charp pngtext) CONS_Debug(DBG_RENDER, "libpng warning at %p: %s", PNG, pngtext); } -static void M_PNGhdr(png_structp png_ptr, png_infop png_info_ptr, PNG_CONST png_uint_32 width, PNG_CONST png_uint_32 height, const boolean palette) +static void M_PNGhdr(png_structp png_ptr, png_infop png_info_ptr, PNG_CONST png_uint_32 width, PNG_CONST png_uint_32 height, PNG_CONST png_byte *palette) { const png_byte png_interlace = PNG_INTERLACE_NONE; //PNG_INTERLACE_ADAM7 if (palette) @@ -680,15 +680,13 @@ static void M_PNGhdr(png_structp png_ptr, png_infop png_info_ptr, PNG_CONST png_ png_colorp png_PLTE = png_malloc(png_ptr, sizeof(png_color)*256); //palette png_uint_16 i; - RGBA_t *pal = ((cv_screenshot_colorprofile.value) - ? pLocalPalette - : pMasterPalette); + const png_byte *pal = palette; for (i = 0; i < 256; i++) { - png_PLTE[i].red = pal[i].s.red; - png_PLTE[i].green = pal[i].s.green; - png_PLTE[i].blue = pal[i].s.blue; + png_PLTE[i].red = *pal; pal++; + png_PLTE[i].green = *pal; pal++; + png_PLTE[i].blue = *pal; pal++; } png_set_IHDR(png_ptr, png_info_ptr, width, height, 8, PNG_COLOR_TYPE_PALETTE, @@ -964,7 +962,7 @@ static void M_PNGfix_acTL(png_structp png_ptr, png_infop png_info_ptr, #endif } -static boolean M_SetupaPNG(png_const_charp filename, boolean palette) +static boolean M_SetupaPNG(png_const_charp filename, png_bytep pal) { apng_FILE = fopen(filename,"wb+"); // + mode for reading if (!apng_FILE) @@ -1016,7 +1014,7 @@ static boolean M_SetupaPNG(png_const_charp filename, boolean palette) png_set_compression_strategy(apng_ptr, cv_zlib_strategya.value); png_set_compression_window_bits(apng_ptr, cv_zlib_window_bitsa.value); - M_PNGhdr(apng_ptr, apng_info_ptr, vid.width, vid.height, palette); + M_PNGhdr(apng_ptr, apng_info_ptr, vid.width, vid.height, pal); M_PNGText(apng_ptr, apng_info_ptr, true); From 1a759a49049d72a0d0352459ffa0ec767427abef Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Sun, 10 Nov 2019 00:04:11 -0300 Subject: [PATCH 17/27] GIF recording (cherry picked from commit d467d2b2295a9660631774b9edb29555cc5c30fe) --- src/hardware/hw_main.c | 4 ++-- src/m_anigif.c | 52 +++++++++++++++++++++++++++++++++++++++--- src/m_misc.c | 8 ++----- src/r_data.h | 2 ++ src/sdl/i_video.c | 5 ++-- src/v_video.c | 27 ++++++++++++++++++---- src/v_video.h | 12 ++++++++++ 7 files changed, 91 insertions(+), 19 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 73e65cceb..a22e5b586 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -582,7 +582,7 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, boolean is if (nrPlaneVerts < 3) //not even a triangle ? return; - if ((UINT32)nrPlaneVerts > UINT16_MAX) // FIXME: exceeds plVerts size + if (nrPlaneVerts > INT16_MAX) // FIXME: exceeds plVerts size { CONS_Debug(DBG_RENDER, "polygon size of %d exceeds max value of %d vertices\n", nrPlaneVerts, UINT16_MAX); return; @@ -3229,7 +3229,7 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, if (nrPlaneVerts < 3) //not even a triangle ? return; - if (nrPlaneVerts > UINT16_MAX) // FIXME: exceeds plVerts size + if (nrPlaneVerts > INT16_MAX) // FIXME: exceeds plVerts size { CONS_Debug(DBG_RENDER, "polygon size of %s exceeds max value of %d vertices\n", sizeu1(nrPlaneVerts), UINT16_MAX); return; diff --git a/src/m_anigif.c b/src/m_anigif.c index 64254163d..1e5ece33b 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -20,6 +20,10 @@ #include "i_video.h" #include "m_misc.h" +#ifdef HWRENDER +#include "hardware/hw_main.h" +#endif + // GIFs are always little-endian #include "byteptr.h" @@ -457,6 +461,32 @@ const UINT8 gifframe_gchead[4] = {0x21,0xF9,0x04,0x04}; // GCE, bytes, packed by static UINT8 *gifframe_data = NULL; static size_t gifframe_size = 8192; +#ifdef HWRENDER +static void hwrconvert(void) +{ + UINT8 *linear = HWR_GetScreenshot(); + UINT8 *dest = screens[2]; + UINT8 r, g, b; + INT32 x, y; + size_t i = 0; + + InitColorLUT(); + + for (y = 0; y < vid.height; y++) + { + for (x = 0; x < vid.width; x++, i += 3) + { + r = (UINT8)linear[i]; + g = (UINT8)linear[i + 1]; + b = (UINT8)linear[i + 2]; + dest[(y * vid.width) + x] = colorlookup[r >> SHIFTCOLORBITS][g >> SHIFTCOLORBITS][b >> SHIFTCOLORBITS]; + } + } + + free(linear); +} +#endif + // // GIF_framewrite // writes a frame into the file. @@ -482,7 +512,12 @@ static void GIF_framewrite(void) GIF_optimizeregion(cur_screen, movie_screen, &blitx, &blity, &blitw, &blith); // blit to temp screen - I_ReadScreen(movie_screen); + if (rendermode == render_soft) + I_ReadScreen(movie_screen); +#ifdef HWRENDER + else if (rendermode == render_opengl) + hwrconvert(); +#endif } else { @@ -491,7 +526,18 @@ static void GIF_framewrite(void) blith = vid.height; if (gif_frames == 0) - I_ReadScreen(movie_screen); + { + if (rendermode == render_soft) + I_ReadScreen(movie_screen); +#ifdef HWRENDER + else if (rendermode == render_opengl) + { + hwrconvert(); + VID_BlitLinearScreen(screens[2], screens[0], vid.width*vid.bpp, vid.height, vid.width*vid.bpp, vid.rowbytes); + } +#endif + } + movie_screen = screens[0]; } @@ -580,7 +626,7 @@ static void GIF_framewrite(void) // INT32 GIF_open(const char *filename) { -#ifdef HWRENDER +#if 0 if (rendermode != render_soft) { CONS_Alert(CONS_WARNING, M_GetText("GIFs cannot be taken in non-software modes!\n")); diff --git a/src/m_misc.c b/src/m_misc.c index acd150169..800d34e79 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1120,12 +1120,8 @@ void M_StartMovie(void) switch (cv_moviemode.value) { case MM_GIF: - if (rendermode == render_soft) - { - moviemode = M_StartMovieGIF(pathname); - break; - } - /* FALLTHRU */ + moviemode = M_StartMovieGIF(pathname); + break; case MM_APNG: moviemode = M_StartMovieAPNG(pathname); break; diff --git a/src/r_data.h b/src/r_data.h index cd61bbaac..e5dd3764a 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -99,6 +99,8 @@ void R_MakeInvertmap(void); #endif const char *R_ColormapNameForNum(INT32 num); +UINT8 NearestColor(UINT8 r, UINT8 g, UINT8 b); + extern INT32 numtextures; #endif diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index c900417ab..1a8175dc3 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1647,6 +1647,7 @@ INT32 VID_SetMode(INT32 modeNum) //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); SDLSetMode(vid.width, vid.height, USE_FULLSCREEN); + Impl_VideoSetupBuffer(); if (rendermode == render_soft) { @@ -1655,8 +1656,6 @@ INT32 VID_SetMode(INT32 modeNum) SDL_FreeSurface(bufSurface); bufSurface = NULL; } - - Impl_VideoSetupBuffer(); } return SDL_TRUE; @@ -1779,7 +1778,7 @@ static void Impl_VideoSetupSDLBuffer(void) static void Impl_VideoSetupBuffer(void) { // Set up game's software render buffer - if (rendermode == render_soft) + //if (rendermode == render_soft) { vid.rowbytes = vid.width * vid.bpp; vid.direct = NULL; diff --git a/src/v_video.c b/src/v_video.c index c482debda..2fbdbb1f9 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2867,6 +2867,27 @@ Unoptimized version #endif } +// Taken from my videos-in-SRB2 project +// Generates a color look-up table +// which has up to 64 colors at each channel +// (see the defines in v_video.h) + +UINT8 colorlookup[CLUTSIZE][CLUTSIZE][CLUTSIZE]; + +void InitColorLUT(void) +{ + UINT8 r, g, b; + static boolean clutinit = false; + if (!clutinit) + { + for (r = 0; r < CLUTSIZE; r++) + for (g = 0; g < CLUTSIZE; g++) + for (b = 0; b < CLUTSIZE; b++) + colorlookup[r][g][b] = NearestColor(r << SHIFTCOLORBITS, g << SHIFTCOLORBITS, b << SHIFTCOLORBITS); + clutinit = true; + } +} + // V_Init // old software stuff, buffers are allocated at video mode setup // here we set the screens[x] pointers accordingly @@ -2878,13 +2899,9 @@ void V_Init(void) const INT32 screensize = vid.rowbytes * vid.height; LoadMapPalette(); - // hardware modes do not use screens[] pointers + for (i = 0; i < NUMSCREENS; i++) screens[i] = NULL; - if (rendermode != render_soft) - { - return; // be sure to cause a NULL read/write error so we detect it, in case of.. - } // start address of NUMSCREENS * width*height vidbuffers if (base) diff --git a/src/v_video.h b/src/v_video.h index 7478c6903..c9751a34a 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -36,6 +36,18 @@ cv_rsaturation, cv_ysaturation, cv_gsaturation, cv_csaturation, cv_bsaturation, // Allocates buffer screens, call before R_Init. void V_Init(void); +// Taken from my videos-in-SRB2 project +// Generates a color look-up table +// which has up to 64 colors at each channel + +#define COLORBITS 6 +#define SHIFTCOLORBITS (8-COLORBITS) +#define CLUTSIZE (1< Date: Mon, 11 Nov 2019 00:02:22 -0300 Subject: [PATCH 18/27] Recreate the CLUT when the palette changes (cherry picked from commit 6e0ff4a4a40306a59c8b18d03ae86560e6a52a4a) --- src/v_video.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/v_video.c b/src/v_video.c index 2fbdbb1f9..41505eef3 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2878,13 +2878,15 @@ void InitColorLUT(void) { UINT8 r, g, b; static boolean clutinit = false; - if (!clutinit) + static RGBA_t *lastpalette = NULL; + if ((!clutinit) || (lastpalette != pLocalPalette)) { for (r = 0; r < CLUTSIZE; r++) for (g = 0; g < CLUTSIZE; g++) for (b = 0; b < CLUTSIZE; b++) colorlookup[r][g][b] = NearestColor(r << SHIFTCOLORBITS, g << SHIFTCOLORBITS, b << SHIFTCOLORBITS); clutinit = true; + lastpalette = pLocalPalette; } } From 2e62f5c793355b9b566eae4f5c77bdedb444a528 Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Tue, 17 Dec 2019 15:20:22 -0300 Subject: [PATCH 19/27] Don't use the local palette, because OpenGL mixes it into the textures themselves (cherry picked from commit 0af71fafc57fb842a8c7a9a4853d8c7fbb2bf7fc) --- src/m_anigif.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/m_anigif.c b/src/m_anigif.c index 1e5ece33b..fb9ebaffd 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -432,8 +432,11 @@ static void GIF_headwrite(void) // write color table { - RGBA_t *pal = ((cv_screenshot_colorprofile.value) - ? pLocalPalette + RGBA_t *pal = ((cv_screenshot_colorprofile.value +#ifdef HWRENDER + && (rendermode == render_soft) +#endif + ) ? pLocalPalette : pMasterPalette); for (i = 0; i < 256; i++) From b8f5166d8e08b237d5fc993b9465725faa156218 Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Tue, 17 Dec 2019 15:37:43 -0300 Subject: [PATCH 20/27] Avoid recreating the color LUT mid-recording-frame (cherry picked from commit c3f0e6aa4472f0754a7f392759b9f93cb3c7651b) --- src/m_anigif.c | 21 +++++++++++++-------- src/v_video.c | 6 +++--- src/v_video.h | 2 +- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/m_anigif.c b/src/m_anigif.c index fb9ebaffd..c298ad705 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -33,6 +33,7 @@ consvar_t cv_gif_downscale = {"gif_downscale", "On", CV_SAVE, CV_OnOff, NULL, 0 #ifdef HAVE_ANIGIF static boolean gif_optimize = false; // So nobody can do something dumb static boolean gif_downscale = false; // like changing cvars mid output +static RGBA_t *gif_palette = NULL; static FILE *gif_out = NULL; static INT32 gif_frames = 0; @@ -432,13 +433,7 @@ static void GIF_headwrite(void) // write color table { - RGBA_t *pal = ((cv_screenshot_colorprofile.value -#ifdef HWRENDER - && (rendermode == render_soft) -#endif - ) ? pLocalPalette - : pMasterPalette); - + RGBA_t *pal = gif_palette; for (i = 0; i < 256; i++) { WRITEUINT8(p, pal[i].s.red); @@ -473,7 +468,7 @@ static void hwrconvert(void) INT32 x, y; size_t i = 0; - InitColorLUT(); + InitColorLUT(gif_palette); for (y = 0; y < vid.height; y++) { @@ -643,6 +638,16 @@ INT32 GIF_open(const char *filename) gif_optimize = (!!cv_gif_optimize.value); gif_downscale = (!!cv_gif_downscale.value); + + // GIF color table + // In hardware mode, uses the master palette + gif_palette = ((cv_screenshot_colorprofile.value +#ifdef HWRENDER + && (rendermode == render_soft) +#endif + ) ? pLocalPalette + : pMasterPalette); + GIF_headwrite(); gif_frames = 0; return 1; diff --git a/src/v_video.c b/src/v_video.c index 41505eef3..3300e16bc 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2874,19 +2874,19 @@ Unoptimized version UINT8 colorlookup[CLUTSIZE][CLUTSIZE][CLUTSIZE]; -void InitColorLUT(void) +void InitColorLUT(RGBA_t *palette) { UINT8 r, g, b; static boolean clutinit = false; static RGBA_t *lastpalette = NULL; - if ((!clutinit) || (lastpalette != pLocalPalette)) + if ((!clutinit) || (lastpalette != palette)) { for (r = 0; r < CLUTSIZE; r++) for (g = 0; g < CLUTSIZE; g++) for (b = 0; b < CLUTSIZE; b++) colorlookup[r][g][b] = NearestColor(r << SHIFTCOLORBITS, g << SHIFTCOLORBITS, b << SHIFTCOLORBITS); clutinit = true; - lastpalette = pLocalPalette; + lastpalette = palette; } } diff --git a/src/v_video.h b/src/v_video.h index c9751a34a..4e78e9f9e 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -46,7 +46,7 @@ void V_Init(void); extern UINT8 colorlookup[CLUTSIZE][CLUTSIZE][CLUTSIZE]; -void InitColorLUT(void); +void InitColorLUT(RGBA_t *palette); // Set the current RGB palette lookup to use for palettized graphics void V_SetPalette(INT32 palettenum); From f106ba7ac4913618574c5392caa639a20648c18f Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Mon, 27 Jan 2020 13:55:13 -0300 Subject: [PATCH 21/27] Fix color LUT using the wrong palette (cherry picked from commit 636093a59ddd95b25d79c4ebff51dc6412de1956) --- src/m_anigif.c | 18 +++++------------- src/r_data.c | 12 ++++++++---- src/r_data.h | 3 ++- src/v_video.c | 3 +-- src/v_video.h | 5 +---- 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/m_anigif.c b/src/m_anigif.c index c298ad705..08b0903de 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -624,14 +624,6 @@ static void GIF_framewrite(void) // INT32 GIF_open(const char *filename) { -#if 0 - if (rendermode != render_soft) - { - CONS_Alert(CONS_WARNING, M_GetText("GIFs cannot be taken in non-software modes!\n")); - return 0; - } -#endif - gif_out = fopen(filename, "wb"); if (!gif_out) return 0; @@ -640,13 +632,13 @@ INT32 GIF_open(const char *filename) gif_downscale = (!!cv_gif_downscale.value); // GIF color table - // In hardware mode, uses the master palette - gif_palette = ((cv_screenshot_colorprofile.value + // In hardware mode, forces the local palette #ifdef HWRENDER - && (rendermode == render_soft) + if (rendermode == render_opengl) + gif_palette = pLocalPalette; + else #endif - ) ? pLocalPalette - : pMasterPalette); + gif_palette = ((cv_screenshot_colorprofile.value) ? pLocalPalette : pMasterPalette); GIF_headwrite(); gif_frames = 0; diff --git a/src/r_data.c b/src/r_data.c index 843ed2acb..b37431870 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1427,16 +1427,20 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) // Thanks to quake2 source! // utils3/qdata/images.c -UINT8 NearestColor(UINT8 r, UINT8 g, UINT8 b) +UINT8 NearestPaletteColor(UINT8 r, UINT8 g, UINT8 b, RGBA_t *palette) { int dr, dg, db; int distortion, bestdistortion = 256 * 256 * 4, bestcolor = 0, i; + // Use master palette if none specified + if (palette == NULL) + palette = pMasterPalette; + for (i = 0; i < 256; i++) { - dr = r - pMasterPalette[i].s.red; - dg = g - pMasterPalette[i].s.green; - db = b - pMasterPalette[i].s.blue; + dr = r - palette[i].s.red; + dg = g - palette[i].s.green; + db = b - palette[i].s.blue; distortion = dr*dr + dg*dg + db*db; if (distortion < bestdistortion) { diff --git a/src/r_data.h b/src/r_data.h index e5dd3764a..86ba0885b 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -99,7 +99,8 @@ void R_MakeInvertmap(void); #endif const char *R_ColormapNameForNum(INT32 num); -UINT8 NearestColor(UINT8 r, UINT8 g, UINT8 b); +UINT8 NearestPaletteColor(UINT8 r, UINT8 g, UINT8 b, RGBA_t *palette); +#define NearestColor(r, g, b) NearestPaletteColor(r, g, b, NULL) extern INT32 numtextures; diff --git a/src/v_video.c b/src/v_video.c index 3300e16bc..517cae719 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2867,7 +2867,6 @@ Unoptimized version #endif } -// Taken from my videos-in-SRB2 project // Generates a color look-up table // which has up to 64 colors at each channel // (see the defines in v_video.h) @@ -2884,7 +2883,7 @@ void InitColorLUT(RGBA_t *palette) for (r = 0; r < CLUTSIZE; r++) for (g = 0; g < CLUTSIZE; g++) for (b = 0; b < CLUTSIZE; b++) - colorlookup[r][g][b] = NearestColor(r << SHIFTCOLORBITS, g << SHIFTCOLORBITS, b << SHIFTCOLORBITS); + colorlookup[r][g][b] = NearestPaletteColor(r << SHIFTCOLORBITS, g << SHIFTCOLORBITS, b << SHIFTCOLORBITS, palette); clutinit = true; lastpalette = palette; } diff --git a/src/v_video.h b/src/v_video.h index 4e78e9f9e..ee7a681d8 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -36,10 +36,7 @@ cv_rsaturation, cv_ysaturation, cv_gsaturation, cv_csaturation, cv_bsaturation, // Allocates buffer screens, call before R_Init. void V_Init(void); -// Taken from my videos-in-SRB2 project -// Generates a color look-up table -// which has up to 64 colors at each channel - +// Color look-up table #define COLORBITS 6 #define SHIFTCOLORBITS (8-COLORBITS) #define CLUTSIZE (1< Date: Wed, 29 Jan 2020 13:47:55 -0300 Subject: [PATCH 22/27] Local Color Table for GIF movie mode (cherry picked from commit 5a330803ec5bea2ca7b6b30bf7972b11753b571d) --- src/d_netcmd.c | 1 + src/m_anigif.c | 89 ++++++++++++++++++++++++++++++++++++++------------ src/m_anigif.h | 2 +- 3 files changed, 71 insertions(+), 21 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 36cb01adf..21bdd033e 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -805,6 +805,7 @@ void D_RegisterClientCommands(void) // GIF variables CV_RegisterVar(&cv_gif_optimize); CV_RegisterVar(&cv_gif_downscale); + CV_RegisterVar(&cv_gif_localcolortable); #ifdef WALLSPLATS CV_RegisterVar(&cv_splats); diff --git a/src/m_anigif.c b/src/m_anigif.c index 08b0903de..31bc11070 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -19,6 +19,7 @@ #include "v_video.h" #include "i_video.h" #include "m_misc.h" +#include "st_stuff.h" // st_palette #ifdef HWRENDER #include "hardware/hw_main.h" @@ -29,10 +30,12 @@ consvar_t cv_gif_optimize = {"gif_optimize", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_gif_downscale = {"gif_downscale", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_gif_localcolortable = {"gif_localcolortable", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; #ifdef HAVE_ANIGIF static boolean gif_optimize = false; // So nobody can do something dumb static boolean gif_downscale = false; // like changing cvars mid output +static boolean gif_localcolortable = false; static RGBA_t *gif_palette = NULL; static FILE *gif_out = NULL; @@ -393,6 +396,41 @@ const UINT8 gifhead_nsid[19] = {0x21,0xFF,0x0B, // extension block + size 0x4E,0x45,0x54,0x53,0x43,0x41,0x50,0x45,0x32,0x2E,0x30, // NETSCAPE2.0 0x03,0x01,0xFF,0xFF,0x00}; // sub-block, repetitions + +// +// GIF_setpalette +// determine the gif palette. +// +static void GIF_setpalette(void) +{ + // In hardware mode, uses the master palette + size_t palnum = (rendermode == render_soft) ? ((gif_localcolortable) ? max(st_palette, 0) : 0) : 0; + gif_palette = ((cv_screenshot_colorprofile.value +#ifdef HWRENDER + && (rendermode == render_soft) +#endif + ) ? &pLocalPalette[palnum*256] + : &pMasterPalette[palnum*256]); +} + +// +// GIF_palwrite +// writes the gif palette. +// used both for the header and the local color table. +// +static UINT8 *GIF_palwrite(UINT8 *p) +{ + INT32 i; + RGBA_t *pal = gif_palette; + for (i = 0; i < 256; i++) + { + WRITEUINT8(p, pal[i].s.red); + WRITEUINT8(p, pal[i].s.green); + WRITEUINT8(p, pal[i].s.blue); + } + return p; +} + // // GIF_headwrite // writes the gif header to the currently open output file. @@ -402,8 +440,10 @@ static void GIF_headwrite(void) { UINT8 *gifhead = Z_Malloc(800, PU_STATIC, NULL); UINT8 *p = gifhead; - INT32 i; + UINT8 *last_p; UINT16 rwidth, rheight; + size_t totalbytes; + INT32 i; if (!gif_out) return; @@ -423,30 +463,37 @@ static void GIF_headwrite(void) rwidth = vid.width; rheight = vid.height; } + + last_p = p; WRITEUINT16(p, rwidth); WRITEUINT16(p, rheight); // colors, aspect, etc - WRITEUINT8(p, 0xFF); // TRANSPARENTPIXEL + WRITEUINT8(p, (gif_localcolortable ? 0xF0 : 0xF7)); // (0xF7 = 1111 0111) WRITEUINT8(p, 0x00); WRITEUINT8(p, 0x00); + // Lactozilla: should be 800 without a local color table + totalbytes = sizeof(gifhead_base) + sizeof(gifhead_nsid) + (p - last_p); + // write color table + if (!gif_localcolortable) { - RGBA_t *pal = gif_palette; - for (i = 0; i < 256; i++) - { - WRITEUINT8(p, pal[i].s.red); - WRITEUINT8(p, pal[i].s.green); - WRITEUINT8(p, pal[i].s.blue); - } + p = GIF_palwrite(p); + totalbytes += (256 * 3); + } + else + { + // write a dummy palette + for (i = 0; i < 6; i++, totalbytes++) + WRITEUINT8(p, 0); } // write extension block WRITEMEM(p, gifhead_nsid, sizeof(gifhead_nsid)); // write to file and be done with it! - fwrite(gifhead, 1, 800, gif_out); + fwrite(gifhead, 1, totalbytes, gif_out); Z_Free(gifhead); } @@ -566,7 +613,15 @@ static void GIF_framewrite(void) WRITEUINT16(p, (UINT16)(blity / scrbuf_downscaleamt)); WRITEUINT16(p, (UINT16)(blitw / scrbuf_downscaleamt)); WRITEUINT16(p, (UINT16)(blith / scrbuf_downscaleamt)); - WRITEUINT8(p, 0); // no local table of colors + + if (!gif_localcolortable) + WRITEUINT8(p, 0); // no local table of colors + else + { + WRITEUINT8(p, 0x87); // (0x87 = 1000 0111) + GIF_setpalette(); + p = GIF_palwrite(p); + } scrbuf_pos = movie_screen + blitx + (blity * vid.width); scrbuf_writeend = scrbuf_pos + (blitw - 1) + ((blith - 1) * vid.width); @@ -630,15 +685,9 @@ INT32 GIF_open(const char *filename) gif_optimize = (!!cv_gif_optimize.value); gif_downscale = (!!cv_gif_downscale.value); - - // GIF color table - // In hardware mode, forces the local palette -#ifdef HWRENDER - if (rendermode == render_opengl) - gif_palette = pLocalPalette; - else -#endif - gif_palette = ((cv_screenshot_colorprofile.value) ? pLocalPalette : pMasterPalette); + gif_localcolortable = (!!cv_gif_localcolortable.value); + if (!gif_localcolortable) + GIF_setpalette(); GIF_headwrite(); gif_frames = 0; diff --git a/src/m_anigif.h b/src/m_anigif.h index 6d94ecf8c..bec481d59 100644 --- a/src/m_anigif.h +++ b/src/m_anigif.h @@ -27,6 +27,6 @@ void GIF_frame(void); INT32 GIF_close(void); #endif -extern consvar_t cv_gif_optimize, cv_gif_downscale; +extern consvar_t cv_gif_optimize, cv_gif_downscale, cv_gif_localcolortable; #endif From e75baf70b0bd6ebee402c0b22b15df154fecde4f Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Wed, 29 Jan 2020 13:56:39 -0300 Subject: [PATCH 23/27] Uh (cherry picked from commit 999e72ab325301d248837f5337eb8f90143231ef) --- src/m_anigif.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/m_anigif.c b/src/m_anigif.c index 31bc11070..c10d70229 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -434,7 +434,6 @@ static UINT8 *GIF_palwrite(UINT8 *p) // // GIF_headwrite // writes the gif header to the currently open output file. -// NOTE that this code does not accomodate for palette changes. // static void GIF_headwrite(void) { From 6f5416954e14fa3f8895624dbf87715760813bd7 Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Wed, 29 Jan 2020 17:31:27 -0300 Subject: [PATCH 24/27] Only write a Local Color Table if the frame's palette differs from the header's palette (cherry picked from commit 85211dcc09c922e0d42b4eeea387dcecc8e989ae) --- src/m_anigif.c | 73 +++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/src/m_anigif.c b/src/m_anigif.c index c10d70229..b914cb14c 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -35,8 +35,12 @@ consvar_t cv_gif_localcolortable = {"gif_localcolortable", "On", CV_SAVE, CV_On #ifdef HAVE_ANIGIF static boolean gif_optimize = false; // So nobody can do something dumb static boolean gif_downscale = false; // like changing cvars mid output + +// Palette handling static boolean gif_localcolortable = false; -static RGBA_t *gif_palette = NULL; +static boolean gif_colorprofile = false; +static RGBA_t *gif_headerpalette = NULL; +static RGBA_t *gif_framepalette = NULL; static FILE *gif_out = NULL; static INT32 gif_frames = 0; @@ -398,14 +402,13 @@ const UINT8 gifhead_nsid[19] = {0x21,0xFF,0x0B, // extension block + size // -// GIF_setpalette -// determine the gif palette. +// GIF_getpalette +// determine the palette for the current frame. // -static void GIF_setpalette(void) +static RGBA_t *GIF_getpalette(size_t palnum) { // In hardware mode, uses the master palette - size_t palnum = (rendermode == render_soft) ? ((gif_localcolortable) ? max(st_palette, 0) : 0) : 0; - gif_palette = ((cv_screenshot_colorprofile.value + return ((gif_colorprofile #ifdef HWRENDER && (rendermode == render_soft) #endif @@ -416,12 +419,11 @@ static void GIF_setpalette(void) // // GIF_palwrite // writes the gif palette. -// used both for the header and the local color table. +// used both for the header and local color tables. // -static UINT8 *GIF_palwrite(UINT8 *p) +static UINT8 *GIF_palwrite(UINT8 *p, RGBA_t *pal) { INT32 i; - RGBA_t *pal = gif_palette; for (i = 0; i < 256; i++) { WRITEUINT8(p, pal[i].s.red); @@ -439,10 +441,7 @@ static void GIF_headwrite(void) { UINT8 *gifhead = Z_Malloc(800, PU_STATIC, NULL); UINT8 *p = gifhead; - UINT8 *last_p; UINT16 rwidth, rheight; - size_t totalbytes; - INT32 i; if (!gif_out) return; @@ -463,36 +462,22 @@ static void GIF_headwrite(void) rheight = vid.height; } - last_p = p; WRITEUINT16(p, rwidth); WRITEUINT16(p, rheight); // colors, aspect, etc - WRITEUINT8(p, (gif_localcolortable ? 0xF0 : 0xF7)); // (0xF7 = 1111 0111) + WRITEUINT8(p, 0xF7); // (0xF7 = 1111 0111) WRITEUINT8(p, 0x00); WRITEUINT8(p, 0x00); - // Lactozilla: should be 800 without a local color table - totalbytes = sizeof(gifhead_base) + sizeof(gifhead_nsid) + (p - last_p); - // write color table - if (!gif_localcolortable) - { - p = GIF_palwrite(p); - totalbytes += (256 * 3); - } - else - { - // write a dummy palette - for (i = 0; i < 6; i++, totalbytes++) - WRITEUINT8(p, 0); - } + p = GIF_palwrite(p, gif_headerpalette); // write extension block WRITEMEM(p, gifhead_nsid, sizeof(gifhead_nsid)); // write to file and be done with it! - fwrite(gifhead, 1, totalbytes, gif_out); + fwrite(gifhead, 1, 800, gif_out); Z_Free(gifhead); } @@ -514,7 +499,7 @@ static void hwrconvert(void) INT32 x, y; size_t i = 0; - InitColorLUT(gif_palette); + InitColorLUT(gif_framepalette); for (y = 0; y < vid.height; y++) { @@ -540,6 +525,7 @@ static void GIF_framewrite(void) UINT8 *p; UINT8 *movie_screen = screens[2]; INT32 blitx, blity, blitw, blith; + boolean palchanged; if (!gifframe_data) gifframe_data = Z_Malloc(gifframe_size, PU_STATIC, NULL); @@ -548,8 +534,18 @@ static void GIF_framewrite(void) if (!gif_out) return; + // Lactozilla: Compare the header's palette with the current frame's palette and see if it changed. + if (gif_localcolortable) + { + gif_framepalette = GIF_getpalette((rendermode == render_soft) ? ((gif_localcolortable) ? max(st_palette, 0) : 0) : 0); + palchanged = memcmp(gif_headerpalette, gif_framepalette, sizeof(RGBA_t) * 256); + } + else + palchanged = false; + // Compare image data (for optimizing GIF) - if (gif_optimize && gif_frames > 0) + // If the palette has changed, the entire frame is considered to be different. + if (gif_optimize && gif_frames > 0 && (!palchanged)) { // before blit movie_screen points to last frame, cur_screen points to this frame UINT8 *cur_screen = screens[0]; @@ -617,9 +613,14 @@ static void GIF_framewrite(void) WRITEUINT8(p, 0); // no local table of colors else { - WRITEUINT8(p, 0x87); // (0x87 = 1000 0111) - GIF_setpalette(); - p = GIF_palwrite(p); + if (palchanged) + { + // The palettes are different, so write the Local Color Table! + WRITEUINT8(p, 0x87); // (0x87 = 1000 0111) + p = GIF_palwrite(p, gif_framepalette); + } + else + WRITEUINT8(p, 0); // They are equal, no Local Color Table needed. } scrbuf_pos = movie_screen + blitx + (blity * vid.width); @@ -685,8 +686,8 @@ INT32 GIF_open(const char *filename) gif_optimize = (!!cv_gif_optimize.value); gif_downscale = (!!cv_gif_downscale.value); gif_localcolortable = (!!cv_gif_localcolortable.value); - if (!gif_localcolortable) - GIF_setpalette(); + gif_colorprofile = (!!cv_screenshot_colorprofile.value); + gif_headerpalette = GIF_getpalette(0); GIF_headwrite(); gif_frames = 0; From 21a168d41013445e90093c7c5428cec37cb2ab0e Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Mon, 3 Feb 2020 02:24:22 -0300 Subject: [PATCH 25/27] What (cherry picked from commit d1e8744583b9a868665b4b3a5e4803a29829f7a0) --- src/m_anigif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/m_anigif.c b/src/m_anigif.c index b914cb14c..15528599b 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -537,7 +537,7 @@ static void GIF_framewrite(void) // Lactozilla: Compare the header's palette with the current frame's palette and see if it changed. if (gif_localcolortable) { - gif_framepalette = GIF_getpalette((rendermode == render_soft) ? ((gif_localcolortable) ? max(st_palette, 0) : 0) : 0); + gif_framepalette = GIF_getpalette(max(st_palette, 0)); palchanged = memcmp(gif_headerpalette, gif_framepalette, sizeof(RGBA_t) * 256); } else From ef028e5822c4c1f19f81ec5aa4d9505dc087b818 Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 23 Mar 2020 17:50:51 -0700 Subject: [PATCH 26/27] Add a comment because this is confusing --- src/m_anigif.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/m_anigif.c b/src/m_anigif.c index 15528599b..eef94a522 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -466,6 +466,10 @@ static void GIF_headwrite(void) WRITEUINT16(p, rheight); // colors, aspect, etc + /* + also these are magical values, check out + https://tronche.com/computer-graphics/gif/gif89a.html#screen-descriptor + */ WRITEUINT8(p, 0xF7); // (0xF7 = 1111 0111) WRITEUINT8(p, 0x00); WRITEUINT8(p, 0x00); From 0a0dede69e509ec5905b04222387bba1fe84e3b2 Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 24 Mar 2020 15:13:07 -0700 Subject: [PATCH 27/27] Revert "Correcting gamma to match base SRB2." This reverts commit cdf8c54f2d1feae314daebbaee61f0e03e1fb929. --- src/v_video.c | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index 517cae719..d7e8b64c1 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -120,6 +120,7 @@ http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter24.html Please check it out if you're trying to maintain this. toast 18/04/17 */ + float Cubepal[2][2][2][3]; // returns whether to apply cube, selectively avoiding expensive operations @@ -305,31 +306,6 @@ static boolean InitCube(void) return true; } -/* -So it turns out that the way gamma was implemented previously, the default -colour profile of the game was messed up. Since this bad decision has been -around for a long time, and the intent is to keep the base game looking the -same, I'm not gonna be the one to remove this base modification. -toast 20/04/17 -*/ -const UINT8 correctiontable[256] = - {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16, - 17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32, - 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48, - 49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64, - 65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80, - 81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96, - 97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112, - 113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128, - 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, - 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, - 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175, - 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, - 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207, - 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223, - 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239, - 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255}; - // keep a copy of the palette so that we can get the RGB value for a color index at any time. static void LoadPalette(const char *lumpname) { @@ -347,9 +323,9 @@ static void LoadPalette(const char *lumpname) pal = W_CacheLumpNum(lumpnum, PU_CACHE); for (i = 0; i < palsize; i++) { - pMasterPalette[i].s.red = pLocalPalette[i].s.red = correctiontable[*pal++]; - pMasterPalette[i].s.green = pLocalPalette[i].s.green = correctiontable[*pal++]; - pMasterPalette[i].s.blue = pLocalPalette[i].s.blue = correctiontable[*pal++]; + pMasterPalette[i].s.red = pLocalPalette[i].s.red = *pal++; + pMasterPalette[i].s.green = pLocalPalette[i].s.green = *pal++; + pMasterPalette[i].s.blue = pLocalPalette[i].s.blue = *pal++; pMasterPalette[i].s.alpha = pLocalPalette[i].s.alpha = 0xFF; // lerp of colour cubing!