| 4771 | } |
| 4772 | |
| 4773 | void reshade::runtime::save_screenshot(const char *postfix_in) |
| 4774 | { |
| 4775 | std::string postfix; |
| 4776 | if (postfix_in != nullptr) |
| 4777 | postfix = postfix_in; |
| 4778 | |
| 4779 | const unsigned int screenshot_count = _screenshot_count; |
| 4780 | // Use PNG or JPEG XL for HDR (no tonemapping is implemented, so this is the only way to capture a screenshot in HDR) |
| 4781 | const unsigned int screenshot_format = |
| 4782 | (_back_buffer_format == api::format::r16g16b16a16_float || _back_buffer_color_space == api::color_space::hdr10_pq) ? (_screenshot_format == 3 ? 5 : 4) : _screenshot_format; |
| 4783 | |
| 4784 | std::string screenshot_name = expand_macro_string(_screenshot_name, { |
| 4785 | { "AppName", g_target_executable_path.stem().u8string() }, |
| 4786 | { "PresetName", _current_preset_path.stem().u8string() }, |
| 4787 | { "BeforeAfter", postfix }, |
| 4788 | { "Count", std::to_string(screenshot_count) } |
| 4789 | }, _current_time); |
| 4790 | |
| 4791 | if (!postfix.empty() && _screenshot_name.find("%BeforeAfter%") == std::string::npos) |
| 4792 | { |
| 4793 | screenshot_name += ' '; |
| 4794 | screenshot_name += postfix; |
| 4795 | } |
| 4796 | |
| 4797 | switch (screenshot_format) |
| 4798 | { |
| 4799 | case 0: |
| 4800 | screenshot_name += ".bmp"; |
| 4801 | break; |
| 4802 | case 1: |
| 4803 | case 4: |
| 4804 | screenshot_name += ".png"; |
| 4805 | break; |
| 4806 | case 2: |
| 4807 | screenshot_name += ".jpg"; |
| 4808 | break; |
| 4809 | case 3: |
| 4810 | case 5: |
| 4811 | screenshot_name += ".jxl"; |
| 4812 | break; |
| 4813 | default: |
| 4814 | return; |
| 4815 | } |
| 4816 | |
| 4817 | const std::filesystem::path screenshot_path = g_reshade_base_path / _screenshot_path / std::filesystem::u8path(screenshot_name).lexically_normal(); |
| 4818 | |
| 4819 | log::message(log::level::info, "Saving screenshot to '%s'.", screenshot_path.u8string().c_str()); |
| 4820 | |
| 4821 | _last_screenshot_save_successful = true; |
| 4822 | |
| 4823 | if (std::vector<uint8_t> pixels(static_cast<size_t>(_width) * static_cast<size_t>(_height) * (screenshot_format >= 4 ? 6 : 4)); |
| 4824 | get_texture_data( |
| 4825 | _back_buffer_resolved != 0 ? _back_buffer_resolved : _swapchain->get_current_back_buffer(), |
| 4826 | _back_buffer_resolved != 0 ? api::resource_usage::render_target : api::resource_usage::present, |
| 4827 | pixels.data(), |
| 4828 | screenshot_format >= 4 ? (_back_buffer_format == api::format::r16g16b16a16_float ? api::format::r16g16b16_float : api::format::r16g16b16_unorm) : api::format::r8g8b8a8_unorm)) |
| 4829 | { |
| 4830 | const bool include_preset = |
nothing calls this directly
no test coverage detected