1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 09:39:43 +01:00

Upscale screenshots 2x

The plan is to have Steam screenshots always be 2x, but in the VVVVVV
screenshots directory (for F6 keybind) save both 1x and 2x.

Again, just for now, the 2x screenshot is being saved to a temporary
location for testing and will get proper timestamps later.
This commit is contained in:
Misa 2024-01-07 17:56:26 -08:00 committed by Misa Elizabeth Kai
parent 20f0fafa5e
commit 93ec2c6cca
8 changed files with 76 additions and 4 deletions

View file

@ -34,9 +34,19 @@ SDL_Surface* GRAPHICS_tempScreenshot(void)
return graphics.tempScreenshot;
}
SDL_Surface* GRAPHICS_tempScreenshot2x(void)
{
return graphics.tempScreenshot2x;
}
uint8_t UTIL_TakeScreenshot(SDL_Surface** surface)
{
return TakeScreenshot(surface);
}
uint8_t UTIL_UpscaleScreenshot2x(SDL_Surface* src, SDL_Surface** dest)
{
return UpscaleScreenshot2x(src, dest);
}
} /* extern "C" */

View file

@ -11,7 +11,9 @@ extern "C" {
char* HELP_number_words(int _t, const char* number_class);
uint32_t LOC_toupper_ch(uint32_t ch);
SDL_Surface* GRAPHICS_tempScreenshot(void);
SDL_Surface* GRAPHICS_tempScreenshot2x(void);
uint8_t UTIL_TakeScreenshot(SDL_Surface** surface);
uint8_t UTIL_UpscaleScreenshot2x(SDL_Surface* src, SDL_Surface** dest);
#ifdef __cplusplus
}

View file

@ -112,6 +112,7 @@ void Graphics::init(void)
backgroundTexture = NULL;
foregroundTexture = NULL;
tempScreenshot = NULL;
tempScreenshot2x = NULL;
towerbg = TowerBG();
titlebg = TowerBG();
trinketr = 0;
@ -222,6 +223,7 @@ void Graphics::destroy_buffers(void)
VVV_freefunc(SDL_FreeSurface, tempFilterSrc);
VVV_freefunc(SDL_FreeSurface, tempFilterDest);
VVV_freefunc(SDL_FreeSurface, tempScreenshot);
VVV_freefunc(SDL_FreeSurface, tempScreenshot2x);
}
void Graphics::drawspritesetcol(int x, int y, int t, int c)

View file

@ -333,6 +333,7 @@ public:
SDL_Texture* foregroundTexture;
SDL_Texture* tempScrollingTexture;
SDL_Surface* tempScreenshot;
SDL_Surface* tempScreenshot2x;
TowerBG towerbg;
TowerBG titlebg;

View file

@ -523,6 +523,19 @@ bool SaveScreenshot(void)
return false;
}
success = UpscaleScreenshot2x(graphics.tempScreenshot, &graphics.tempScreenshot2x);
if (!success)
{
vlog_error("Could not upscale screenshot to 2x");
return false;
}
success = SaveImage(graphics.tempScreenshot2x, "screenshots/test2x.png");
if (!success)
{
return false;
}
vlog_info("Saved screenshot");
return true;
}

View file

@ -346,3 +346,40 @@ bool TakeScreenshot(SDL_Surface** surface)
return true;
}
bool UpscaleScreenshot2x(SDL_Surface* src, SDL_Surface** dest)
{
if (src == NULL)
{
SDL_assert(0 && "src is NULL!");
return false;
}
if (dest == NULL)
{
SDL_assert(0 && "dest is NULL!");
return false;
}
if (*dest == NULL)
{
*dest = SDL_CreateRGBSurface(
0, src->w * 2, src->h * 2, src->format->BitsPerPixel, 0, 0, 0, 0
);
if (*dest == NULL)
{
WHINE_ONCE_ARGS(
("Could not create temporary surface: %s", SDL_GetError())
);
return false;
}
}
int result = SDL_BlitScaled(src, NULL, *dest, NULL);
if (result != 0)
{
WHINE_ONCE_ARGS(("Could not blit surface: %s", SDL_GetError()));
return false;
}
return true;
}

View file

@ -15,5 +15,6 @@ void UpdateFilter(void);
void ApplyFilter(SDL_Surface** src, SDL_Surface** dest);
bool TakeScreenshot(SDL_Surface** surface);
bool UpscaleScreenshot2x(SDL_Surface* src, SDL_Surface** dest);
#endif /* GRAPHICSUTIL_H */

View file

@ -131,13 +131,19 @@ static void run_screenshot()
{
return;
}
SDL_Surface* surface2x = GRAPHICS_tempScreenshot2x();
success = UTIL_UpscaleScreenshot2x(surface, &surface2x);
if (!success)
{
return;
}
SteamAPI_ISteamScreenshots_WriteScreenshot(
steamScreenshots,
surface->pixels,
surface->w * surface->h * surface->format->BytesPerPixel,
surface->w,
surface->h
surface2x->pixels,
surface2x->w * surface2x->h * surface2x->format->BytesPerPixel,
surface2x->w,
surface2x->h
);
}