Skip to content

Commit 41e1f19

Browse files
authored
[JO] Fix level transition screen (#1254)
When redsaurus fixed the save screenshot (in ff21085 ), they must have missed the double usage of SCR_GetScreenshot. Besides being used for the savegame thumbnails, it's used directly as an argument for DrawStrechRaw. DrawStrechRaw expects a RGBA buffer to draw to the screen. For drawing the level transition screen correctly I also had to flip the image in RE_GetScreenShot, so I also changed the flipping behaviour when saving the savegame.
1 parent 199ddc7 commit 41e1f19

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

code/client/cl_scrn.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,8 @@ void SCR_PrecacheScreenshot()
554554

555555
}
556556

557+
// Returns a SG_SCR_WIDTH x SG_SCR_HEIGHT screenshot buffer
558+
// Must match color components with DrawStretchRaw: 4
557559
byte *SCR_GetScreenshot(qboolean *qValid)
558560
{
559561
if (!screenDataValid) {

code/rd-vanilla/tr_draw.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,11 @@ void RE_GetScreenShot(byte *buffer, int w, int h)
198198
b += src[2];
199199
}
200200
}
201-
dst = buffer + 3 * ( y * w + x );
201+
dst = buffer + 4 * ((h - y - 1) * w + x );
202202
dst[0] = r / 12;
203203
dst[1] = g / 12;
204204
dst[2] = b / 12;
205+
dst[3] = 255;
205206
}
206207
}
207208

code/server/sv_savegame.cpp

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,19 +1030,20 @@ static void SG_WriteScreenshot(qboolean qbAutosave, const char *psMapName)
10301030

10311031
byte *pbRawScreenShot = NULL;
10321032
byte *byBlank = NULL;
1033+
byte *src, *dst;
10331034

10341035
if( qbAutosave )
10351036
{
10361037
// try to read a levelshot (any valid TGA/JPG etc named the same as the map)...
10371038
//
10381039
int iWidth = SG_SCR_WIDTH;
10391040
int iHeight= SG_SCR_HEIGHT;
1040-
const size_t bySize = SG_SCR_WIDTH * SG_SCR_HEIGHT * 4;
1041-
byte *src, *dst;
1042-
1041+
const size_t bySize = SG_SCR_WIDTH * SG_SCR_HEIGHT * 4;
1042+
10431043
byBlank = new byte[bySize];
1044-
pbRawScreenShot = SCR_TempRawImage_ReadFromFile(va("levelshots/%s.tga",psMapName), &iWidth, &iHeight, byBlank, qtrue); // qtrue = vert flip
1044+
pbRawScreenShot = SCR_TempRawImage_ReadFromFile(va("levelshots/%s.tga",psMapName), &iWidth, &iHeight, byBlank, qfalse); // qfalse = vert flip
10451045

1046+
// SaveJPGToBuffer expects a 3 component RGB image, so resample
10461047
if (pbRawScreenShot)
10471048
{
10481049
for (int y = 0; y < iHeight; y++)
@@ -1061,23 +1062,36 @@ static void SG_WriteScreenshot(qboolean qbAutosave, const char *psMapName)
10611062

10621063
if (!pbRawScreenShot)
10631064
{
1065+
const size_t bySize = SG_SCR_WIDTH * SG_SCR_HEIGHT * 3;
1066+
1067+
byBlank = new byte[bySize];
10641068
pbRawScreenShot = SCR_GetScreenshot(0);
1069+
1070+
// We can't just do the same resampling as with qbAutosave as we would alter the cached buffer
1071+
// That might be used elsewhere and is expected to have RGBA data, like for drawing the level transition screenshot
1072+
if (pbRawScreenShot)
1073+
{
1074+
for (int y = 0; y < SG_SCR_HEIGHT; y++)
1075+
{
1076+
for (int x = 0; x < SG_SCR_WIDTH; x++)
1077+
{
1078+
src = pbRawScreenShot + 4 * (y * SG_SCR_WIDTH + x);
1079+
dst = byBlank + 3 * (y * SG_SCR_WIDTH + x);
1080+
dst[0] = src[0];
1081+
dst[1] = src[1];
1082+
dst[2] = src[2];
1083+
}
1084+
}
1085+
pbRawScreenShot = byBlank;
1086+
}
10651087
}
10661088

1067-
10681089
size_t iJPGDataSize = 0;
10691090
size_t bufSize = SG_SCR_WIDTH * SG_SCR_HEIGHT * 3;
10701091
byte *pJPGData = (byte *)Z_Malloc( static_cast<int>(bufSize), TAG_TEMP_WORKSPACE, qfalse, 4 );
10711092

1072-
#ifdef JK2_MODE
1073-
bool flip_vertical = true;
1074-
#else
1075-
bool flip_vertical = false;
1076-
#endif // JK2_MODE
1077-
1078-
iJPGDataSize = re.SaveJPGToBuffer(pJPGData, bufSize, JPEG_IMAGE_QUALITY, SG_SCR_WIDTH, SG_SCR_HEIGHT, pbRawScreenShot, 0, flip_vertical );
1079-
if ( qbAutosave )
1080-
delete[] byBlank;
1093+
iJPGDataSize = re.SaveJPGToBuffer(pJPGData, bufSize, JPEG_IMAGE_QUALITY, SG_SCR_WIDTH, SG_SCR_HEIGHT, pbRawScreenShot, 0, false );
1094+
delete[] byBlank;
10811095

10821096
saved_game.write_chunk<uint32_t>(
10831097
INT_ID('S', 'H', 'L', 'N'),

0 commit comments

Comments
 (0)