#ifndef BMP_H
#define BMP_H

#include <stdint.h>

/* Change struct name to bitmap header */
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_alignment; /* 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;

typedef struct bitmap_file {
	char *filename;
	bitmap *bitmap_metadata;
} bitmap_file;

typedef struct bitmap_pixel_color {
	uint8_t blue;
	uint8_t green;
	uint8_t red;
} bitmap_pixel_color;

/* Change struct name to bitmap header */
bitmap init_bitmap(const int32_t image_width_in, const int32_t image_height_in);
/* Change the name to init_bitmap_file */
bitmap_file write_to_bitmap(const bitmap *bitmap_in, const char *filename);

uint32_t calc_bitmap_row_byte_position_start(const bitmap *bitmap_in, const uint32_t row_in);
uint32_t calc_bitmap_file_size_bytes(const bitmap *bitmap_in);
uint32_t calc_bitmap_pixel_array_size_bytes(const bitmap *bitmap_in);
uint32_t calc_bitmap_header_size_bytes();

int write_bitmap_pixel(const int8_t fd, const bitmap_file *bitmap_file_in, const bitmap_pixel_color *bitmap_pixel_in, const int32_t x_in, const int32_t y_in); 

#endif
