]> code.delx.au - refind/blob - libeg/image.c
Fixed bug: ICNS file in main icons directory would override PNG file in
[refind] / libeg / image.c
1 /*
2 * libeg/image.c
3 * Image handling functions
4 *
5 * Copyright (c) 2006 Christoph Pfisterer
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
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
18 * distribution.
19 *
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.
23 *
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.
35 */
36
37 #include "libegint.h"
38 #include "../refind/global.h"
39 #include "../refind/lib.h"
40 #include "../refind/screen.h"
41 #include "../include/refit_call_wrapper.h"
42 #include "lodepng.h"
43
44 #define MAX_FILE_SIZE (1024*1024*1024)
45
46 #ifndef __MAKEWITH_GNUEFI
47 #define LibLocateHandle gBS->LocateHandleBuffer
48 #define LibOpenRoot EfiLibOpenRoot
49 #endif
50
51 //
52 // Basic image handling
53 //
54
55 EG_IMAGE * egCreateImage(IN UINTN Width, IN UINTN Height, IN BOOLEAN HasAlpha)
56 {
57 EG_IMAGE *NewImage;
58
59 NewImage = (EG_IMAGE *) AllocatePool(sizeof(EG_IMAGE));
60 if (NewImage == NULL)
61 return NULL;
62 NewImage->PixelData = (EG_PIXEL *) AllocatePool(Width * Height * sizeof(EG_PIXEL));
63 if (NewImage->PixelData == NULL) {
64 FreePool(NewImage);
65 return NULL;
66 }
67
68 NewImage->Width = Width;
69 NewImage->Height = Height;
70 NewImage->HasAlpha = HasAlpha;
71 return NewImage;
72 }
73
74 EG_IMAGE * egCreateFilledImage(IN UINTN Width, IN UINTN Height, IN BOOLEAN HasAlpha, IN EG_PIXEL *Color)
75 {
76 EG_IMAGE *NewImage;
77
78 NewImage = egCreateImage(Width, Height, HasAlpha);
79 if (NewImage == NULL)
80 return NULL;
81
82 egFillImage(NewImage, Color);
83 return NewImage;
84 }
85
86 EG_IMAGE * egCopyImage(IN EG_IMAGE *Image)
87 {
88 EG_IMAGE *NewImage;
89
90 NewImage = egCreateImage(Image->Width, Image->Height, Image->HasAlpha);
91 if (NewImage == NULL)
92 return NULL;
93
94 CopyMem(NewImage->PixelData, Image->PixelData, Image->Width * Image->Height * sizeof(EG_PIXEL));
95 return NewImage;
96 }
97
98 // Returns a smaller image composed of the specified crop area from the larger area.
99 // If the specified area is larger than is in the original, returns NULL.
100 EG_IMAGE * egCropImage(IN EG_IMAGE *Image, IN UINTN StartX, IN UINTN StartY, IN UINTN Width, IN UINTN Height) {
101 EG_IMAGE *NewImage = NULL;
102 UINTN x, y;
103
104 if (((StartX + Width) > Image->Width) || ((StartY + Height) > Image->Height))
105 return NULL;
106
107 NewImage = egCreateImage(Width, Height, Image->HasAlpha);
108 if (NewImage == NULL)
109 return NULL;
110
111 for (y = 0; y < Height; y++) {
112 for (x = 0; x < Width; x++) {
113 NewImage->PixelData[y * NewImage->Width + x] = Image->PixelData[(y + StartY) * Image->Width + x + StartX];
114 }
115 }
116 return NewImage;
117 } // EG_IMAGE * egCropImage()
118
119 VOID egFreeImage(IN EG_IMAGE *Image)
120 {
121 if (Image != NULL) {
122 if (Image->PixelData != NULL)
123 FreePool(Image->PixelData);
124 FreePool(Image);
125 }
126 }
127
128 //
129 // Basic file operations
130 //
131
132 EFI_STATUS egLoadFile(IN EFI_FILE* BaseDir, IN CHAR16 *FileName, OUT UINT8 **FileData, OUT UINTN *FileDataLength)
133 {
134 EFI_STATUS Status;
135 EFI_FILE_HANDLE FileHandle;
136 EFI_FILE_INFO *FileInfo;
137 UINT64 ReadSize;
138 UINTN BufferSize;
139 UINT8 *Buffer;
140
141 Status = refit_call5_wrapper(BaseDir->Open, BaseDir, &FileHandle, FileName, EFI_FILE_MODE_READ, 0);
142 if (EFI_ERROR(Status)) {
143 return Status;
144 }
145
146 FileInfo = LibFileInfo(FileHandle);
147 if (FileInfo == NULL) {
148 refit_call1_wrapper(FileHandle->Close, FileHandle);
149 return EFI_NOT_FOUND;
150 }
151 ReadSize = FileInfo->FileSize;
152 if (ReadSize > MAX_FILE_SIZE)
153 ReadSize = MAX_FILE_SIZE;
154 FreePool(FileInfo);
155
156 BufferSize = (UINTN)ReadSize; // was limited to 1 GB above, so this is safe
157 Buffer = (UINT8 *) AllocatePool(BufferSize);
158 if (Buffer == NULL) {
159 refit_call1_wrapper(FileHandle->Close, FileHandle);
160 return EFI_OUT_OF_RESOURCES;
161 }
162
163 Status = refit_call3_wrapper(FileHandle->Read, FileHandle, &BufferSize, Buffer);
164 refit_call1_wrapper(FileHandle->Close, FileHandle);
165 if (EFI_ERROR(Status)) {
166 FreePool(Buffer);
167 return Status;
168 }
169
170 *FileData = Buffer;
171 *FileDataLength = BufferSize;
172 return EFI_SUCCESS;
173 }
174
175 static EFI_GUID ESPGuid = { 0xc12a7328, 0xf81f, 0x11d2, { 0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b } };
176
177 static EFI_STATUS egFindESP(OUT EFI_FILE_HANDLE *RootDir)
178 {
179 EFI_STATUS Status;
180 UINTN HandleCount = 0;
181 EFI_HANDLE *Handles;
182
183 Status = LibLocateHandle(ByProtocol, &ESPGuid, NULL, &HandleCount, &Handles);
184 if (!EFI_ERROR(Status) && HandleCount > 0) {
185 *RootDir = LibOpenRoot(Handles[0]);
186 if (*RootDir == NULL)
187 Status = EFI_NOT_FOUND;
188 FreePool(Handles);
189 }
190 return Status;
191 }
192
193 EFI_STATUS egSaveFile(IN EFI_FILE* BaseDir OPTIONAL, IN CHAR16 *FileName,
194 IN UINT8 *FileData, IN UINTN FileDataLength)
195 {
196 EFI_STATUS Status;
197 EFI_FILE_HANDLE FileHandle;
198 UINTN BufferSize;
199
200 if (BaseDir == NULL) {
201 Status = egFindESP(&BaseDir);
202 if (EFI_ERROR(Status))
203 return Status;
204 }
205
206 Status = refit_call5_wrapper(BaseDir->Open, BaseDir, &FileHandle, FileName,
207 EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0);
208 if (EFI_ERROR(Status))
209 return Status;
210
211 BufferSize = FileDataLength;
212 Status = refit_call3_wrapper(FileHandle->Write, FileHandle, &BufferSize, FileData);
213 refit_call1_wrapper(FileHandle->Close, FileHandle);
214
215 return Status;
216 }
217
218 //
219 // Loading images from files and embedded data
220 //
221
222 // Decode the specified image data. The IconSize parameter is relevant only
223 // for ICNS, for which it selects which ICNS sub-image is decoded.
224 // Returns a pointer to the resulting EG_IMAGE or NULL if decoding failed.
225 static EG_IMAGE * egDecodeAny(IN UINT8 *FileData, IN UINTN FileDataLength, IN UINTN IconSize, IN BOOLEAN WantAlpha)
226 {
227 EG_IMAGE *NewImage = NULL;
228
229 NewImage = egDecodeICNS(FileData, FileDataLength, IconSize, WantAlpha);
230 if (NewImage == NULL)
231 NewImage = egDecodePNG(FileData, FileDataLength, IconSize, WantAlpha);
232 if (NewImage == NULL)
233 NewImage = egDecodeBMP(FileData, FileDataLength, IconSize, WantAlpha);
234
235 return NewImage;
236 }
237
238 EG_IMAGE * egLoadImage(IN EFI_FILE* BaseDir, IN CHAR16 *FileName, IN BOOLEAN WantAlpha)
239 {
240 EFI_STATUS Status;
241 UINT8 *FileData;
242 UINTN FileDataLength;
243 EG_IMAGE *NewImage;
244
245 if (BaseDir == NULL || FileName == NULL)
246 return NULL;
247
248 // load file
249 Status = egLoadFile(BaseDir, FileName, &FileData, &FileDataLength);
250 if (EFI_ERROR(Status))
251 return NULL;
252
253 // decode it
254 NewImage = egDecodeAny(FileData, FileDataLength, 128, WantAlpha);
255 FreePool(FileData);
256
257 return NewImage;
258 }
259
260 // Load an icon from (BaseDir)/Path, extracting the icon of size IconSize x IconSize.
261 // Returns a pointer to the image data, or NULL if the icon could not be loaded.
262 EG_IMAGE * egLoadIcon(IN EFI_FILE* BaseDir, IN CHAR16 *Path, IN UINTN IconSize)
263 {
264 EFI_STATUS Status;
265 UINT8 *FileData;
266 UINTN FileDataLength;
267 EG_IMAGE *NewImage;
268
269 if (BaseDir == NULL || Path == NULL)
270 return NULL;
271
272 // load file
273 Status = egLoadFile(BaseDir, Path, &FileData, &FileDataLength);
274 if (EFI_ERROR(Status))
275 return NULL;
276
277 // decode it
278 NewImage = egDecodeAny(FileData, FileDataLength, IconSize, TRUE);
279 FreePool(FileData);
280 if ((NewImage->Width != IconSize) || (NewImage->Height != IconSize)) {
281 Print(L"Warning: Attempt to load icon of the wrong size from '%s'\n", Path);
282 MyFreePool(NewImage);
283 NewImage = NULL;
284 }
285
286 return NewImage;
287 } // EG_IMAGE *egLoadIcon()
288
289 // Returns an icon with any extension in ICON_EXTENSIONS from either the directory
290 // specified by GlobalConfig.IconsDir or DEFAULT_ICONS_DIR. The input BaseName
291 // should be the icon name without an extension. For instance, if BaseName is
292 // os_linux, GlobalConfig.IconsDir is myicons, DEFAULT_ICONS_DIR is icons, and
293 // ICON_EXTENSIONS is "icns,png", this function will return myicons/os_linux.icns,
294 // myicons/os_linux.png, icons/os_linux.icns, or icons/os_linux.png, in that
295 // order of preference. Returns NULL if no such icon can be found. All file
296 // references are relative to SelfDir.
297 EG_IMAGE * egFindIcon(IN CHAR16 *BaseName, IN UINTN IconSize) {
298 CHAR16 *LoadDir, *Extension;
299 CHAR16 FileName[256];
300 UINTN i;
301 EG_IMAGE *Image = NULL;
302
303 if (GlobalConfig.IconsDir != NULL)
304 LoadDir = GlobalConfig.IconsDir;
305 else
306 LoadDir = StrDuplicate(DEFAULT_ICONS_DIR);
307
308 while ((LoadDir != NULL) && (Image == NULL)) {
309 i = 0;
310 while (((Extension = FindCommaDelimited(ICON_EXTENSIONS, i++)) != NULL) && (Image == NULL)) {
311 SPrint(FileName, 255, L"%s\\%s.%s", LoadDir, BaseName, Extension);
312 Image = egLoadIcon(SelfDir, FileName, IconSize);
313 MyFreePool(Extension);
314 } // while()
315 if (LoadDir == GlobalConfig.IconsDir) {
316 LoadDir = StrDuplicate(DEFAULT_ICONS_DIR);
317 } else {
318 MyFreePool(LoadDir);
319 LoadDir = NULL;
320 } // if/else
321 } // while()
322 return Image;
323 } // EG_IMAGE * egFindIcon()
324
325 EG_IMAGE * egPrepareEmbeddedImage(IN EG_EMBEDDED_IMAGE *EmbeddedImage, IN BOOLEAN WantAlpha)
326 {
327 EG_IMAGE *NewImage;
328 UINT8 *CompData;
329 UINTN CompLen;
330 UINTN PixelCount;
331
332 // sanity check
333 if (EmbeddedImage->PixelMode > EG_MAX_EIPIXELMODE ||
334 (EmbeddedImage->CompressMode != EG_EICOMPMODE_NONE && EmbeddedImage->CompressMode != EG_EICOMPMODE_RLE))
335 return NULL;
336
337 // allocate image structure and pixel buffer
338 NewImage = egCreateImage(EmbeddedImage->Width, EmbeddedImage->Height, WantAlpha);
339 if (NewImage == NULL)
340 return NULL;
341
342 CompData = (UINT8 *)EmbeddedImage->Data; // drop const
343 CompLen = EmbeddedImage->DataLength;
344 PixelCount = EmbeddedImage->Width * EmbeddedImage->Height;
345
346 // FUTURE: for EG_EICOMPMODE_EFICOMPRESS, decompress whole data block here
347
348 if (EmbeddedImage->PixelMode == EG_EIPIXELMODE_GRAY ||
349 EmbeddedImage->PixelMode == EG_EIPIXELMODE_GRAY_ALPHA) {
350
351 // copy grayscale plane and expand
352 if (EmbeddedImage->CompressMode == EG_EICOMPMODE_RLE) {
353 egDecompressIcnsRLE(&CompData, &CompLen, PLPTR(NewImage, r), PixelCount);
354 } else {
355 egInsertPlane(CompData, PLPTR(NewImage, r), PixelCount);
356 CompData += PixelCount;
357 }
358 egCopyPlane(PLPTR(NewImage, r), PLPTR(NewImage, g), PixelCount);
359 egCopyPlane(PLPTR(NewImage, r), PLPTR(NewImage, b), PixelCount);
360
361 } else if (EmbeddedImage->PixelMode == EG_EIPIXELMODE_COLOR ||
362 EmbeddedImage->PixelMode == EG_EIPIXELMODE_COLOR_ALPHA) {
363
364 // copy color planes
365 if (EmbeddedImage->CompressMode == EG_EICOMPMODE_RLE) {
366 egDecompressIcnsRLE(&CompData, &CompLen, PLPTR(NewImage, r), PixelCount);
367 egDecompressIcnsRLE(&CompData, &CompLen, PLPTR(NewImage, g), PixelCount);
368 egDecompressIcnsRLE(&CompData, &CompLen, PLPTR(NewImage, b), PixelCount);
369 } else {
370 egInsertPlane(CompData, PLPTR(NewImage, r), PixelCount);
371 CompData += PixelCount;
372 egInsertPlane(CompData, PLPTR(NewImage, g), PixelCount);
373 CompData += PixelCount;
374 egInsertPlane(CompData, PLPTR(NewImage, b), PixelCount);
375 CompData += PixelCount;
376 }
377
378 } else {
379
380 // set color planes to black
381 egSetPlane(PLPTR(NewImage, r), 0, PixelCount);
382 egSetPlane(PLPTR(NewImage, g), 0, PixelCount);
383 egSetPlane(PLPTR(NewImage, b), 0, PixelCount);
384
385 }
386
387 if (WantAlpha && (EmbeddedImage->PixelMode == EG_EIPIXELMODE_GRAY_ALPHA ||
388 EmbeddedImage->PixelMode == EG_EIPIXELMODE_COLOR_ALPHA ||
389 EmbeddedImage->PixelMode == EG_EIPIXELMODE_ALPHA)) {
390
391 // copy alpha plane
392 if (EmbeddedImage->CompressMode == EG_EICOMPMODE_RLE) {
393 egDecompressIcnsRLE(&CompData, &CompLen, PLPTR(NewImage, a), PixelCount);
394 } else {
395 egInsertPlane(CompData, PLPTR(NewImage, a), PixelCount);
396 CompData += PixelCount;
397 }
398
399 } else {
400 egSetPlane(PLPTR(NewImage, a), WantAlpha ? 255 : 0, PixelCount);
401 }
402
403 return NewImage;
404 }
405
406 //
407 // Compositing
408 //
409
410 VOID egRestrictImageArea(IN EG_IMAGE *Image,
411 IN UINTN AreaPosX, IN UINTN AreaPosY,
412 IN OUT UINTN *AreaWidth, IN OUT UINTN *AreaHeight)
413 {
414 if (AreaPosX >= Image->Width || AreaPosY >= Image->Height) {
415 // out of bounds, operation has no effect
416 *AreaWidth = 0;
417 *AreaHeight = 0;
418 } else {
419 // calculate affected area
420 if (*AreaWidth > Image->Width - AreaPosX)
421 *AreaWidth = Image->Width - AreaPosX;
422 if (*AreaHeight > Image->Height - AreaPosY)
423 *AreaHeight = Image->Height - AreaPosY;
424 }
425 }
426
427 VOID egFillImage(IN OUT EG_IMAGE *CompImage, IN EG_PIXEL *Color)
428 {
429 UINTN i;
430 EG_PIXEL FillColor;
431 EG_PIXEL *PixelPtr;
432
433 FillColor = *Color;
434 if (!CompImage->HasAlpha)
435 FillColor.a = 0;
436
437 PixelPtr = CompImage->PixelData;
438 for (i = 0; i < CompImage->Width * CompImage->Height; i++, PixelPtr++)
439 *PixelPtr = FillColor;
440 }
441
442 VOID egFillImageArea(IN OUT EG_IMAGE *CompImage,
443 IN UINTN AreaPosX, IN UINTN AreaPosY,
444 IN UINTN AreaWidth, IN UINTN AreaHeight,
445 IN EG_PIXEL *Color)
446 {
447 UINTN x, y;
448 EG_PIXEL FillColor;
449 EG_PIXEL *PixelPtr;
450 EG_PIXEL *PixelBasePtr;
451
452 egRestrictImageArea(CompImage, AreaPosX, AreaPosY, &AreaWidth, &AreaHeight);
453
454 if (AreaWidth > 0) {
455 FillColor = *Color;
456 if (!CompImage->HasAlpha)
457 FillColor.a = 0;
458
459 PixelBasePtr = CompImage->PixelData + AreaPosY * CompImage->Width + AreaPosX;
460 for (y = 0; y < AreaHeight; y++) {
461 PixelPtr = PixelBasePtr;
462 for (x = 0; x < AreaWidth; x++, PixelPtr++)
463 *PixelPtr = FillColor;
464 PixelBasePtr += CompImage->Width;
465 }
466 }
467 }
468
469 VOID egRawCopy(IN OUT EG_PIXEL *CompBasePtr, IN EG_PIXEL *TopBasePtr,
470 IN UINTN Width, IN UINTN Height,
471 IN UINTN CompLineOffset, IN UINTN TopLineOffset)
472 {
473 UINTN x, y;
474 EG_PIXEL *TopPtr, *CompPtr;
475
476 for (y = 0; y < Height; y++) {
477 TopPtr = TopBasePtr;
478 CompPtr = CompBasePtr;
479 for (x = 0; x < Width; x++) {
480 *CompPtr = *TopPtr;
481 TopPtr++, CompPtr++;
482 }
483 TopBasePtr += TopLineOffset;
484 CompBasePtr += CompLineOffset;
485 }
486 }
487
488 VOID egRawCompose(IN OUT EG_PIXEL *CompBasePtr, IN EG_PIXEL *TopBasePtr,
489 IN UINTN Width, IN UINTN Height,
490 IN UINTN CompLineOffset, IN UINTN TopLineOffset)
491 {
492 UINTN x, y;
493 EG_PIXEL *TopPtr, *CompPtr;
494 UINTN Alpha;
495 UINTN RevAlpha;
496 UINTN Temp;
497
498 for (y = 0; y < Height; y++) {
499 TopPtr = TopBasePtr;
500 CompPtr = CompBasePtr;
501 for (x = 0; x < Width; x++) {
502 Alpha = TopPtr->a;
503 RevAlpha = 255 - Alpha;
504 Temp = (UINTN)CompPtr->b * RevAlpha + (UINTN)TopPtr->b * Alpha + 0x80;
505 CompPtr->b = (Temp + (Temp >> 8)) >> 8;
506 Temp = (UINTN)CompPtr->g * RevAlpha + (UINTN)TopPtr->g * Alpha + 0x80;
507 CompPtr->g = (Temp + (Temp >> 8)) >> 8;
508 Temp = (UINTN)CompPtr->r * RevAlpha + (UINTN)TopPtr->r * Alpha + 0x80;
509 CompPtr->r = (Temp + (Temp >> 8)) >> 8;
510 /*
511 CompPtr->b = ((UINTN)CompPtr->b * RevAlpha + (UINTN)TopPtr->b * Alpha) / 255;
512 CompPtr->g = ((UINTN)CompPtr->g * RevAlpha + (UINTN)TopPtr->g * Alpha) / 255;
513 CompPtr->r = ((UINTN)CompPtr->r * RevAlpha + (UINTN)TopPtr->r * Alpha) / 255;
514 */
515 TopPtr++, CompPtr++;
516 }
517 TopBasePtr += TopLineOffset;
518 CompBasePtr += CompLineOffset;
519 }
520 }
521
522 VOID egComposeImage(IN OUT EG_IMAGE *CompImage, IN EG_IMAGE *TopImage, IN UINTN PosX, IN UINTN PosY)
523 {
524 UINTN CompWidth, CompHeight;
525
526 CompWidth = TopImage->Width;
527 CompHeight = TopImage->Height;
528 egRestrictImageArea(CompImage, PosX, PosY, &CompWidth, &CompHeight);
529
530 // compose
531 if (CompWidth > 0) {
532 if (TopImage->HasAlpha) {
533 egRawCompose(CompImage->PixelData + PosY * CompImage->Width + PosX, TopImage->PixelData,
534 CompWidth, CompHeight, CompImage->Width, TopImage->Width);
535 } else {
536 egRawCopy(CompImage->PixelData + PosY * CompImage->Width + PosX, TopImage->PixelData,
537 CompWidth, CompHeight, CompImage->Width, TopImage->Width);
538 }
539 }
540 } /* VOID egComposeImage() */
541
542 EG_IMAGE * egEnsureImageSize(IN EG_IMAGE *Image, IN UINTN Width, IN UINTN Height, IN EG_PIXEL *Color)
543 {
544 EG_IMAGE *NewImage;
545
546 if (Image == NULL)
547 return NULL;
548 if (Image->Width == Width && Image->Height == Height)
549 return Image;
550
551 NewImage = egCreateFilledImage(Width, Height, Image->HasAlpha, Color);
552 if (NewImage == NULL) {
553 egFreeImage(Image);
554 return NULL;
555 }
556 Image->HasAlpha = FALSE;
557 egComposeImage(NewImage, Image, 0, 0);
558 egFreeImage(Image);
559
560 return NewImage;
561 }
562
563 //
564 // misc internal functions
565 //
566
567 VOID egInsertPlane(IN UINT8 *SrcDataPtr, IN UINT8 *DestPlanePtr, IN UINTN PixelCount)
568 {
569 UINTN i;
570
571 for (i = 0; i < PixelCount; i++) {
572 *DestPlanePtr = *SrcDataPtr++;
573 DestPlanePtr += 4;
574 }
575 }
576
577 VOID egSetPlane(IN UINT8 *DestPlanePtr, IN UINT8 Value, IN UINTN PixelCount)
578 {
579 UINTN i;
580
581 for (i = 0; i < PixelCount; i++) {
582 *DestPlanePtr = Value;
583 DestPlanePtr += 4;
584 }
585 }
586
587 VOID egCopyPlane(IN UINT8 *SrcPlanePtr, IN UINT8 *DestPlanePtr, IN UINTN PixelCount)
588 {
589 UINTN i;
590
591 for (i = 0; i < PixelCount; i++) {
592 *DestPlanePtr = *SrcPlanePtr;
593 DestPlanePtr += 4, SrcPlanePtr += 4;
594 }
595 }
596
597 /* EOF */