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-2014 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 Status
= refit_call5_wrapper(BaseDir
->Open
, BaseDir
, &FileHandle
, FileName
, EFI_FILE_MODE_READ
, 0);
212 if (EFI_ERROR(Status
)) {
216 FileInfo
= LibFileInfo(FileHandle
);
217 if (FileInfo
== NULL
) {
218 refit_call1_wrapper(FileHandle
->Close
, FileHandle
);
219 return EFI_NOT_FOUND
;
221 ReadSize
= FileInfo
->FileSize
;
222 if (ReadSize
> MAX_FILE_SIZE
)
223 ReadSize
= MAX_FILE_SIZE
;
226 BufferSize
= (UINTN
)ReadSize
; // was limited to 1 GB above, so this is safe
227 Buffer
= (UINT8
*) AllocatePool(BufferSize
);
228 if (Buffer
== NULL
) {
229 refit_call1_wrapper(FileHandle
->Close
, FileHandle
);
230 return EFI_OUT_OF_RESOURCES
;
233 Status
= refit_call3_wrapper(FileHandle
->Read
, FileHandle
, &BufferSize
, Buffer
);
234 refit_call1_wrapper(FileHandle
->Close
, FileHandle
);
235 if (EFI_ERROR(Status
)) {
241 *FileDataLength
= BufferSize
;
245 static EFI_GUID ESPGuid
= { 0xc12a7328, 0xf81f, 0x11d2, { 0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b } };
247 EFI_STATUS
egFindESP(OUT EFI_FILE_HANDLE
*RootDir
)
250 UINTN HandleCount
= 0;
253 Status
= LibLocateHandle(ByProtocol
, &ESPGuid
, NULL
, &HandleCount
, &Handles
);
254 if (!EFI_ERROR(Status
) && HandleCount
> 0) {
255 *RootDir
= LibOpenRoot(Handles
[0]);
256 if (*RootDir
== NULL
)
257 Status
= EFI_NOT_FOUND
;
263 EFI_STATUS
egSaveFile(IN EFI_FILE
* BaseDir OPTIONAL
, IN CHAR16
*FileName
,
264 IN UINT8
*FileData
, IN UINTN FileDataLength
)
267 EFI_FILE_HANDLE FileHandle
;
270 if (BaseDir
== NULL
) {
271 Status
= egFindESP(&BaseDir
);
272 if (EFI_ERROR(Status
))
276 Status
= refit_call5_wrapper(BaseDir
->Open
, BaseDir
, &FileHandle
, FileName
,
277 EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
| EFI_FILE_MODE_CREATE
, 0);
278 if (EFI_ERROR(Status
))
281 BufferSize
= FileDataLength
;
282 Status
= refit_call3_wrapper(FileHandle
->Write
, FileHandle
, &BufferSize
, FileData
);
283 refit_call1_wrapper(FileHandle
->Close
, FileHandle
);
289 // Loading images from files and embedded data
292 // Decode the specified image data. The IconSize parameter is relevant only
293 // for ICNS, for which it selects which ICNS sub-image is decoded.
294 // Returns a pointer to the resulting EG_IMAGE or NULL if decoding failed.
295 static EG_IMAGE
* egDecodeAny(IN UINT8
*FileData
, IN UINTN FileDataLength
, IN UINTN IconSize
, IN BOOLEAN WantAlpha
)
297 EG_IMAGE
*NewImage
= NULL
;
299 NewImage
= egDecodeICNS(FileData
, FileDataLength
, IconSize
, WantAlpha
);
300 if (NewImage
== NULL
)
301 NewImage
= egDecodePNG(FileData
, FileDataLength
, IconSize
, WantAlpha
);
302 if (NewImage
== NULL
)
303 NewImage
= egDecodeBMP(FileData
, FileDataLength
, IconSize
, WantAlpha
);
308 EG_IMAGE
* egLoadImage(IN EFI_FILE
* BaseDir
, IN CHAR16
*FileName
, IN BOOLEAN WantAlpha
)
312 UINTN FileDataLength
;
315 if (BaseDir
== NULL
|| FileName
== NULL
)
319 Status
= egLoadFile(BaseDir
, FileName
, &FileData
, &FileDataLength
);
320 if (EFI_ERROR(Status
))
324 NewImage
= egDecodeAny(FileData
, FileDataLength
, 128 /* arbitrary value */, WantAlpha
);
330 // Load an icon from (BaseDir)/Path, extracting the icon of size IconSize x IconSize.
331 // Returns a pointer to the image data, or NULL if the icon could not be loaded.
332 EG_IMAGE
* egLoadIcon(IN EFI_FILE
* BaseDir
, IN CHAR16
*Path
, IN UINTN IconSize
)
336 UINTN FileDataLength
;
337 EG_IMAGE
*Image
, *NewImage
;
339 if (BaseDir
== NULL
|| Path
== NULL
)
343 Status
= egLoadFile(BaseDir
, Path
, &FileData
, &FileDataLength
);
344 if (EFI_ERROR(Status
))
348 Image
= egDecodeAny(FileData
, FileDataLength
, IconSize
, TRUE
);
350 if ((Image
->Width
!= IconSize
) || (Image
->Height
!= IconSize
)) {
351 NewImage
= egScaleImage(Image
, IconSize
, IconSize
);
353 Print(L
"Warning: Unable to scale icon of the wrong size from '%s'\n", Path
);
359 } // EG_IMAGE *egLoadIcon()
361 // Returns an icon of any type from the specified subdirectory using the specified
362 // base name. All directory references are relative to BaseDir. For instance, if
363 // SubdirName is "myicons" and BaseName is "os_linux", this function will return
364 // an image based on "myicons/os_linux.icns" or "myicons/os_linux.png", in that
365 // order of preference. Returns NULL if no such file is a valid icon file.
366 EG_IMAGE
* egLoadIconAnyType(IN EFI_FILE
*BaseDir
, IN CHAR16
*SubdirName
, IN CHAR16
*BaseName
, IN UINTN IconSize
) {
367 EG_IMAGE
*Image
= NULL
;
369 CHAR16 FileName
[256];
372 while (((Extension
= FindCommaDelimited(ICON_EXTENSIONS
, i
++)) != NULL
) && (Image
== NULL
)) {
373 SPrint(FileName
, 255, L
"%s\\%s.%s", SubdirName
, BaseName
, Extension
);
374 Image
= egLoadIcon(BaseDir
, FileName
, IconSize
);
375 MyFreePool(Extension
);
379 } // EG_IMAGE *egLoadIconAnyType()
381 // Returns an icon with any extension in ICON_EXTENSIONS from either the directory
382 // specified by GlobalConfig.IconsDir or DEFAULT_ICONS_DIR. The input BaseName
383 // should be the icon name without an extension. For instance, if BaseName is
384 // os_linux, GlobalConfig.IconsDir is myicons, DEFAULT_ICONS_DIR is icons, and
385 // ICON_EXTENSIONS is "icns,png", this function will return myicons/os_linux.icns,
386 // myicons/os_linux.png, icons/os_linux.icns, or icons/os_linux.png, in that
387 // order of preference. Returns NULL if no such icon can be found. All file
388 // references are relative to SelfDir.
389 EG_IMAGE
* egFindIcon(IN CHAR16
*BaseName
, IN UINTN IconSize
) {
390 EG_IMAGE
*Image
= NULL
;
392 if (GlobalConfig
.IconsDir
!= NULL
) {
393 Image
= egLoadIconAnyType(SelfDir
, GlobalConfig
.IconsDir
, BaseName
, IconSize
);
397 Image
= egLoadIconAnyType(SelfDir
, DEFAULT_ICONS_DIR
, BaseName
, IconSize
);
401 } // EG_IMAGE * egFindIcon()
403 EG_IMAGE
* egPrepareEmbeddedImage(IN EG_EMBEDDED_IMAGE
*EmbeddedImage
, IN BOOLEAN WantAlpha
)
411 if (EmbeddedImage
->PixelMode
> EG_MAX_EIPIXELMODE
||
412 (EmbeddedImage
->CompressMode
!= EG_EICOMPMODE_NONE
&& EmbeddedImage
->CompressMode
!= EG_EICOMPMODE_RLE
))
415 // allocate image structure and pixel buffer
416 NewImage
= egCreateImage(EmbeddedImage
->Width
, EmbeddedImage
->Height
, WantAlpha
);
417 if (NewImage
== NULL
)
420 CompData
= (UINT8
*)EmbeddedImage
->Data
; // drop const
421 CompLen
= EmbeddedImage
->DataLength
;
422 PixelCount
= EmbeddedImage
->Width
* EmbeddedImage
->Height
;
424 // FUTURE: for EG_EICOMPMODE_EFICOMPRESS, decompress whole data block here
426 if (EmbeddedImage
->PixelMode
== EG_EIPIXELMODE_GRAY
||
427 EmbeddedImage
->PixelMode
== EG_EIPIXELMODE_GRAY_ALPHA
) {
429 // copy grayscale plane and expand
430 if (EmbeddedImage
->CompressMode
== EG_EICOMPMODE_RLE
) {
431 egDecompressIcnsRLE(&CompData
, &CompLen
, PLPTR(NewImage
, r
), PixelCount
);
433 egInsertPlane(CompData
, PLPTR(NewImage
, r
), PixelCount
);
434 CompData
+= PixelCount
;
436 egCopyPlane(PLPTR(NewImage
, r
), PLPTR(NewImage
, g
), PixelCount
);
437 egCopyPlane(PLPTR(NewImage
, r
), PLPTR(NewImage
, b
), PixelCount
);
439 } else if (EmbeddedImage
->PixelMode
== EG_EIPIXELMODE_COLOR
||
440 EmbeddedImage
->PixelMode
== EG_EIPIXELMODE_COLOR_ALPHA
) {
443 if (EmbeddedImage
->CompressMode
== EG_EICOMPMODE_RLE
) {
444 egDecompressIcnsRLE(&CompData
, &CompLen
, PLPTR(NewImage
, r
), PixelCount
);
445 egDecompressIcnsRLE(&CompData
, &CompLen
, PLPTR(NewImage
, g
), PixelCount
);
446 egDecompressIcnsRLE(&CompData
, &CompLen
, PLPTR(NewImage
, b
), PixelCount
);
448 egInsertPlane(CompData
, PLPTR(NewImage
, r
), PixelCount
);
449 CompData
+= PixelCount
;
450 egInsertPlane(CompData
, PLPTR(NewImage
, g
), PixelCount
);
451 CompData
+= PixelCount
;
452 egInsertPlane(CompData
, PLPTR(NewImage
, b
), PixelCount
);
453 CompData
+= PixelCount
;
458 // set color planes to black
459 egSetPlane(PLPTR(NewImage
, r
), 0, PixelCount
);
460 egSetPlane(PLPTR(NewImage
, g
), 0, PixelCount
);
461 egSetPlane(PLPTR(NewImage
, b
), 0, PixelCount
);
465 if (WantAlpha
&& (EmbeddedImage
->PixelMode
== EG_EIPIXELMODE_GRAY_ALPHA
||
466 EmbeddedImage
->PixelMode
== EG_EIPIXELMODE_COLOR_ALPHA
||
467 EmbeddedImage
->PixelMode
== EG_EIPIXELMODE_ALPHA
)) {
470 if (EmbeddedImage
->CompressMode
== EG_EICOMPMODE_RLE
) {
471 egDecompressIcnsRLE(&CompData
, &CompLen
, PLPTR(NewImage
, a
), PixelCount
);
473 egInsertPlane(CompData
, PLPTR(NewImage
, a
), PixelCount
);
474 CompData
+= PixelCount
;
478 egSetPlane(PLPTR(NewImage
, a
), WantAlpha
? 255 : 0, PixelCount
);
488 VOID
egRestrictImageArea(IN EG_IMAGE
*Image
,
489 IN UINTN AreaPosX
, IN UINTN AreaPosY
,
490 IN OUT UINTN
*AreaWidth
, IN OUT UINTN
*AreaHeight
)
492 if (AreaPosX
>= Image
->Width
|| AreaPosY
>= Image
->Height
) {
493 // out of bounds, operation has no effect
497 // calculate affected area
498 if (*AreaWidth
> Image
->Width
- AreaPosX
)
499 *AreaWidth
= Image
->Width
- AreaPosX
;
500 if (*AreaHeight
> Image
->Height
- AreaPosY
)
501 *AreaHeight
= Image
->Height
- AreaPosY
;
505 VOID
egFillImage(IN OUT EG_IMAGE
*CompImage
, IN EG_PIXEL
*Color
)
512 if (!CompImage
->HasAlpha
)
515 PixelPtr
= CompImage
->PixelData
;
516 for (i
= 0; i
< CompImage
->Width
* CompImage
->Height
; i
++, PixelPtr
++)
517 *PixelPtr
= FillColor
;
520 VOID
egFillImageArea(IN OUT EG_IMAGE
*CompImage
,
521 IN UINTN AreaPosX
, IN UINTN AreaPosY
,
522 IN UINTN AreaWidth
, IN UINTN AreaHeight
,
528 EG_PIXEL
*PixelBasePtr
;
530 egRestrictImageArea(CompImage
, AreaPosX
, AreaPosY
, &AreaWidth
, &AreaHeight
);
534 if (!CompImage
->HasAlpha
)
537 PixelBasePtr
= CompImage
->PixelData
+ AreaPosY
* CompImage
->Width
+ AreaPosX
;
538 for (y
= 0; y
< AreaHeight
; y
++) {
539 PixelPtr
= PixelBasePtr
;
540 for (x
= 0; x
< AreaWidth
; x
++, PixelPtr
++)
541 *PixelPtr
= FillColor
;
542 PixelBasePtr
+= CompImage
->Width
;
547 VOID
egRawCopy(IN OUT EG_PIXEL
*CompBasePtr
, IN EG_PIXEL
*TopBasePtr
,
548 IN UINTN Width
, IN UINTN Height
,
549 IN UINTN CompLineOffset
, IN UINTN TopLineOffset
)
552 EG_PIXEL
*TopPtr
, *CompPtr
;
554 for (y
= 0; y
< Height
; y
++) {
556 CompPtr
= CompBasePtr
;
557 for (x
= 0; x
< Width
; x
++) {
561 TopBasePtr
+= TopLineOffset
;
562 CompBasePtr
+= CompLineOffset
;
566 VOID
egRawCompose(IN OUT EG_PIXEL
*CompBasePtr
, IN EG_PIXEL
*TopBasePtr
,
567 IN UINTN Width
, IN UINTN Height
,
568 IN UINTN CompLineOffset
, IN UINTN TopLineOffset
)
571 EG_PIXEL
*TopPtr
, *CompPtr
;
576 for (y
= 0; y
< Height
; y
++) {
578 CompPtr
= CompBasePtr
;
579 for (x
= 0; x
< Width
; x
++) {
581 RevAlpha
= 255 - Alpha
;
582 Temp
= (UINTN
)CompPtr
->b
* RevAlpha
+ (UINTN
)TopPtr
->b
* Alpha
+ 0x80;
583 CompPtr
->b
= (Temp
+ (Temp
>> 8)) >> 8;
584 Temp
= (UINTN
)CompPtr
->g
* RevAlpha
+ (UINTN
)TopPtr
->g
* Alpha
+ 0x80;
585 CompPtr
->g
= (Temp
+ (Temp
>> 8)) >> 8;
586 Temp
= (UINTN
)CompPtr
->r
* RevAlpha
+ (UINTN
)TopPtr
->r
* Alpha
+ 0x80;
587 CompPtr
->r
= (Temp
+ (Temp
>> 8)) >> 8;
589 CompPtr->b = ((UINTN)CompPtr->b * RevAlpha + (UINTN)TopPtr->b * Alpha) / 255;
590 CompPtr->g = ((UINTN)CompPtr->g * RevAlpha + (UINTN)TopPtr->g * Alpha) / 255;
591 CompPtr->r = ((UINTN)CompPtr->r * RevAlpha + (UINTN)TopPtr->r * Alpha) / 255;
595 TopBasePtr
+= TopLineOffset
;
596 CompBasePtr
+= CompLineOffset
;
600 VOID
egComposeImage(IN OUT EG_IMAGE
*CompImage
, IN EG_IMAGE
*TopImage
, IN UINTN PosX
, IN UINTN PosY
)
602 UINTN CompWidth
, CompHeight
;
604 CompWidth
= TopImage
->Width
;
605 CompHeight
= TopImage
->Height
;
606 egRestrictImageArea(CompImage
, PosX
, PosY
, &CompWidth
, &CompHeight
);
610 if (TopImage
->HasAlpha
) {
611 egRawCompose(CompImage
->PixelData
+ PosY
* CompImage
->Width
+ PosX
, TopImage
->PixelData
,
612 CompWidth
, CompHeight
, CompImage
->Width
, TopImage
->Width
);
614 egRawCopy(CompImage
->PixelData
+ PosY
* CompImage
->Width
+ PosX
, TopImage
->PixelData
,
615 CompWidth
, CompHeight
, CompImage
->Width
, TopImage
->Width
);
618 } /* VOID egComposeImage() */
620 // EG_IMAGE * egEnsureImageSize(IN EG_IMAGE *Image, IN UINTN Width, IN UINTN Height, IN EG_PIXEL *Color)
622 // EG_IMAGE *NewImage;
624 // if (Image == NULL)
626 // if (Image->Width == Width && Image->Height == Height)
629 // NewImage = egCreateFilledImage(Width, Height, Image->HasAlpha, Color);
630 // if (NewImage == NULL) {
631 // egFreeImage(Image);
634 // Image->HasAlpha = FALSE;
635 // egComposeImage(NewImage, Image, 0, 0);
636 // egFreeImage(Image);
642 // misc internal functions
645 VOID
egInsertPlane(IN UINT8
*SrcDataPtr
, IN UINT8
*DestPlanePtr
, IN UINTN PixelCount
)
649 for (i
= 0; i
< PixelCount
; i
++) {
650 *DestPlanePtr
= *SrcDataPtr
++;
655 VOID
egSetPlane(IN UINT8
*DestPlanePtr
, IN UINT8 Value
, IN UINTN PixelCount
)
659 for (i
= 0; i
< PixelCount
; i
++) {
660 *DestPlanePtr
= Value
;
665 VOID
egCopyPlane(IN UINT8
*SrcPlanePtr
, IN UINT8
*DestPlanePtr
, IN UINTN PixelCount
)
669 for (i
= 0; i
< PixelCount
; i
++) {
670 *DestPlanePtr
= *SrcPlanePtr
;
671 DestPlanePtr
+= 4, SrcPlanePtr
+= 4;