2021-01-22 11:46:09 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Pierre Hoffmeister
|
2021-04-19 23:43:04 +02:00
|
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
2021-01-22 11:46:09 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-01-22 11:46:09 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-03-15 11:08:43 +01:00
|
|
|
#include <AK/Optional.h>
|
2021-01-22 11:46:09 +01:00
|
|
|
#include <AK/Vector.h>
|
2021-04-19 23:43:04 +02:00
|
|
|
#include <LibGfx/Forward.h>
|
2023-03-21 14:58:06 -04:00
|
|
|
#include <LibGfx/ImageFormats/PNGShared.h>
|
2021-01-22 11:46:09 +01:00
|
|
|
|
|
|
|
|
namespace Gfx {
|
|
|
|
|
|
|
|
|
|
class PNGChunk;
|
|
|
|
|
|
2023-03-15 11:08:43 +01:00
|
|
|
// 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;
|
|
|
|
|
};
|
|
|
|
|
|
2021-01-22 11:46:09 +01:00
|
|
|
class PNGWriter {
|
|
|
|
|
public:
|
2023-03-15 11:08:43 +01:00
|
|
|
using Options = PNGWriterOptions;
|
|
|
|
|
|
|
|
|
|
static ErrorOr<ByteBuffer> encode(Gfx::Bitmap const&, Options options = Options {});
|
2021-01-22 11:46:09 +01:00
|
|
|
|
|
|
|
|
private:
|
2022-03-14 13:26:37 -06:00
|
|
|
PNGWriter() = default;
|
2021-04-19 23:43:04 +02:00
|
|
|
|
2021-01-22 11:46:09 +01:00
|
|
|
Vector<u8> m_data;
|
2022-12-05 20:49:13 +01:00
|
|
|
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);
|
2023-03-15 11:08:43 +01:00
|
|
|
ErrorOr<void> add_iCCP_chunk(ReadonlyBytes icc_data);
|
2022-12-05 20:49:13 +01:00
|
|
|
ErrorOr<void> add_IDAT_chunk(Gfx::Bitmap const&);
|
|
|
|
|
ErrorOr<void> add_IEND_chunk();
|
2021-01-22 11:46:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|