From 93ec2c6ccaa881b41606f9c942016dfbbfc09782 Mon Sep 17 00:00:00 2001 From: Misa Date: Sun, 7 Jan 2024 17:56:26 -0800 Subject: [PATCH] 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. --- desktop_version/src/CWrappers.cpp | 10 ++++++ desktop_version/src/CWrappers.h | 2 ++ desktop_version/src/Graphics.cpp | 2 ++ desktop_version/src/Graphics.h | 1 + desktop_version/src/GraphicsResources.cpp | 13 ++++++++ desktop_version/src/GraphicsUtil.cpp | 37 +++++++++++++++++++++++ desktop_version/src/GraphicsUtil.h | 1 + desktop_version/src/SteamNetwork.c | 14 ++++++--- 8 files changed, 76 insertions(+), 4 deletions(-) diff --git a/desktop_version/src/CWrappers.cpp b/desktop_version/src/CWrappers.cpp index 90246eba..8eb31abc 100644 --- a/desktop_version/src/CWrappers.cpp +++ b/desktop_version/src/CWrappers.cpp @@ -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" */ diff --git a/desktop_version/src/CWrappers.h b/desktop_version/src/CWrappers.h index 857799ab..94fa1494 100644 --- a/desktop_version/src/CWrappers.h +++ b/desktop_version/src/CWrappers.h @@ -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 } diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index 02611a0f..48f1be1e 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -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) diff --git a/desktop_version/src/Graphics.h b/desktop_version/src/Graphics.h index 10167520..666b049c 100644 --- a/desktop_version/src/Graphics.h +++ b/desktop_version/src/Graphics.h @@ -333,6 +333,7 @@ public: SDL_Texture* foregroundTexture; SDL_Texture* tempScrollingTexture; SDL_Surface* tempScreenshot; + SDL_Surface* tempScreenshot2x; TowerBG towerbg; TowerBG titlebg; diff --git a/desktop_version/src/GraphicsResources.cpp b/desktop_version/src/GraphicsResources.cpp index a74b6712..be87f821 100644 --- a/desktop_version/src/GraphicsResources.cpp +++ b/desktop_version/src/GraphicsResources.cpp @@ -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; } diff --git a/desktop_version/src/GraphicsUtil.cpp b/desktop_version/src/GraphicsUtil.cpp index b1368af6..55e89b1a 100644 --- a/desktop_version/src/GraphicsUtil.cpp +++ b/desktop_version/src/GraphicsUtil.cpp @@ -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; +} diff --git a/desktop_version/src/GraphicsUtil.h b/desktop_version/src/GraphicsUtil.h index ffa89b51..4bdd217a 100644 --- a/desktop_version/src/GraphicsUtil.h +++ b/desktop_version/src/GraphicsUtil.h @@ -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 */ diff --git a/desktop_version/src/SteamNetwork.c b/desktop_version/src/SteamNetwork.c index 9af5f9cd..6720d11d 100644 --- a/desktop_version/src/SteamNetwork.c +++ b/desktop_version/src/SteamNetwork.c @@ -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 ); }