13#include <Library/BaseLib.h>
14#include <Library/MemoryAllocationLib.h>
15#include <Library/DebugLib.h>
49 IN UINT32 IcnsImageSize,
52 IN UINT32 MatchHeight,
65 ASSERT (Scale == 1 || Scale == 2);
74 return EFI_INVALID_PARAMETER;
79 return EFI_SECURITY_VIOLATION;
88 RecordLength = SwapBytes32 (Record->
Size);
97 || BaseOverflowAddU32 (Offset, RecordLength, &Offset)
98 || (Offset > IcnsImageSize))
100 return EFI_SECURITY_VIOLATION;
113 if (!EFI_ERROR (Status) && (MatchWidth > 0) && (MatchHeight > 0)) {
115 ? ( (Image->Width > MatchWidth * Scale) || (Image->Height > MatchWidth * Scale)
116 || (Image->Width == 0) || (Image->Height == 0))
117 : ((Image->Width != MatchWidth * Scale) || (Image->Height != MatchHeight * Scale)))
119 FreePool (Image->Buffer);
122 "OCUI: Expected %dx%d, actual %dx%d, allow less: %d\n",
129 Status = EFI_UNSUPPORTED;
143 if ((RecordT8MK != NULL) && (RecordIT32 != NULL)) {
144 Image->Width = MatchWidth;
145 Image->Height = MatchHeight;
146 ImageSize = (MatchWidth * MatchHeight) *
sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
147 Image->Buffer = AllocateZeroPool (ImageSize);
149 if (Image->Buffer == NULL) {
150 return EFI_OUT_OF_RESOURCES;
157 (UINT8 *)Image->Buffer,
159 RecordIT32->
Data + sizeof (UINT32),
166 if (DecodedBytes != ImageSize) {
167 FreePool (Image->Buffer);
168 return EFI_UNSUPPORTED;
176 return EFI_NOT_FOUND;
183 IN UINT32 DataLength,
192 ASSERT (Scale == 1 || Scale == 2);
195 return EFI_INVALID_PARAMETER;
200 Image->Height = SwapBytes16 (Label->
Height);
204 || (DataLength != sizeof (
APPLE_DISK_LABEL) + Image->Width * Image->Height))
206 DEBUG ((DEBUG_INFO,
"OCUI: Invalid label has %dx%d dims at %u size\n", Image->Width, Image->Height, DataLength));
207 return EFI_SECURITY_VIOLATION;
210 Image->Buffer = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)AllocatePool (
211 Image->Width * Image->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
214 if (Image->Buffer == NULL) {
215 return EFI_OUT_OF_RESOURCES;
219 for (PixelIdx = 0; PixelIdx < Image->Width * Image->Height; PixelIdx++) {
220 Image->Buffer[PixelIdx].Blue = 0;
221 Image->Buffer[PixelIdx].Green = 0;
222 Image->Buffer[PixelIdx].Red = 0;
226 for (PixelIdx = 0; PixelIdx < Image->Width * Image->Height; PixelIdx++) {
241 IN UINTN ImageDataSize,
242 IN BOOLEAN PremultiplyAlpha
246 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BufferWalker;
253 (VOID **)&Image->Buffer,
259 if (EFI_ERROR (Status)) {
260 DEBUG ((DEBUG_INFO,
"OCUI: DecodePNG - %r\n", Status));
264 if (PremultiplyAlpha) {
265 BufferWalker = Image->Buffer;
266 for (Index = 0; Index < (UINTN)Image->Width * Image->Height; ++Index) {
267 TmpChannel = (UINT8)((BufferWalker->Blue * BufferWalker->Reserved) / 0xFF);
268 BufferWalker->Blue = (UINT8)((BufferWalker->Red * BufferWalker->Reserved) / 0xFF);
269 BufferWalker->Green = (UINT8)((BufferWalker->Green * BufferWalker->Reserved) / 0xFF);
270 BufferWalker->Red = TmpChannel;
282 IN CONST EFI_GRAPHICS_OUTPUT_BLT_PIXEL *HighlightPixel
285 EFI_GRAPHICS_OUTPUT_BLT_PIXEL PremulPixel;
287 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *
Buffer;
294 ASSERT (SelectedImage != NULL);
295 ASSERT (SourceImage != NULL);
296 ASSERT (SourceImage->Buffer != NULL);
297 ASSERT (HighlightPixel != NULL);
301 Buffer = AllocateCopyPool (
302 SourceImage->Width * SourceImage->Height * sizeof (*SourceImage->Buffer),
306 return EFI_OUT_OF_RESOURCES;
309 PremulPixel.Blue = (UINT8)((HighlightPixel->Blue * HighlightPixel->Reserved) / 0xFF);
310 PremulPixel.Green = (UINT8)((HighlightPixel->Green * HighlightPixel->Reserved) / 0xFF);
311 PremulPixel.Red = (UINT8)((HighlightPixel->Red * HighlightPixel->Reserved) / 0xFF);
312 PremulPixel.Reserved = HighlightPixel->Reserved;
315 IndexY = 0, RowOffset = 0;
316 IndexY < SourceImage->Height;
317 ++IndexY, RowOffset += SourceImage->Width
323 for (ColumnOffset = 0; ColumnOffset < SourceImage->Width; ++ColumnOffset) {
324 if (SourceImage->Buffer[RowOffset + ColumnOffset].Reserved != 0) {
327 if (FirstUnsetX != 0) {
332 while (FirstUnsetX < ColumnOffset) {
334 &
Buffer[RowOffset + FirstUnsetX],
343 }
else if ((FirstUnsetX == 0) && OneSet) {
344 FirstUnsetX = ColumnOffset;
349 SelectedImage->Width = SourceImage->Width;
350 SelectedImage->Height = SourceImage->Height;
351 SelectedImage->Buffer =
Buffer;
#define APPLE_DISK_LABEL_MAX_WIDTH
#define APPLE_DISK_LABEL_MAX_HEIGHT
struct APPLE_ICNS_RECORD_ APPLE_ICNS_RECORD
VOID GuiBlendPixelSolid(IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackPixel, IN CONST EFI_GRAPHICS_OUTPUT_BLT_PIXEL *FrontPixel)
EFI_STATUS GuiLabelToImage(OUT GUI_IMAGE *Image, IN VOID *RawData, IN UINT32 DataLength, IN UINT8 Scale, IN BOOLEAN Inverted)
EFI_STATUS GuiIcnsToImageIcon(OUT GUI_IMAGE *Image, IN VOID *IcnsImage, IN UINT32 IcnsImageSize, IN UINT8 Scale, IN UINT32 MatchWidth, IN UINT32 MatchHeight, IN BOOLEAN AllowLess)
EFI_STATUS GuiCreateHighlightedImage(OUT GUI_IMAGE *SelectedImage, IN CONST GUI_IMAGE *SourceImage, IN CONST EFI_GRAPHICS_OUTPUT_BLT_PIXEL *HighlightPixel)
EFI_STATUS GuiPngToImage(OUT GUI_IMAGE *Image, IN VOID *ImageData, IN UINTN ImageDataSize, IN BOOLEAN PremultiplyAlpha)
STATIC CONST UINT8 gAppleDiskLabelImagePalette[256]
UINT32 DecompressMaskedRLE24(OUT UINT8 *Dst, IN UINT32 DstLen, IN UINT8 *Src, IN UINT32 SrcLen, IN UINT8 *Mask, IN UINT32 MaskLen, IN BOOLEAN Premultiply)
EFI_STATUS OcDecodePng(IN VOID *Buffer, IN UINTN Size, OUT VOID **RawData, OUT UINT32 *Width, OUT UINT32 *Height, OUT BOOLEAN *HasAlphaType OPTIONAL)
OC_TYPING_BUFFER_ENTRY Buffer[OC_TYPING_BUFFER_SIZE]
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)