74 lines
1.9 KiB
C++
74 lines
1.9 KiB
C++
|
|
#pragma once
|
|
|
|
#if !defined(IWA_RESOURCE_BITMAP_HPP_INCLUDED)
|
|
#define IWA_RESOURCE_BITMAP_HPP_INCLUDED
|
|
|
|
#include <memory>
|
|
#include <span>
|
|
#include <vector>
|
|
#include <glm/vec4.hpp>
|
|
#include <mijin/container/optional.hpp>
|
|
#include <mijin/container/typeless_buffer.hpp>
|
|
#include "../object.hpp"
|
|
#include "../vkwrapper.hpp"
|
|
|
|
namespace iwa
|
|
{
|
|
enum class ColorChannel
|
|
{
|
|
R = 0,
|
|
G = 1,
|
|
B = 2,
|
|
A = 3
|
|
};
|
|
|
|
struct ChannelMapping
|
|
{
|
|
ColorChannel from;
|
|
ColorChannel to;
|
|
};
|
|
|
|
struct BitmapCreationArgs
|
|
{
|
|
vk::Format format;
|
|
vk::Extent2D size;
|
|
mijin::Optional<mijin::TypelessBuffer> initialData;
|
|
};
|
|
|
|
class Bitmap : public Object<Bitmap>
|
|
{
|
|
private:
|
|
mijin::TypelessBuffer mData;
|
|
vk::Format mFormat;
|
|
vk::Extent2D mSize;
|
|
std::unique_ptr<class BitmapViewBase> mView;
|
|
public:
|
|
explicit Bitmap(BitmapCreationArgs args, ObjectPtr<BaseObject> owner = nullptr);
|
|
~Bitmap() override;
|
|
|
|
// properties
|
|
inline vk::Format getFormat() const { return mFormat; }
|
|
inline vk::Extent2D getSize() const { return mSize; }
|
|
inline std::span<std::uint8_t> getData() { return mData.makeSpan<std::uint8_t>(); }
|
|
inline std::span<const std::uint8_t> getData() const { return mData.makeSpan<const std::uint8_t>(); }
|
|
|
|
// access
|
|
// TODO: maybe add accessors for whole rows or the whole image?
|
|
[[nodiscard]] glm::vec4 getPixel(unsigned x, unsigned y) const;
|
|
[[nodiscard]] std::vector<glm::vec4> getPixels(unsigned x, unsigned y, unsigned width, unsigned height) const;
|
|
[[nodiscard]] inline std::vector<glm::vec4> getAllPixels() const {
|
|
return getPixels(0, 0, mSize.width, mSize.height);
|
|
}
|
|
|
|
// drawing
|
|
void fill(const glm::vec4& color);
|
|
void copyChannels(const Bitmap& other, const std::vector<ChannelMapping>& mappings);
|
|
void multiply(const glm::vec4& color);
|
|
private:
|
|
void createView();
|
|
};
|
|
} // namespace iwa
|
|
|
|
#endif // !defined(IWA_RESOURCE_BITMAP_HPP_INCLUDED)
|