2020-10-18 14:39:22 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Ben Jilks <benjyjilks@gmail.com>
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-10-18 14:39:22 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/ByteBuffer.h>
|
|
|
|
|
|
|
|
|
|
namespace Gfx {
|
|
|
|
|
|
|
|
|
|
class Bitmap;
|
|
|
|
|
|
2023-03-12 10:24:30 -04:00
|
|
|
// This is not a nested struct to work around https://llvm.org/PR36684
|
|
|
|
|
struct BMPWriterOptions {
|
2021-07-03 23:50:21 +02:00
|
|
|
enum class DibHeader : u32 {
|
|
|
|
|
Info = 40,
|
|
|
|
|
V3 = 56,
|
|
|
|
|
V4 = 108,
|
2023-03-15 11:54:24 +01:00
|
|
|
V5 = 124,
|
2020-10-18 14:39:22 +00:00
|
|
|
};
|
2023-03-15 11:54:24 +01:00
|
|
|
DibHeader dib_header = DibHeader::V5;
|
2023-03-15 12:05:36 +01:00
|
|
|
|
|
|
|
|
Optional<ReadonlyBytes> icc_data;
|
2023-03-12 10:24:30 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class BMPWriter {
|
|
|
|
|
public:
|
|
|
|
|
using Options = BMPWriterOptions;
|
2023-03-12 12:09:29 -04:00
|
|
|
static ErrorOr<ByteBuffer> encode(Bitmap const&, Options options = Options {});
|
|
|
|
|
|
|
|
|
|
private:
|
2023-03-12 10:24:30 -04:00
|
|
|
BMPWriter() = default;
|
2020-10-18 14:39:22 +00:00
|
|
|
|
2023-03-12 13:22:19 -04:00
|
|
|
ErrorOr<ByteBuffer> dump(Bitmap const&, Options options);
|
2021-07-03 23:50:21 +02:00
|
|
|
|
2023-03-12 10:21:29 -04:00
|
|
|
enum class Compression : u32 {
|
|
|
|
|
BI_RGB = 0,
|
|
|
|
|
BI_BITFIELDS = 3,
|
|
|
|
|
};
|
|
|
|
|
|
2023-03-12 12:15:08 -04:00
|
|
|
static ByteBuffer compress_pixel_data(ByteBuffer, Compression);
|
2023-03-12 10:21:29 -04:00
|
|
|
|
2021-07-03 23:50:21 +02:00
|
|
|
Compression m_compression { Compression::BI_BITFIELDS };
|
2023-03-12 10:21:29 -04:00
|
|
|
|
2021-07-03 23:50:21 +02:00
|
|
|
int m_bytes_per_pixel { 4 };
|
|
|
|
|
bool m_include_alpha_channel { true };
|
2020-10-18 14:39:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|