From 8564b59e1491ef7e72fef7a44adbd5903dc31590 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 29 Nov 2023 20:56:05 +0200 Subject: [PATCH] image: Remove inheritance from Netbpm This inheritance made no sense --- userspace/image/Image.cpp | 2 +- userspace/image/Image.h | 6 ++++-- userspace/image/Netbpm.cpp | 6 +++--- userspace/image/Netbpm.h | 13 +------------ 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/userspace/image/Image.cpp b/userspace/image/Image.cpp index bf81cd07..7dcaa138 100644 --- a/userspace/image/Image.cpp +++ b/userspace/image/Image.cpp @@ -70,7 +70,7 @@ BAN::UniqPtr Image::load_from_file(BAN::StringView path) case 0x3350: case 0x3250: case 0x3150: - if (auto res = Netbpm::create(addr, st.st_size); res.is_error()) + if (auto res = load_netbpm(addr, st.st_size); res.is_error()) fprintf(stderr, "%s\n", strerror(res.error().get_error_code())); else image = res.release_value(); diff --git a/userspace/image/Image.h b/userspace/image/Image.h index 613ff5a4..87ec66c1 100644 --- a/userspace/image/Image.h +++ b/userspace/image/Image.h @@ -22,15 +22,17 @@ public: bool render_to_framebuffer(); -protected: +private: Image(uint64_t width, uint64_t height, BAN::Vector&& bitmap) : m_width(width) , m_height(height) , m_bitmap(BAN::move(bitmap)) { } -protected: +private: const uint64_t m_width; const uint64_t m_height; const BAN::Vector m_bitmap; + + friend class BAN::UniqPtr; }; diff --git a/userspace/image/Netbpm.cpp b/userspace/image/Netbpm.cpp index 6d65b0ac..5f424882 100644 --- a/userspace/image/Netbpm.cpp +++ b/userspace/image/Netbpm.cpp @@ -29,7 +29,7 @@ BAN::Optional parse_u64(const uint8_t*& data, size_t data_size) return {}; } -BAN::ErrorOr> Netbpm::create(const void* mmap_addr, size_t size) +BAN::ErrorOr> load_netbpm(const void* mmap_addr, size_t size) { if (size < 11) { @@ -88,7 +88,7 @@ BAN::ErrorOr> Netbpm::create(const void* mmap_addr, size_t printf("Netbpm image %llux%llu\n", *width, *height); - BAN::Vector bitmap; + BAN::Vector bitmap; TRY(bitmap.resize(*width * *height)); // Fill bitmap @@ -104,5 +104,5 @@ BAN::ErrorOr> Netbpm::create(const void* mmap_addr, size_t } } - return TRY(BAN::UniqPtr::create(*width, *height, BAN::move(bitmap))); + return TRY(BAN::UniqPtr::create(*width, *height, BAN::move(bitmap))); } diff --git a/userspace/image/Netbpm.h b/userspace/image/Netbpm.h index 325d85fa..203a7582 100644 --- a/userspace/image/Netbpm.h +++ b/userspace/image/Netbpm.h @@ -1,14 +1,3 @@ #include "Image.h" -class Netbpm : public Image -{ -public: - static BAN::ErrorOr> create(const void* mmap_addr, size_t size); - -private: - Netbpm(uint64_t width, uint64_t height, BAN::Vector&& bitmap) - : Image(width, height, BAN::move(bitmap)) - { } - - friend class BAN::UniqPtr; -}; +BAN::ErrorOr> load_netbpm(const void* mmap_addr, size_t size);