From 373535f329ccb36abe704c06bb3bf020c5ecc242 Mon Sep 17 00:00:00 2001 From: Brad Parker Date: Wed, 8 Feb 2017 00:16:27 -0500 Subject: [PATCH] DOS: improve color accuracy and scaling, thanks to aliaspider --- gfx/drivers/vga_gfx.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gfx/drivers/vga_gfx.c b/gfx/drivers/vga_gfx.c index 78a14d6dd4..5f8a89c31c 100644 --- a/gfx/drivers/vga_gfx.c +++ b/gfx/drivers/vga_gfx.c @@ -222,14 +222,14 @@ static bool vga_gfx_frame(void *data, const void *frame, for (x = 0; x < VGA_WIDTH; x++) { /* scale incoming frame to fit the screen */ - unsigned scaled_x = (width / (float)VGA_WIDTH) * x; - unsigned scaled_y = (height / (float)VGA_HEIGHT) * y; + unsigned scaled_x = (width * x) / VGA_WIDTH; + unsigned scaled_y = (height * y) / VGA_HEIGHT; unsigned short pixel = ((unsigned short*)frame_to_copy)[width * scaled_y + scaled_x]; /* convert RGB565 to BGR332 */ - unsigned r = (7.0f / 31.0f) * ((pixel & 0xF800) >> 11); - unsigned g = (7.0f / 63.0f) * ((pixel & 0x07E0) >> 5); - unsigned b = (3.0f / 31.0f) * ((pixel & 0x001F) >> 0); + unsigned r = ((pixel & 0xF800) >> 13); + unsigned g = ((pixel & 0x07E0) >> 8); + unsigned b = ((pixel & 0x001F) >> 3); vga_frame[VGA_WIDTH * y + x] = (b << 6) | (g << 3) | r; } @@ -369,12 +369,12 @@ static void vga_set_texture_frame(void *data, for(x = 0; x < VGA_WIDTH; x++) { /* scale incoming frame to fit the screen */ - unsigned scaled_x = (width / (float)VGA_WIDTH) * x; - unsigned scaled_y = (height / (float)VGA_HEIGHT) * y; + unsigned scaled_x = (width * x) / VGA_WIDTH; + unsigned scaled_y = (height * y) / VGA_HEIGHT; unsigned short pixel = video_frame[width * scaled_y + scaled_x]; - unsigned r = (7.0f / 15.0f) * ((pixel & 0xF000) >> 12); - unsigned g = (7.0f / 15.0f) * ((pixel & 0xF00) >> 8); - unsigned b = (3.0f / 15.0f) * ((pixel & 0xF0) >> 4); + unsigned r = ((pixel & 0xF000) >> 13); + unsigned g = ((pixel & 0xF00) >> 9); + unsigned b = ((pixel & 0xF0) >> 6); vga_menu_frame[VGA_WIDTH * y + x] = (b << 6) | (g << 3) | r; } }