summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorOlivier De Canniere <olivier.decanniere96@gmail.com>2022-04-07 14:23:54 +0200
committerLinus Groh <mail@linusgroh.de>2022-04-13 15:21:27 +0100
commitbe4913c1fbea17dbdea61afd64dae5c7da7ace5c (patch)
treec7e34d311e71786e910d3542cbae7aacfc4c0814 /Userland
parent44a555852504039d017404b983793b13ceb9afbf (diff)
downloadserenity-be4913c1fbea17dbdea61afd64dae5c7da7ace5c.zip
PixelPaint: Add exporting to the QOI image format
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();