Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement screenshot feature #2074

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SirQuartz
Copy link

@SirQuartz SirQuartz commented Oct 9, 2022

This pull request adds the ability to take screenshots from within the emulator.

It will save the screenshot and name the file using this format: "Screenshot - [Title_Name or Title_ID] - [Datetime] - [Time in nanoseconds since epoch].png". The menu button is found under Display > Take Screenshot and can also be activated by pressing F12.

Screenshots are saved to Documents\Xenia\Screenshots\{Game Title or Game ID} by default.

Xenia.Screenshot.Feature.V2.mp4

Take Screenshot

Resolves: #2049, #2039

@SirQuartz SirQuartz force-pushed the screenshot branch 2 times, most recently from 69c3356 to 30d7a1d Compare October 9, 2022 06:28
@SirQuartz SirQuartz changed the title Add screenshot feature Implement screenshot feature Oct 9, 2022
@SirQuartz SirQuartz force-pushed the screenshot branch 5 times, most recently from 9d75fe3 to 9f2f055 Compare October 9, 2022 09:11
@Razzile
Copy link
Member

Razzile commented Oct 9, 2022

nice work! I'm kinda surprised how easy this was to implement.
Do we have a way of notifying users that the screenshot has been saved (maybe imgui has some kind of notification functionality)?
Also I'd change the output filename to something like {title or title ID} - {date}.png

src/xenia/app/emulator_window.cc Outdated Show resolved Hide resolved
src/xenia/app/emulator_window.cc Outdated Show resolved Hide resolved
src/xenia/app/emulator_window.cc Outdated Show resolved Hide resolved
src/xenia/app/emulator_window.h Outdated Show resolved Hide resolved
src/xenia/app/emulator_window.cc Show resolved Hide resolved
src/xenia/app/emulator_window.cc Outdated Show resolved Hide resolved
src/xenia/app/emulator_window.cc Outdated Show resolved Hide resolved
src/xenia/app/emulator_window.cc Outdated Show resolved Hide resolved
src/xenia/app/emulator_window.cc Outdated Show resolved Hide resolved
src/xenia/app/emulator_window.cc Outdated Show resolved Hide resolved
}

void EmulatorWindow::ExportImage(const xe::ui::RawImage& image) {
auto path = std::filesystem::path("screenshot.png");
Copy link
Member

@Triang3l Triang3l Oct 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be desirable to save the screenshots somewhere in a more user-faced directory. The best default location would likely be a subdirectory (preferably something like Xenia/game name with characters not supported in paths on the host file system filtered out, or Xenia/title ID if there's no game name provided in the XEX) in the user images directory in the OS. Other non-default options may be a directory specified in the config, and the executable directory in case the emulator was launched in the portable mode.

@SirQuartz
Copy link
Author

SirQuartz commented Oct 10, 2022

nice work! I'm kinda surprised how easy this was to implement. Do we have a way of notifying users that the screenshot has been saved (maybe imgui has some kind of notification functionality)? Also I'd change the output filename to something like {title or title ID} - {date}.png

Thanks! I was honestly surprised too. It helped that the project already included a third-party library that would save image files and that there was already a method to capture the raw render output. Also, GitHub Copilot sleuthed about half of the solution, and I deduced the rest to get it working. Otherwise, I wouldn't have even known about the stbi_write_to_func() method.

I'll see about making the filename more descriptive, probably something like "Screenshot - [Title_Name or Title_ID] - [Datetime] - [Time in milliseconds since epoch].png". The time since the epoch in milliseconds will look like a long random number, but also never be the same, it can only ever increase. That way, it can give a unique file name.

And yeah, I can add a message box with imgui to say "Screenshot saved to [screenshot path]".

@SirQuartz SirQuartz force-pushed the screenshot branch 3 times, most recently from 8a39e38 to 65cb39b Compare October 10, 2022 22:06
@Wunkolo
Copy link
Contributor

Wunkolo commented Oct 11, 2022

I'll see about making the filename more descriptive, probably something like "Screenshot - [Title_Name or Title_ID] - [Datetime] - [Time in milliseconds since epoch].png"

Maybe something like ISO 8601? So the date format is something like %Y%m%dT%H%M%S which maps to time-strings such as 20221011T102845 which is sortable alphabetically in a file-browser and pretty human-readable.

@Razzile
Copy link
Member

Razzile commented Oct 12, 2022

nice work! I'm kinda surprised how easy this was to implement. Do we have a way of notifying users that the screenshot has been saved (maybe imgui has some kind of notification functionality)? Also I'd change the output filename to something like {title or title ID} - {date}.png

Thanks! I was honestly surprised too. It helped that the project already included a third-party library that would save image files and that there was already a method to capture the raw render output. Also, GitHub Copilot sleuthed about half of the solution, and I deduced the rest to get it working. Otherwise, I wouldn't have even known about the stbi_write_to_func() method.

I'll see about making the filename more descriptive, probably something like "Screenshot - [Title_Name or Title_ID] - [Datetime] - [Time in milliseconds since epoch].png". The time since the epoch in milliseconds will look like a long random number, but also never be the same, it can only ever increase. That way, it can give a unique file name.

And yeah, I can add a message box with imgui to say "Screenshot saved to [screenshot path]".

You used github copilot for this? How did that process work?

A message box might be too intrusive. maybe if imgui has no notification widget (that doesn't get in the way/steal context) you could add <SCREENSHOT SAVED> to the window title for a second or two

@SirQuartz
Copy link
Author

Yeah, GitHub Copilot is surprisingly helpful in finding the missing pieces to a solution at times. Especially in this case where the answer was just sitting right in front of me but I hadn't noticed it yet. In this case, I didn't know the project had a save-to-PNG method, but GitHub Copilot did, which saved me a lot of time. The only way I would have known about that would have been by searching through every file in the project until I randomly stumbled upon it.

Github.Copilot.mp4

GitHub Copilot will use the context of the rest of your project to help find what you're looking for, and it does it remarkably quickly. It doesn't always work perfectly, and won't always give you what you're looking for. Most of the time you still need to fill in the rest or make changes. Overall, it's still very useful and I'd recommend it.

I'll see about changing the title instead of showing a message box when a screenshot is saved.

@Razzile
Copy link
Member

Razzile commented Oct 13, 2022

Yeah, GitHub Copilot is surprisingly helpful in finding the missing pieces to a solution at times. Especially in this case where the answer was just sitting right in front of me but I hadn't noticed it yet. In this case, I didn't know the project had a save-to-PNG method, but GitHub Copilot did, which saved me a lot of time. The only way I would have known about that would have been by searching through every file in the project until I randomly stumbled upon it.
Github.Copilot.mp4

GitHub Copilot will use the context of the rest of your project to help find what you're looking for, and it does it remarkably quickly. It doesn't always work perfectly, and won't always give you what you're looking for. Most of the time you still need to fill in the rest or make changes. Overall, it's still very useful and I'd recommend it.

I'll see about changing the title instead of showing a message box when a screenshot is saved.

Wow that's actually pretty insane. This is the first time I've seen github copilot be used for anything other than hello world or basic algorithms

@SirQuartz
Copy link
Author

Wow that's actually pretty insane. This is the first time I've seen github copilot be used for anything other than hello world or basic algorithms

I've seen it construct some really advanced functions that would've taken me hours or days to figure out. This is actually a pretty decent example of a practical use for it in the real world.

@Masamune3210
Copy link

Does it still have the issue of randomly spitting out chunks of other people's code? Or has it been trained enough for it to be genericized

@SirQuartz
Copy link
Author

SirQuartz commented Oct 13, 2022

Does it still have the issue of randomly spitting out chunks of other people's code? Or has it been trained enough for it to be genericized

I've personally never seen that happen, but I have the "suggestions matching public code" option disabled so maybe that's why? Either way, it's pretty good at coming up with original solutions, as is the case in this example. As I said, it favors using the context of your project and what it already has for methods to come up with a solution over just randomly yoinking one from the internet.

For the most part, it just constructs a generic method based on the prompt or context of the current and previous lines.

Copilot

@@ -928,6 +937,68 @@ void EmulatorWindow::ToggleFullscreen() {
SetFullscreen(!window_->IsFullscreen());
}

void EmulatorWindow::TakeScreenshot() {
xe::ui::RawImage image;
if (!GetGraphicsSystemPresenter()->CaptureGuestOutput(image) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that not all games output the image with the same aspect ratio as the display. Halo 3, for example, presents a 1152x640 image, which has an aspect ratio of 16.2:9 rather than 16:9, so it may appear slightly stretched horizontally. Also, we apply FXAA before writing to the guest output image (for simplicity, as it needs to work at the game's resolution), but CAS or FSR after that — so this will include just the FXAA-processed image with the size provided by the game.

Gliniak pushed a commit to xenia-canary/xenia-canary that referenced this pull request Jun 19, 2024
Added a screenshot functionality based on this pr xenia-project#2074 and added some minor adjustments.

GUI wise, "take screenshot" is under the Display menu and the keyboard shortcut to take it is F10

The screenshots folder will save to where xenia.exe or xenia_canary.exe is located. As for save paths, it will only use the id of the game due to illegal characters in some titles.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Screenshot key/dump button?
5 participants