C-Playground/lib/bmp.h

52 lines
1.4 KiB
C

#ifndef BMP_H
#define BMP_H
#include <stdint.h>
typedef struct bitmap {
/* File Header */
/* The header field used to identify the BMP and DIB file is 0x42 0x4D in hexadecimal, same as BM in ASCII. The following entries are possible:
BM
Windows 3.1x, 95, NT, ... etc.
BA
OS/2 struct bitmap array
CI
OS/2 struct color icon
CP
OS/2 const color pointer
IC
OS/2 struct icon
PT
OS/2 pointer */
uint16_t padding_allignment; /* The compiler will pad structs automatically to ensure the struct is byte aligned. (i.e 54 bytes to 56). We declare padding allignment ourselves and we will make sure to account for this. */
uint8_t header_field[2];
uint32_t file_size_bytes;
uint16_t reserved1;
uint16_t reserved2;
uint32_t image_data_start_offset;
/* Bitmap Info Header */
uint32_t info_header_size_bytes;
int32_t image_width;
int32_t image_height;
uint16_t color_planes_used;
uint16_t bits_per_pixel;
uint32_t compression_method;
uint32_t image_size;
int32_t horizontal_resolution_pixels_per_metre;
int32_t vertical_resolution_pixels_per_metre;
uint32_t colors_in_palette;
uint32_t important_colors;
} bitmap;
bitmap init_bitmap(int32_t image_width_in, int32_t image_height_in);
uint32_t calc_bitmap_file_size_bytes(bitmap *bitmap_in);
uint32_t calc_bitmap_pixel_array_size_bytes(bitmap *bitmap_in);
uint32_t calc_bitmap_header_size_bytes();
int write_to_bitmap(bitmap *bitmap_in, char *filename);
#endif