diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-04-03 14:15:35 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-04-03 14:15:35 +0200 |
commit | c0009e3173da25eb26a62ac251962ba7e810ec41 (patch) | |
tree | 0e8f205a79aef1bd8aba6eec5f669e0afaf2db7c /SharedGraphics | |
parent | 3dc3754cdebd369fea0e57d899bf0e4ee2debc2b (diff) | |
download | serenity-c0009e3173da25eb26a62ac251962ba7e810ec41.zip |
PNGLoader: Use MappedFile.
Diffstat (limited to 'SharedGraphics')
-rw-r--r-- | SharedGraphics/PNGLoader.cpp | 39 |
1 files changed, 4 insertions, 35 deletions
diff --git a/SharedGraphics/PNGLoader.cpp b/SharedGraphics/PNGLoader.cpp index 53f1d2fda1..a4928c45e1 100644 --- a/SharedGraphics/PNGLoader.cpp +++ b/SharedGraphics/PNGLoader.cpp @@ -1,5 +1,6 @@ #include <SharedGraphics/PNGLoader.h> #include <AK/NetworkOrdered.h> +#include <AK/MappedFile.h> #include <sys/mman.h> #include <sys/stat.h> #include <unistd.h> @@ -101,42 +102,10 @@ static bool process_chunk(Streamer&, PNGLoadingContext& context); RetainPtr<GraphicsBitmap> load_png(const String& path) { - int fd = open(path.characters(), O_RDONLY); - if (fd < 0) { - perror("open"); + MappedFile mapped_file(path); + if (!mapped_file.is_valid()) return nullptr; - } - - struct stat st; - if (fstat(fd, &st) < 0) { - perror("fstat"); - if (close(fd) < 0) - perror("close"); - return nullptr; - } - - if (st.st_size < 8) { - if (close(fd) < 0) - perror("close"); - return nullptr; - } - - auto* mapped_file = (byte*)mmap(nullptr, st.st_size, PROT_READ, MAP_SHARED, fd, 0); - if (mapped_file == MAP_FAILED) { - if (close(fd) < 0) - perror("close"); - return nullptr; - } - - auto bitmap = load_png_impl(mapped_file, st.st_size); - - if (munmap(mapped_file, st.st_size) < 0) - perror("munmap"); - - if (close(fd) < 0) - perror("close"); - - return bitmap; + return load_png_impl((const byte*)mapped_file.pointer(), mapped_file.size()); } [[gnu::always_inline]] static inline byte paeth_predictor(int a, int b, int c) |