Bitmap export is pixel conversion, not an ImmutableBitmap-specific operation. It needs a source bitmap and color space, and callers should provide those explicitly instead of routing through the immutable snapshot abstraction. Move the export formats, flags, result type, and conversion implementation into a new BitmapExport helper. Keep BitmapExportResult.h as a forwarding header for existing includes while making BitmapExport.h the new home for the public API. Update WebGL and the LibGfx export test to use the standalone helper directly.
55 lines
1.2 KiB
C++
55 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2024, the Ladybird developers.
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/ByteBuffer.h>
|
|
#include <AK/Error.h>
|
|
#include <AK/Forward.h>
|
|
#include <LibGfx/ColorSpace.h>
|
|
#include <LibGfx/Forward.h>
|
|
|
|
namespace Gfx {
|
|
|
|
#define ENUMERATE_EXPORT_FORMATS(X) \
|
|
X(Gray8) \
|
|
X(Alpha8) \
|
|
X(RGB565) \
|
|
X(RGBA5551) \
|
|
X(RGBA4444) \
|
|
X(RGB888) \
|
|
X(RGBA8888)
|
|
|
|
enum class ExportFormat : u8 {
|
|
#define ENUMERATE_EXPORT_FORMAT(format) format,
|
|
ENUMERATE_EXPORT_FORMATS(ENUMERATE_EXPORT_FORMAT)
|
|
#undef ENUMERATE_EXPORT_FORMAT
|
|
};
|
|
|
|
[[nodiscard]] StringView export_format_name(ExportFormat);
|
|
|
|
struct ExportFlags {
|
|
enum : u8 {
|
|
PremultiplyAlpha = 1 << 0,
|
|
FlipY = 1 << 1,
|
|
};
|
|
};
|
|
|
|
struct BitmapExportResult {
|
|
ByteBuffer buffer;
|
|
int width { 0 };
|
|
int height { 0 };
|
|
};
|
|
|
|
[[nodiscard]] ErrorOr<BitmapExportResult> export_bitmap_to_byte_buffer(
|
|
Bitmap const&,
|
|
ColorSpace const&,
|
|
ExportFormat,
|
|
int flags,
|
|
Optional<int> target_width,
|
|
Optional<int> target_height);
|
|
|
|
}
|