From 79ba5d9c260ca4e2890b8e9c9efd79e3df5fe763 Mon Sep 17 00:00:00 2001 From: Alexandre Bouvier Date: Thu, 12 Oct 2023 16:36:26 +0200 Subject: cmake: prefer system stb headers --- src/common/CMakeLists.txt | 6 +++++- src/common/stb.cpp | 8 ++++++++ src/common/stb.h | 8 ++++++++ src/core/hle/service/caps/caps_manager.cpp | 20 ++++++++++---------- 4 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 src/common/stb.cpp create mode 100644 src/common/stb.h (limited to 'src') 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 socket_types.h spin_lock.cpp spin_lock.h + stb.cpp + stb.h steady_clock.cpp steady_clock.h stream.cpp @@ -208,6 +210,8 @@ if (MSVC) /we4254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data /we4800 # Implicit conversion from 'type' to bool. Possible information loss ) +else() + set_source_files_properties(stb.cpp PROPERTIES COMPILE_OPTIONS "-Wno-implicit-fallthrough;-Wno-missing-declarations;-Wno-missing-field-initializers") endif() if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") @@ -223,7 +227,7 @@ endif() create_target_directory_groups(common) -target_link_libraries(common PUBLIC Boost::context Boost::headers fmt::fmt microprofile Threads::Threads) +target_link_libraries(common PUBLIC Boost::context Boost::headers fmt::fmt microprofile stb::headers Threads::Threads) target_link_libraries(common PRIVATE lz4::lz4 zstd::zstd LLVM::Demangle) 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 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#define STB_IMAGE_IMPLEMENTATION +#define STB_IMAGE_RESIZE_IMPLEMENTATION +#define STB_IMAGE_WRITE_IMPLEMENTATION + +#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 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include +#include +#include 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 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include -#include -#include -#include #include "common/fs/file.h" #include "common/fs/path_util.h" #include "common/logging/log.h" +#include "common/stb.h" #include "core/core.h" #include "core/hle/service/caps/caps_manager.h" #include "core/hle/service/caps/caps_result.h" @@ -409,6 +407,12 @@ Result AlbumManager::LoadImage(std::span out_image, const std::filesystem::p return ResultSuccess; } +static void PNGToMemory(void* context, void* png, int len) { + std::vector* png_image = static_cast*>(context); + png_image->reserve(len); + std::memcpy(png_image->data(), png, len); +} + Result AlbumManager::SaveImage(ApplicationAlbumEntry& out_entry, std::span image, u64 title_id, const AlbumFileDateTime& date) const { const auto screenshot_path = @@ -422,16 +426,12 @@ Result AlbumManager::SaveImage(ApplicationAlbumEntry& out_entry, std::span png_image; + if (!stbi_write_png_to_func(PNGToMemory, &png_image, 1280, 720, STBI_rgb_alpha, image.data(), + 0)) { return ResultFileCountLimit; } - std::vector png_image(len); - std::memcpy(png_image.data(), png, len); - if (db_file.Write(png_image) != png_image.size()) { return ResultFileCountLimit; } -- cgit v1.2.3