summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/PixelPaint/Image.cpp12
-rw-r--r--Userland/Applications/PixelPaint/Image.h1
-rw-r--r--Userland/Applications/PixelPaint/MainWidget.cpp13
3 files changed, 26 insertions, 0 deletions
diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp
index f64edc2cad..f4832189e1 100644
--- a/Userland/Applications/PixelPaint/Image.cpp
+++ b/Userland/Applications/PixelPaint/Image.cpp
@@ -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) {
diff --git a/Userland/Applications/PixelPaint/Image.h b/Userland/Applications/PixelPaint/Image.h
index c425e18ffe..97e37eef5f 100644
--- a/Userland/Applications/PixelPaint/Image.h
+++ b/Userland/Applications/PixelPaint/Image.h
@@ -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&);
diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp
index eb00abeebf..625e7df559 100644
--- a/Userland/Applications/PixelPaint/MainWidget.cpp
+++ b/Userland/Applications/PixelPaint/MainWidget.cpp
@@ -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();