Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add screenshotPNG command #262

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Remove packAlign from R_LevelShot()
Filling the resample buffer didn't correctly handle offset for packAlign
if it didn't match the alignment returned by Hunk_AllocateTempMemory().

There isn't SIMD or something that the code wants a specific alignment.
Hunk_AllocateTempMemory() is aligned to sizeof(intptr_t) anyway so there
isn't a reason to add a memory alignment here.
zturtleman committed May 24, 2024
commit af7812f1a04fe2cc2bbee777cf9fad095f528446
32 changes: 9 additions & 23 deletions code/renderergl1/tr_init.c
Original file line number Diff line number Diff line change
@@ -532,11 +532,10 @@ the menu system, sampled down from full screen distorted images
void R_LevelShot( screenshotType_e type, const char *ext ) {
char fileName[MAX_OSPATH];
byte *source, *allsource;
byte *resample, *resamplestart;
byte *resample;
size_t offset = 0, memcount;
int spadlen, rpadlen;
int padwidth, linelen;
GLint packAlign;
int spadlen;
int linelen;
byte *src, *dst;
int x, y;
int r, g, b;
@@ -562,21 +561,10 @@ void R_LevelShot( screenshotType_e type, const char *ext ) {
allsource = RB_ReadPixels(0, 0, glConfig.vidWidth, glConfig.vidHeight, &offset, &spadlen);
source = allsource + offset;

//
// Based on RB_ReadPixels
qglGetIntegerv(GL_PACK_ALIGNMENT, &packAlign);

linelen = width * 3;
padwidth = PAD(linelen, packAlign);
memcount = linelen * height;

// Allocate a few more bytes so that we can choose an alignment we like
resample = ri.Hunk_AllocateTempMemory(padwidth * height + offset + packAlign - 1);

resamplestart = PADP((intptr_t) resample + offset, packAlign);

offset = resamplestart - resample;
rpadlen = padwidth - linelen;
//
resample = ri.Hunk_AllocateTempMemory(memcount);

// resample from source
xScale = glConfig.vidWidth / (float)(width * 4.0f);
@@ -600,18 +588,16 @@ void R_LevelShot( screenshotType_e type, const char *ext ) {
}
}

memcount = (width * 3 + rpadlen) * height;

// gamma correct
if(glConfig.deviceSupportsGamma)
R_GammaCorrect(resample + offset, memcount);
R_GammaCorrect(resample, memcount);

if ( type == ST_TGA )
RE_SaveTGA(fileName, width, height, resample + offset, rpadlen);
RE_SaveTGA(fileName, width, height, resample, 0);
else if ( type == ST_JPEG )
RE_SaveJPG(fileName, r_screenshotJpegQuality->integer, width, height, resample + offset, rpadlen);
RE_SaveJPG(fileName, r_screenshotJpegQuality->integer, width, height, resample, 0);
else if ( type == ST_PNG )
RE_SavePNG(fileName, width, height, resample + offset, rpadlen);
RE_SavePNG(fileName, width, height, resample, 0);

ri.Hunk_FreeTempMemory(resample);
ri.Hunk_FreeTempMemory(allsource);
32 changes: 9 additions & 23 deletions code/renderergl2/tr_init.c
Original file line number Diff line number Diff line change
@@ -623,11 +623,10 @@ the menu system, sampled down from full screen distorted images
void R_LevelShot( screenshotType_e type, const char *ext ) {
char fileName[MAX_OSPATH];
byte *source, *allsource;
byte *resample, *resamplestart;
byte *resample;
size_t offset = 0, memcount;
int spadlen, rpadlen;
int padwidth, linelen;
GLint packAlign;
int spadlen;
int linelen;
byte *src, *dst;
int x, y;
int r, g, b;
@@ -653,21 +652,10 @@ void R_LevelShot( screenshotType_e type, const char *ext ) {
allsource = RB_ReadPixels(0, 0, glConfig.vidWidth, glConfig.vidHeight, &offset, &spadlen);
source = allsource + offset;

//
// Based on RB_ReadPixels
qglGetIntegerv(GL_PACK_ALIGNMENT, &packAlign);

linelen = width * 3;
padwidth = PAD(linelen, packAlign);
memcount = linelen * height;

// Allocate a few more bytes so that we can choose an alignment we like
resample = ri.Hunk_AllocateTempMemory(padwidth * height + offset + packAlign - 1);

resamplestart = PADP((intptr_t) resample + offset, packAlign);

offset = resamplestart - resample;
rpadlen = padwidth - linelen;
//
resample = ri.Hunk_AllocateTempMemory(memcount);

// resample from source
xScale = glConfig.vidWidth / (float)(width * 4.0f);
@@ -691,18 +679,16 @@ void R_LevelShot( screenshotType_e type, const char *ext ) {
}
}

memcount = (width * 3 + rpadlen) * height;

// gamma correct
if(glConfig.deviceSupportsGamma)
R_GammaCorrect(resample + offset, memcount);
R_GammaCorrect(resample, memcount);

if ( type == ST_TGA )
RE_SaveTGA(fileName, width, height, resample + offset, rpadlen);
RE_SaveTGA(fileName, width, height, resample, 0);
else if ( type == ST_JPEG )
RE_SaveJPG(fileName, r_screenshotJpegQuality->integer, width, height, resample + offset, rpadlen);
RE_SaveJPG(fileName, r_screenshotJpegQuality->integer, width, height, resample, 0);
else if ( type == ST_PNG )
RE_SavePNG(fileName, width, height, resample + offset, rpadlen);
RE_SavePNG(fileName, width, height, resample, 0);

ri.Hunk_FreeTempMemory(resample);
ri.Hunk_FreeTempMemory(allsource);