#pragma once #include #include #include #include #include #include #define BMP_BYTE_CODE 0x4D42 #pragma pack(push, 1) struct BMPFILEHEADER { uint16_t bfType; uint32_t bfSize; uint32_t bfReserved; uint32_t bfOffBits; }; struct BMPINFOHEADER { uint32_t biSize; uint32_t biWidth; uint32_t biHeight; uint16_t biPlanes; uint16_t biBitCount; uint32_t biCompression; uint32_t biSizeImage; int32_t biXPelsPerMeter; int32_t biYPelsPerMeter; uint32_t biClrUsed; uint32_t biClrImportant; }; #pragma pack(pop) /** * @class BMP * @brief BMP file data and helper functions * * @author Michael John * @version 01.00 * @date 25/08/2021 * * @todo * * @bug */ class BMP { public: BMP() = default; ~BMP(); /** @brief Copy Constructor * * @param other BMP to copy from to this */ BMP(const BMP& other); /** @brief Assignment operator * * @param other BMP to copy from to this */ BMP& operator=(const BMP&); /** @brief Reads in a BMP image of the string fileName * * @param fileName fileName of BMP including extension * @return true if successfully read in */ bool readInBMP(const std::string& fileName); /** @brief gets the BMP file format Header struct of a read in BMP file * * @return the BMP file header struct */ BMPFILEHEADER* getFileHeader() const; /** @brief gets the BMP file information Header struct of a read in BMP file * * @return the BMP information header struct */ BMPINFOHEADER* getInfoHeader() const; /** @brief Returns a pointer to the BMP's image pixels * * @return pointer to the image pixels */ unsigned char* getPixels(); /** @brief Rotates a BMP image to orientation defined by degrees parameter * * @param degrees - rotation angle */ void rotateBMP(double degrees); protected: private: BMPFILEHEADER* m_fileHeader{nullptr}; /// BMP format file header pointer BMPINFOHEADER* m_infoHeader{ nullptr}; /// BMP format info header pointer - image variables unsigned char* m_pixels{nullptr}; /// pointer to BMP image pixels std::size_t m_pixelsSize{0}; /// size of m_pixels void Clear(); /// deletes and clears pointer data /** @brief Copy helper method * Copies heap memory from other BMP to this * @return true on successful copy */ bool copy(const BMP& other); };