Debian Codegraph @

Source/Core/InputCommon/ImageOperations.h

raw symbols SCIP
1 // Copyright 2019 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <optional>
7 #include <string>
8 #include <vector>
9
10 #include "Common/CommonTypes.h"
11 #include "Common/MathUtil.h"
12 #include "Common/Matrix.h"
13
14 namespace InputCommon
15 {
16 struct Pixel
17 {
18 u8 r = 0;
19 u8 g = 0;
20 u8 b = 0;
21 u8 a = 0;
22
23 bool operator==(const Pixel& o) const { return r == o.r && g == o.g && b == o.b && a == o.a; }
24 };
25
26 using Point = Common::TVec2<u32>;
27 using Rect = MathUtil::Rectangle<u32>;
28
29 struct ImagePixelData
30 {
31 ImagePixelData() = default;
32
33 explicit ImagePixelData(std::vector<Pixel> image_pixels, u32 width_, u32 height_)
34 : pixels(std::move(image_pixels)), width(width_), height(height_)
35 {
36 }
37
38 explicit ImagePixelData(u32 width_, u32 height_, const Pixel& default_color = Pixel{0, 0, 0, 0})
39 : pixels(width_ * height_, default_color), width(width_), height(height_)
40 {
41 }
42 std::vector<Pixel> pixels;
43 u32 width = 0;
44 u32 height = 0;
45 };
46
47 void CopyImageRegion(const ImagePixelData& src, ImagePixelData& dst, const Rect& src_region,
48 const Rect& dst_region);
49
50 std::optional<ImagePixelData> LoadImage(const std::string& path);
51
52 bool WriteImage(const std::string& path, const ImagePixelData& image);
53
54 enum class ResizeMode
55 {
56 Nearest,
57 };
58
59 ImagePixelData Resize(ResizeMode mode, const ImagePixelData& src, u32 new_width, u32 new_height);
60
61 ImagePixelData ResizeKeepAspectRatio(ResizeMode mode, const ImagePixelData& src, u32 new_width,
62 u32 new_height, const Pixel& background_color);
63 } // namespace InputCommon