Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
1.9 kB
3
Indexable
#include <iostream>
#include <fstream>

#pragma once


struct BMPFileHeader {
    uint16_t file_type{0x4D42};          // File type always BM which is 0x4D42
    uint32_t file_size{0};               // Size of the file (in bytes)
    uint16_t reserved1{0};               // Reserved, always 0
    uint16_t reserved2{0};               // Reserved, always 0
    uint32_t offset_data{0};             // Start position of pixel data (bytes from the beginning of the file)
};


struct BMPInfoHeader {
    uint32_t header_size{0};                      // Size of this header (in bytes)
    int32_t width{0};                      // width of bitmap in pixels
    int32_t height{0};                     // width of bitmap in pixels
    //       (if positive, bottom-up, with origin in lower left corner)
    //       (if negative, top-down, with origin in upper left corner)
    uint16_t planes{1};                    // No. of planes for the target device, this is always 1
    uint16_t bits_per_pixel{4};                 // No. of bits per pixel
    uint32_t compression{0};
    uint32_t size_image{0};                // 0 - for uncompressed images
    int32_t x_pixels_per_meter{0};
    int32_t y_pixels_per_meter{0};
    uint32_t colors_used{5};
    // No. color indexes in the color table. Use 0 for the max number of colors allowed by bit_count
    uint32_t colors_important{0};
    // No. of colors used for displaying the bitmap. If 0 all colors are required
};


struct BMPColorTable {
    uint8_t white[3] = {255, 255, 255};
    uint8_t green[3] = {0, 128, 0};
    uint8_t yellow[3] = {0, 255, 255};
    uint8_t purple[3] = {128, 0, 128};
    uint8_t black[3] = {0, 0, 0};
};


struct BMP {
    BMPFileHeader file_header;
    BMPInfoHeader bmp_info_header;
    BMPColorTable bmp_color_table;
    std::vector <uint8_t> data;
};