You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.6 KiB
C
54 lines
1.6 KiB
C
3 months ago
|
#pragma once
|
||
|
#include <vector>
|
||
|
#include <string>
|
||
|
#include <cstdint>
|
||
|
#include <fstream>
|
||
|
#include <stdexcept>
|
||
|
|
||
|
#pragma pack(push, 1)
|
||
|
struct BmpHeader {
|
||
|
uint16_t signature; // 'BM'
|
||
|
uint32_t fileSize; // Size of the BMP file
|
||
|
uint16_t reserved1; // Reserved
|
||
|
uint16_t reserved2; // Reserved
|
||
|
uint32_t dataOffset; // Offset to the start of image data
|
||
|
};
|
||
|
|
||
|
struct BmpInfoHeader {
|
||
|
uint32_t headerSize; // Size of the info header
|
||
|
int32_t width; // Width of the image
|
||
|
int32_t height; // Height of the image
|
||
|
uint16_t planes; // Number of color planes
|
||
|
uint16_t bitsPerPixel; // Bits per pixel
|
||
|
uint32_t compression; // Compression type
|
||
|
uint32_t imageSize; // Image size in bytes
|
||
|
int32_t xPixelsPerMeter; // X resolution
|
||
|
int32_t yPixelsPerMeter; // Y resolution
|
||
|
uint32_t colorsUsed; // Number of colors used
|
||
|
uint32_t colorsImportant;// Number of important colors
|
||
|
};
|
||
|
#pragma pack(pop)
|
||
|
|
||
|
struct BmpInfo {
|
||
|
int32_t width;
|
||
|
int32_t height;
|
||
|
int32_t bitsPerPixel;
|
||
|
uint32_t dataOffset;
|
||
|
int32_t rowPadding;
|
||
|
int32_t rowSize;
|
||
|
};
|
||
|
|
||
|
class BmpLoader {
|
||
|
public:
|
||
|
static BmpInfo readBmpInfo(const std::string& filePath);
|
||
|
static std::vector<uint8_t> readBmpRegion(
|
||
|
const std::string& filePath,
|
||
|
const BmpInfo& info,
|
||
|
int32_t startX, int32_t startY,
|
||
|
int32_t width, int32_t height);
|
||
|
static std::vector<float> readBmpRegionAsFloat(
|
||
|
const std::string& filePath,
|
||
|
const BmpInfo& info,
|
||
|
int32_t startX, int32_t startY,
|
||
|
int32_t width, int32_t height);
|
||
|
};
|