/* * Copyright (c) 2023-2025, Aliaksandr Kalenik * Copyright (c) 2026, Gregory Bertilson * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include class SkImage; namespace Gfx { struct ImmutableBitmapImpl; #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, }; }; class ImmutableBitmap final : public AtomicRefCounted { public: static NonnullRefPtr create(NonnullRefPtr const& bitmap, ColorSpace color_space = {}); static NonnullRefPtr create(NonnullRefPtr const& bitmap, AlphaType, ColorSpace color_space = {}); static NonnullRefPtr create_snapshot_from_painting_surface(NonnullRefPtr const&); static ErrorOr> create_from_yuv(NonnullOwnPtr); ~ImmutableBitmap(); bool ensure_sk_image(SkiaBackendContext&) const; int width() const; int height() const; IntRect rect() const; IntSize size() const; AlphaType alpha_type() const; SkImage const* sk_image() const; [[nodiscard]] ErrorOr export_to_byte_buffer(ExportFormat format, int flags, Optional target_width, Optional target_height) const; Color get_pixel(int x, int y) const; // Returns nullptr for YUV-backed bitmaps RefPtr bitmap() const; private: mutable NonnullOwnPtr m_impl; explicit ImmutableBitmap(NonnullOwnPtr&&); void lock_context(); void unlock_context(); }; }