Skip to content

Commit 6e6b78a

Browse files
committed
Aspect ratio and scaling correction for PCE an GameGear
1 parent 6016b5f commit 6e6b78a

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/drivers/video.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,9 +1275,9 @@ void clear_screen(SDL_Surface *dst_surface) {
12751275

12761276

12771277
/// Nearest neighboor optimized with possible out of screen coordinates (for cropping)
1278-
static void flip_NNOptimized_AllowOutOfScreen(const MDFN_Surface *src_surface, SDL_Surface *dst_surface, int new_w, int new_h) {
1279-
int w1 = src_surface->w;
1280-
int h1 = src_surface->h;
1278+
static void flip_NNOptimized_AllowOutOfScreen(const MDFN_Surface *src_surface, MDFN_Rect &src_rect, SDL_Surface *dst_surface, int new_w, int new_h) {
1279+
int w1 = src_rect.w;
1280+
int h1 = src_rect.h;
12811281
int w2 = new_w;
12821282
int h2 = new_h;
12831283
int x_ratio = (int) ((w1 << 16) / w2);
@@ -1292,6 +1292,10 @@ static void flip_NNOptimized_AllowOutOfScreen(const MDFN_Surface *src_surface, S
12921292
}
12931293
int x_padding_ratio = x_padding * w1 / w2;
12941294
//printf("w1=%d, h1=%d, w2=%d, h2=%d\n", w1, h1, w2, h2);
1295+
//printf("src_surface->pitch32=%d, src_surface->pitchinpix=%d\n", src_surface->pitch32, src_surface->pitchinpix);
1296+
1297+
/// --- Offset to get first src_pixels row
1298+
uint32_t *src_row = src_surface->pixels + src_surface->pitchinpix * src_rect.y + src_rect.x;
12951299

12961300
for (int i = 0; i < h2; i++) {
12971301
if (i >= RES_HW_SCREEN_VERTICAL) {
@@ -1300,7 +1304,7 @@ static void flip_NNOptimized_AllowOutOfScreen(const MDFN_Surface *src_surface, S
13001304

13011305
uint32_t *t = ((uint32_t *)dst_surface->pixels) + ((i + y_padding) * ((w2 > RES_HW_SCREEN_HORIZONTAL) ? RES_HW_SCREEN_HORIZONTAL : w2)) ;
13021306
y2 = (i * y_ratio) >> 16;
1303-
uint32_t *p = src_surface->pixels + (y2 * w1 + x_padding_ratio);
1307+
uint32_t *p = src_row + (y2 * src_surface->pitchinpix) + x_padding_ratio;
13041308
int rat = 0;
13051309
for (int j = 0; j < w2; j++) {
13061310
if (j >= RES_HW_SCREEN_HORIZONTAL) {
@@ -1309,7 +1313,7 @@ static void flip_NNOptimized_AllowOutOfScreen(const MDFN_Surface *src_surface, S
13091313
x2 = rat >> 16;
13101314
*t++ = p[x2];
13111315
rat += x_ratio;
1312-
//printf("y=%d, x=%d, y2=%d, x2=%d, (y2*w1)+x2=%d\n", i, j, y2, x2, (y2 * src_surface->w) + x2);
1316+
//printf("y=%d, x=%d, y2=%d, x2=%d, (y2*w1)+x2=%d\n", i, j, y2, x2, (y2 * w1) + x2);
13131317
}
13141318
}
13151319
}
@@ -1337,6 +1341,13 @@ void BlitScreen(MDFN_Surface *msurface, const MDFN_Rect *DisplayRect, const int3
13371341
/* Correct colors */
13381342
msurface->SetFormat(*pf_needed, TRUE);
13391343

1344+
/* Get source rectangle */
1345+
src_rect.x = DisplayRect->x;
1346+
src_rect.w = DisplayRect->w;
1347+
src_rect.y = DisplayRect->y;
1348+
src_rect.h = DisplayRect->h;
1349+
//printf("********** src_rect={%d, %d} %dx%d\n", src_rect.x, src_rect.y, src_rect.w, src_rect.h);
1350+
13401351
/* Clear screen if AR changed */
13411352
static int prev_aspect_ratio = aspect_ratio;
13421353
if (prev_aspect_ratio != aspect_ratio || need_screen_cleared) {
@@ -1350,17 +1361,17 @@ void BlitScreen(MDFN_Surface *msurface, const MDFN_Rect *DisplayRect, const int3
13501361
switch (aspect_ratio) {
13511362
case ASPECT_RATIOS_TYPE_STRETCHED:
13521363
/* Stretched NN*/
1353-
flip_NNOptimized_AllowOutOfScreen(msurface, hw_screen, hw_screen->w, hw_screen->h);
1364+
flip_NNOptimized_AllowOutOfScreen(msurface, src_rect, hw_screen, hw_screen->w, hw_screen->h);
13541365
break;
13551366

13561367
case ASPECT_RATIOS_TYPE_CROPPED:
1357-
flip_NNOptimized_AllowOutOfScreen(msurface, hw_screen,
1368+
flip_NNOptimized_AllowOutOfScreen(msurface, src_rect, hw_screen,
13581369
MAX(msurface->w*RES_HW_SCREEN_VERTICAL/msurface->h, RES_HW_SCREEN_HORIZONTAL),
13591370
RES_HW_SCREEN_VERTICAL);
13601371
break;
13611372

13621373
case ASPECT_RATIOS_TYPE_SCALED:
1363-
flip_NNOptimized_AllowOutOfScreen(msurface, hw_screen,
1374+
flip_NNOptimized_AllowOutOfScreen(msurface, src_rect, hw_screen,
13641375
RES_HW_SCREEN_HORIZONTAL,
13651376
MIN(msurface->h*RES_HW_SCREEN_HORIZONTAL/msurface->w, RES_HW_SCREEN_VERTICAL));
13661377
break;
@@ -1370,7 +1381,7 @@ void BlitScreen(MDFN_Surface *msurface, const MDFN_Rect *DisplayRect, const int3
13701381
RES_HW_SCREEN_VERTICAL);
13711382
h_zoomed = MIN(h_scaled + aspect_ratio_factor_percent*(RES_HW_SCREEN_VERTICAL - h_scaled)/100,
13721383
RES_HW_SCREEN_VERTICAL);
1373-
flip_NNOptimized_AllowOutOfScreen(msurface, hw_screen,
1384+
flip_NNOptimized_AllowOutOfScreen(msurface, src_rect, hw_screen,
13741385
MAX(msurface->w*h_zoomed/msurface->h, RES_HW_SCREEN_HORIZONTAL),
13751386
MIN(h_zoomed, RES_HW_SCREEN_VERTICAL));
13761387
break;

0 commit comments

Comments
 (0)