mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +00:00
LibGfx: Add a new Bitmap::is_path_a_supported_image_format() method
Move the image file detection code to the File class to prevent code duplication.
This commit is contained in:
parent
17aa917073
commit
56158a4281
Notes:
sideshowbarker
2024-07-19 05:38:04 +09:00
Author: https://github.com/asliturk Commit: https://github.com/SerenityOS/serenity/commit/56158a42818 Pull-request: https://github.com/SerenityOS/serenity/pull/2557 Reviewed-by: https://github.com/bugaevc
2 changed files with 20 additions and 5 deletions
|
@ -29,8 +29,8 @@
|
|||
#include <AK/SharedBuffer.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibGfx/PNGLoader.h>
|
||||
#include <LibGfx/GIFLoader.h>
|
||||
#include <LibGfx/PNGLoader.h>
|
||||
#include <LibGfx/ShareableBitmap.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
@ -86,10 +86,11 @@ RefPtr<Bitmap> Bitmap::create_wrapper(BitmapFormat format, const IntSize& size,
|
|||
|
||||
RefPtr<Bitmap> Bitmap::load_from_file(const StringView& path)
|
||||
{
|
||||
if(path.ends_with(".png"))
|
||||
return load_png(path);
|
||||
if(path.ends_with(".gif"))
|
||||
return load_gif(path);
|
||||
#define __ENUMERATE_IMAGE_FORMAT(Name, Ext) \
|
||||
if (path.ends_with(Ext)) \
|
||||
return load_##Name(path);
|
||||
ENUMERATE_IMAGE_FORMATS
|
||||
#undef __ENUMERATE_IMAGE_FORMAT
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,10 @@
|
|||
#include <LibGfx/Forward.h>
|
||||
#include <LibGfx/Rect.h>
|
||||
|
||||
#define ENUMERATE_IMAGE_FORMATS \
|
||||
__ENUMERATE_IMAGE_FORMAT(png, ".png") \
|
||||
__ENUMERATE_IMAGE_FORMAT(gif, ".gif")
|
||||
|
||||
namespace Gfx {
|
||||
|
||||
enum class BitmapFormat {
|
||||
|
@ -54,6 +58,16 @@ public:
|
|||
static RefPtr<Bitmap> create_wrapper(BitmapFormat, const IntSize&, size_t pitch, RGBA32*);
|
||||
static RefPtr<Bitmap> load_from_file(const StringView& path);
|
||||
static RefPtr<Bitmap> create_with_shared_buffer(BitmapFormat, NonnullRefPtr<SharedBuffer>&&, const IntSize&);
|
||||
static bool is_path_a_supported_image_format(const StringView& path)
|
||||
{
|
||||
#define __ENUMERATE_IMAGE_FORMAT(Name, Ext) \
|
||||
if (path.ends_with(Ext)) \
|
||||
return true;
|
||||
ENUMERATE_IMAGE_FORMATS
|
||||
#undef __ENUMERATE_IMAGE_FORMAT
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
RefPtr<Gfx::Bitmap> rotated(Gfx::RotationDirection) const;
|
||||
RefPtr<Gfx::Bitmap> flipped(Gfx::Orientation) const;
|
||||
|
|
Loading…
Add table
Reference in a new issue