29 unsigned char** textureDataPtrPtr)
32 "Invalid file name.");
33 ASSERT(textureDataPtrPtr != NULL,
34 "Cannot use NULL pointer to store image data.");
39 unsigned char* loadedTexture = NULL;
42 file = fopen(fileName,
"rb");
44 ASSERT(file != NULL,
"Failed to open file");
53 loadedTexture = (
unsigned char*) malloc(bitmapInfoHeader.
biSizeImage);
55 ASSERT(loadedTexture != NULL,
"Could not allocate memory to store texture image data.");
58 fseek(file, bitmapFileHeader.
bfOffBits, 0);
61 fread(loadedTexture, bitmapInfoHeader.
biSizeImage, 1, file);
63 unsigned char tempElement;
66 for (
unsigned int imageIdx = 0;
70 tempElement = loadedTexture[imageIdx];
71 loadedTexture[imageIdx] = loadedTexture[imageIdx + 2];
72 loadedTexture[imageIdx + 2] = tempElement;
79 *textureDataPtrPtr = loadedTexture;
82 if (imageHeightPtr != NULL)
84 *imageHeightPtr = bitmapInfoHeader.
biHeight;
87 if (imageWidthPtr != NULL)
89 *imageWidthPtr = bitmapInfoHeader.
biWidth;
97 bitmapFileHeaderPtr != NULL,
98 "Invalid arguments used to read bitmap file header.");
100 fread(&bitmapFileHeaderPtr->
bfType,
sizeof(bitmapFileHeaderPtr->
bfType), 1, filePtr);
101 fread(&bitmapFileHeaderPtr->
bfSize,
sizeof(bitmapFileHeaderPtr->
bfSize), 1, filePtr);
104 fread(&bitmapFileHeaderPtr->
bfOffBits,
sizeof(bitmapFileHeaderPtr->
bfOffBits), 1, filePtr);
108 "Invalid file type read");
115 bitmapInfoHeaderPtr != NULL,
116 "Invalid arguments used to read bitmap info header.");
118 fread(&bitmapInfoHeaderPtr->
biSize,
sizeof(bitmapInfoHeaderPtr->
biSize), 1, filePtr);
119 fread(&bitmapInfoHeaderPtr->
biWidth,
sizeof(bitmapInfoHeaderPtr->
biWidth), 1, filePtr);
120 fread(&bitmapInfoHeaderPtr->
biHeight,
sizeof(bitmapInfoHeaderPtr->
biHeight), 1, filePtr);
121 fread(&bitmapInfoHeaderPtr->
biPlanes,
sizeof(bitmapInfoHeaderPtr->
biPlanes), 1, filePtr);
127 fread(&bitmapInfoHeaderPtr->
biClrUsed,
sizeof(bitmapInfoHeaderPtr->
biClrUsed), 1, filePtr);
static void readBitmapFileHeader(FILE *filePtr, tagBITMAPFILEHEADER *bitmapFileHeaderPtr)
Read BMP file header.
static void readBitmapInforHeader(FILE *filePtr, tagBITMAPINFOHEADER *bitmapInfoHeaderPtr)
Read BMP info header.
static void loadBmpImageData(const char *fileName, int *imageWidthPtr, int *imageHeightPtr, unsigned char **textureDataPtrPtr)
Load BMP texture data from a file into memory.