cpp-bmp-reader/image-lib/bmpimage.h

88 lines
No EOL
2.1 KiB
C++

#pragma once
#include <cstdint>
#include <string>
#include <fstream>
#include <array>
#include <functional>
#include <font-lib/psf.h>
#include "pixelarray.h"
const char PADDING_ZEROES[3] = {0, 0, 0};
#pragma pack(push, 1)
struct BitmapFileHeader {
char signature[2] = {'B', 'M'};
uint32_t fileSize = 0;
uint16_t reserved1 = 0;
uint16_t reserved2 = 0;
uint32_t imageDataOffset = 54;
};
#pragma pack(pop)
#pragma pack(push, 1)
struct BITMAPINFOHEADER {
uint32_t HeaderSize = 40;
uint32_t BitmapWidth = 0;
uint32_t BitmapHeight = 0;
uint16_t ColorPlanes = 1;
uint16_t BitsPerPixel = 24;
uint32_t CompressionMethod = 0;
uint32_t ImageSize = 0;
int32_t HorizontalPixelPerMetre = 0;
int32_t VerticalPixelPerMetre = 0;
uint32_t NumberOfColors = 0;
uint32_t NumberOfImportantColors = 0;
};
#pragma pack(pop)
class BMPImage {
BitmapFileHeader fileHeader;
BITMAPINFOHEADER infoHeader;
PixelArray pixelArray;
public:
BMPImage(const BitmapFileHeader &fileHeader, const BITMAPINFOHEADER &infoHeader, const PixelArray &pixelArray);
BMPImage(const PixelArray &pixelArray);
~BMPImage();
[[nodiscard]] const uint32_t &width() const;
[[nodiscard]] const uint32_t &height() const;
[[nodiscard]] PixelArray pixels();
[[nodiscard]] PixelArray pixels_copy();
[[nodiscard]] BitmapFileHeader fileHeader_copy();
[[nodiscard]] BITMAPINFOHEADER infoHeader_copy();
void save(const std::string &);
BMPImage appendRight(BMPImage &);
BMPImage overlay(BMPImage &, uint32_t, uint32_t);
BMPImage applyFilter(const std::function<uint8_t (std::array<int,9>&)>& filter);
};
BMPImage readBMPImage(const std::string &filename);
BMPImage grayscale(BMPImage &);
BMPImage invertColors(BMPImage &);
BMPImage upscale2x(BMPImage &);
BMPImage downscale2x(BMPImage &);
BMPImage upscale1_5x(BMPImage &);
BMPImage upscale1_5x_ver2(BMPImage &); // TODO: BAD
BMPImage upscale2x_ver2(BMPImage &); // TODO: BAD
BMPImage textImg(const std::u16string &, Font *font, uint8_t scale = 1, Pixel background_color = Pixel{0, 0, 0},
Pixel font_color = Pixel{255, 255, 255});