mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-13 06:32:54 +00:00
PixelPaint: Add exporting to the QOI image format
This commit is contained in:
parent
44a5558525
commit
be4913c1fb
Notes:
sideshowbarker
2024-07-17 11:50:27 +09:00
Author: https://github.com/iCristalrope
Commit: be4913c1fb
Pull-request: https://github.com/SerenityOS/serenity/pull/13558
Reviewed-by: https://github.com/kleinesfilmroellchen ✅
Reviewed-by: https://github.com/linusg ✅
3 changed files with 26 additions and 0 deletions
|
@ -19,6 +19,7 @@
|
|||
#include <LibGfx/BMPWriter.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibGfx/PNGWriter.h>
|
||||
#include <LibGfx/QOIWriter.h>
|
||||
#include <LibImageDecoderClient/Client.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -212,6 +213,17 @@ ErrorOr<void> Image::export_png_to_file(Core::File& file, bool preserve_alpha_ch
|
|||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> Image::export_qoi_to_file(Core::File& file) const
|
||||
{
|
||||
auto bitmap = TRY(try_compose_bitmap(Gfx::BitmapFormat::BGRA8888));
|
||||
|
||||
auto encoded_data = Gfx::QOIWriter::encode(bitmap);
|
||||
if (!file.write(encoded_data.data(), encoded_data.size()))
|
||||
return Error::from_errno(file.error());
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void Image::add_layer(NonnullRefPtr<Layer> layer)
|
||||
{
|
||||
for (auto& existing_layer : m_layers) {
|
||||
|
|
|
@ -71,6 +71,7 @@ public:
|
|||
ErrorOr<void> write_to_file(String const& file_path) const;
|
||||
ErrorOr<void> export_bmp_to_file(Core::File&, bool preserve_alpha_channel);
|
||||
ErrorOr<void> export_png_to_file(Core::File&, bool preserve_alpha_channel);
|
||||
ErrorOr<void> export_qoi_to_file(Core::File&) const;
|
||||
|
||||
void move_layer_to_front(Layer&);
|
||||
void move_layer_to_back(Layer&);
|
||||
|
|
|
@ -191,6 +191,19 @@ void MainWidget::initialize_menubar(GUI::Window& window)
|
|||
GUI::MessageBox::show_error(&window, String::formatted("Export to PNG failed: {}", result.error()));
|
||||
}));
|
||||
|
||||
m_export_submenu->add_action(
|
||||
GUI::Action::create(
|
||||
"As &QOI", [&](auto&) {
|
||||
auto* editor = current_image_editor();
|
||||
VERIFY(editor);
|
||||
auto response = FileSystemAccessClient::Client::the().try_save_file(&window, "untitled", "qoi");
|
||||
if (response.is_error())
|
||||
return;
|
||||
auto result = editor->image().export_qoi_to_file(response.value());
|
||||
if (result.is_error())
|
||||
GUI::MessageBox::show_error(&window, String::formatted("Export to QOI failed: {}", result.error()));
|
||||
}));
|
||||
|
||||
m_export_submenu->set_icon(g_icon_bag.file_export);
|
||||
|
||||
file_menu.add_separator();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue