mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-12 01:10:42 +00:00
LibGfx: Add a simple GrayscaleBitmap class
This is very similar to the existing CharacterBitmap class but instead intended for small static grayscale bitmaps (such as signed distance fields).
This commit is contained in:
parent
87b8a36e56
commit
429d7b002b
Notes:
sideshowbarker
2024-07-17 02:21:14 +09:00
Author: https://github.com/MacDue Commit: https://github.com/SerenityOS/serenity/commit/429d7b002b Pull-request: https://github.com/SerenityOS/serenity/pull/17933 Reviewed-by: https://github.com/AtkinsSJ ✅ Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/gmta Reviewed-by: https://github.com/srikavin
1 changed files with 38 additions and 0 deletions
38
Userland/Libraries/LibGfx/GrayscaleBitmap.h
Normal file
38
Userland/Libraries/LibGfx/GrayscaleBitmap.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2023, MacDue <macdue@dueutil.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Size.h"
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/StringView.h>
|
||||
|
||||
namespace Gfx {
|
||||
|
||||
class GrayscaleBitmap {
|
||||
public:
|
||||
GrayscaleBitmap() = delete;
|
||||
constexpr GrayscaleBitmap(ReadonlyBytes data, unsigned width, unsigned height)
|
||||
: m_data(data)
|
||||
, m_size(width, height)
|
||||
{
|
||||
VERIFY(width * height == data.size());
|
||||
}
|
||||
|
||||
constexpr u8 pixel_at(unsigned x, unsigned y) const { return m_data[y * width() + x]; }
|
||||
constexpr ReadonlyBytes data() const { return m_data; }
|
||||
|
||||
constexpr IntSize size() const { return m_size; }
|
||||
constexpr unsigned width() const { return m_size.width(); }
|
||||
constexpr unsigned height() const { return m_size.height(); }
|
||||
|
||||
private:
|
||||
ReadonlyBytes m_data {};
|
||||
IntSize m_size {};
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in a new issue