@@ -910,6 +910,34 @@ app_emulator_export_save_to_path(
910910 );
911911}
912912
913+ void
914+ app_emulator_screenshot_resize (
915+ uint32_t * src ,
916+ uint32_t src_width ,
917+ uint32_t src_height ,
918+ uint32_t * dst ,
919+ uint32_t dst_width ,
920+ uint32_t dst_height
921+ ) {
922+ uint32_t i ;
923+ uint32_t scale_factor ;
924+
925+ scale_factor = dst_width / src_width ;
926+
927+ hs_assert (src_width * scale_factor == dst_width );
928+ hs_assert (src_height * scale_factor == dst_height );
929+
930+ for (i = 0 ; i < dst_width * dst_height ; ++ i ) {
931+ uint32_t src_x ;
932+ uint32_t src_y ;
933+
934+ src_x = (i % dst_width ) / scale_factor ;
935+ src_y = (i / dst_width ) / scale_factor ;
936+
937+ dst [i ] = src [src_y * src_width + src_x ];
938+ }
939+ }
940+
913941/*
914942** Take a screenshot of the game and writes it to the disk.
915943*/
@@ -919,18 +947,46 @@ app_emulator_screenshot_path(
919947 char const * path
920948) {
921949 int out ;
950+ uint32_t * rescaled_screenshot ;
951+ uint32_t rescaled_width ;
952+ uint32_t rescaled_height ;
953+
954+ // Sanity & paranoia check, shouldn't be useful under normal circumstances
955+ if (app -> settings .video .display_size >= 1 && app -> settings .video .display_size <= 5 ) {
956+ rescaled_width = app -> settings .video .display_size * GBA_SCREEN_WIDTH ;
957+ rescaled_height = app -> settings .video .display_size * GBA_SCREEN_HEIGHT ;
958+ } else {
959+ rescaled_width = GBA_SCREEN_WIDTH ;
960+ rescaled_height = GBA_SCREEN_HEIGHT ;
961+ }
922962
963+ rescaled_screenshot = malloc (rescaled_width * rescaled_height * sizeof (uint32_t ));
964+ hs_assert (rescaled_screenshot );
965+
966+ // Grab the framebuffer from the shared data and rescale it to the appropriate size
923967 pthread_mutex_lock (& app -> emulation .gba -> shared_data .framebuffer .lock );
924- out = stbi_write_png (
925- path ,
968+ app_emulator_screenshot_resize (
969+ app -> emulation . gba -> shared_data . framebuffer . data ,
926970 GBA_SCREEN_WIDTH ,
927971 GBA_SCREEN_HEIGHT ,
928- 4 ,
929- app -> emulation . gba -> shared_data . framebuffer . data ,
930- GBA_SCREEN_WIDTH * sizeof ( uint32_t )
972+ rescaled_screenshot ,
973+ rescaled_width ,
974+ rescaled_height
931975 );
932976 pthread_mutex_unlock (& app -> emulation .gba -> shared_data .framebuffer .lock );
933977
978+ // Write the screenshot on the disk
979+ out = stbi_write_png (
980+ path ,
981+ rescaled_width ,
982+ rescaled_height ,
983+ 4 ,
984+ rescaled_screenshot ,
985+ rescaled_width * sizeof (uint32_t )
986+ );
987+
988+ free (rescaled_screenshot );
989+
934990 if (out ) {
935991 app_new_notification (
936992 app ,
0 commit comments