Skip to content

Commit

Permalink
platform, add integer scaling for sdl windows
Browse files Browse the repository at this point in the history
  • Loading branch information
irixxxx committed Sep 9, 2024
1 parent d9df8fc commit 232dc6c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 36 deletions.
26 changes: 13 additions & 13 deletions platform/common/menu_pico.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,24 @@ static void make_bg(int no_scale, int from_screen)
if (!no_scale && g_menuscreen_w / w >= 2 && g_menuscreen_h / h >= 2)
{
int xf = g_menuscreen_w / w, yf = g_menuscreen_h / h;
int f = no_scale ? 1 : xf < yf ? xf : yf;
int xs = f * w, ys = f * h;
unsigned short t;
int i, j, k, l;
int f = no_scale ? 1 : xf < yf ? xf : yf, xs = f * w, ys = f * h;
int x = (g_menuscreen_w - xs)/2, y = (g_menuscreen_h - ys)/2;
uint16_t *p = (uint16_t *)g_menubg_ptr;
uint16_t *q = (uint16_t *)src;

x = (g_menuscreen_w - xs)/2, y = (g_menuscreen_h - ys)/2;
dst = (short *)g_menubg_ptr + y * g_menuscreen_w + x;
int i, j, k, l;
p += y * g_menuscreen_pp + x;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++, src++) {
t = (PXMASKH(*src,1)>>1) - (PXMASKH(*src,3)>>3);
for (j = 0; j < w; j++, q++) {
uint16_t t = (PXMASKH(*q,1)>>1) - (PXMASKH(*q,3)>>3);
for (l = 0; l < f; l++)
*dst++ = t;
*p++ = t;
}
src += pp - w;
dst += g_menuscreen_w - xs;
p += g_menuscreen_pp - xs;
q += pp - w;
for (k = 1; k < f; k++) {
memcpy(dst, dst-g_menuscreen_w, g_menuscreen_w*2);
dst += g_menuscreen_w;
memcpy(p, p-g_menuscreen_pp, g_menuscreen_w*2);
p += g_menuscreen_pp;
}
}
return;
Expand Down
62 changes: 39 additions & 23 deletions platform/common/plat_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,29 @@ void rgb565_to_uyvy(void *d, const void *s, int w, int h, int pitch, int dpitch,
}
}

void copy_intscale(void *dst, int w, int h, int pp, void *src, int sw, int sh, int spp)
{
int xf = w / sw, yf = h / sh;
int f = xf < yf ? xf : yf, xs = f * sw, ys = f * sh;
int x = (w - xs)/2, y = (h - ys)/2;
uint16_t *p = (uint16_t *)dst;
uint16_t *q = (uint16_t *)src;

int i, j, k, l;
p += y * pp + x;
for (i = 0; i < sh; i++) {
for (j = 0; j < sw; j++, q++)
for (l = 0; l < f; l++)
*p++ = *q;
p += pp - xs;
q += spp - sw;
for (k = 1; k < f; k++) {
memcpy(p, p-pp, w*2);
p += pp;
}
}
}

static int clear_buf_cnt, clear_stat_cnt;

static void resize_buffers(void)
Expand All @@ -190,17 +213,12 @@ void plat_video_set_size(int w, int h)
{
if (area.w != w || area.h != h) {
area = (struct area) { w, h };
if (plat_sdl_change_video_mode(w, h, 0) < 0) {
// failed, revert to original resolution
area = (struct area) { g_screen_width,g_screen_height };
plat_sdl_change_video_mode(g_screen_width, g_screen_height, 0);
}
if (!plat_sdl_overlay && !plat_sdl_gl_active) {
g_screen_width = plat_sdl_screen->w;
g_screen_height = plat_sdl_screen->h;
g_screen_ppitch = plat_sdl_screen->pitch/2;
g_screen_ptr = plat_sdl_screen->pixels;
} else {
if (plat_sdl_overlay || plat_sdl_gl_active) {
if (plat_sdl_change_video_mode(w, h, 0) < 0) {
// failed, revert to original resolution
area = (struct area) { g_screen_width,g_screen_height };
plat_sdl_change_video_mode(g_screen_width, g_screen_height, 0);
}
g_screen_width = w;
g_screen_height = h;
g_screen_ppitch = w;
Expand Down Expand Up @@ -236,15 +254,13 @@ void plat_video_flip(void)
gl_flip(shadow_fb, g_screen_ppitch, g_screen_height);
}
else {
if (SDL_MUSTLOCK(plat_sdl_screen)) {
copy_intscale(plat_sdl_screen->pixels, plat_sdl_screen->w, plat_sdl_screen->h, plat_sdl_screen->pitch/2, shadow_fb, 320, 240, 320);
if (SDL_MUSTLOCK(plat_sdl_screen))
SDL_UnlockSurface(plat_sdl_screen);
SDL_Flip(plat_sdl_screen);
SDL_Flip(plat_sdl_screen);
if (SDL_MUSTLOCK(plat_sdl_screen))
SDL_LockSurface(plat_sdl_screen);
} else
SDL_Flip(plat_sdl_screen);
g_screen_ppitch = plat_sdl_screen->pitch/2;
g_screen_ptr = plat_sdl_screen->pixels;
plat_video_set_buffer(g_screen_ptr);

if (clear_buf_cnt) {
memset(g_screen_ptr, 0, plat_sdl_screen->pitch*plat_sdl_screen->h);
clear_buf_cnt--;
Expand Down Expand Up @@ -356,17 +372,17 @@ void plat_video_loop_prepare(void)
}
g_screen_ppitch = g_screen_width;
g_screen_ptr = shadow_fb;
plat_video_set_size(g_screen_width, g_screen_height);
}
else {
g_screen_width = plat_sdl_screen->w;
g_screen_height = plat_sdl_screen->h;
g_screen_ppitch = plat_sdl_screen->pitch/2;
g_screen_width = 320;
g_screen_height = 240;
g_screen_ppitch = 320;
if (SDL_MUSTLOCK(plat_sdl_screen))
SDL_LockSurface(plat_sdl_screen);
g_screen_ptr = plat_sdl_screen->pixels;
g_screen_ptr = shadow_fb;
}

plat_video_set_size(g_screen_width, g_screen_height);
plat_video_set_buffer(g_screen_ptr);
}

Expand Down

0 comments on commit 232dc6c

Please sign in to comment.