// BMP.h // extracts/inserts data from/into .bmp file // Adapted by Josh Holtrop from the original access_bmp.c by gw // Supports reading and creating 24-bit color BMP images #include #define BMP_RED 2 #define BMP_GREEN 1 #define BMP_BLUE 0 class BMP { public: typedef struct { char id[2]; int file_size; int reserved; int offset; } __attribute__ ((packed)) header_t; typedef struct { int header_size; int width; int height; unsigned short int color_planes; unsigned short int color_depth; unsigned int compression; int image_size; int xresolution; int yresolution; int num_colors; int num_important_colors; } __attribute__ ((packed)) info_t; BMP(const char * fileName); BMP(const char * fileName, int width, int height, unsigned char * data); ~BMP(); void read(unsigned char * buf); int getWidth() { return m_info.width; } int getHeight() { return m_info.height; } protected: FILE * m_fp; header_t m_header; info_t m_info; bool open(const char * fileName); bool create(const char * fileName, int width, int height, unsigned char * data); void close(); };