diff options
author | german77 <juangerman-13@hotmail.com> | 2023-10-18 07:05:44 +0200 |
---|---|---|
committer | Narr the Reg <juangerman-13@hotmail.com> | 2023-10-23 18:18:22 +0200 |
commit | 897b411ae76a817421453120ca0d0812e3de233f (patch) | |
tree | c4d69fd35790e21605c6382b29107186e5e2a6a1 /src/core/hle/service/caps/caps_manager.cpp | |
parent | externals: stb: Add image write (diff) | |
download | yuzu-897b411ae76a817421453120ca0d0812e3de233f.tar yuzu-897b411ae76a817421453120ca0d0812e3de233f.tar.gz yuzu-897b411ae76a817421453120ca0d0812e3de233f.tar.bz2 yuzu-897b411ae76a817421453120ca0d0812e3de233f.tar.lz yuzu-897b411ae76a817421453120ca0d0812e3de233f.tar.xz yuzu-897b411ae76a817421453120ca0d0812e3de233f.tar.zst yuzu-897b411ae76a817421453120ca0d0812e3de233f.zip |
Diffstat (limited to 'src/core/hle/service/caps/caps_manager.cpp')
-rw-r--r-- | src/core/hle/service/caps/caps_manager.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/core/hle/service/caps/caps_manager.cpp b/src/core/hle/service/caps/caps_manager.cpp index 2b4e3f076..9c9454b99 100644 --- a/src/core/hle/service/caps/caps_manager.cpp +++ b/src/core/hle/service/caps/caps_manager.cpp @@ -4,6 +4,7 @@ #include <sstream> #include <stb_image.h> #include <stb_image_resize.h> +#include <stb_image_write.h> #include "common/fs/file.h" #include "common/fs/path_util.h" @@ -227,6 +228,49 @@ Result AlbumManager::LoadAlbumScreenShotThumbnail( +static_cast<int>(out_image_output.height), decoder_options.flags); } +Result AlbumManager::SaveScreenShot(ApplicationAlbumEntry& out_entry, + const ScreenShotAttribute& attribute, + std::span<const u8> image_data, u64 aruid) { + return SaveScreenShot(out_entry, attribute, {}, image_data, aruid); +} + +Result AlbumManager::SaveScreenShot(ApplicationAlbumEntry& out_entry, + const ScreenShotAttribute& attribute, + const ApplicationData& app_data, std::span<const u8> image_data, + u64 aruid) { + const u64 title_id = system.GetApplicationProcessProgramID(); + const auto& user_clock = system.GetTimeManager().GetStandardUserSystemClockCore(); + + s64 posix_time{}; + Result result = user_clock.GetCurrentTime(system, posix_time); + + if (result.IsError()) { + return result; + } + + const auto date = ConvertToAlbumDateTime(posix_time); + + return SaveImage(out_entry, image_data, title_id, date); +} + +Result AlbumManager::SaveEditedScreenShot(ApplicationAlbumEntry& out_entry, + const ScreenShotAttribute& attribute, + const AlbumFileId& file_id, + std::span<const u8> image_data) { + const auto& user_clock = system.GetTimeManager().GetStandardUserSystemClockCore(); + + s64 posix_time{}; + Result result = user_clock.GetCurrentTime(system, posix_time); + + if (result.IsError()) { + return result; + } + + const auto date = ConvertToAlbumDateTime(posix_time); + + return SaveImage(out_entry, image_data, file_id.application_id, date); +} + Result AlbumManager::GetFile(std::filesystem::path& out_path, const AlbumFileId& file_id) const { const auto file = album_files.find(file_id); @@ -365,6 +409,45 @@ Result AlbumManager::LoadImage(std::span<u8> out_image, const std::filesystem::p return ResultSuccess; } +Result AlbumManager::SaveImage(ApplicationAlbumEntry& out_entry, std::span<const u8> image, + u64 title_id, const AlbumFileDateTime& date) const { + const auto screenshot_path = + Common::FS::GetYuzuPathString(Common::FS::YuzuPath::ScreenshotsDir); + const std::string formatted_date = + fmt::format("{:04}-{:02}-{:02}_{:02}-{:02}-{:02}-{:03}", date.year, date.month, date.day, + date.hour, date.minute, date.second, 0); + const std::string file_path = + fmt::format("{}/{:016x}_{}.png", screenshot_path, title_id, formatted_date); + + const Common::FS::IOFile db_file{file_path, Common::FS::FileAccessMode::Write, + Common::FS::FileType::BinaryFile}; + + s32 len; + const u8* png = stbi_write_png_to_mem(image.data(), 0, 1280, 720, STBI_rgb_alpha, &len); + + if (!png) { + return ResultFileCountLimit; + } + + std::vector<u8> png_image(len); + std::memcpy(png_image.data(), png, len); + + if (db_file.Write(png_image) != png_image.size()) { + return ResultFileCountLimit; + } + + out_entry = { + .size = png_image.size(), + .hash = {}, + .datetime = date, + .storage = AlbumStorage::Sd, + .content = ContentType::Screenshot, + .unknown = 1, + }; + + return ResultSuccess; +} + AlbumFileDateTime AlbumManager::ConvertToAlbumDateTime(u64 posix_time) const { Time::TimeZone::CalendarInfo calendar_date{}; const auto& time_zone_manager = |