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:
47
LibImage/include/LibImage/Image.h
Normal file
47
LibImage/include/LibImage/Image.h
Normal 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>;
|
||||
};
|
||||
|
||||
}
|
||||
10
LibImage/include/LibImage/Netbpm.h
Normal file
10
LibImage/include/LibImage/Netbpm.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <BAN/ByteSpan.h>
|
||||
|
||||
#include <LibImage/Image.h>
|
||||
|
||||
namespace LibImage
|
||||
{
|
||||
|
||||
BAN::ErrorOr<BAN::UniqPtr<Image>> load_netbpm(BAN::ConstByteSpan);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user