diff options
Diffstat (limited to '')
| -rw-r--r-- | src/common/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | src/common/stb.cpp | 8 | ||||
| -rw-r--r-- | src/common/stb.h | 8 | ||||
| -rw-r--r-- | src/core/hle/service/caps/caps_manager.cpp | 20 |
4 files changed, 31 insertions, 11 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 8a1861051..e216eb3de 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -120,6 +120,8 @@ add_library(common STATIC | |||
| 120 | socket_types.h | 120 | socket_types.h |
| 121 | spin_lock.cpp | 121 | spin_lock.cpp |
| 122 | spin_lock.h | 122 | spin_lock.h |
| 123 | stb.cpp | ||
| 124 | stb.h | ||
| 123 | steady_clock.cpp | 125 | steady_clock.cpp |
| 124 | steady_clock.h | 126 | steady_clock.h |
| 125 | stream.cpp | 127 | stream.cpp |
| @@ -208,6 +210,8 @@ if (MSVC) | |||
| 208 | /we4254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data | 210 | /we4254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data |
| 209 | /we4800 # Implicit conversion from 'type' to bool. Possible information loss | 211 | /we4800 # Implicit conversion from 'type' to bool. Possible information loss |
| 210 | ) | 212 | ) |
| 213 | else() | ||
| 214 | set_source_files_properties(stb.cpp PROPERTIES COMPILE_OPTIONS "-Wno-implicit-fallthrough;-Wno-missing-declarations;-Wno-missing-field-initializers") | ||
| 211 | endif() | 215 | endif() |
| 212 | 216 | ||
| 213 | if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") | 217 | if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| @@ -223,7 +227,7 @@ endif() | |||
| 223 | 227 | ||
| 224 | create_target_directory_groups(common) | 228 | create_target_directory_groups(common) |
| 225 | 229 | ||
| 226 | target_link_libraries(common PUBLIC Boost::context Boost::headers fmt::fmt microprofile Threads::Threads) | 230 | target_link_libraries(common PUBLIC Boost::context Boost::headers fmt::fmt microprofile stb::headers Threads::Threads) |
| 227 | target_link_libraries(common PRIVATE lz4::lz4 zstd::zstd LLVM::Demangle) | 231 | target_link_libraries(common PRIVATE lz4::lz4 zstd::zstd LLVM::Demangle) |
| 228 | 232 | ||
| 229 | if (ANDROID) | 233 | if (ANDROID) |
diff --git a/src/common/stb.cpp b/src/common/stb.cpp new file mode 100644 index 000000000..d3b16665d --- /dev/null +++ b/src/common/stb.cpp | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #define STB_IMAGE_IMPLEMENTATION | ||
| 5 | #define STB_IMAGE_RESIZE_IMPLEMENTATION | ||
| 6 | #define STB_IMAGE_WRITE_IMPLEMENTATION | ||
| 7 | |||
| 8 | #include "common/stb.h" | ||
diff --git a/src/common/stb.h b/src/common/stb.h new file mode 100644 index 000000000..e5c197c11 --- /dev/null +++ b/src/common/stb.h | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include <stb_image.h> | ||
| 7 | #include <stb_image_resize.h> | ||
| 8 | #include <stb_image_write.h> | ||
diff --git a/src/core/hle/service/caps/caps_manager.cpp b/src/core/hle/service/caps/caps_manager.cpp index 9c9454b99..7d733eb54 100644 --- a/src/core/hle/service/caps/caps_manager.cpp +++ b/src/core/hle/service/caps/caps_manager.cpp | |||
| @@ -2,13 +2,11 @@ | |||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | #include <sstream> | 4 | #include <sstream> |
| 5 | #include <stb_image.h> | ||
| 6 | #include <stb_image_resize.h> | ||
| 7 | #include <stb_image_write.h> | ||
| 8 | 5 | ||
| 9 | #include "common/fs/file.h" | 6 | #include "common/fs/file.h" |
| 10 | #include "common/fs/path_util.h" | 7 | #include "common/fs/path_util.h" |
| 11 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 9 | #include "common/stb.h" | ||
| 12 | #include "core/core.h" | 10 | #include "core/core.h" |
| 13 | #include "core/hle/service/caps/caps_manager.h" | 11 | #include "core/hle/service/caps/caps_manager.h" |
| 14 | #include "core/hle/service/caps/caps_result.h" | 12 | #include "core/hle/service/caps/caps_result.h" |
| @@ -409,6 +407,12 @@ Result AlbumManager::LoadImage(std::span<u8> out_image, const std::filesystem::p | |||
| 409 | return ResultSuccess; | 407 | return ResultSuccess; |
| 410 | } | 408 | } |
| 411 | 409 | ||
| 410 | static void PNGToMemory(void* context, void* png, int len) { | ||
| 411 | std::vector<u8>* png_image = static_cast<std::vector<u8>*>(context); | ||
| 412 | png_image->reserve(len); | ||
| 413 | std::memcpy(png_image->data(), png, len); | ||
| 414 | } | ||
| 415 | |||
| 412 | Result AlbumManager::SaveImage(ApplicationAlbumEntry& out_entry, std::span<const u8> image, | 416 | Result AlbumManager::SaveImage(ApplicationAlbumEntry& out_entry, std::span<const u8> image, |
| 413 | u64 title_id, const AlbumFileDateTime& date) const { | 417 | u64 title_id, const AlbumFileDateTime& date) const { |
| 414 | const auto screenshot_path = | 418 | const auto screenshot_path = |
| @@ -422,16 +426,12 @@ Result AlbumManager::SaveImage(ApplicationAlbumEntry& out_entry, std::span<const | |||
| 422 | const Common::FS::IOFile db_file{file_path, Common::FS::FileAccessMode::Write, | 426 | const Common::FS::IOFile db_file{file_path, Common::FS::FileAccessMode::Write, |
| 423 | Common::FS::FileType::BinaryFile}; | 427 | Common::FS::FileType::BinaryFile}; |
| 424 | 428 | ||
| 425 | s32 len; | 429 | std::vector<u8> png_image; |
| 426 | const u8* png = stbi_write_png_to_mem(image.data(), 0, 1280, 720, STBI_rgb_alpha, &len); | 430 | if (!stbi_write_png_to_func(PNGToMemory, &png_image, 1280, 720, STBI_rgb_alpha, image.data(), |
| 427 | 431 | 0)) { | |
| 428 | if (!png) { | ||
| 429 | return ResultFileCountLimit; | 432 | return ResultFileCountLimit; |
| 430 | } | 433 | } |
| 431 | 434 | ||
| 432 | std::vector<u8> png_image(len); | ||
| 433 | std::memcpy(png_image.data(), png, len); | ||
| 434 | |||
| 435 | if (db_file.Write(png_image) != png_image.size()) { | 435 | if (db_file.Write(png_image) != png_image.size()) { |
| 436 | return ResultFileCountLimit; | 436 | return ResultFileCountLimit; |
| 437 | } | 437 | } |