decoder_BMP.h (2097B)
1 #ifndef DECODER_BMP_H 2 #define DECODER_BMP_H 3 4 #include "decoder.h" 5 #include <stdint.h> 6 #include <lua.h> 7 8 /* BMP File Header (14 bytes) */ 9 typedef struct { 10 uint16_t signature; // "BM" = 0x4D42 11 uint32_t file_size; // Size of BMP file in bytes 12 uint16_t reserved1; // Reserved, must be 0 13 uint16_t reserved2; // Reserved, must be 0 14 uint32_t data_offset; // Offset to bitmap data 15 } __attribute__((packed)) bmp_file_header_t; 16 17 /* BMP Info Header (40 bytes - BITMAPINFOHEADER) */ 18 typedef struct { 19 uint32_t header_size; // Size of this header (40 bytes) 20 int32_t width; // Width of bitmap in pixels 21 int32_t height; // Height of bitmap in pixels (negative = top-down) 22 uint16_t planes; // Number of color planes (must be 1) 23 uint16_t bpp; // Bits per pixel (1, 4, 8, 16, 24, 32) 24 uint32_t compression; // Compression type (0=none, 1=RLE8, 2=RLE4) 25 uint32_t image_size; // Size of image data (0 if uncompressed) 26 int32_t x_pixels_per_m; // Horizontal resolution 27 int32_t y_pixels_per_m; // Vertical resolution 28 uint32_t colors_used; // Number of colors in palette (0=all) 29 uint32_t colors_important;// Important colors (0=all) 30 } __attribute__((packed)) bmp_info_header_t; 31 32 /* BMP compression types */ 33 #define BMP_BI_RGB 0 // No compression 34 #define BMP_BI_RLE8 1 // 8-bit RLE 35 #define BMP_BI_RLE4 2 // 4-bit RLE 36 #define BMP_BI_BITFIELDS 3 // Bit field encoding 37 38 /* BMP color palette entry */ 39 typedef struct { 40 uint8_t blue; 41 uint8_t green; 42 uint8_t red; 43 uint8_t reserved; 44 } __attribute__((packed)) bmp_palette_entry_t; 45 46 /* BMP decoding functions */ 47 image_t* bmp_decode(const uint8_t* data, uint32_t data_size); 48 image_t* bmp_load_file(const char* filename); 49 50 /* BMP encoding functions */ 51 int bmp_encode(image_t* img, uint8_t** out_data, uint32_t* out_size); 52 int bmp_save_file(image_t* img, const char* filename); 53 54 /* Lua bindings */ 55 int lua_bmp_load(lua_State* L); 56 int lua_bmp_save(lua_State* L); 57 58 #endif /* DECODER_BMP_H */