@@ -1318,6 +1318,9 @@ void PCSX::GUI::endFrame() {
1318
1318
if (ImGui::MenuItem (_ (" Hard Reset" ), " Shift+F8" )) {
1319
1319
g_system->hardReset ();
1320
1320
}
1321
+ if (ImGui::MenuItem (_ (" Take Screenshot" ))) {
1322
+ saveScreenShot ();
1323
+ }
1321
1324
ImGui::EndMenu ();
1322
1325
}
1323
1326
ImGui::Separator ();
@@ -2891,3 +2894,60 @@ void PCSX::GUI::changeScale(float scale) {
2891
2894
m_allScales.emplace (scale);
2892
2895
ImGui::SetCurrentFont (getMainFont ());
2893
2896
}
2897
+
2898
+ clip::image PCSX::GUI::convertScreenshotToImage (PCSX::GPU::ScreenShot&& screenshot) {
2899
+ clip::image_spec spec;
2900
+ spec.width = screenshot.width ;
2901
+ spec.height = screenshot.height ;
2902
+ if (screenshot.bpp == PCSX::GPU::ScreenShot::BPP_16) {
2903
+ spec.bits_per_pixel = 16 ;
2904
+ spec.bytes_per_row = screenshot.width * 2 ;
2905
+ spec.red_mask = 0x1f ; // 0x7c00;
2906
+ spec.green_mask = 0x3e0 ;
2907
+ spec.blue_mask = 0x7c00 ; // 0x1f;
2908
+ spec.alpha_mask = 0 ;
2909
+ spec.red_shift = 0 ; // 10;
2910
+ spec.green_shift = 5 ;
2911
+ spec.blue_shift = 10 ; // 0;
2912
+ spec.alpha_shift = 0 ;
2913
+ } else {
2914
+ spec.bits_per_pixel = 24 ;
2915
+ spec.bytes_per_row = screenshot.width * 3 ;
2916
+ spec.red_mask = 0xff0000 ;
2917
+ spec.green_mask = 0xff00 ;
2918
+ spec.blue_mask = 0xff ;
2919
+ spec.alpha_mask = 0 ;
2920
+ spec.red_shift = 16 ;
2921
+ spec.green_shift = 8 ;
2922
+ spec.blue_shift = 0 ;
2923
+ spec.alpha_shift = 0 ;
2924
+ }
2925
+ clip::image img (screenshot.data .data (), spec);
2926
+ return img.to_rgba8888 ();
2927
+ }
2928
+
2929
+ bool PCSX::GUI::writeImagePNG (std::string filename, clip::image&& img) { return img.export_to_png (filename); }
2930
+
2931
+ std::string PCSX::GUI::getDateString () {
2932
+ auto now = std::chrono::system_clock::now ();
2933
+ auto in_time_t = std::chrono::system_clock::to_time_t (now);
2934
+
2935
+ auto local_time = std::localtime (&in_time_t );
2936
+
2937
+ std::stringstream ss;
2938
+ ss << std::put_time (local_time, " %Y-%m-%d-%H-%M-%S" );
2939
+
2940
+ std::string datetime_string = ss.str ();
2941
+
2942
+ return datetime_string;
2943
+ }
2944
+
2945
+ bool PCSX::GUI::saveScreenShot () {
2946
+ std::filesystem::path path =
2947
+ g_system->getPersistentDir () / (getSaveStatePrefix (true ) + getDateString () + " .png" );
2948
+ auto screenshot = g_emulator->m_gpu ->takeScreenShot ();
2949
+ clip::image img = convertScreenshotToImage (std::move (screenshot));
2950
+ bool success = writeImagePNG (path.string (), std::move (img));
2951
+
2952
+ return success;
2953
+ }
0 commit comments