RDFU  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
LoadBMP.c File Reference

Functions for 24-bit bitmap loading. More...

#include "EfiScannerHeaders.h"
#include "Screen.h"
Include dependency graph for LoadBMP.c:

Go to the source code of this file.

Classes

struct  tagBITMAPFILEHEADER
 
struct  tagBITMAPINFOHEADER
 
struct  _BITMAPMAINHEADER
 

Macros

#define PIXEL_INDEX   BMPHdr->biWidth * (BMPHdr->biHeight - 1 - y)
 

Typedefs

typedef struct tagBITMAPFILEHEADER BITMAPFILEHEADER
 
typedef struct
tagBITMAPFILEHEADER * 
PBITMAPFILEHEADER
 
typedef struct tagBITMAPINFOHEADER BITMAPINFOHEADER
 
typedef struct
tagBITMAPINFOHEADER * 
PBITMAPINFOHEADER
 
typedef struct _BITMAPMAINHEADER BITMAPMAINHEADER
 
typedef struct _BITMAPMAINHEADER * PBITMAPMAINHEADER
 

Functions

GIMAGE * ImageAllocateStruct (UINTN Width, UINTN Height)
 
VOID ImageFree (GIMAGE *Image)
 
VOID ImageApplyAlphaChannel (GIMAGE *Image, UINTN Alpha)
 
GIMAGE * ImageLoadBMPFromMem (UINT8 *BMPInMem, UINTN BMPSize)
 

Detailed Description

Functions for 24-bit bitmap loading.

Author
Piotr Bania
Date
Feb 2013 Functions for 24-bit bitmap loading

Definition in file LoadBMP.c.

Macro Definition Documentation

#define PIXEL_INDEX   BMPHdr->biWidth * (BMPHdr->biHeight - 1 - y)

Referenced by ImageLoadBMPFromMem().

Typedef Documentation

Function Documentation

GIMAGE* ImageAllocateStruct ( UINTN  Width,
UINTN  Height 
)

Function allocates memory and initializes the GIMAGE structure.

Parameters
WidthWidth of BMP
HeightHeight of BMP
Return values
PointerOn success function returns pointer to created GIMAGE structure
NULLOn error

Definition at line 69 of file LoadBMP.c.

References _GIMAGE::Data, _GIMAGE::Height, MemAllocate(), MemFree(), and _GIMAGE::Width.

Referenced by ImageLoadBMPFromMem().

70 {
71  GIMAGE *ImageMem;
72 
73  ImageMem = (GIMAGE*)MemAllocate(sizeof(GIMAGE));
74  if (!ImageMem)
75  return 0;
76 
77  // now allocate the image data
78  ImageMem->Data = (RGBPIXEL*)MemAllocate(Width * Height * sizeof(RGBPIXEL));
79  if (!ImageMem->Data)
80  {
81  MemFree(ImageMem);
82  return 0;
83  }
84 
85  ImageMem->Width = Width;
86  ImageMem->Height = Height;
87 
88  return ImageMem;
89 }

Here is the call graph for this function:

Here is the caller graph for this function:

VOID ImageApplyAlphaChannel ( GIMAGE *  Image,
UINTN  Alpha 
)

Function applies the Alpha value to each pixel. (this function is never used)

Parameters
ImagePointer to the GIMAGE structure allocated by ImageAllocateStruct
AlphaAlpha value
Return values
NONE

Definition at line 121 of file LoadBMP.c.

References _RGBPIXEL::alpha, _GIMAGE::Data, _GIMAGE::Height, and _GIMAGE::Width.

122 {
123  UINTN i;
124 
125  for (i = 0; i < (Image->Height * Image->Width); i++)
126  Image->Data[i].alpha = (UINT8)Alpha;
127 }
VOID ImageFree ( GIMAGE *  Image)

Function frees the allocated Image.

Parameters
ImagePointer to the GIMAGE structure allocated by ImageAllocateStruct
Return values
NONE

Definition at line 102 of file LoadBMP.c.

References _GIMAGE::Data, and MemFree().

103 {
104  MemFree(Image->Data);
105  MemFree(Image);
106 }

Here is the call graph for this function:

GIMAGE* ImageLoadBMPFromMem ( UINT8 *  BMPInMem,
UINTN  BMPSize 
)

Function loads 24bit BMP from memory.

Parameters
BMPInMemPointer to BMP data in memory
BMPSizeSize of the BMP data
Return values
GIMAGE*On success pointer to created GIMAGE structure
NULLOn error

Definition at line 146 of file LoadBMP.c.

References _RGBPIXEL::alpha, _RGBPIXEL::b, _BITMAPMAINHEADER::bFile, tagBITMAPFILEHEADER::bfOffBits, tagBITMAPFILEHEADER::bfType, tagBITMAPINFOHEADER::biBitCount, tagBITMAPINFOHEADER::biCompression, tagBITMAPINFOHEADER::biHeight, _BITMAPMAINHEADER::bInfo, tagBITMAPINFOHEADER::biWidth, _GIMAGE::Data, _RGBPIXEL::g, ImageAllocateStruct(), PIXEL_INDEX, and _RGBPIXEL::r.

Referenced by ScreenShowSplashLogo().

147 {
148 
149  GIMAGE *Image;
150  UINTN LineOffset;
151  PBITMAPMAINHEADER BMPMainHdr;
152  PBITMAPFILEHEADER BMPFileHdr;
153  PBITMAPINFOHEADER BMPHdr;
154  RGBPIXEL *Pixel;
155 
156  UINT8 *ImageDataPtr, *ImageDataBasePtr;
157 
158  LONG x, y;
159 
160  if (!BMPInMem || !BMPSize)
161  return 0;
162 
163 
164  // validate the BMP itself
165  BMPMainHdr = (PBITMAPMAINHEADER)BMPInMem;
166  BMPFileHdr = (PBITMAPFILEHEADER)&BMPMainHdr->bFile;
167 
168  if (BMPFileHdr->bfType != 'MB')
169  return 0;
170 
171  BMPHdr = (PBITMAPINFOHEADER)&BMPMainHdr->bInfo;
172  if (BMPHdr->biCompression != 0)
173  return 0;
174 
175  // we only support 24bits per pixel
176  if (BMPHdr->biBitCount != 24)
177  return 0;
178 
179  LineOffset = BMPHdr->biWidth * 3;
180 
181  if ((BMPFileHdr->bfOffBits + (LineOffset * BMPHdr->biHeight)) > BMPSize)
182  return 0;
183 
184 
185  Image = ImageAllocateStruct(BMPHdr->biWidth, BMPHdr->biHeight);
186  if (!Image)
187  return 0;
188 
189 
190  ImageDataBasePtr = (UINT8*)(BMPInMem + BMPFileHdr->bfOffBits);
191 
192  for (y = 0; y < BMPHdr->biHeight; y++)
193  {
194  ImageDataPtr = ImageDataBasePtr;
195  ImageDataBasePtr += LineOffset;
196 #define PIXEL_INDEX BMPHdr->biWidth * (BMPHdr->biHeight - 1 - y)
197  Pixel = &Image->Data[PIXEL_INDEX];
198 
199  for (x = 0; x < BMPHdr->biWidth; x++)
200  {
201  // copy the pixel data
202  Pixel->b = ImageDataPtr[0];
203  Pixel->g = ImageDataPtr[1];
204  Pixel->r = ImageDataPtr[2];
205  Pixel->alpha = 0; //255; // no alpha
206  ImageDataPtr += 3;
207  Pixel++;
208  }
209  }
210 
211  return Image;
212 }

Here is the call graph for this function:

Here is the caller graph for this function: