From 375799fa79d1af76f33299acc20a11a167a021f8 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 17 Aug 2023 12:32:50 +0200 Subject: project: restructure libraries and build env --- source/lib/src/wallpaper.cpp | 91 -------------------------------------------- 1 file changed, 91 deletions(-) delete mode 100644 source/lib/src/wallpaper.cpp (limited to 'source/lib/src/wallpaper.cpp') diff --git a/source/lib/src/wallpaper.cpp b/source/lib/src/wallpaper.cpp deleted file mode 100644 index c9c5cfe..0000000 --- a/source/lib/src/wallpaper.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include "wanda/logging.hpp" -#include "wanda/magic.hpp" -#include "wanda/optional.hpp" -#include "wanda/setting.hpp" -#include "wanda/wallpaper.hpp" - -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -namespace wanda -{ - namespace - { - auto magic_instance = magic{}; - - auto load_image(std::filesystem::path wallpaper) - { - auto image = boost::gil::rgb8_image_t{}; - - switch (magic_instance.type(wallpaper)) - { - case magic::mime_type::image_jpeg: - boost::gil::read_and_convert_image(wallpaper.native(), image, boost::gil::jpeg_tag{}); - break; - case magic::mime_type::image_png: - boost::gil::read_and_convert_image(wallpaper.native(), image, boost::gil::png_tag{}); - break; - } - - return image; - } - - auto average_colors(boost::gil::rgb8_image_t image) - { - auto accumulator = boost::gil::rgb64f_pixel_t{}; - auto view = const_view(image); - - std::ranges::for_each(view, [&](auto const & source_pixel) { - at_c<0>(accumulator) += std::pow(boost::gil::at_c<0>(source_pixel), 2); - at_c<1>(accumulator) += std::pow(boost::gil::at_c<1>(source_pixel), 2); - at_c<2>(accumulator) += std::pow(boost::gil::at_c<2>(source_pixel), 2); - }); - - at_c<0>(accumulator) = std::sqrt(at_c<0>(accumulator) / view.size()); - at_c<1>(accumulator) = std::sqrt(at_c<1>(accumulator) / view.size()); - at_c<2>(accumulator) = std::sqrt(at_c<2>(accumulator) / view.size()); - - return accumulator; - } - - } // namespace - - void set_wallpaper(std::filesystem::path wallpaper) - { - using namespace wanda::literals; - using namespace wanda::std_ext; - using namespace std::string_literals; - - auto image = load_image(wallpaper); - auto color = average_colors(std::move(image)); - auto hexstring = fmt::format("#{:02X}{:02X}{:02X}", - static_cast(at_c<0>(color)), - static_cast(at_c<1>(color)), - static_cast(at_c<2>(color))); - - with("org.gnome.desktop.background"_setting, [&](auto & setting) { - with(setting["primary-color"_key], [&](auto & value) { - value = hexstring; - }); - with(setting["picture-uri"_key], [&](auto & value) { - value = "file://" + wallpaper.native(); - }) || - [&] { get_logger()->error("invalid settings key"); }; - with(setting["picture-uri-dark"_key], [&](auto & value) { - value = "file://" + wallpaper.native(); - }) || - [&] { get_logger()->error("invalid settings key"); }; - }) || - [&] { get_logger()->error("invalid setting"); }; - } - -} // namespace wanda -- cgit v1.2.3