diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-03-23 12:37:33 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-03-23 12:37:33 +0100 |
commit | 92627154a7e1e7e5284f8db20ba18b93711d28fe (patch) | |
tree | 219b462a65af76fa7cc39ff9381e66214c57e658 | |
parent | 1355d09c720cf04e58c7b5478150764781d6bf13 (diff) | |
download | serenity-92627154a7e1e7e5284f8db20ba18b93711d28fe.zip |
FileManager: Add basic thumbnailing of PNG images.
These use nearest neighbor and are computed synchronously on directory load
so it's neither fast nor very beautiful. These issues both need work on
other parts of the system to fix.
-rw-r--r-- | Applications/FileManager/DirectoryModel.cpp | 16 | ||||
-rw-r--r-- | Applications/FileManager/DirectoryModel.h | 2 | ||||
-rw-r--r-- | SharedGraphics/GraphicsBitmap.h | 1 |
3 files changed, 17 insertions, 2 deletions
diff --git a/Applications/FileManager/DirectoryModel.cpp b/Applications/FileManager/DirectoryModel.cpp index 8ec45ea55a..0b3bd1d50a 100644 --- a/Applications/FileManager/DirectoryModel.cpp +++ b/Applications/FileManager/DirectoryModel.cpp @@ -6,6 +6,8 @@ #include <pwd.h> #include <AK/FileSystemPath.h> #include <AK/StringBuilder.h> +#include <SharedGraphics/GraphicsBitmap.h> +#include <SharedGraphics/Painter.h> DirectoryModel::DirectoryModel() { @@ -79,8 +81,18 @@ const GraphicsBitmap& DirectoryModel::icon_for(const Entry& entry) const return *m_socket_icon; if (entry.mode & S_IXUSR) return *m_executable_icon; - if (entry.name.ends_with(".png")) - return *m_filetype_image_icon; + if (entry.name.ends_with(".png")) { + if (!entry.thumbnail) { + if (auto png_bitmap = GraphicsBitmap::load_from_file(entry.full_path(*this))) { + entry.thumbnail = GraphicsBitmap::create(png_bitmap->format(), { 32, 32 }); + Painter painter(*entry.thumbnail); + painter.draw_scaled_bitmap(entry.thumbnail->rect(), *png_bitmap, png_bitmap->rect()); + } + } + if (!entry.thumbnail) + return *m_filetype_image_icon; + return *entry.thumbnail; + } return *m_file_icon; } diff --git a/Applications/FileManager/DirectoryModel.h b/Applications/FileManager/DirectoryModel.h index 592eac9887..6e743596e5 100644 --- a/Applications/FileManager/DirectoryModel.h +++ b/Applications/FileManager/DirectoryModel.h @@ -45,8 +45,10 @@ private: uid_t uid { 0 }; uid_t gid { 0 }; ino_t inode { 0 }; + mutable RetainPtr<GraphicsBitmap> thumbnail; bool is_directory() const { return S_ISDIR(mode); } bool is_executable() const { return mode & S_IXUSR; } + String full_path(const DirectoryModel& model) const { return String::format("%s/%s", model.path().characters(), name.characters()); } }; const Entry& entry(int index) const diff --git a/SharedGraphics/GraphicsBitmap.h b/SharedGraphics/GraphicsBitmap.h index 26f3efa396..e48584df69 100644 --- a/SharedGraphics/GraphicsBitmap.h +++ b/SharedGraphics/GraphicsBitmap.h @@ -30,6 +30,7 @@ public: int shared_buffer_id() const { return m_shared_buffer ? m_shared_buffer->shared_buffer_id() : -1; } bool has_alpha_channel() const { return m_format == Format::RGBA32; } + Format format() const { return m_format; } private: GraphicsBitmap(Format, const Size&); |