From fd3af4c5d32a34b27c45b478c74fa1127b6438b9 Mon Sep 17 00:00:00 2001 From: iwubcode Date: Sat, 17 Aug 2019 14:40:58 -0500 Subject: InputCommon: Introducing the "Dynamic Input Texture". Configuration links an emulated input action to an image based on what host key is defined for that emulated input. Specific regions are called out in configuration that mark where to replace an input button with a host key image. --- Source/Core/InputCommon/ImageOperations.h | 65 +++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Source/Core/InputCommon/ImageOperations.h (limited to 'Source/Core/InputCommon/ImageOperations.h') diff --git a/Source/Core/InputCommon/ImageOperations.h b/Source/Core/InputCommon/ImageOperations.h new file mode 100644 index 0000000000..28d3859ff5 --- /dev/null +++ b/Source/Core/InputCommon/ImageOperations.h @@ -0,0 +1,65 @@ +// Copyright 2019 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include + +#include "Common/CommonTypes.h" +#include "Common/MathUtil.h" +#include "Common/Matrix.h" + +namespace InputCommon +{ +struct Pixel +{ + u8 r = 0; + u8 g = 0; + u8 b = 0; + u8 a = 0; + + bool operator==(const Pixel& o) const { return r == o.r && g == o.g && b == o.b && a == o.a; } + bool operator!=(const Pixel& o) const { return !(o == *this); } +}; + +using Point = Common::TVec2; +using Rect = MathUtil::Rectangle; + +struct ImagePixelData +{ + ImagePixelData() = default; + + explicit ImagePixelData(std::vector image_pixels, u32 width, u32 height) + : pixels(std::move(image_pixels)), width(width), height(height) + { + } + + explicit ImagePixelData(u32 width, u32 height, const Pixel& default_color = Pixel{0, 0, 0, 0}) + : pixels(width * height, default_color), width(width), height(height) + { + } + std::vector pixels; + u32 width = 0; + u32 height = 0; +}; + +void CopyImageRegion(const ImagePixelData& src, ImagePixelData& dst, const Rect& src_region, + const Rect& dst_region); + +std::optional LoadImage(const std::string& path); + +bool WriteImage(const std::string& path, const ImagePixelData& image); + +enum class ResizeMode +{ + Nearest, +}; + +ImagePixelData Resize(ResizeMode mode, const ImagePixelData& src, u32 new_width, u32 new_height); + +ImagePixelData ResizeKeepAspectRatio(ResizeMode mode, const ImagePixelData& src, u32 new_width, + u32 new_height, const Pixel& background_color); +} // namespace InputCommon -- cgit v1.2.3