1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:38:11 +00:00
serenity/Userland/Libraries/LibGfx/PNGWriter.h
Andreas Kling d88c7fee32 LibGfx+Userland: Make PNGWriter::encode() return ErrorOr<ByteBuffer>
This is a first step towards handling PNG encoding failures instead of
just falling over and crashing the program.

This initial step will cause encode() to return an error if the final
ByteBuffer copy fails to allocate. There are more potential failures
that will be surfaced by subsequent commits.

Two FIXMEs were killed in the making of this patch. :^)
2022-12-08 13:01:11 +00:00

33 lines
717 B
C++

/*
* 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;
void add_chunk(PNGChunk&);
void add_png_header();
void add_IHDR_chunk(u32 width, u32 height, u8 bit_depth, PNG::ColorType color_type, u8 compression_method, u8 filter_method, u8 interlace_method);
void add_IDAT_chunk(Gfx::Bitmap const&);
void add_IEND_chunk();
};
}