3 * Image handling functions
5 * Copyright (c) 2006 Christoph Pfisterer
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the
20 * * Neither the name of Christoph Pfisterer nor the names of the
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 * Modifications copyright (c) 2012-2015 Roderick W. Smith
39 * Modifications distributed under the terms of the GNU General Public
40 * License (GPL) version 3 (GPLv3), a copy of which must be distributed
41 * with this source code or binaries made from it.
46 #include "../refind/global.h"
47 #include "../refind/lib.h"
48 #include "../refind/screen.h"
49 #include "../include/refit_call_wrapper.h"
52 #define MAX_FILE_SIZE (1024*1024*1024)
54 #ifndef __MAKEWITH_GNUEFI
55 #define LibLocateHandle gBS->LocateHandleBuffer
56 #define LibOpenRoot EfiLibOpenRoot
60 // Basic image handling
63 EG_IMAGE
* egCreateImage(IN UINTN Width
, IN UINTN Height
, IN BOOLEAN HasAlpha
)
67 NewImage
= (EG_IMAGE
*) AllocatePool(sizeof(EG_IMAGE
));
70 NewImage
->PixelData
= (EG_PIXEL
*) AllocatePool(Width
* Height
* sizeof(EG_PIXEL
));
71 if (NewImage
->PixelData
== NULL
) {
72 egFreeImage(NewImage
);
76 NewImage
->Width
= Width
;
77 NewImage
->Height
= Height
;
78 NewImage
->HasAlpha
= HasAlpha
;
82 EG_IMAGE
* egCreateFilledImage(IN UINTN Width
, IN UINTN Height
, IN BOOLEAN HasAlpha
, IN EG_PIXEL
*Color
)
86 NewImage
= egCreateImage(Width
, Height
, HasAlpha
);
90 egFillImage(NewImage
, Color
);
94 EG_IMAGE
* egCopyImage(IN EG_IMAGE
*Image
)
96 EG_IMAGE
*NewImage
= NULL
;
99 NewImage
= egCreateImage(Image
->Width
, Image
->Height
, Image
->HasAlpha
);
100 if (NewImage
== NULL
)
103 CopyMem(NewImage
->PixelData
, Image
->PixelData
, Image
->Width
* Image
->Height
* sizeof(EG_PIXEL
));
107 // Returns a smaller image composed of the specified crop area from the larger area.
108 // If the specified area is larger than is in the original, returns NULL.
109 EG_IMAGE
* egCropImage(IN EG_IMAGE
*Image
, IN UINTN StartX
, IN UINTN StartY
, IN UINTN Width
, IN UINTN Height
) {
110 EG_IMAGE
*NewImage
= NULL
;
113 if (((StartX
+ Width
) > Image
->Width
) || ((StartY
+ Height
) > Image
->Height
))
116 NewImage
= egCreateImage(Width
, Height
, Image
->HasAlpha
);
117 if (NewImage
== NULL
)
120 for (y
= 0; y
< Height
; y
++) {
121 for (x
= 0; x
< Width
; x
++) {
122 NewImage
->PixelData
[y
* NewImage
->Width
+ x
] = Image
->PixelData
[(y
+ StartY
) * Image
->Width
+ x
+ StartX
];
126 } // EG_IMAGE * egCropImage()
128 // The following function implements a bilinear image scaling algorithm, based on
129 // code presented at http://tech-algorithm.com/articles/bilinear-image-scaling/.
130 // Resize an image; returns pointer to resized image if successful, NULL otherwise.
131 // Calling function is responsible for freeing allocated memory.
132 EG_IMAGE
* egScaleImage(IN EG_IMAGE
*Image
, IN UINTN NewWidth
, IN UINTN NewHeight
) {
133 EG_IMAGE
*NewImage
= NULL
;
138 float x_ratio
, y_ratio
, x_diff
, y_diff
;
140 if ((Image
== NULL
) || (Image
->Height
== 0) || (Image
->Width
== 0) || (NewWidth
== 0) || (NewHeight
== 0))
143 if ((Image
->Width
== NewWidth
) && (Image
->Height
== NewHeight
))
144 return (egCopyImage(Image
));
146 NewImage
= egCreateImage(NewWidth
, NewHeight
, Image
->HasAlpha
);
147 if (NewImage
== NULL
)
150 x_ratio
= ((float)(Image
->Width
- 1)) / NewWidth
;
151 y_ratio
= ((float)(Image
->Height
- 1)) / NewHeight
;
153 for (i
= 0; i
< NewHeight
; i
++) {
154 for (j
= 0; j
< NewWidth
; j
++) {
155 x
= (UINTN
)(x_ratio
* j
);
156 y
= (UINTN
)(y_ratio
* i
);
157 x_diff
= (x_ratio
* j
) - x
;
158 y_diff
= (y_ratio
* i
) - y
;
159 Index
= ((y
* Image
->Width
) + x
);
160 a
= Image
->PixelData
[Index
];
161 b
= Image
->PixelData
[Index
+ 1];
162 c
= Image
->PixelData
[Index
+ Image
->Width
];
163 d
= Image
->PixelData
[Index
+ Image
->Width
+ 1];
166 // Yb = Ab(1-Image->Width)(1-Image->Height) + Bb(Image->Width)(1-Image->Height) + Cb(Image->Height)(1-Image->Width) + Db(wh)
167 NewImage
->PixelData
[Offset
].b
= (a
.b
)*(1-x_diff
)*(1-y_diff
) + (b
.b
)*(x_diff
)*(1-y_diff
) +
168 (c
.b
)*(y_diff
)*(1-x_diff
) + (d
.b
)*(x_diff
*y_diff
);
171 // Yg = Ag(1-Image->Width)(1-Image->Height) + Bg(Image->Width)(1-Image->Height) + Cg(Image->Height)(1-Image->Width) + Dg(wh)
172 NewImage
->PixelData
[Offset
].g
= (a
.g
)*(1-x_diff
)*(1-y_diff
) + (b
.g
)*(x_diff
)*(1-y_diff
) +
173 (c
.g
)*(y_diff
)*(1-x_diff
) + (d
.g
)*(x_diff
*y_diff
);
176 // Yr = Ar(1-Image->Width)(1-Image->Height) + Br(Image->Width)(1-Image->Height) + Cr(Image->Height)(1-Image->Width) + Dr(wh)
177 NewImage
->PixelData
[Offset
].r
= (a
.r
)*(1-x_diff
)*(1-y_diff
) + (b
.r
)*(x_diff
)*(1-y_diff
) +
178 (c
.r
)*(y_diff
)*(1-x_diff
) + (d
.r
)*(x_diff
*y_diff
);
181 NewImage
->PixelData
[Offset
++].a
= (a
.a
)*(1-x_diff
)*(1-y_diff
) + (b
.a
)*(x_diff
)*(1-y_diff
) +
182 (c
.a
)*(y_diff
)*(1-x_diff
) + (d
.a
)*(x_diff
*y_diff
);
187 } // EG_IMAGE * egScaleImage()
189 VOID
egFreeImage(IN EG_IMAGE
*Image
)
192 if (Image
->PixelData
!= NULL
)
193 FreePool(Image
->PixelData
);
199 // Basic file operations
202 EFI_STATUS
egLoadFile(IN EFI_FILE
*BaseDir
, IN CHAR16
*FileName
, OUT UINT8
**FileData
, OUT UINTN
*FileDataLength
)
205 EFI_FILE_HANDLE FileHandle
;
206 EFI_FILE_INFO
*FileInfo
;
211 if ((BaseDir
== NULL
) || (FileName
== NULL
))
212 return EFI_NOT_FOUND
;
214 Status
= refit_call5_wrapper(BaseDir
->Open
, BaseDir
, &FileHandle
, FileName
, EFI_FILE_MODE_READ
, 0);
215 if (EFI_ERROR(Status
)) {
219 FileInfo
= LibFileInfo(FileHandle
);
220 if (FileInfo
== NULL
) {
221 refit_call1_wrapper(FileHandle
->Close
, FileHandle
);
222 return EFI_NOT_FOUND
;
224 ReadSize
= FileInfo
->FileSize
;
225 if (ReadSize
> MAX_FILE_SIZE
)
226 ReadSize
= MAX_FILE_SIZE
;
229 BufferSize
= (UINTN
)ReadSize
; // was limited to 1 GB above, so this is safe
230 Buffer
= (UINT8
*) AllocatePool(BufferSize
);
231 if (Buffer
== NULL
) {
232 refit_call1_wrapper(FileHandle
->Close
, FileHandle
);
233 return EFI_OUT_OF_RESOURCES
;
236 Status
= refit_call3_wrapper(FileHandle
->Read
, FileHandle
, &BufferSize
, Buffer
);
237 refit_call1_wrapper(FileHandle
->Close
, FileHandle
);
238 if (EFI_ERROR(Status
)) {
244 *FileDataLength
= BufferSize
;
248 static EFI_GUID ESPGuid
= { 0xc12a7328, 0xf81f, 0x11d2, { 0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b } };
250 EFI_STATUS
egFindESP(OUT EFI_FILE_HANDLE
*RootDir
)
253 UINTN HandleCount
= 0;
256 Status
= LibLocateHandle(ByProtocol
, &ESPGuid
, NULL
, &HandleCount
, &Handles
);
257 if (!EFI_ERROR(Status
) && HandleCount
> 0) {
258 *RootDir
= LibOpenRoot(Handles
[0]);
259 if (*RootDir
== NULL
)
260 Status
= EFI_NOT_FOUND
;
266 EFI_STATUS
egSaveFile(IN EFI_FILE
* BaseDir OPTIONAL
, IN CHAR16
*FileName
,
267 IN UINT8
*FileData
, IN UINTN FileDataLength
)
270 EFI_FILE_HANDLE FileHandle
;
273 if (BaseDir
== NULL
) {
274 Status
= egFindESP(&BaseDir
);
275 if (EFI_ERROR(Status
))
279 Status
= refit_call5_wrapper(BaseDir
->Open
, BaseDir
, &FileHandle
, FileName
,
280 EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
| EFI_FILE_MODE_CREATE
, 0);
281 if (EFI_ERROR(Status
))
284 BufferSize
= FileDataLength
;
285 Status
= refit_call3_wrapper(FileHandle
->Write
, FileHandle
, &BufferSize
, FileData
);
286 refit_call1_wrapper(FileHandle
->Close
, FileHandle
);
292 // Loading images from files and embedded data
295 // Decode the specified image data. The IconSize parameter is relevant only
296 // for ICNS, for which it selects which ICNS sub-image is decoded.
297 // Returns a pointer to the resulting EG_IMAGE or NULL if decoding failed.
298 static EG_IMAGE
* egDecodeAny(IN UINT8
*FileData
, IN UINTN FileDataLength
, IN UINTN IconSize
, IN BOOLEAN WantAlpha
)
300 EG_IMAGE
*NewImage
= NULL
;
302 NewImage
= egDecodeICNS(FileData
, FileDataLength
, IconSize
, WantAlpha
);
303 if (NewImage
== NULL
)
304 NewImage
= egDecodePNG(FileData
, FileDataLength
, IconSize
, WantAlpha
);
305 if (NewImage
== NULL
)
306 NewImage
= egDecodeBMP(FileData
, FileDataLength
, IconSize
, WantAlpha
);
311 EG_IMAGE
* egLoadImage(IN EFI_FILE
* BaseDir
, IN CHAR16
*FileName
, IN BOOLEAN WantAlpha
)
315 UINTN FileDataLength
;
318 if (BaseDir
== NULL
|| FileName
== NULL
)
322 Status
= egLoadFile(BaseDir
, FileName
, &FileData
, &FileDataLength
);
323 if (EFI_ERROR(Status
))
327 NewImage
= egDecodeAny(FileData
, FileDataLength
, 128 /* arbitrary value */, WantAlpha
);
333 // Load an icon from (BaseDir)/Path, extracting the icon of size IconSize x IconSize.
334 // Returns a pointer to the image data, or NULL if the icon could not be loaded.
335 EG_IMAGE
* egLoadIcon(IN EFI_FILE
* BaseDir
, IN CHAR16
*Path
, IN UINTN IconSize
)
339 UINTN FileDataLength
;
340 EG_IMAGE
*Image
, *NewImage
;
342 if (BaseDir
== NULL
|| Path
== NULL
)
346 Status
= egLoadFile(BaseDir
, Path
, &FileData
, &FileDataLength
);
347 if (EFI_ERROR(Status
))
351 Image
= egDecodeAny(FileData
, FileDataLength
, IconSize
, TRUE
);
353 if ((Image
->Width
!= IconSize
) || (Image
->Height
!= IconSize
)) {
354 NewImage
= egScaleImage(Image
, IconSize
, IconSize
);
356 Print(L
"Warning: Unable to scale icon of the wrong size from '%s'\n", Path
);
362 } // EG_IMAGE *egLoadIcon()
364 // Returns an icon of any type from the specified subdirectory using the specified
365 // base name. All directory references are relative to BaseDir. For instance, if
366 // SubdirName is "myicons" and BaseName is "os_linux", this function will return
367 // an image based on "myicons/os_linux.icns" or "myicons/os_linux.png", in that
368 // order of preference. Returns NULL if no such file is a valid icon file.
369 EG_IMAGE
* egLoadIconAnyType(IN EFI_FILE
*BaseDir
, IN CHAR16
*SubdirName
, IN CHAR16
*BaseName
, IN UINTN IconSize
) {
370 EG_IMAGE
*Image
= NULL
;
372 CHAR16 FileName
[256];
375 while (((Extension
= FindCommaDelimited(ICON_EXTENSIONS
, i
++)) != NULL
) && (Image
== NULL
)) {
376 SPrint(FileName
, 255, L
"%s\\%s.%s", SubdirName
, BaseName
, Extension
);
377 Image
= egLoadIcon(BaseDir
, FileName
, IconSize
);
378 MyFreePool(Extension
);
382 } // EG_IMAGE *egLoadIconAnyType()
384 // Returns an icon with any extension in ICON_EXTENSIONS from either the directory
385 // specified by GlobalConfig.IconsDir or DEFAULT_ICONS_DIR. The input BaseName
386 // should be the icon name without an extension. For instance, if BaseName is
387 // os_linux, GlobalConfig.IconsDir is myicons, DEFAULT_ICONS_DIR is icons, and
388 // ICON_EXTENSIONS is "icns,png", this function will return myicons/os_linux.icns,
389 // myicons/os_linux.png, icons/os_linux.icns, or icons/os_linux.png, in that
390 // order of preference. Returns NULL if no such icon can be found. All file
391 // references are relative to SelfDir.
392 EG_IMAGE
* egFindIcon(IN CHAR16
*BaseName
, IN UINTN IconSize
) {
393 EG_IMAGE
*Image
= NULL
;
395 if (GlobalConfig
.IconsDir
!= NULL
) {
396 Image
= egLoadIconAnyType(SelfDir
, GlobalConfig
.IconsDir
, BaseName
, IconSize
);
400 Image
= egLoadIconAnyType(SelfDir
, DEFAULT_ICONS_DIR
, BaseName
, IconSize
);
404 } // EG_IMAGE * egFindIcon()
406 EG_IMAGE
* egPrepareEmbeddedImage(IN EG_EMBEDDED_IMAGE
*EmbeddedImage
, IN BOOLEAN WantAlpha
)
414 if (EmbeddedImage
->PixelMode
> EG_MAX_EIPIXELMODE
||
415 (EmbeddedImage
->CompressMode
!= EG_EICOMPMODE_NONE
&& EmbeddedImage
->CompressMode
!= EG_EICOMPMODE_RLE
))
418 // allocate image structure and pixel buffer
419 NewImage
= egCreateImage(EmbeddedImage
->Width
, EmbeddedImage
->Height
, WantAlpha
);
420 if (NewImage
== NULL
)
423 CompData
= (UINT8
*)EmbeddedImage
->Data
; // drop const
424 CompLen
= EmbeddedImage
->DataLength
;
425 PixelCount
= EmbeddedImage
->Width
* EmbeddedImage
->Height
;
427 // FUTURE: for EG_EICOMPMODE_EFICOMPRESS, decompress whole data block here
429 if (EmbeddedImage
->PixelMode
== EG_EIPIXELMODE_GRAY
||
430 EmbeddedImage
->PixelMode
== EG_EIPIXELMODE_GRAY_ALPHA
) {
432 // copy grayscale plane and expand
433 if (EmbeddedImage
->CompressMode
== EG_EICOMPMODE_RLE
) {
434 egDecompressIcnsRLE(&CompData
, &CompLen
, PLPTR(NewImage
, r
), PixelCount
);
436 egInsertPlane(CompData
, PLPTR(NewImage
, r
), PixelCount
);
437 CompData
+= PixelCount
;
439 egCopyPlane(PLPTR(NewImage
, r
), PLPTR(NewImage
, g
), PixelCount
);
440 egCopyPlane(PLPTR(NewImage
, r
), PLPTR(NewImage
, b
), PixelCount
);
442 } else if (EmbeddedImage
->PixelMode
== EG_EIPIXELMODE_COLOR
||
443 EmbeddedImage
->PixelMode
== EG_EIPIXELMODE_COLOR_ALPHA
) {
446 if (EmbeddedImage
->CompressMode
== EG_EICOMPMODE_RLE
) {
447 egDecompressIcnsRLE(&CompData
, &CompLen
, PLPTR(NewImage
, r
), PixelCount
);
448 egDecompressIcnsRLE(&CompData
, &CompLen
, PLPTR(NewImage
, g
), PixelCount
);
449 egDecompressIcnsRLE(&CompData
, &CompLen
, PLPTR(NewImage
, b
), PixelCount
);
451 egInsertPlane(CompData
, PLPTR(NewImage
, r
), PixelCount
);
452 CompData
+= PixelCount
;
453 egInsertPlane(CompData
, PLPTR(NewImage
, g
), PixelCount
);
454 CompData
+= PixelCount
;
455 egInsertPlane(CompData
, PLPTR(NewImage
, b
), PixelCount
);
456 CompData
+= PixelCount
;
461 // set color planes to black
462 egSetPlane(PLPTR(NewImage
, r
), 0, PixelCount
);
463 egSetPlane(PLPTR(NewImage
, g
), 0, PixelCount
);
464 egSetPlane(PLPTR(NewImage
, b
), 0, PixelCount
);
468 if (WantAlpha
&& (EmbeddedImage
->PixelMode
== EG_EIPIXELMODE_GRAY_ALPHA
||
469 EmbeddedImage
->PixelMode
== EG_EIPIXELMODE_COLOR_ALPHA
||
470 EmbeddedImage
->PixelMode
== EG_EIPIXELMODE_ALPHA
)) {
473 if (EmbeddedImage
->CompressMode
== EG_EICOMPMODE_RLE
) {
474 egDecompressIcnsRLE(&CompData
, &CompLen
, PLPTR(NewImage
, a
), PixelCount
);
476 egInsertPlane(CompData
, PLPTR(NewImage
, a
), PixelCount
);
477 CompData
+= PixelCount
;
481 egSetPlane(PLPTR(NewImage
, a
), WantAlpha
? 255 : 0, PixelCount
);
491 VOID
egRestrictImageArea(IN EG_IMAGE
*Image
,
492 IN UINTN AreaPosX
, IN UINTN AreaPosY
,
493 IN OUT UINTN
*AreaWidth
, IN OUT UINTN
*AreaHeight
)
495 if (AreaPosX
>= Image
->Width
|| AreaPosY
>= Image
->Height
) {
496 // out of bounds, operation has no effect
500 // calculate affected area
501 if (*AreaWidth
> Image
->Width
- AreaPosX
)
502 *AreaWidth
= Image
->Width
- AreaPosX
;
503 if (*AreaHeight
> Image
->Height
- AreaPosY
)
504 *AreaHeight
= Image
->Height
- AreaPosY
;
508 VOID
egFillImage(IN OUT EG_IMAGE
*CompImage
, IN EG_PIXEL
*Color
)
515 if (!CompImage
->HasAlpha
)
518 PixelPtr
= CompImage
->PixelData
;
519 for (i
= 0; i
< CompImage
->Width
* CompImage
->Height
; i
++, PixelPtr
++)
520 *PixelPtr
= FillColor
;
523 VOID
egFillImageArea(IN OUT EG_IMAGE
*CompImage
,
524 IN UINTN AreaPosX
, IN UINTN AreaPosY
,
525 IN UINTN AreaWidth
, IN UINTN AreaHeight
,
531 EG_PIXEL
*PixelBasePtr
;
533 egRestrictImageArea(CompImage
, AreaPosX
, AreaPosY
, &AreaWidth
, &AreaHeight
);
537 if (!CompImage
->HasAlpha
)
540 PixelBasePtr
= CompImage
->PixelData
+ AreaPosY
* CompImage
->Width
+ AreaPosX
;
541 for (y
= 0; y
< AreaHeight
; y
++) {
542 PixelPtr
= PixelBasePtr
;
543 for (x
= 0; x
< AreaWidth
; x
++, PixelPtr
++)
544 *PixelPtr
= FillColor
;
545 PixelBasePtr
+= CompImage
->Width
;
550 VOID
egRawCopy(IN OUT EG_PIXEL
*CompBasePtr
, IN EG_PIXEL
*TopBasePtr
,
551 IN UINTN Width
, IN UINTN Height
,
552 IN UINTN CompLineOffset
, IN UINTN TopLineOffset
)
555 EG_PIXEL
*TopPtr
, *CompPtr
;
557 for (y
= 0; y
< Height
; y
++) {
559 CompPtr
= CompBasePtr
;
560 for (x
= 0; x
< Width
; x
++) {
564 TopBasePtr
+= TopLineOffset
;
565 CompBasePtr
+= CompLineOffset
;
569 VOID
egRawCompose(IN OUT EG_PIXEL
*CompBasePtr
, IN EG_PIXEL
*TopBasePtr
,
570 IN UINTN Width
, IN UINTN Height
,
571 IN UINTN CompLineOffset
, IN UINTN TopLineOffset
)
574 EG_PIXEL
*TopPtr
, *CompPtr
;
579 for (y
= 0; y
< Height
; y
++) {
581 CompPtr
= CompBasePtr
;
582 for (x
= 0; x
< Width
; x
++) {
584 RevAlpha
= 255 - Alpha
;
585 Temp
= (UINTN
)CompPtr
->b
* RevAlpha
+ (UINTN
)TopPtr
->b
* Alpha
+ 0x80;
586 CompPtr
->b
= (Temp
+ (Temp
>> 8)) >> 8;
587 Temp
= (UINTN
)CompPtr
->g
* RevAlpha
+ (UINTN
)TopPtr
->g
* Alpha
+ 0x80;
588 CompPtr
->g
= (Temp
+ (Temp
>> 8)) >> 8;
589 Temp
= (UINTN
)CompPtr
->r
* RevAlpha
+ (UINTN
)TopPtr
->r
* Alpha
+ 0x80;
590 CompPtr
->r
= (Temp
+ (Temp
>> 8)) >> 8;
592 CompPtr->b = ((UINTN)CompPtr->b * RevAlpha + (UINTN)TopPtr->b * Alpha) / 255;
593 CompPtr->g = ((UINTN)CompPtr->g * RevAlpha + (UINTN)TopPtr->g * Alpha) / 255;
594 CompPtr->r = ((UINTN)CompPtr->r * RevAlpha + (UINTN)TopPtr->r * Alpha) / 255;
598 TopBasePtr
+= TopLineOffset
;
599 CompBasePtr
+= CompLineOffset
;
603 VOID
egComposeImage(IN OUT EG_IMAGE
*CompImage
, IN EG_IMAGE
*TopImage
, IN UINTN PosX
, IN UINTN PosY
)
605 UINTN CompWidth
, CompHeight
;
607 CompWidth
= TopImage
->Width
;
608 CompHeight
= TopImage
->Height
;
609 egRestrictImageArea(CompImage
, PosX
, PosY
, &CompWidth
, &CompHeight
);
613 if (TopImage
->HasAlpha
) {
614 egRawCompose(CompImage
->PixelData
+ PosY
* CompImage
->Width
+ PosX
, TopImage
->PixelData
,
615 CompWidth
, CompHeight
, CompImage
->Width
, TopImage
->Width
);
617 egRawCopy(CompImage
->PixelData
+ PosY
* CompImage
->Width
+ PosX
, TopImage
->PixelData
,
618 CompWidth
, CompHeight
, CompImage
->Width
, TopImage
->Width
);
621 } /* VOID egComposeImage() */
624 // misc internal functions
627 VOID
egInsertPlane(IN UINT8
*SrcDataPtr
, IN UINT8
*DestPlanePtr
, IN UINTN PixelCount
)
631 for (i
= 0; i
< PixelCount
; i
++) {
632 *DestPlanePtr
= *SrcDataPtr
++;
637 VOID
egSetPlane(IN UINT8
*DestPlanePtr
, IN UINT8 Value
, IN UINTN PixelCount
)
641 for (i
= 0; i
< PixelCount
; i
++) {
642 *DestPlanePtr
= Value
;
647 VOID
egCopyPlane(IN UINT8
*SrcPlanePtr
, IN UINT8
*DestPlanePtr
, IN UINTN PixelCount
)
651 for (i
= 0; i
< PixelCount
; i
++) {
652 *DestPlanePtr
= *SrcPlanePtr
;
653 DestPlanePtr
+= 4, SrcPlanePtr
+= 4;