#ifndef BITMAP_HPP_
#define BITMAP_HPP_

#include <vector>
#include <cstdint>
#include <string>
#include <optional>
#include <Utilities/Extern.hpp>
#include <Utilities/RGBABytes.hpp>

class Bitmap
{
private:
    std::vector<uint8_t> rgbaPixels;
    glm::uvec2 size;

public:
    Bitmap() = delete;

    Bitmap(glm::uvec2 size, const uint8_t *rgba = nullptr);

    static std::optional<Bitmap> fromFile(std::string path);
    static Bitmap fromFileOrDefault(std::string path);
    static glm::vec4 decodeXYZW8(uint32_t rgba8);
    static uint32_t encodeXYZW8(glm::vec4 v);
    static glm::vec3 sRGBToLinear(glm::vec3 srgb);
    static glm::vec3 linearToSRGB(glm::vec3 linearRgb);
    static glm::vec3 rgb2hsv(glm::vec3 rgb);
    static glm::vec3 hsv2rgb(glm::vec3 hsv);

    glm::uvec2 getSize();
    uint32_t getRGBA8(glm::uvec2 pos);
    RGBABytes getColor(glm::uvec2 pos);
    void setColor(glm::uvec2 pos, RGBABytes color);
    void setColor(glm::uvec2 pos, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
    glm::vec4 getLinearColor(glm::uvec2 pos);
    void setSRGBColor(glm::uvec2 pos, glm::vec4 srgba);
    void setLinearColor(glm::uvec2 pos, glm::vec4 rgba);
    void writeToPNG(std::string path);
    void applyNoiseHSV(Bitmap &biasMap);
    uint8_t* data();
};

#endif