Skip to content

Commit

Permalink
Add integer scaling option (#2)
Browse files Browse the repository at this point in the history
This patch adds option ‚3‘ integer scaling. dst_rect is an integral
multiple of src_rect. Should prevent scaling artifacts.
  • Loading branch information
gizmo98 authored and joolswills committed Nov 18, 2016
1 parent 5bd7159 commit 9d9af1f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion include/SDL_hints.h
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,15 @@ extern "C" {
* "1" - Requested video resolution will be scaled to desktop resolution.
* Aspect ratio of requested video resolution will be respected.
* "2" - Requested video resolution will be scaled to desktop resolution.
* "3" - Requested video resolution will be scaled to desktop resolution.
* Aspect ratio of requested video resolution will be respected.
* If possible output resolution will be integral multiple of video
* resolution.
*/
#define SDL_HINT_VIDEO_RPI_SCALE_MODE "SDL_VIDEO_RPI_SCALE_MODE"

/**
* \brief Tell dispmanx to set an specific aspect ratio.
* \brief Tell dispmanx to set a specific aspect ratio.
*
* This hint only applies to the rpi video driver.
*
Expand Down
21 changes: 21 additions & 0 deletions src/video/raspberry/SDL_rpivideo.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,33 @@ RPI_CreateWindow(_THIS, SDL_Window * window)

float srcAspect = 1;
float dstAspect = 1;
int factor_x = 0;
int factor_y = 0;

if (hintScale != NULL)
scalemode = *hintScale;

/* Create a dispman element and associate a window to it */
switch(scalemode) {
case '3':
/* Pixel perfect scaling mode. */
factor_x = (display->desktop_mode.w / window->w);
factor_y = (display->desktop_mode.h / window->h);
if ((factor_x != 0) && (factor_y != 0)) {
if (factor_x >= factor_y) {
dst_rect.width = window->w * factor_y;
dst_rect.height = window->h * factor_y;
}
else {
dst_rect.width = window->w * factor_x;
dst_rect.height = window->h * factor_x;
}
/* Center window. */
dst_rect.x = (display->desktop_mode.w - dst_rect.width) / 2;
dst_rect.y = (display->desktop_mode.h - dst_rect.height) / 2;
break;
}
/* If integer scale is not possible fallback to mode 1. */
case '1':
/* Fullscreen mode. */
/* Calculate source and destination aspect ratios. */
Expand Down

0 comments on commit 9d9af1f

Please sign in to comment.