Commits (1)
...@@ -302,7 +302,7 @@ pointymult, pointy5, pointy3, xbr4, xbr2, xmult, ymult, csrc->h * yscale, ratio ...@@ -302,7 +302,7 @@ pointymult, pointy5, pointy3, xbr4, xbr2, xmult, ymult, csrc->h * yscale, ratio
} }
// And finally, interpolate if needed // And finally, interpolate if needed
if (ratio < 1) { if (fheight != csrc->h) {
interpolate_height(csrc->data, ctarget->data, csrc->w, csrc->h, fheight); interpolate_height(csrc->data, ctarget->data, csrc->w, csrc->h, fheight);
ctarget->h = fheight; ctarget->h = fheight;
ctarget->w = csrc->w; ctarget->w = csrc->w;
...@@ -313,7 +313,7 @@ pointymult, pointy5, pointy3, xbr4, xbr2, xmult, ymult, csrc->h * yscale, ratio ...@@ -313,7 +313,7 @@ pointymult, pointy5, pointy3, xbr4, xbr2, xmult, ymult, csrc->h * yscale, ratio
ctarget = ret1; ctarget = ret1;
} }
if (ratio > 1) { if (fwidth != csrc->w) {
interpolate_width(csrc->data, ctarget->data, csrc->w, csrc->h, fwidth); interpolate_width(csrc->data, ctarget->data, csrc->w, csrc->h, fwidth);
ctarget->h = csrc->h; ctarget->h = csrc->h;
ctarget->w = fwidth; ctarget->w = fwidth;
......
...@@ -323,6 +323,76 @@ void sdl_flush(void) ...@@ -323,6 +323,76 @@ void sdl_flush(void)
sdl_user_func(SDL_USEREVENT_FLUSH); sdl_user_func(SDL_USEREVENT_FLUSH);
} }
/*
* Returns true if the specified width/height can use the
* internal scaler
*
* vstat lock must be held
*/
static bool
window_can_scale_internally(int winwidth, int winheight)
{
int idealmw;
int idealmh;
int idealh;
int idealw;
// First, figure out if width or height controlls the image size.
idealmw = lround((double)cvstat.scale_numerator / cvstat.scale_denominator * cvstat.scrnwidth);
idealmh = lround((double)cvstat.scale_denominator / cvstat.scale_numerator * cvstat.scrnheight);
idealw = lround(winheight * cvstat.scale_numerator / cvstat.scale_denominator * cvstat.scrnwidth / cvstat.scrnheight);
idealh = lround(winwidth * cvstat.scale_denominator / cvstat.scale_numerator * cvstat.scrnheight / cvstat.scrnwidth);
if (idealw < winwidth) {
// Height controls size...
if (winheight % idealmh == 0)
return true;
}
else {
// Width controls size...
if (winwidth % idealmw == 0)
return true;
}
return false;
}
static void
internal_scaling_factors(int winwidth, int winheight, int *x, int *y)
{
int idealmh;
int idealmw;
int idealh;
int idealw;
// First, figure out if width or height controlls the image size.
idealmw = lround((double)cvstat.scale_numerator / cvstat.scale_denominator * cvstat.scrnwidth);
idealmh = lround((double)cvstat.scale_denominator / cvstat.scale_numerator * cvstat.scrnheight);
idealw = lround((double)winheight * cvstat.scale_numerator / cvstat.scale_denominator * cvstat.scrnwidth / cvstat.scrnheight);
idealh = lround((double)winwidth * cvstat.scale_denominator / cvstat.scale_numerator * cvstat.scrnheight / cvstat.scrnwidth);
if (idealw < winwidth) {
// Height controls size...
if (idealh == winheight) {
idealmw = cvstat.scrnwidth;
*x = lround((double)idealw / idealmw);
*y = lround((double)idealh / idealmh);
return;
}
}
else {
// Width controls size...
if (idealw == winwidth) {
idealmh = cvstat.scrnheight;
*x = lround((double)idealw / idealmw);
*y = lround((double)idealh / idealmh);
return;
}
}
*x = 1;
*y = 1;
}
static int sdl_init_mode(int mode) static int sdl_init_mode(int mode)
{ {
int oldcols; int oldcols;
...@@ -370,6 +440,7 @@ static int sdl_init_mode(int mode) ...@@ -370,6 +440,7 @@ static int sdl_init_mode(int mode)
vstat.vmultiplier = 1; vstat.vmultiplier = 1;
cvstat = vstat; cvstat = vstat;
internal_scaling = window_can_scale_internally(vstat.winwidth, vstat.winheight);
pthread_mutex_unlock(&vstatlock); pthread_mutex_unlock(&vstatlock);
pthread_mutex_unlock(&blinker_lock); pthread_mutex_unlock(&blinker_lock);
...@@ -420,6 +491,7 @@ void sdl_setwinsize_locked(int w, int h) ...@@ -420,6 +491,7 @@ void sdl_setwinsize_locked(int w, int h)
h = cvstat.scrnheight; h = cvstat.scrnheight;
cvstat.winwidth = vstat.winwidth = w; cvstat.winwidth = vstat.winwidth = w;
cvstat.winheight = vstat.winheight = h; cvstat.winheight = vstat.winheight = h;
internal_scaling = window_can_scale_internally(cvstat.winwidth, cvstat.winheight);
} }
void sdl_setwinsize(int w, int h) void sdl_setwinsize(int w, int h)
...@@ -862,6 +934,7 @@ void sdl_video_event_thread(void *data) ...@@ -862,6 +934,7 @@ void sdl_video_event_thread(void *data)
else { else {
cvstat.winwidth = w; cvstat.winwidth = w;
cvstat.winheight = h; cvstat.winheight = h;
internal_scaling = window_can_scale_internally(w, h);
} }
setup_surfaces_locked(); setup_surfaces_locked();
pthread_mutex_unlock(&vstatlock); pthread_mutex_unlock(&vstatlock);
...@@ -977,13 +1050,12 @@ void sdl_video_event_thread(void *data) ...@@ -977,13 +1050,12 @@ void sdl_video_event_thread(void *data)
pthread_mutex_lock(&vstatlock); pthread_mutex_lock(&vstatlock);
pthread_mutex_lock(&win_mutex); pthread_mutex_lock(&win_mutex);
if ((ev.window.data1 % cvstat.scrnwidth) && (ev.window.data2 % cvstat.scrnheight)) { internal_scaling = window_can_scale_internally(ev.window.data1, ev.window.data2);
newh = "2"; if (internal_scaling) {
internal_scaling = false; newh = "0";
} }
else { else {
newh = "0"; newh = "2";
internal_scaling = true;
} }
sdl.GetWindowSize(win, &cvstat.winwidth, &cvstat.winheight); sdl.GetWindowSize(win, &cvstat.winwidth, &cvstat.winheight);
if (strcmp(newh, sdl.GetHint(SDL_HINT_RENDER_SCALE_QUALITY))) { if (strcmp(newh, sdl.GetHint(SDL_HINT_RENDER_SCALE_QUALITY))) {
...@@ -1041,7 +1113,9 @@ void sdl_video_event_thread(void *data) ...@@ -1041,7 +1113,9 @@ void sdl_video_event_thread(void *data)
if (internal_scaling) { if (internal_scaling) {
struct graphics_buffer *gb; struct graphics_buffer *gb;
gb = do_scale(list, cvstat.winwidth / cvstat.scrnwidth, cvstat.winheight / cvstat.scrnheight, int xscale, yscale;
internal_scaling_factors(cvstat.winwidth, cvstat.winheight, &xscale, &yscale);
gb = do_scale(list, xscale, yscale,
(double)cvstat.scale_numerator / cvstat.scale_denominator); (double)cvstat.scale_numerator / cvstat.scale_denominator);
src.x = 0; src.x = 0;
src.y = 0; src.y = 0;
......