summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx/PNGWriter.h
blob: 2f53fe99073faa2beb32fc436d2b75dc5ce39741 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
 * Copyright (c) 2021, Pierre Hoffmeister
 * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/Vector.h>
#include <LibGfx/Forward.h>
#include <LibGfx/PNGShared.h>

namespace Gfx {

class PNGChunk;

class PNGWriter {
public:
    static ErrorOr<ByteBuffer> encode(Gfx::Bitmap const&);

private:
    PNGWriter() = default;

    Vector<u8> m_data;
    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_IDAT_chunk(Gfx::Bitmap const&);
    ErrorOr<void> add_IEND_chunk();
};

}