mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:47:34 +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
2 changed files with 20 additions and 5 deletions
|
@ -29,8 +29,8 @@
|
||||||
#include <AK/SharedBuffer.h>
|
#include <AK/SharedBuffer.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <LibGfx/PNGLoader.h>
|
|
||||||
#include <LibGfx/GIFLoader.h>
|
#include <LibGfx/GIFLoader.h>
|
||||||
|
#include <LibGfx/PNGLoader.h>
|
||||||
#include <LibGfx/ShareableBitmap.h>
|
#include <LibGfx/ShareableBitmap.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.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)
|
RefPtr<Bitmap> Bitmap::load_from_file(const StringView& path)
|
||||||
{
|
{
|
||||||
if(path.ends_with(".png"))
|
#define __ENUMERATE_IMAGE_FORMAT(Name, Ext) \
|
||||||
return load_png(path);
|
if (path.ends_with(Ext)) \
|
||||||
if(path.ends_with(".gif"))
|
return load_##Name(path);
|
||||||
return load_gif(path);
|
ENUMERATE_IMAGE_FORMATS
|
||||||
|
#undef __ENUMERATE_IMAGE_FORMAT
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,10 @@
|
||||||
#include <LibGfx/Forward.h>
|
#include <LibGfx/Forward.h>
|
||||||
#include <LibGfx/Rect.h>
|
#include <LibGfx/Rect.h>
|
||||||
|
|
||||||
|
#define ENUMERATE_IMAGE_FORMATS \
|
||||||
|
__ENUMERATE_IMAGE_FORMAT(png, ".png") \
|
||||||
|
__ENUMERATE_IMAGE_FORMAT(gif, ".gif")
|
||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
|
|
||||||
enum class BitmapFormat {
|
enum class BitmapFormat {
|
||||||
|
@ -54,6 +58,16 @@ public:
|
||||||
static RefPtr<Bitmap> create_wrapper(BitmapFormat, const IntSize&, size_t pitch, RGBA32*);
|
static RefPtr<Bitmap> create_wrapper(BitmapFormat, const IntSize&, size_t pitch, RGBA32*);
|
||||||
static RefPtr<Bitmap> load_from_file(const StringView& path);
|
static RefPtr<Bitmap> load_from_file(const StringView& path);
|
||||||
static RefPtr<Bitmap> create_with_shared_buffer(BitmapFormat, NonnullRefPtr<SharedBuffer>&&, const IntSize&);
|
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> rotated(Gfx::RotationDirection) const;
|
||||||
RefPtr<Gfx::Bitmap> flipped(Gfx::Orientation) const;
|
RefPtr<Gfx::Bitmap> flipped(Gfx::Orientation) const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue