mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 02:55:49 +03:00
PixelPaint: Support opening more image file formats
Previously we could only open .pp files, now we can open all formats supported by Gfx::Bitmap::load_from_file
This commit is contained in:
parent
566d3cb393
commit
76adac103e
Notes:
sideshowbarker
2024-07-18 17:00:41 +09:00
Author: https://github.com/mrkct Commit: https://github.com/SerenityOS/serenity/commit/76adac103ec Pull-request: https://github.com/SerenityOS/serenity/pull/7652 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/awesomekling
@ -12,8 +12,11 @@
|
||||
#include <AK/JsonValue.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGfx/BMPLoader.h>
|
||||
#include <LibGfx/BMPWriter.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibGfx/ImageDecoder.h>
|
||||
#include <LibGfx/PNGLoader.h>
|
||||
#include <LibGfx/PNGWriter.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@ -49,7 +52,22 @@ void Image::paint_into(GUI::Painter& painter, const Gfx::IntRect& dest_rect)
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<Image> Image::create_from_file(const String& file_path)
|
||||
RefPtr<Image> Image::create_from_bitmap(RefPtr<Gfx::Bitmap> bitmap)
|
||||
{
|
||||
auto image = create_with_size({ bitmap->width(), bitmap->height() });
|
||||
if (image.is_null())
|
||||
return nullptr;
|
||||
|
||||
auto layer = Layer::create_with_bitmap(*image, *bitmap, "Background");
|
||||
if (layer.is_null())
|
||||
return nullptr;
|
||||
|
||||
image->add_layer(layer.release_nonnull());
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
RefPtr<Image> Image::create_from_pixel_paint_file(String const& file_path)
|
||||
{
|
||||
auto file = fopen(file_path.characters(), "r");
|
||||
fseek(file, 0L, SEEK_END);
|
||||
@ -87,6 +105,16 @@ RefPtr<Image> Image::create_from_file(const String& file_path)
|
||||
return image;
|
||||
}
|
||||
|
||||
RefPtr<Image> Image::create_from_file(String const& file_path)
|
||||
{
|
||||
auto bitmap = Gfx::Bitmap::load_from_file(file_path);
|
||||
if (bitmap) {
|
||||
return create_from_bitmap(bitmap);
|
||||
}
|
||||
|
||||
return create_from_pixel_paint_file(file_path);
|
||||
}
|
||||
|
||||
void Image::save(const String& file_path) const
|
||||
{
|
||||
// Build json file
|
||||
|
@ -37,7 +37,8 @@ protected:
|
||||
class Image : public RefCounted<Image> {
|
||||
public:
|
||||
static RefPtr<Image> create_with_size(const Gfx::IntSize&);
|
||||
static RefPtr<Image> create_from_file(const String& file_path);
|
||||
static RefPtr<Image> create_from_file(String const& file_path);
|
||||
static RefPtr<Image> create_from_bitmap(RefPtr<Gfx::Bitmap> bitmap);
|
||||
|
||||
size_t layer_count() const { return m_layers.size(); }
|
||||
const Layer& layer(size_t index) const { return m_layers.at(index); }
|
||||
@ -74,6 +75,8 @@ public:
|
||||
private:
|
||||
explicit Image(const Gfx::IntSize&);
|
||||
|
||||
static RefPtr<Image> create_from_pixel_paint_file(String const& file_path);
|
||||
|
||||
void did_change();
|
||||
void did_modify_layer_stack();
|
||||
|
||||
|
@ -49,7 +49,7 @@ int main(int argc, char** argv)
|
||||
|
||||
const char* image_file = nullptr;
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_positional_argument(image_file, "Pixel Paint image file (*.pp) to open", "path", Core::ArgsParser::Required::No);
|
||||
args_parser.add_positional_argument(image_file, "Image file to open", "path", Core::ArgsParser::Required::No);
|
||||
args_parser.parse(argc, argv);
|
||||
|
||||
auto app_icon = GUI::Icon::default_icon("app-pixel-paint");
|
||||
|
Loading…
Reference in New Issue
Block a user