#include "imagefiles.h"
#include <stdlib.h>
#include <stdio.h>
/*
bmp loadBitmapImage(char* path)
{
    FILE* inFile;
    bmp image;

    inFile = fopen(path, "rb");
    if( !inFile )
    {
        fprintf(stderr, "Could not open bitmap image file [%s].\n", path);
        exit(4);
    }

    if( fread(image.header, 1, 54, inFile) != 54 )
    {
        fprintf(stderr, "Could not read bitmap image header for [%s].\n", path);
        exit(5);
    }

    // All bitmap images begin their header with "BM". 
    // This check just validates this
    if( image.header[0] != 'B' || image.header[1] != 'M' )
    {
        fprintf(stderr, "Bitmap image at [%s] has improper header.\n", path);
        exit(6);
    }

    // Cast the char pointer of the header to an int pointer and dereference it to get an int out
    image.dataPos = *(int*) &(image.header[0x0A]);   // Pointer casting to get the data start position information from the header
    image.imageSize = *(int*) &(image.header[0x22]); // Extract image size information from the header
    image.width = *(int*) &(image.header[0x12]);
    image.height = *(int*) &(image.header[0x16]);

    // Correct for any misformatted data start information
    if( image.dataPos == 0 )
    {
        image.dataPos = 54;
    }

    // Correct for missing image size (in bytes) information
    if( image.imageSize == 0 )
    {
        image.imageSize = 3*image.width*image.height;
    }

    // Allocate the image buffer
    image.data = (unsigned char*) malloc(sizeof(char) * imageSize);

    if( image.data == NULL )
    {
        fprintf(stderr, "Failed to allocate memory while attempting to open bitmap image at [%s].\n", path);
        exit(7);
    }
    
    fread(data, 1, imageSize, inFile);

    fclose(inFile);
}*/
