diff options
Diffstat (limited to '')
| -rw-r--r-- | src/input_common/drivers/camera.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/input_common/drivers/camera.cpp b/src/input_common/drivers/camera.cpp new file mode 100644 index 000000000..dceea67e0 --- /dev/null +++ b/src/input_common/drivers/camera.cpp | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include <fmt/format.h> | ||
| 5 | |||
| 6 | #include "common/param_package.h" | ||
| 7 | #include "input_common/drivers/camera.h" | ||
| 8 | |||
| 9 | namespace InputCommon { | ||
| 10 | constexpr PadIdentifier identifier = { | ||
| 11 | .guid = Common::UUID{}, | ||
| 12 | .port = 0, | ||
| 13 | .pad = 0, | ||
| 14 | }; | ||
| 15 | |||
| 16 | Camera::Camera(std::string input_engine_) : InputEngine(std::move(input_engine_)) { | ||
| 17 | PreSetController(identifier); | ||
| 18 | } | ||
| 19 | |||
| 20 | void Camera::SetCameraData(std::size_t width, std::size_t height, std::vector<u32> data) { | ||
| 21 | const std::size_t desired_width = getImageWidth(); | ||
| 22 | const std::size_t desired_height = getImageHeight(); | ||
| 23 | status.data.resize(desired_width * desired_height); | ||
| 24 | |||
| 25 | // Resize image to desired format | ||
| 26 | for (std::size_t y = 0; y < desired_height; y++) { | ||
| 27 | for (std::size_t x = 0; x < desired_width; x++) { | ||
| 28 | const std::size_t pixel_index = y * desired_width + x; | ||
| 29 | const std::size_t old_x = width * x / desired_width; | ||
| 30 | const std::size_t old_y = height * y / desired_height; | ||
| 31 | const std::size_t data_pixel_index = old_y * width + old_x; | ||
| 32 | status.data[pixel_index] = static_cast<u8>(data[data_pixel_index] & 0xFF); | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | SetCamera(identifier, status); | ||
| 37 | } | ||
| 38 | |||
| 39 | std::size_t Camera::getImageWidth() const { | ||
| 40 | switch (status.format) { | ||
| 41 | case Common::Input::CameraFormat::Size320x240: | ||
| 42 | return 320; | ||
| 43 | case Common::Input::CameraFormat::Size160x120: | ||
| 44 | return 160; | ||
| 45 | case Common::Input::CameraFormat::Size80x60: | ||
| 46 | return 80; | ||
| 47 | case Common::Input::CameraFormat::Size40x30: | ||
| 48 | return 40; | ||
| 49 | case Common::Input::CameraFormat::Size20x15: | ||
| 50 | return 20; | ||
| 51 | case Common::Input::CameraFormat::None: | ||
| 52 | default: | ||
| 53 | return 0; | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | std::size_t Camera::getImageHeight() const { | ||
| 58 | switch (status.format) { | ||
| 59 | case Common::Input::CameraFormat::Size320x240: | ||
| 60 | return 240; | ||
| 61 | case Common::Input::CameraFormat::Size160x120: | ||
| 62 | return 120; | ||
| 63 | case Common::Input::CameraFormat::Size80x60: | ||
| 64 | return 60; | ||
| 65 | case Common::Input::CameraFormat::Size40x30: | ||
| 66 | return 30; | ||
| 67 | case Common::Input::CameraFormat::Size20x15: | ||
| 68 | return 15; | ||
| 69 | case Common::Input::CameraFormat::None: | ||
| 70 | default: | ||
| 71 | return 0; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | Common::Input::CameraError Camera::SetCameraFormat( | ||
| 76 | [[maybe_unused]] const PadIdentifier& identifier_, | ||
| 77 | const Common::Input::CameraFormat camera_format) { | ||
| 78 | status.format = camera_format; | ||
| 79 | return Common::Input::CameraError::None; | ||
| 80 | } | ||
| 81 | |||
| 82 | } // namespace InputCommon | ||