2022-03-05 16:15:00 +01:00
|
|
|
#ifndef BMPPP_BMP_H
|
|
|
|
#define BMPPP_BMP_H
|
|
|
|
|
|
|
|
#include <Eule/Vector2.h>
|
|
|
|
#include <vector>
|
|
|
|
#include <cstdint>
|
|
|
|
#include "Colormodes.h"
|
|
|
|
|
|
|
|
namespace Leonetienne::BmpPP {
|
|
|
|
|
2022-03-05 20:40:49 +01:00
|
|
|
class BmpWriter;
|
2022-03-05 22:00:57 +01:00
|
|
|
class BmpReader;
|
2022-03-05 20:40:49 +01:00
|
|
|
|
2022-03-05 16:15:00 +01:00
|
|
|
class BMP {
|
|
|
|
public:
|
2022-03-06 01:18:16 +01:00
|
|
|
//! Will create an uninitialized image
|
2022-03-05 20:22:36 +01:00
|
|
|
BMP();
|
2022-03-05 22:00:57 +01:00
|
|
|
|
|
|
|
//! Will create an image with the entire pixel buffer set to 0
|
2022-03-05 16:15:00 +01:00
|
|
|
explicit BMP(const Eule::Vector2i& size, const Colormode& colormode = Colormode::RGBA);
|
|
|
|
|
2022-03-05 22:00:57 +01:00
|
|
|
//! Will create a image and read it from a bmp file
|
|
|
|
explicit BMP(const std::string& filename);
|
|
|
|
|
2022-03-05 19:30:41 +01:00
|
|
|
//! Will return a pointer to the first byte of a pixel at a given position
|
2022-03-06 01:18:16 +01:00
|
|
|
[[nodiscard]] std::uint8_t* GetPixel(const Eule::Vector2i& position);
|
2022-03-05 19:30:41 +01:00
|
|
|
|
|
|
|
//! Will return a pointer to the first byte of a pixel at a given position
|
2022-03-06 01:18:16 +01:00
|
|
|
[[nodiscard]] const std::uint8_t* GetPixel(const Eule::Vector2i& position) const;
|
2022-03-05 19:30:41 +01:00
|
|
|
|
|
|
|
//! Will set the color of a pixel at a given position
|
|
|
|
void SetPixel(const Eule::Vector2i& position, const std::uint8_t r, const std::uint8_t g, const std::uint8_t b, const std::uint8_t a = 0xFF);
|
|
|
|
|
2022-03-05 19:51:57 +01:00
|
|
|
//! Will basically reconstruct this image, to fit a new resolution
|
|
|
|
void ReInitialize(const Eule::Vector2i& size);
|
|
|
|
|
|
|
|
//! Will basically reconstruct this image, to fit a new resolution and new format
|
|
|
|
void ReInitialize(const Eule::Vector2i& size, const Colormode& colormode);
|
|
|
|
|
2022-03-05 19:37:02 +01:00
|
|
|
//! Will return a pointer to the raw pixel data
|
2022-03-06 01:18:16 +01:00
|
|
|
[[nodiscard]] std::uint8_t* data();
|
2022-03-05 19:37:02 +01:00
|
|
|
|
|
|
|
//! Will return a pointer to the raw pixel data
|
2022-03-06 01:18:16 +01:00
|
|
|
[[nodiscard]] const std::uint8_t* data() const;
|
2022-03-05 19:37:02 +01:00
|
|
|
|
|
|
|
//! Will return the dimensions of the image
|
2022-03-06 01:18:16 +01:00
|
|
|
[[nodiscard]] const Eule::Vector2i& GetDimensions() const;
|
2022-03-05 19:37:02 +01:00
|
|
|
|
|
|
|
//! Will return the color mode of the image
|
2022-03-06 01:18:16 +01:00
|
|
|
[[nodiscard]] const Colormode& GetColormode() const;
|
2022-03-05 16:15:00 +01:00
|
|
|
|
2022-03-05 19:37:02 +01:00
|
|
|
//! Will return the amount of color channels used
|
2022-03-06 01:18:16 +01:00
|
|
|
[[nodiscard]] std::size_t GetNumColorChannels() const;
|
2022-03-05 19:37:02 +01:00
|
|
|
|
|
|
|
//! Will return the size of the raw pixel buffer, in bytes
|
2022-03-06 01:18:16 +01:00
|
|
|
[[nodiscard]] std::size_t GetPixelbufferSize() const;
|
2022-03-05 19:37:02 +01:00
|
|
|
|
2022-03-05 20:22:36 +01:00
|
|
|
//! Will return whether this image is initialized or not
|
2022-03-06 01:18:16 +01:00
|
|
|
[[nodiscard]] bool IsInitialized() const;
|
2022-03-05 20:22:36 +01:00
|
|
|
|
|
|
|
//! Will write the bmp image to a file.
|
|
|
|
//! Returns false, if unable to open the file
|
|
|
|
bool Write(const std::string& filename) const;
|
|
|
|
|
2022-03-05 20:40:49 +01:00
|
|
|
//! Will read a bmp image from a file.
|
|
|
|
//! Returns false, if unable to open, or parse, file
|
|
|
|
bool Read(const std::string& filename);
|
|
|
|
|
2022-03-06 01:18:16 +01:00
|
|
|
//! Will mirror the image horizontally
|
|
|
|
void MirrorHorizontally();
|
|
|
|
|
|
|
|
//! Will mirror the image vertically
|
|
|
|
void MirrorVertically();
|
|
|
|
|
|
|
|
//! Will rotate the image by 90deg, clockwise
|
|
|
|
void Rotate90degClockwise();
|
|
|
|
|
|
|
|
//! Will rotate the image by 90deg, counterclockwise
|
|
|
|
void Rotate90degCounterclockwise();
|
|
|
|
|
|
|
|
//! Will rotate the image by 180deg
|
|
|
|
void Rotate180deg();
|
|
|
|
|
|
|
|
//! Will convert the images colormode
|
|
|
|
void ConvertColormode(const Colormode& colormode);
|
|
|
|
|
|
|
|
//! Will swap two channels. Useful for, for example, easy BGR to RGB conversion.
|
|
|
|
void SwapChannels(const std::size_t& channel1, const std::size_t& channel2);
|
|
|
|
|
2022-03-05 19:37:02 +01:00
|
|
|
private:
|
2022-03-05 16:15:00 +01:00
|
|
|
Eule::Vector2i size;
|
2022-03-05 19:30:41 +01:00
|
|
|
Colormode colormode;
|
2022-03-05 16:15:00 +01:00
|
|
|
std::vector<std::uint8_t> pixelBuffer;
|
2022-03-05 20:22:36 +01:00
|
|
|
bool isInitialized = false;
|
2022-03-05 20:40:49 +01:00
|
|
|
|
|
|
|
friend class BmpWriter;
|
2022-03-05 22:00:57 +01:00
|
|
|
friend class BmpReader;
|
2022-03-05 16:15:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //BMPPP_BMP_H
|