mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 09:37:34 +00:00
LibGfx/PortableFormat: Add PortableFormatWriter
Currently, the encoder only output ppm files, but it can easily be extended to support both PBM and PGM.
This commit is contained in:
parent
e32267c902
commit
9c9bd271c8
3 changed files with 93 additions and 0 deletions
38
Userland/Libraries/LibGfx/PortableFormatWriter.h
Normal file
38
Userland/Libraries/LibGfx/PortableFormatWriter.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Lucas Chollet <lucas.chollet@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
|
||||
namespace Gfx {
|
||||
|
||||
// This is not a nested struct to work around https://llvm.org/PR36684
|
||||
struct PortableFormatWriterOptions {
|
||||
enum class Format {
|
||||
ASCII,
|
||||
Raw,
|
||||
};
|
||||
|
||||
Format format = Format::Raw;
|
||||
StringView comment = "Generated with SerenityOS - LibGfx."sv;
|
||||
};
|
||||
|
||||
class PortableFormatWriter {
|
||||
public:
|
||||
using Options = PortableFormatWriterOptions;
|
||||
|
||||
static ErrorOr<ByteBuffer> encode(Bitmap const&, Options options = Options {});
|
||||
|
||||
private:
|
||||
PortableFormatWriter() = delete;
|
||||
|
||||
static ErrorOr<void> add_header(ByteBuffer&, Options const& options, u32 width, u32 height, u32 max_value);
|
||||
static ErrorOr<void> add_pixels(ByteBuffer&, Options const& options, Bitmap const&);
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue