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), or (at your option) any later version.
44 * This program is free software: you can redistribute it and/or modify
45 * it under the terms of the GNU General Public License as published by
46 * the Free Software Foundation, either version 3 of the License, or
47 * (at your option) any later version.
49 * This program is distributed in the hope that it will be useful,
50 * but WITHOUT ANY WARRANTY; without even the implied warranty of
51 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52 * GNU General Public License for more details.
54 * You should have received a copy of the GNU General Public License
55 * along with this program. If not, see <http://www.gnu.org/licenses/>.
59 #include "../refind/global.h"
60 #include "../refind/lib.h"
61 #include "../refind/screen.h"
62 #include "../include/refit_call_wrapper.h"
65 #define MAX_FILE_SIZE (1024*1024*1024)
67 #ifndef __MAKEWITH_GNUEFI
68 #define LibLocateHandle gBS->LocateHandleBuffer
69 #define LibOpenRoot EfiLibOpenRoot
73 // Basic image handling
76 EG_IMAGE
* egCreateImage(IN UINTN Width
, IN UINTN Height
, IN BOOLEAN HasAlpha
)
80 NewImage
= (EG_IMAGE
*) AllocatePool(sizeof(EG_IMAGE
));
83 NewImage
->PixelData
= (EG_PIXEL
*) AllocatePool(Width
* Height
* sizeof(EG_PIXEL
));
84 if (NewImage
->PixelData
== NULL
) {
85 egFreeImage(NewImage
);
89 NewImage
->Width
= Width
;
90 NewImage
->Height
= Height
;
91 NewImage
->HasAlpha
= HasAlpha
;
95 EG_IMAGE
* egCreateFilledImage(IN UINTN Width
, IN UINTN Height
, IN BOOLEAN HasAlpha
, IN EG_PIXEL
*Color
)
99 NewImage
= egCreateImage(Width
, Height
, HasAlpha
);
100 if (NewImage
== NULL
)
103 egFillImage(NewImage
, Color
);
107 EG_IMAGE
* egCopyImage(IN EG_IMAGE
*Image
)
109 EG_IMAGE
*NewImage
= NULL
;
112 NewImage
= egCreateImage(Image
->Width
, Image
->Height
, Image
->HasAlpha
);
113 if (NewImage
== NULL
)
116 CopyMem(NewImage
->PixelData
, Image
->PixelData
, Image
->Width
* Image
->Height
* sizeof(EG_PIXEL
));
120 // Returns a smaller image composed of the specified crop area from the larger area.
121 // If the specified area is larger than is in the original, returns NULL.
122 EG_IMAGE
* egCropImage(IN EG_IMAGE
*Image
, IN UINTN StartX
, IN UINTN StartY
, IN UINTN Width
, IN UINTN Height
) {
123 EG_IMAGE
*NewImage
= NULL
;
126 if (((StartX
+ Width
) > Image
->Width
) || ((StartY
+ Height
) > Image
->Height
))
129 NewImage
= egCreateImage(Width
, Height
, Image
->HasAlpha
);
130 if (NewImage
== NULL
)
133 for (y
= 0; y
< Height
; y
++) {
134 for (x
= 0; x
< Width
; x
++) {
135 NewImage
->PixelData
[y
* NewImage
->Width
+ x
] = Image
->PixelData
[(y
+ StartY
) * Image
->Width
+ x
+ StartX
];
139 } // EG_IMAGE * egCropImage()
141 // The following function implements a bilinear image scaling algorithm, based on
142 // code presented at http://tech-algorithm.com/articles/bilinear-image-scaling/.
143 // Resize an image; returns pointer to resized image if successful, NULL otherwise.
144 // Calling function is responsible for freeing allocated memory.
145 EG_IMAGE
* egScaleImage(IN EG_IMAGE
*Image
, IN UINTN NewWidth
, IN UINTN NewHeight
) {
146 EG_IMAGE
*NewImage
= NULL
;
151 float x_ratio
, y_ratio
, x_diff
, y_diff
;
153 if ((Image
== NULL
) || (Image
->Height
== 0) || (Image
->Width
== 0) || (NewWidth
== 0) || (NewHeight
== 0))
156 if ((Image
->Width
== NewWidth
) && (Image
->Height
== NewHeight
))
157 return (egCopyImage(Image
));
159 NewImage
= egCreateImage(NewWidth
, NewHeight
, Image
->HasAlpha
);
160 if (NewImage
== NULL
)
163 x_ratio
= ((float)(Image
->Width
- 1)) / NewWidth
;
164 y_ratio
= ((float)(Image
->Height
- 1)) / NewHeight
;
166 for (i
= 0; i
< NewHeight
; i
++) {
167 for (j
= 0; j
< NewWidth
; j
++) {
168 x
= (UINTN
)(x_ratio
* j
);
169 y
= (UINTN
)(y_ratio
* i
);
170 x_diff
= (x_ratio
* j
) - x
;
171 y_diff
= (y_ratio
* i
) - y
;
172 Index
= ((y
* Image
->Width
) + x
);
173 a
= Image
->PixelData
[Index
];
174 b
= Image
->PixelData
[Index
+ 1];
175 c
= Image
->PixelData
[Index
+ Image
->Width
];
176 d
= Image
->PixelData
[Index
+ Image
->Width
+ 1];
179 // Yb = Ab(1-Image->Width)(1-Image->Height) + Bb(Image->Width)(1-Image->Height) + Cb(Image->Height)(1-Image->Width) + Db(wh)
180 NewImage
->PixelData
[Offset
].b
= (a
.b
)*(1-x_diff
)*(1-y_diff
) + (b
.b
)*(x_diff
)*(1-y_diff
) +
181 (c
.b
)*(y_diff
)*(1-x_diff
) + (d
.b
)*(x_diff
*y_diff
);
184 // Yg = Ag(1-Image->Width)(1-Image->Height) + Bg(Image->Width)(1-Image->Height) + Cg(Image->Height)(1-Image->Width) + Dg(wh)
185 NewImage
->PixelData
[Offset
].g
= (a
.g
)*(1-x_diff
)*(1-y_diff
) + (b
.g
)*(x_diff
)*(1-y_diff
) +
186 (c
.g
)*(y_diff
)*(1-x_diff
) + (d
.g
)*(x_diff
*y_diff
);
189 // Yr = Ar(1-Image->Width)(1-Image->Height) + Br(Image->Width)(1-Image->Height) + Cr(Image->Height)(1-Image->Width) + Dr(wh)
190 NewImage
->PixelData
[Offset
].r
= (a
.r
)*(1-x_diff
)*(1-y_diff
) + (b
.r
)*(x_diff
)*(1-y_diff
) +
191 (c
.r
)*(y_diff
)*(1-x_diff
) + (d
.r
)*(x_diff
*y_diff
);
194 NewImage
->PixelData
[Offset
++].a
= (a
.a
)*(1-x_diff
)*(1-y_diff
) + (b
.a
)*(x_diff
)*(1-y_diff
) +
195 (c
.a
)*(y_diff
)*(1-x_diff
) + (d
.a
)*(x_diff
*y_diff
);
200 } // EG_IMAGE * egScaleImage()
202 VOID
egFreeImage(IN EG_IMAGE
*Image
)
205 if (Image
->PixelData
!= NULL
)
206 FreePool(Image
->PixelData
);
212 // Basic file operations
215 EFI_STATUS
egLoadFile(IN EFI_FILE
*BaseDir
, IN CHAR16
*FileName
, OUT UINT8
**FileData
, OUT UINTN
*FileDataLength
)
218 EFI_FILE_HANDLE FileHandle
;
219 EFI_FILE_INFO
*FileInfo
;
224 if ((BaseDir
== NULL
) || (FileName
== NULL
))
225 return EFI_NOT_FOUND
;
227 Status
= refit_call5_wrapper(BaseDir
->Open
, BaseDir
, &FileHandle
, FileName
, EFI_FILE_MODE_READ
, 0);
228 if (EFI_ERROR(Status
)) {
232 FileInfo
= LibFileInfo(FileHandle
);
233 if (FileInfo
== NULL
) {
234 refit_call1_wrapper(FileHandle
->Close
, FileHandle
);
235 return EFI_NOT_FOUND
;
237 ReadSize
= FileInfo
->FileSize
;
238 if (ReadSize
> MAX_FILE_SIZE
)
239 ReadSize
= MAX_FILE_SIZE
;
242 BufferSize
= (UINTN
)ReadSize
; // was limited to 1 GB above, so this is safe
243 Buffer
= (UINT8
*) AllocatePool(BufferSize
);
244 if (Buffer
== NULL
) {
245 refit_call1_wrapper(FileHandle
->Close
, FileHandle
);
246 return EFI_OUT_OF_RESOURCES
;
249 Status
= refit_call3_wrapper(FileHandle
->Read
, FileHandle
, &BufferSize
, Buffer
);
250 refit_call1_wrapper(FileHandle
->Close
, FileHandle
);
251 if (EFI_ERROR(Status
)) {
257 *FileDataLength
= BufferSize
;
261 static EFI_GUID ESPGuid
= { 0xc12a7328, 0xf81f, 0x11d2, { 0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b } };
263 EFI_STATUS
egFindESP(OUT EFI_FILE_HANDLE
*RootDir
)
266 UINTN HandleCount
= 0;
269 Status
= LibLocateHandle(ByProtocol
, &ESPGuid
, NULL
, &HandleCount
, &Handles
);
270 if (!EFI_ERROR(Status
) && HandleCount
> 0) {
271 *RootDir
= LibOpenRoot(Handles
[0]);
272 if (*RootDir
== NULL
)
273 Status
= EFI_NOT_FOUND
;
279 EFI_STATUS
egSaveFile(IN EFI_FILE
* BaseDir OPTIONAL
, IN CHAR16
*FileName
,
280 IN UINT8
*FileData
, IN UINTN FileDataLength
)
283 EFI_FILE_HANDLE FileHandle
;
286 if (BaseDir
== NULL
) {
287 Status
= egFindESP(&BaseDir
);
288 if (EFI_ERROR(Status
))
292 Status
= refit_call5_wrapper(BaseDir
->Open
, BaseDir
, &FileHandle
, FileName
,
293 EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
| EFI_FILE_MODE_CREATE
, 0);
294 if (EFI_ERROR(Status
))
297 BufferSize
= FileDataLength
;
298 Status
= refit_call3_wrapper(FileHandle
->Write
, FileHandle
, &BufferSize
, FileData
);
299 refit_call1_wrapper(FileHandle
->Close
, FileHandle
);
305 // Loading images from files and embedded data
308 // Decode the specified image data. The IconSize parameter is relevant only
309 // for ICNS, for which it selects which ICNS sub-image is decoded.
310 // Returns a pointer to the resulting EG_IMAGE or NULL if decoding failed.
311 static EG_IMAGE
* egDecodeAny(IN UINT8
*FileData
, IN UINTN FileDataLength
, IN UINTN IconSize
, IN BOOLEAN WantAlpha
)
313 EG_IMAGE
*NewImage
= NULL
;
315 NewImage
= egDecodeICNS(FileData
, FileDataLength
, IconSize
, WantAlpha
);
316 if (NewImage
== NULL
)
317 NewImage
= egDecodePNG(FileData
, FileDataLength
, IconSize
, WantAlpha
);
318 if (NewImage
== NULL
)
319 NewImage
= egDecodeBMP(FileData
, FileDataLength
, IconSize
, WantAlpha
);
324 EG_IMAGE
* egLoadImage(IN EFI_FILE
* BaseDir
, IN CHAR16
*FileName
, IN BOOLEAN WantAlpha
)
328 UINTN FileDataLength
;
331 if (BaseDir
== NULL
|| FileName
== NULL
)
335 Status
= egLoadFile(BaseDir
, FileName
, &FileData
, &FileDataLength
);
336 if (EFI_ERROR(Status
))
340 NewImage
= egDecodeAny(FileData
, FileDataLength
, 128 /* arbitrary value */, WantAlpha
);
346 // Load an icon from (BaseDir)/Path, extracting the icon of size IconSize x IconSize.
347 // Returns a pointer to the image data, or NULL if the icon could not be loaded.
348 EG_IMAGE
* egLoadIcon(IN EFI_FILE
* BaseDir
, IN CHAR16
*Path
, IN UINTN IconSize
)
352 UINTN FileDataLength
;
353 EG_IMAGE
*Image
, *NewImage
;
355 if (BaseDir
== NULL
|| Path
== NULL
)
359 Status
= egLoadFile(BaseDir
, Path
, &FileData
, &FileDataLength
);
360 if (EFI_ERROR(Status
))
364 Image
= egDecodeAny(FileData
, FileDataLength
, IconSize
, TRUE
);
366 if ((Image
->Width
!= IconSize
) || (Image
->Height
!= IconSize
)) {
367 NewImage
= egScaleImage(Image
, IconSize
, IconSize
);
369 Print(L
"Warning: Unable to scale icon of the wrong size from '%s'\n", Path
);
375 } // EG_IMAGE *egLoadIcon()
377 // Returns an icon of any type from the specified subdirectory using the specified
378 // base name. All directory references are relative to BaseDir. For instance, if
379 // SubdirName is "myicons" and BaseName is "os_linux", this function will return
380 // an image based on "myicons/os_linux.icns" or "myicons/os_linux.png", in that
381 // order of preference. Returns NULL if no such file is a valid icon file.
382 EG_IMAGE
* egLoadIconAnyType(IN EFI_FILE
*BaseDir
, IN CHAR16
*SubdirName
, IN CHAR16
*BaseName
, IN UINTN IconSize
) {
383 EG_IMAGE
*Image
= NULL
;
385 CHAR16 FileName
[256];
388 while (((Extension
= FindCommaDelimited(ICON_EXTENSIONS
, i
++)) != NULL
) && (Image
== NULL
)) {
389 SPrint(FileName
, 255, L
"%s\\%s.%s", SubdirName
, BaseName
, Extension
);
390 Image
= egLoadIcon(BaseDir
, FileName
, IconSize
);
391 MyFreePool(Extension
);
395 } // EG_IMAGE *egLoadIconAnyType()
397 // Returns an icon with any extension in ICON_EXTENSIONS from either the directory
398 // specified by GlobalConfig.IconsDir or DEFAULT_ICONS_DIR. The input BaseName
399 // should be the icon name without an extension. For instance, if BaseName is
400 // os_linux, GlobalConfig.IconsDir is myicons, DEFAULT_ICONS_DIR is icons, and
401 // ICON_EXTENSIONS is "icns,png", this function will return myicons/os_linux.icns,
402 // myicons/os_linux.png, icons/os_linux.icns, or icons/os_linux.png, in that
403 // order of preference. Returns NULL if no such icon can be found. All file
404 // references are relative to SelfDir.
405 EG_IMAGE
* egFindIcon(IN CHAR16
*BaseName
, IN UINTN IconSize
) {
406 EG_IMAGE
*Image
= NULL
;
408 if (GlobalConfig
.IconsDir
!= NULL
) {
409 Image
= egLoadIconAnyType(SelfDir
, GlobalConfig
.IconsDir
, BaseName
, IconSize
);
413 Image
= egLoadIconAnyType(SelfDir
, DEFAULT_ICONS_DIR
, BaseName
, IconSize
);
417 } // EG_IMAGE * egFindIcon()
419 EG_IMAGE
* egPrepareEmbeddedImage(IN EG_EMBEDDED_IMAGE
*EmbeddedImage
, IN BOOLEAN WantAlpha
)
427 if (EmbeddedImage
->PixelMode
> EG_MAX_EIPIXELMODE
||
428 (EmbeddedImage
->CompressMode
!= EG_EICOMPMODE_NONE
&& EmbeddedImage
->CompressMode
!= EG_EICOMPMODE_RLE
))
431 // allocate image structure and pixel buffer
432 NewImage
= egCreateImage(EmbeddedImage
->Width
, EmbeddedImage
->Height
, WantAlpha
);
433 if (NewImage
== NULL
)
436 CompData
= (UINT8
*)EmbeddedImage
->Data
; // drop const
437 CompLen
= EmbeddedImage
->DataLength
;
438 PixelCount
= EmbeddedImage
->Width
* EmbeddedImage
->Height
;
440 // FUTURE: for EG_EICOMPMODE_EFICOMPRESS, decompress whole data block here
442 if (EmbeddedImage
->PixelMode
== EG_EIPIXELMODE_GRAY
||
443 EmbeddedImage
->PixelMode
== EG_EIPIXELMODE_GRAY_ALPHA
) {
445 // copy grayscale plane and expand
446 if (EmbeddedImage
->CompressMode
== EG_EICOMPMODE_RLE
) {
447 egDecompressIcnsRLE(&CompData
, &CompLen
, PLPTR(NewImage
, r
), PixelCount
);
449 egInsertPlane(CompData
, PLPTR(NewImage
, r
), PixelCount
);
450 CompData
+= PixelCount
;
452 egCopyPlane(PLPTR(NewImage
, r
), PLPTR(NewImage
, g
), PixelCount
);
453 egCopyPlane(PLPTR(NewImage
, r
), PLPTR(NewImage
, b
), PixelCount
);
455 } else if (EmbeddedImage
->PixelMode
== EG_EIPIXELMODE_COLOR
||
456 EmbeddedImage
->PixelMode
== EG_EIPIXELMODE_COLOR_ALPHA
) {
459 if (EmbeddedImage
->CompressMode
== EG_EICOMPMODE_RLE
) {
460 egDecompressIcnsRLE(&CompData
, &CompLen
, PLPTR(NewImage
, r
), PixelCount
);
461 egDecompressIcnsRLE(&CompData
, &CompLen
, PLPTR(NewImage
, g
), PixelCount
);
462 egDecompressIcnsRLE(&CompData
, &CompLen
, PLPTR(NewImage
, b
), PixelCount
);
464 egInsertPlane(CompData
, PLPTR(NewImage
, r
), PixelCount
);
465 CompData
+= PixelCount
;
466 egInsertPlane(CompData
, PLPTR(NewImage
, g
), PixelCount
);
467 CompData
+= PixelCount
;
468 egInsertPlane(CompData
, PLPTR(NewImage
, b
), PixelCount
);
469 CompData
+= PixelCount
;
474 // set color planes to black
475 egSetPlane(PLPTR(NewImage
, r
), 0, PixelCount
);
476 egSetPlane(PLPTR(NewImage
, g
), 0, PixelCount
);
477 egSetPlane(PLPTR(NewImage
, b
), 0, PixelCount
);
481 if (WantAlpha
&& (EmbeddedImage
->PixelMode
== EG_EIPIXELMODE_GRAY_ALPHA
||
482 EmbeddedImage
->PixelMode
== EG_EIPIXELMODE_COLOR_ALPHA
||
483 EmbeddedImage
->PixelMode
== EG_EIPIXELMODE_ALPHA
)) {
486 if (EmbeddedImage
->CompressMode
== EG_EICOMPMODE_RLE
) {
487 egDecompressIcnsRLE(&CompData
, &CompLen
, PLPTR(NewImage
, a
), PixelCount
);
489 egInsertPlane(CompData
, PLPTR(NewImage
, a
), PixelCount
);
490 CompData
+= PixelCount
;
494 egSetPlane(PLPTR(NewImage
, a
), WantAlpha
? 255 : 0, PixelCount
);
504 VOID
egRestrictImageArea(IN EG_IMAGE
*Image
,
505 IN UINTN AreaPosX
, IN UINTN AreaPosY
,
506 IN OUT UINTN
*AreaWidth
, IN OUT UINTN
*AreaHeight
)
508 if (AreaPosX
>= Image
->Width
|| AreaPosY
>= Image
->Height
) {
509 // out of bounds, operation has no effect
513 // calculate affected area
514 if (*AreaWidth
> Image
->Width
- AreaPosX
)
515 *AreaWidth
= Image
->Width
- AreaPosX
;
516 if (*AreaHeight
> Image
->Height
- AreaPosY
)
517 *AreaHeight
= Image
->Height
- AreaPosY
;
521 VOID
egFillImage(IN OUT EG_IMAGE
*CompImage
, IN EG_PIXEL
*Color
)
528 if (!CompImage
->HasAlpha
)
531 PixelPtr
= CompImage
->PixelData
;
532 for (i
= 0; i
< CompImage
->Width
* CompImage
->Height
; i
++, PixelPtr
++)
533 *PixelPtr
= FillColor
;
536 VOID
egFillImageArea(IN OUT EG_IMAGE
*CompImage
,
537 IN UINTN AreaPosX
, IN UINTN AreaPosY
,
538 IN UINTN AreaWidth
, IN UINTN AreaHeight
,
544 EG_PIXEL
*PixelBasePtr
;
546 egRestrictImageArea(CompImage
, AreaPosX
, AreaPosY
, &AreaWidth
, &AreaHeight
);
550 if (!CompImage
->HasAlpha
)
553 PixelBasePtr
= CompImage
->PixelData
+ AreaPosY
* CompImage
->Width
+ AreaPosX
;
554 for (y
= 0; y
< AreaHeight
; y
++) {
555 PixelPtr
= PixelBasePtr
;
556 for (x
= 0; x
< AreaWidth
; x
++, PixelPtr
++)
557 *PixelPtr
= FillColor
;
558 PixelBasePtr
+= CompImage
->Width
;
563 VOID
egRawCopy(IN OUT EG_PIXEL
*CompBasePtr
, IN EG_PIXEL
*TopBasePtr
,
564 IN UINTN Width
, IN UINTN Height
,
565 IN UINTN CompLineOffset
, IN UINTN TopLineOffset
)
568 EG_PIXEL
*TopPtr
, *CompPtr
;
570 for (y
= 0; y
< Height
; y
++) {
572 CompPtr
= CompBasePtr
;
573 for (x
= 0; x
< Width
; x
++) {
577 TopBasePtr
+= TopLineOffset
;
578 CompBasePtr
+= CompLineOffset
;
582 VOID
egRawCompose(IN OUT EG_PIXEL
*CompBasePtr
, IN EG_PIXEL
*TopBasePtr
,
583 IN UINTN Width
, IN UINTN Height
,
584 IN UINTN CompLineOffset
, IN UINTN TopLineOffset
)
587 EG_PIXEL
*TopPtr
, *CompPtr
;
592 for (y
= 0; y
< Height
; y
++) {
594 CompPtr
= CompBasePtr
;
595 for (x
= 0; x
< Width
; x
++) {
597 RevAlpha
= 255 - Alpha
;
598 Temp
= (UINTN
)CompPtr
->b
* RevAlpha
+ (UINTN
)TopPtr
->b
* Alpha
+ 0x80;
599 CompPtr
->b
= (Temp
+ (Temp
>> 8)) >> 8;
600 Temp
= (UINTN
)CompPtr
->g
* RevAlpha
+ (UINTN
)TopPtr
->g
* Alpha
+ 0x80;
601 CompPtr
->g
= (Temp
+ (Temp
>> 8)) >> 8;
602 Temp
= (UINTN
)CompPtr
->r
* RevAlpha
+ (UINTN
)TopPtr
->r
* Alpha
+ 0x80;
603 CompPtr
->r
= (Temp
+ (Temp
>> 8)) >> 8;
605 CompPtr->b = ((UINTN)CompPtr->b * RevAlpha + (UINTN)TopPtr->b * Alpha) / 255;
606 CompPtr->g = ((UINTN)CompPtr->g * RevAlpha + (UINTN)TopPtr->g * Alpha) / 255;
607 CompPtr->r = ((UINTN)CompPtr->r * RevAlpha + (UINTN)TopPtr->r * Alpha) / 255;
611 TopBasePtr
+= TopLineOffset
;
612 CompBasePtr
+= CompLineOffset
;
616 VOID
egComposeImage(IN OUT EG_IMAGE
*CompImage
, IN EG_IMAGE
*TopImage
, IN UINTN PosX
, IN UINTN PosY
)
618 UINTN CompWidth
, CompHeight
;
620 CompWidth
= TopImage
->Width
;
621 CompHeight
= TopImage
->Height
;
622 egRestrictImageArea(CompImage
, PosX
, PosY
, &CompWidth
, &CompHeight
);
626 if (TopImage
->HasAlpha
) {
627 egRawCompose(CompImage
->PixelData
+ PosY
* CompImage
->Width
+ PosX
, TopImage
->PixelData
,
628 CompWidth
, CompHeight
, CompImage
->Width
, TopImage
->Width
);
630 egRawCopy(CompImage
->PixelData
+ PosY
* CompImage
->Width
+ PosX
, TopImage
->PixelData
,
631 CompWidth
, CompHeight
, CompImage
->Width
, TopImage
->Width
);
634 } /* VOID egComposeImage() */
637 // misc internal functions
640 VOID
egInsertPlane(IN UINT8
*SrcDataPtr
, IN UINT8
*DestPlanePtr
, IN UINTN PixelCount
)
644 for (i
= 0; i
< PixelCount
; i
++) {
645 *DestPlanePtr
= *SrcDataPtr
++;
650 VOID
egSetPlane(IN UINT8
*DestPlanePtr
, IN UINT8 Value
, IN UINTN PixelCount
)
654 for (i
= 0; i
< PixelCount
; i
++) {
655 *DestPlanePtr
= Value
;
660 VOID
egCopyPlane(IN UINT8
*SrcPlanePtr
, IN UINT8
*DestPlanePtr
, IN UINTN PixelCount
)
664 for (i
= 0; i
< PixelCount
; i
++) {
665 *DestPlanePtr
= *SrcPlanePtr
;
666 DestPlanePtr
+= 4, SrcPlanePtr
+= 4;