LibImage: Move userspace image parsing to its own library

The image utility now uses this tool instead of parsing images on its
own.
This commit is contained in:
2024-06-14 11:05:54 +03:00
parent 05e9d76c77
commit 672ce40618
12 changed files with 347 additions and 303 deletions

View File

@@ -0,0 +1,47 @@
#pragma once
#include <BAN/StringView.h>
#include <BAN/UniqPtr.h>
#include <BAN/Vector.h>
namespace LibImage
{
class Image
{
public:
struct Color
{
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
};
public:
static BAN::ErrorOr<BAN::UniqPtr<Image>> load_from_file(BAN::StringView path);
Color get_color(uint64_t x, uint64_t y) const { return m_bitmap[y * width() + x]; }
const BAN::Vector<Color> bitmap() const { return m_bitmap; }
uint64_t width() const { return m_width; }
uint64_t height() const { return m_height; }
private:
Image(uint64_t width, uint64_t height, BAN::Vector<Color>&& bitmap)
: m_width(width)
, m_height(height)
, m_bitmap(BAN::move(bitmap))
{
ASSERT(m_bitmap.size() >= width * height);
}
private:
const uint64_t m_width;
const uint64_t m_height;
const BAN::Vector<Color> m_bitmap;
friend class BAN::UniqPtr<Image>;
};
}

View File

@@ -0,0 +1,10 @@
#include <BAN/ByteSpan.h>
#include <LibImage/Image.h>
namespace LibImage
{
BAN::ErrorOr<BAN::UniqPtr<Image>> load_netbpm(BAN::ConstByteSpan);
}