1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 11:17:35 +00:00

LibGfx: Let PNGWriter optionally embed an ICC profile

This commit is contained in:
Nico Weber 2023-03-15 11:08:43 +01:00 committed by Linus Groh
parent 6e2d3fe0df
commit 189ea375a5
2 changed files with 30 additions and 2 deletions

View file

@ -7,6 +7,7 @@
#pragma once
#include <AK/Optional.h>
#include <AK/Vector.h>
#include <LibGfx/Forward.h>
#include <LibGfx/PNGShared.h>
@ -15,9 +16,18 @@ namespace Gfx {
class PNGChunk;
// This is not a nested struct to work around https://llvm.org/PR36684
struct PNGWriterOptions {
// Data for the iCCP chunk.
// FIXME: Allow writing cICP, sRGB, or gAMA instead too.
Optional<ReadonlyBytes> icc_data;
};
class PNGWriter {
public:
static ErrorOr<ByteBuffer> encode(Gfx::Bitmap const&);
using Options = PNGWriterOptions;
static ErrorOr<ByteBuffer> encode(Gfx::Bitmap const&, Options options = Options {});
private:
PNGWriter() = default;
@ -26,6 +36,7 @@ private:
ErrorOr<void> add_chunk(PNGChunk&);
ErrorOr<void> add_png_header();
ErrorOr<void> add_IHDR_chunk(u32 width, u32 height, u8 bit_depth, PNG::ColorType color_type, u8 compression_method, u8 filter_method, u8 interlace_method);
ErrorOr<void> add_iCCP_chunk(ReadonlyBytes icc_data);
ErrorOr<void> add_IDAT_chunk(Gfx::Bitmap const&);
ErrorOr<void> add_IEND_chunk();
};