From 3fd5d1161f600cdc06c84830826937251d755d81 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Tue, 8 Apr 2025 18:46:58 +0300 Subject: [PATCH] Integer scaling horizontal/vertical aspect fix --- drawing.cpp | 5 +++- include/drawing.h | 1 + od-win32/screenshot.cpp | 4 +-- od-win32/win32_scaler.cpp | 51 +++++++++++++++------------------------ od-win32/win32gfx.cpp | 2 +- 5 files changed, 28 insertions(+), 35 deletions(-) diff --git a/drawing.cpp b/drawing.cpp index 044d22f7..adf92ce9 100644 --- a/drawing.cpp +++ b/drawing.cpp @@ -754,7 +754,7 @@ void store_custom_limits(int w, int h, int x, int y) #endif } -int get_custom_limits(int *pw, int *ph, int *pdx, int *pdy, int *prealh) +int get_custom_limits(int *pw, int *ph, int *pdx, int *pdy, int *prealh, int *hres, int *vres) { struct vidbuf_description *vidinfo = &adisplays[0].gfxvidinfo; int w, h, dx, dy, y1, y2, dbl1, dbl2; @@ -765,6 +765,9 @@ int get_custom_limits(int *pw, int *ph, int *pdx, int *pdy, int *prealh) return 0; } + *hres = hresolution; + *vres = currprefs.gfx_vresolution; + if (!isnativevidbuf(0)) { *pw = vidinfo->inbuffer->outwidth; *ph = vidinfo->inbuffer->outheight; diff --git a/include/drawing.h b/include/drawing.h index 55fd2a1f..70626384 100644 --- a/include/drawing.h +++ b/include/drawing.h @@ -127,6 +127,7 @@ extern void check_custom_limits (void); extern void get_custom_topedge (int *x, int *y, bool max); extern void get_custom_raw_limits (int *pw, int *ph, int *pdx, int *pdy); void get_custom_mouse_limits (int *pw, int *ph, int *pdx, int *pdy, int dbl); +extern int get_custom_limits(int *pw, int *ph, int *pdx, int *pdy, int *prealh, int *hres, int *vres); extern void putpixel(uae_u8 *buf, uae_u8 *genlockbuf, int x, xcolnr c8); extern void allocvidbuffer(int monid, struct vidbuffer *buf, int width, int height, int depth); extern void freevidbuffer(int monid, struct vidbuffer *buf); diff --git a/od-win32/screenshot.cpp b/od-win32/screenshot.cpp index c70b74c0..34894913 100644 --- a/od-win32/screenshot.cpp +++ b/od-win32/screenshot.cpp @@ -216,8 +216,8 @@ static int screenshot_prepare(int monid, int imagemode, struct vidbuffer *vb, bo } if (!WIN32GFX_IsPicassoScreen(mon) && screenshot_clipmode == 1) { - int cw, ch, cx, cy, crealh = 0; - if (get_custom_limits(&cw, &ch, &cx, &cy, &crealh)) { + int cw, ch, cx, cy, crealh = 0, hres, vres; + if (get_custom_limits(&cw, &ch, &cx, &cy, &crealh, &hres, &vres)) { int maxw = currprefs.screenshot_max_width << currprefs.gfx_resolution; int maxh = currprefs.screenshot_max_height << currprefs.gfx_vresolution; int minw = currprefs.screenshot_min_width << currprefs.gfx_resolution; diff --git a/od-win32/win32_scaler.cpp b/od-win32/win32_scaler.cpp index a5f2cd2a..90bc9324 100644 --- a/od-win32/win32_scaler.cpp +++ b/od-win32/win32_scaler.cpp @@ -281,6 +281,8 @@ void getfilterdata(int monid, struct displayscale *ds) if (scalemode) { int cw, ch, cx, cy, cv = 0, crealh = 0; + int hres = currprefs.gfx_resolution; + int vres = currprefs.gfx_vresolution; static int oxmult, oymult; filterxmult = (float)ds->scale; @@ -340,7 +342,7 @@ void getfilterdata(int monid, struct displayscale *ds) } if (scalemode == AUTOSCALE_INTEGER_AUTOSCALE) { - ok = get_custom_limits (&cw, &ch, &cx, &cy, &crealh) != 0; + ok = get_custom_limits (&cw, &ch, &cx, &cy, &crealh, &hres, &vres) != 0; if (ok) { set_custom_limits(cw, ch, cx, cy, true); store_custom_limits(cw, ch, cx, cy); @@ -373,47 +375,34 @@ void getfilterdata(int monid, struct displayscale *ds) extraw = 0; extrah = 0; - xmult = 1.0; - ymult = 1.0; + mult = 1.0f; + xmult = 1.0f; + ymult = 1.0f; filter_horiz_zoom = 0; filter_vert_zoom = 0; filter_horiz_zoom_mult = 1.0; filter_vert_zoom_mult = 1.0; - float m = 1.0f; - if (manual) { - if (currprefs.gfx_resolution >= currprefs.gfx_vresolution) { - m = (float)(1 << (currprefs.gfx_resolution - currprefs.gfx_vresolution)); - } else { - m = 1.0f / (1 << (currprefs.gfx_vresolution - currprefs.gfx_resolution)); - } + if (hres >= vres) { + ymult = (float)(1 << (hres - vres)); + } else { + xmult = (float)(1 << (vres - hres)); } float multadd = 1.0f / (1 << currprefs.gf[idx].gfx_filter_integerscalelimit); if (cw2 > 0 && ch2 > 0) { - if (cw2 > maxw || ch2 > maxh) { - while (cw2 / mult - adjw > maxw || ch2 / mult - adjh > maxh) { + if (cw2 * xmult > maxw || ch2 * ymult > maxh) { + while (cw2 * xmult / mult - adjw > maxw || ch2 * ymult / mult - adjh > maxh) { mult += multadd; } - float multx = mult, multy = mult; - maxw = (int)(maxw * mult); - maxh = (int)(maxh * mult); + maxw = (int)((maxw / xmult) * mult); + maxh = (int)((maxh / ymult) * mult); } else { - while (((cw2 * (mult + multadd)) / m) - adjw <= maxw && ch2 * (mult + multadd) - adjh <= maxh) { + while ((cw2 * (xmult * mult + multadd)) - adjw <= maxw && ch2 * (ymult * mult + multadd) - adjh <= maxh) { mult += multadd; } - - float multx = mult, multy = mult; - // if width is smaller than height, double width (programmed modes) - if (cw2 * (mult + multadd) - adjw <= maxw && cw2 < ch2) { - multx *= 2; - } - // if width is >=2.4x height, double height (non-doublescanned superhires) - if (ch2 * (mult * 2) - adjh <= maxh && cw2 > ch2 * 2.4) { - multy *= 2; - } - maxw = (int)((maxw + mult - multadd) / multx); - maxh = (int)((maxh + mult - multadd) / multy); + maxw = (int)(maxw / (xmult * mult)); + maxh = (int)(maxh / (ymult * mult)); } } @@ -454,14 +443,14 @@ void getfilterdata(int monid, struct displayscale *ds) } else if (scalemode == AUTOSCALE_CENTER) { - cv = get_custom_limits(&cw, &ch, &cx, &cy, &crealh); + cv = get_custom_limits(&cw, &ch, &cx, &cy, &crealh, &hres, &vres); if (cv) { store_custom_limits(cw, ch, cx, cy); } } else if (scalemode == AUTOSCALE_RESIZE) { - cv = get_custom_limits (&cw, &ch, &cx, &cy, &crealh); + cv = get_custom_limits (&cw, &ch, &cx, &cy, &crealh, &hres, &vres); if (cv) { set_custom_limits(cw, ch, cx, cy, false); store_custom_limits(cw, ch, cx, cy); @@ -470,7 +459,7 @@ void getfilterdata(int monid, struct displayscale *ds) } else { - cv = get_custom_limits (&cw, &ch, &cx, &cy, &crealh); + cv = get_custom_limits (&cw, &ch, &cx, &cy, &crealh, &hres, &vres); if (cv) { set_custom_limits (cw, ch, cx, cy, true); store_custom_limits (cw, ch, cx, cy); diff --git a/od-win32/win32gfx.cpp b/od-win32/win32gfx.cpp index 70a57a9a..c1e0a3bb 100644 --- a/od-win32/win32gfx.cpp +++ b/od-win32/win32gfx.cpp @@ -2377,7 +2377,7 @@ int check_prefs_changed_gfx(void) currprefs.gf[0].gfx_filter_autoscale = changed_prefs.gf[0].gfx_filter_autoscale; currprefs.gf[2].gfx_filter_autoscale = changed_prefs.gf[2].gfx_filter_autoscale; - get_custom_limits (NULL, NULL, NULL, NULL, NULL); + get_custom_limits (NULL, NULL, NULL, NULL, NULL, NULL, NULL); fixup_prefs_dimensions (&changed_prefs); return 1; -- 2.47.3