summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx/ImageFormats/QOIWriter.h
diff options
context:
space:
mode:
authorLucas CHOLLET <lucas.chollet@free.fr>2023-03-21 14:58:06 -0400
committerAndreas Kling <kling@serenityos.org>2023-03-21 22:39:25 +0100
commit496b7ffb2b58043a80d90b8b8f44cab1eaa874e8 (patch)
tree1fca47aa8123c9d3e110d45c8af637f95241dcd5 /Userland/Libraries/LibGfx/ImageFormats/QOIWriter.h
parent752f06f228119a70c59e844dcd2b9560e757b0ff (diff)
downloadserenity-496b7ffb2b58043a80d90b8b8f44cab1eaa874e8.zip
LibGfx: Move all image loaders and writers to a subdirectory
Diffstat (limited to 'Userland/Libraries/LibGfx/ImageFormats/QOIWriter.h')
-rw-r--r--Userland/Libraries/LibGfx/ImageFormats/QOIWriter.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGfx/ImageFormats/QOIWriter.h b/Userland/Libraries/LibGfx/ImageFormats/QOIWriter.h
new file mode 100644
index 0000000000..232aad5cd1
--- /dev/null
+++ b/Userland/Libraries/LibGfx/ImageFormats/QOIWriter.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2022, Olivier De Cannière <olivier.decanniere96@gmail.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Error.h>
+#include <AK/Vector.h>
+#include <LibGfx/Bitmap.h>
+
+namespace Gfx {
+
+enum class Colorspace;
+enum class Channels;
+
+class QOIWriter {
+public:
+ static ErrorOr<ByteBuffer> encode(Gfx::Bitmap const&);
+
+private:
+ QOIWriter() = default;
+
+ Vector<u8> m_data;
+ ErrorOr<void> add_header(u32 width, u32 height, Channels, Colorspace);
+ ErrorOr<void> add_rgb_chunk(u8, u8, u8);
+ ErrorOr<void> add_rgba_chunk(u8, u8, u8, u8);
+ ErrorOr<void> add_index_chunk(u32 index);
+ ErrorOr<void> add_diff_chunk(i8 red_difference, i8 green_difference, i8 blue_difference);
+ ErrorOr<void> add_luma_chunk(i8 relative_red_difference, i8 green_difference, i8 relative_blue_difference);
+ ErrorOr<void> add_run_chunk(u32 run_length);
+ ErrorOr<void> add_end_marker();
+
+ Array<Color, 64> running_array;
+ static u32 pixel_hash_function(Color pixel);
+ void insert_into_running_array(Color pixel);
+};
+
+}