2021-01-26 13:25:34 +00:00
|
|
|
#ifndef DITHERING_IMAGE_HPP
|
|
|
|
#define DITHERING_IMAGE_HPP
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace image {
|
|
|
|
enum class color_type {
|
|
|
|
Black,
|
|
|
|
Red,
|
|
|
|
Green,
|
|
|
|
Blue,
|
|
|
|
Alpha,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class file_type {
|
|
|
|
PBM,
|
|
|
|
PGM,
|
|
|
|
PPM,
|
|
|
|
// TODO PNG support
|
|
|
|
};
|
|
|
|
|
2021-02-11 02:33:14 +00:00
|
|
|
class Base {
|
2021-01-26 13:25:34 +00:00
|
|
|
public:
|
2021-02-11 02:33:14 +00:00
|
|
|
Base() = default;
|
|
|
|
virtual ~Base() {}
|
2021-01-26 13:25:34 +00:00
|
|
|
|
2021-02-11 02:33:14 +00:00
|
|
|
Base(const Base &other) = default;
|
|
|
|
Base(Base &&other) = default;
|
2021-01-26 13:25:34 +00:00
|
|
|
|
2021-02-11 02:33:14 +00:00
|
|
|
Base& operator=(const Base &other) = default;
|
|
|
|
Base& operator=(Base &&other) = default;
|
2021-01-26 13:25:34 +00:00
|
|
|
|
|
|
|
virtual void randomize() = 0;
|
|
|
|
|
|
|
|
virtual int getSize() = 0;
|
|
|
|
virtual uint8_t* getData() = 0;
|
2021-02-11 02:33:14 +00:00
|
|
|
virtual const uint8_t* getDataC() const = 0;
|
2021-01-26 13:25:34 +00:00
|
|
|
|
|
|
|
virtual int getTypesCount() = 0;
|
|
|
|
virtual std::vector<color_type> getTypes() = 0;
|
|
|
|
virtual int getTypeStride(color_type type) = 0;
|
|
|
|
|
|
|
|
virtual bool canWriteFile(file_type type) = 0;
|
|
|
|
virtual bool writeToFile(file_type type, bool canOverwrite, const char *filename) = 0;
|
|
|
|
virtual bool writeToFile(file_type type, bool canOverwrite, const std::string &filename) = 0;
|
|
|
|
};
|
|
|
|
|
2021-02-11 02:33:14 +00:00
|
|
|
class Bl : public Base {
|
2021-01-26 13:25:34 +00:00
|
|
|
public:
|
2021-02-11 02:33:14 +00:00
|
|
|
Bl();
|
2021-01-26 13:25:34 +00:00
|
|
|
Bl(int width, int height);
|
|
|
|
Bl(const std::vector<uint8_t> &data, int width);
|
|
|
|
Bl(std::vector<uint8_t> &&data, int width);
|
2021-10-06 08:59:27 +00:00
|
|
|
Bl(const std::vector<float> &data, int width);
|
2021-01-26 13:25:34 +00:00
|
|
|
virtual ~Bl() {}
|
|
|
|
|
|
|
|
Bl(const Bl &other) = default;
|
|
|
|
Bl(Bl &&other) = default;
|
|
|
|
|
|
|
|
Bl& operator=(const Bl &other) = default;
|
|
|
|
Bl& operator=(Bl &&other) = default;
|
|
|
|
|
|
|
|
virtual void randomize() override;
|
|
|
|
|
|
|
|
virtual int getSize() override;
|
|
|
|
virtual uint8_t* getData() override;
|
2021-02-11 02:33:14 +00:00
|
|
|
virtual const uint8_t* getDataC() const override;
|
2021-01-26 13:25:34 +00:00
|
|
|
|
|
|
|
virtual int getTypesCount() override { return 1; }
|
|
|
|
virtual std::vector<color_type> getTypes() override { return { color_type::Black }; }
|
|
|
|
virtual int getTypeStride(color_type) override { return 0; }
|
|
|
|
|
|
|
|
virtual bool canWriteFile(file_type type) override;
|
|
|
|
virtual bool writeToFile(file_type type, bool canOverwrite, const char *filename) override;
|
|
|
|
virtual bool writeToFile(file_type type, bool canOverwrite, const std::string &filename) override;
|
2021-02-11 02:33:14 +00:00
|
|
|
virtual bool isValid() const;
|
2021-01-26 13:25:34 +00:00
|
|
|
private:
|
|
|
|
std::vector<uint8_t> data;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|