From 2b24ee9b53a2150c1becd71fd557dedf8fd5c007 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 19 Dec 2023 01:40:10 +0200 Subject: [PATCH] soft: scale small video in case if aspect ratio is same as window --- src/client/refresh/soft/sw_main.c | 39 ++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index ccbe46d7..69f2742a 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -2225,9 +2225,14 @@ RE_Draw_StretchDirectRaw(int x, int y, int w, int h, int cols, int rows, const b int pitch; Uint32 *pixels; + if (!cols || !rows || !data) + { + return; + } + if (bits != 32 || x || y || w != vid_buffer_width || h != vid_buffer_height || - cols != vid_buffer_width || rows != vid_buffer_height) + cols > vid_buffer_width || rows > vid_buffer_height) { /* Not full screen update */ RE_Draw_StretchRaw(x, y, w, h, cols, rows, data, bits); @@ -2257,11 +2262,39 @@ RE_Draw_StretchDirectRaw(int x, int y, int w, int h, int cols, int rows, const b return; } - memcpy(pixels, data, vid_buffer_width * vid_buffer_height * sizeof(Uint32)); + if (cols == vid_buffer_width && rows == vid_buffer_height) + { + memcpy(pixels, data, vid_buffer_width * vid_buffer_height * sizeof(Uint32)); + } + else + { + int i; + + for (i = 0; i < rows; i++) + { + memcpy(pixels + i * vid_buffer_width, + data + i * cols * sizeof(Uint32), + cols * sizeof(Uint32) + ); + } + } SDL_UnlockTexture(texture); - SDL_RenderCopy(renderer, texture, NULL, NULL); + if (cols == vid_buffer_width && rows == vid_buffer_height) + { + SDL_RenderCopy(renderer, texture, NULL, NULL); + } + else + { + SDL_Rect srcrect; + srcrect.x = 0; + srcrect.y = 0; + srcrect.w = cols; + srcrect.h = rows; + SDL_RenderCopy(renderer, texture, &srcrect, NULL); + } + SDL_RenderPresent(renderer); is_render_flushed = true;