100 UINT32 DataSizePerLine;
103 RETURN_STATUS Status;
107 if ((BmpImage ==
NULL) || (GopBlt ==
NULL) || (GopBltSize ==
NULL)) {
111 if ((PixelHeight ==
NULL) || (PixelWidth ==
NULL)) {
116 DEBUG ((DEBUG_ERROR,
"TranslateBmpToGopBlt: BmpImageSize too small\n"));
122 if ((BmpHeader->CharB !=
'B') || (BmpHeader->CharM !=
'M')) {
123 DEBUG ((DEBUG_ERROR,
"TranslateBmpToGopBlt: BmpHeader->Char fields incorrect\n"));
130 if (BmpHeader->CompressionType != 0) {
131 DEBUG ((DEBUG_ERROR,
"TranslateBmpToGopBlt: Compression Type unsupported.\n"));
135 if ((BmpHeader->PixelHeight == 0) || (BmpHeader->PixelWidth == 0)) {
136 DEBUG ((DEBUG_ERROR,
"TranslateBmpToGopBlt: BmpHeader->PixelHeight or BmpHeader->PixelWidth is 0.\n"));
147 "TranslateBmpToGopBlt: BmpHeader->Headership is not as expected. Headersize is 0x%x\n",
148 BmpHeader->HeaderSize
157 BmpHeader->PixelWidth,
161 if (EFI_ERROR (Status)) {
164 "TranslateBmpToGopBlt: invalid BmpImage... PixelWidth:0x%x BitPerPixel:0x%x\n",
165 BmpHeader->PixelWidth,
171 Status =
SafeUint32Add (DataSizePerLine, 31, &DataSizePerLine);
172 if (EFI_ERROR (Status)) {
175 "TranslateBmpToGopBlt: invalid BmpImage... DataSizePerLine:0x%x\n",
182 DataSizePerLine = (DataSizePerLine >> 3) &(~0x3);
185 BmpHeader->PixelHeight,
189 if (EFI_ERROR (Status)) {
192 "TranslateBmpToGopBlt: invalid BmpImage... DataSizePerLine:0x%x PixelHeight:0x%x\n",
194 BmpHeader->PixelHeight
201 BmpHeader->PixelHeight,
206 if (EFI_ERROR (Status)) {
209 "TranslateBmpToGopBlt: invalid BmpImage... PixelHeight:0x%x DataSizePerLine:0x%x\n",
210 BmpHeader->PixelHeight,
217 if ((BmpHeader->Size != BmpImageSize) ||
218 (BmpHeader->Size < BmpHeader->ImageOffset) ||
219 (BmpHeader->Size - BmpHeader->ImageOffset != DataSize))
221 DEBUG ((DEBUG_ERROR,
"TranslateBmpToGopBlt: invalid BmpImage... \n"));
222 DEBUG ((DEBUG_ERROR,
" BmpHeader->Size: 0x%x\n", BmpHeader->Size));
223 DEBUG ((DEBUG_ERROR,
" BmpHeader->ImageOffset: 0x%x\n", BmpHeader->ImageOffset));
224 DEBUG ((DEBUG_ERROR,
" BmpImageSize: 0x%lx\n", (
UINTN)BmpImageSize));
225 DEBUG ((DEBUG_ERROR,
" DataSize: 0x%lx\n", (
UINTN)DataSize));
267 Image = ((UINT8 *)BmpImage) + BmpHeader->ImageOffset;
274 BmpHeader->PixelWidth,
275 BmpHeader->PixelHeight,
279 if (EFI_ERROR (Status)) {
282 "TranslateBmpToGopBlt: invalid BltBuffer needed size... PixelWidth:0x%x PixelHeight:0x%x\n",
283 BmpHeader->PixelWidth,
284 BmpHeader->PixelHeight
290 Temp = BltBufferSize;
297 if (EFI_ERROR (Status)) {
300 "TranslateBmpToGopBlt: invalid BltBuffer needed size... PixelWidth x PixelHeight:0x%x struct size:0x%x\n",
309 if (*GopBlt ==
NULL) {
313 DEBUG ((DEBUG_INFO,
"Bmp Support: Allocating 0x%X bytes of memory\n", BltBufferSize));
314 *GopBltSize = (
UINTN)BltBufferSize;
317 if (*GopBlt ==
NULL) {
324 if (*GopBltSize < (
UINTN)BltBufferSize) {
325 *GopBltSize = (
UINTN)BltBufferSize;
330 *PixelWidth = BmpHeader->PixelWidth;
331 *PixelHeight = BmpHeader->PixelHeight;
332 DEBUG ((DEBUG_INFO,
"BmpHeader->ImageOffset 0x%X\n", BmpHeader->ImageOffset));
333 DEBUG ((DEBUG_INFO,
"BmpHeader->PixelWidth 0x%X\n", BmpHeader->PixelWidth));
334 DEBUG ((DEBUG_INFO,
"BmpHeader->PixelHeight 0x%X\n", BmpHeader->PixelHeight));
335 DEBUG ((DEBUG_INFO,
"BmpHeader->BitPerPixel 0x%X\n", BmpHeader->
BitPerPixel));
336 DEBUG ((DEBUG_INFO,
"BmpHeader->ImageSize 0x%X\n", BmpHeader->
ImageSize));
337 DEBUG ((DEBUG_INFO,
"BmpHeader->HeaderSize 0x%X\n", BmpHeader->HeaderSize));
338 DEBUG ((DEBUG_INFO,
"BmpHeader->Size 0x%X\n", BmpHeader->Size));
344 for (Height = 0; Height < BmpHeader->PixelHeight; Height++) {
345 Blt = &BltBuffer[(BmpHeader->PixelHeight - Height - 1) * BmpHeader->PixelWidth];
346 for (Width = 0; Width < BmpHeader->PixelWidth; Width++, Image++, Blt++) {
352 for (Index = 0; Index < 8 && Width < BmpHeader->PixelWidth; Index++) {
353 Blt->Red = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Red;
354 Blt->Green = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Green;
355 Blt->Blue = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Blue;
368 Index = (*Image) >> 4;
369 Blt->Red = BmpColorMap[Index].Red;
370 Blt->Green = BmpColorMap[Index].Green;
371 Blt->Blue = BmpColorMap[Index].Blue;
372 if (Width < (BmpHeader->PixelWidth - 1)) {
375 Index = (*Image) & 0x0f;
376 Blt->Red = BmpColorMap[Index].Red;
377 Blt->Green = BmpColorMap[Index].Green;
378 Blt->Blue = BmpColorMap[Index].Blue;
387 Blt->Red = BmpColorMap[*Image].Red;
388 Blt->Green = BmpColorMap[*Image].Green;
389 Blt->Blue = BmpColorMap[*Image].Blue;
396 Blt->Blue = *Image++;
397 Blt->Green = *Image++;
404 Blt->Blue = *Image++;
405 Blt->Green = *Image++;
418 DEBUG ((DEBUG_ERROR,
"Bmp Bit format not supported. 0x%X\n", BmpHeader->
BitPerPixel));
424 ImageIndex = (
UINTN)Image - (
UINTN)ImageHeader;
425 if ((ImageIndex % 4) != 0) {
429 Image = Image + (4 - (ImageIndex % 4));
463 IN UINT32 PixelHeight,
464 IN UINT32 PixelWidth,
465 IN OUT VOID **BmpImage,
466 IN OUT UINT32 *BmpImageSize
469 RETURN_STATUS Status;
478 if ((GopBlt ==
NULL) || (BmpImage ==
NULL) || (BmpImageSize ==
NULL)) {
482 if ((PixelHeight == 0) || (PixelWidth == 0)) {
489 PaddingSize = PixelWidth & 0x3;
495 if (EFI_ERROR (Status)) {
498 "TranslateGopBltToBmp: GopBlt is too large. PixelHeight:0x%x PixelWidth:0x%x\n",
506 if (EFI_ERROR (Status)) {
509 "TranslateGopBltToBmp: GopBlt is too large. PixelHeight:0x%x PixelWidth:0x%x\n",
520 if (EFI_ERROR (Status)) {
523 "TranslateGopBltToBmp: GopBlt is too large. PixelHeight:0x%x PixelWidth:0x%x\n",
531 if (EFI_ERROR (Status)) {
534 "TranslateGopBltToBmp: GopBlt is too large. PixelHeight:0x%x PixelWidth:0x%x\n",
545 if (*BmpImage ==
NULL) {
547 if (*BmpImage ==
NULL) {
548 return EFI_OUT_OF_RESOURCES;
551 *BmpImageSize = BmpSize;
552 }
else if (*BmpImageSize < BmpSize) {
553 *BmpImageSize = BmpSize;
559 BmpImageHeader->Size = *BmpImageSize;
561 BmpImageHeader->PixelWidth = PixelWidth;
562 BmpImageHeader->PixelHeight = PixelHeight;
568 for (Row = 0; Row < PixelHeight; Row++) {
569 BltPixel = &GopBlt[(PixelHeight - Row - 1) * PixelWidth];
571 for (Col = 0; Col < PixelWidth; Col++) {
572 *Image++ = BltPixel->Blue;
573 *Image++ = BltPixel->Green;
574 *Image++ = BltPixel->Red;
581 Image += PaddingSize;
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
RETURN_STATUS EFIAPI TranslateBmpToGopBlt(IN VOID *BmpImage, IN UINTN BmpImageSize, IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL **GopBlt, IN OUT UINTN *GopBltSize, OUT UINTN *PixelHeight, OUT UINTN *PixelWidth)
RETURN_STATUS EFIAPI TranslateGopBltToBmp(IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *GopBlt, IN UINT32 PixelHeight, IN UINT32 PixelWidth, IN OUT VOID **BmpImage, IN OUT UINT32 *BmpImageSize)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define RETURN_BUFFER_TOO_SMALL
#define RETURN_UNSUPPORTED
#define RETURN_OUT_OF_RESOURCES
#define OFFSET_OF(TYPE, Field)
#define RETURN_INVALID_PARAMETER
#define DEBUG(Expression)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
RETURN_STATUS EFIAPI SafeUint32Add(IN UINT32 Augend, IN UINT32 Addend, OUT UINT32 *Result)
RETURN_STATUS EFIAPI SafeUint32Mult(IN UINT32 Multiplicand, IN UINT32 Multiplier, OUT UINT32 *Result)
UINT16 BitPerPixel
1, 4, 8, or 24
UINT32 ImageSize
Compressed image size in bytes.