From: srs5694 Date: Sun, 25 Mar 2012 23:13:05 +0000 (-0400) Subject: Added icons and libeg files X-Git-Url: https://code.delx.au/refind/commitdiff_plain/e22f7ac1eccb5958dd960e157d0f35606f7db26e Added icons and libeg files --- diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f596309 --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +# Makefile for rEFInd +CC=gcc +CXX=g++ +CXXFLAGS=-O2 -fpic -D_REENTRANT -D_GNU_SOURCE -Wall -g +NAMES=prefit +SRCS=$(NAMES:=.c) +OBJS=$(NAMES:=.o) +HEADERS=$(NAMES:=.h) +LOADER_DIR=refind +LIB_DIR=libeg + +# Build the Symbiote library itself. +all: + make -C $(LIB_DIR) -j 6 + make -C $(LOADER_DIR) -j 6 + +clean: + make -C $(LIB_DIR) clean + make -C $(LOADER_DIR) clean +# DO NOT DELETE diff --git a/Makefile.bak b/Makefile.bak new file mode 100644 index 0000000..f596309 --- /dev/null +++ b/Makefile.bak @@ -0,0 +1,20 @@ +# Makefile for rEFInd +CC=gcc +CXX=g++ +CXXFLAGS=-O2 -fpic -D_REENTRANT -D_GNU_SOURCE -Wall -g +NAMES=prefit +SRCS=$(NAMES:=.c) +OBJS=$(NAMES:=.o) +HEADERS=$(NAMES:=.h) +LOADER_DIR=refind +LIB_DIR=libeg + +# Build the Symbiote library itself. +all: + make -C $(LIB_DIR) -j 6 + make -C $(LOADER_DIR) -j 6 + +clean: + make -C $(LIB_DIR) clean + make -C $(LOADER_DIR) clean +# DO NOT DELETE diff --git a/icons/arrow_left.icns b/icons/arrow_left.icns new file mode 100644 index 0000000..3bfaa22 Binary files /dev/null and b/icons/arrow_left.icns differ diff --git a/icons/arrow_right.icns b/icons/arrow_right.icns new file mode 100644 index 0000000..734ce47 Binary files /dev/null and b/icons/arrow_right.icns differ diff --git a/icons/boot_linux.icns b/icons/boot_linux.icns new file mode 100644 index 0000000..609edf7 Binary files /dev/null and b/icons/boot_linux.icns differ diff --git a/icons/boot_win.icns b/icons/boot_win.icns new file mode 100644 index 0000000..a1cc87d Binary files /dev/null and b/icons/boot_win.icns differ diff --git a/icons/func_about.icns b/icons/func_about.icns new file mode 100644 index 0000000..12559f8 Binary files /dev/null and b/icons/func_about.icns differ diff --git a/icons/func_reset.icns b/icons/func_reset.icns new file mode 100644 index 0000000..a674542 Binary files /dev/null and b/icons/func_reset.icns differ diff --git a/icons/func_shutdown.icns b/icons/func_shutdown.icns new file mode 100644 index 0000000..7aeb3d5 Binary files /dev/null and b/icons/func_shutdown.icns differ diff --git a/icons/os_centos.icns b/icons/os_centos.icns new file mode 100644 index 0000000..096d632 Binary files /dev/null and b/icons/os_centos.icns differ diff --git a/icons/os_debian.icns b/icons/os_debian.icns new file mode 100644 index 0000000..c18debd Binary files /dev/null and b/icons/os_debian.icns differ diff --git a/icons/os_ecomstation.icns b/icons/os_ecomstation.icns new file mode 100644 index 0000000..9b1b121 Binary files /dev/null and b/icons/os_ecomstation.icns differ diff --git a/icons/os_fedora.icns b/icons/os_fedora.icns new file mode 100644 index 0000000..627124c Binary files /dev/null and b/icons/os_fedora.icns differ diff --git a/icons/os_freebsd.icns b/icons/os_freebsd.icns new file mode 100644 index 0000000..77a0ba6 Binary files /dev/null and b/icons/os_freebsd.icns differ diff --git a/icons/os_freedos.icns b/icons/os_freedos.icns new file mode 100644 index 0000000..6465496 Binary files /dev/null and b/icons/os_freedos.icns differ diff --git a/icons/os_gentoo.icns b/icons/os_gentoo.icns new file mode 100644 index 0000000..8cb4a11 Binary files /dev/null and b/icons/os_gentoo.icns differ diff --git a/icons/os_hwtest.icns b/icons/os_hwtest.icns new file mode 100644 index 0000000..27113de Binary files /dev/null and b/icons/os_hwtest.icns differ diff --git a/icons/os_legacy.icns b/icons/os_legacy.icns new file mode 100644 index 0000000..f3025bb Binary files /dev/null and b/icons/os_legacy.icns differ diff --git a/icons/os_linux.icns b/icons/os_linux.icns new file mode 100644 index 0000000..6d1dad9 Binary files /dev/null and b/icons/os_linux.icns differ diff --git a/icons/os_mac.icns b/icons/os_mac.icns new file mode 100644 index 0000000..11f76c9 Binary files /dev/null and b/icons/os_mac.icns differ diff --git a/icons/os_mandriva.icns b/icons/os_mandriva.icns new file mode 100644 index 0000000..1c0d20a Binary files /dev/null and b/icons/os_mandriva.icns differ diff --git a/icons/os_mint.icns b/icons/os_mint.icns new file mode 100644 index 0000000..e0a5a72 Binary files /dev/null and b/icons/os_mint.icns differ diff --git a/icons/os_netbsd.icns b/icons/os_netbsd.icns new file mode 100644 index 0000000..ab1e7ba Binary files /dev/null and b/icons/os_netbsd.icns differ diff --git a/icons/os_openbsd.icns b/icons/os_openbsd.icns new file mode 100644 index 0000000..73ed6aa Binary files /dev/null and b/icons/os_openbsd.icns differ diff --git a/icons/os_redhat.icns b/icons/os_redhat.icns new file mode 100644 index 0000000..fa55388 Binary files /dev/null and b/icons/os_redhat.icns differ diff --git a/icons/os_refit.icns b/icons/os_refit.icns new file mode 100644 index 0000000..16ec814 Binary files /dev/null and b/icons/os_refit.icns differ diff --git a/icons/os_slackware.icns b/icons/os_slackware.icns new file mode 100644 index 0000000..24363b6 Binary files /dev/null and b/icons/os_slackware.icns differ diff --git a/icons/os_suse.icns b/icons/os_suse.icns new file mode 100644 index 0000000..a5165e8 Binary files /dev/null and b/icons/os_suse.icns differ diff --git a/icons/os_ubuntu.icns b/icons/os_ubuntu.icns new file mode 100644 index 0000000..36eea1b Binary files /dev/null and b/icons/os_ubuntu.icns differ diff --git a/icons/os_unknown.icns b/icons/os_unknown.icns new file mode 100644 index 0000000..46f06ba Binary files /dev/null and b/icons/os_unknown.icns differ diff --git a/icons/os_win.icns b/icons/os_win.icns new file mode 100644 index 0000000..ca89519 Binary files /dev/null and b/icons/os_win.icns differ diff --git a/icons/tool_part.icns b/icons/tool_part.icns new file mode 100644 index 0000000..a542b53 Binary files /dev/null and b/icons/tool_part.icns differ diff --git a/icons/tool_rescue.icns b/icons/tool_rescue.icns new file mode 100644 index 0000000..8f7b2c2 Binary files /dev/null and b/icons/tool_rescue.icns differ diff --git a/icons/tool_shell.icns b/icons/tool_shell.icns new file mode 100644 index 0000000..916f7ac Binary files /dev/null and b/icons/tool_shell.icns differ diff --git a/icons/vol_external.icns b/icons/vol_external.icns new file mode 100644 index 0000000..f1cc9cf Binary files /dev/null and b/icons/vol_external.icns differ diff --git a/icons/vol_internal.icns b/icons/vol_internal.icns new file mode 100644 index 0000000..790b2b4 Binary files /dev/null and b/icons/vol_internal.icns differ diff --git a/icons/vol_optical.icns b/icons/vol_optical.icns new file mode 100644 index 0000000..13e25f5 Binary files /dev/null and b/icons/vol_optical.icns differ diff --git a/libeg/Makefile b/libeg/Makefile new file mode 100644 index 0000000..73c46db --- /dev/null +++ b/libeg/Makefile @@ -0,0 +1,19 @@ +# +# libeg/Makefile +# Build control file for the libeg library +# + +SRCDIR = . + +VPATH = $(SRCDIR) + +LOCAL_CPPFLAGS = -I$(SRCDIR) -I$(SRCDIR)/../include + +OBJS = screen.o image.o text.o load_bmp.o load_icns.o +TARGET = libeg.a + +all: $(TARGET) + +include $(SRCDIR)/../Make.common + +# EOF diff --git a/libeg/efiConsoleControl.h b/libeg/efiConsoleControl.h new file mode 100644 index 0000000..187f562 --- /dev/null +++ b/libeg/efiConsoleControl.h @@ -0,0 +1,121 @@ +/*++ + +Copyright (c) 2004, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + + ConsoleControl.h + +Abstract: + + Abstraction of a Text mode or UGA screen + +--*/ + +#ifndef __CONSOLE_CONTROL_H__ +#define __CONSOLE_CONTROL_H__ + +#define EFI_CONSOLE_CONTROL_PROTOCOL_GUID \ + { 0xf42f7782, 0x12e, 0x4c12, { 0x99, 0x56, 0x49, 0xf9, 0x43, 0x4, 0xf7, 0x21 } } + +struct _EFI_CONSOLE_CONTROL_PROTOCOL; + + +typedef enum { + EfiConsoleControlScreenText, + EfiConsoleControlScreenGraphics, + EfiConsoleControlScreenMaxValue +} EFI_CONSOLE_CONTROL_SCREEN_MODE; + + +typedef +EFI_STATUS +(EFIAPI *EFI_CONSOLE_CONTROL_PROTOCOL_GET_MODE) ( + IN struct _EFI_CONSOLE_CONTROL_PROTOCOL *This, + OUT EFI_CONSOLE_CONTROL_SCREEN_MODE *Mode, + OUT BOOLEAN *UgaExists, OPTIONAL + OUT BOOLEAN *StdInLocked OPTIONAL + ) +/*++ + + Routine Description: + Return the current video mode information. Also returns info about existence + of UGA Draw devices in system, and if the Std In device is locked. All the + arguments are optional and only returned if a non NULL pointer is passed in. + + Arguments: + This - Protocol instance pointer. + Mode - Are we in text of grahics mode. + UgaExists - TRUE if UGA Spliter has found a UGA device + StdInLocked - TRUE if StdIn device is keyboard locked + + Returns: + EFI_SUCCESS - Mode information returned. + +--*/ +; + + +typedef +EFI_STATUS +(EFIAPI *EFI_CONSOLE_CONTROL_PROTOCOL_SET_MODE) ( + IN struct _EFI_CONSOLE_CONTROL_PROTOCOL *This, + OUT EFI_CONSOLE_CONTROL_SCREEN_MODE Mode + ) +/*++ + + Routine Description: + Set the current mode to either text or graphics. Graphics is + for Quiet Boot. + + Arguments: + This - Protocol instance pointer. + Mode - Mode to set the + + Returns: + EFI_SUCCESS - Mode information returned. + +--*/ +; + + +typedef +EFI_STATUS +(EFIAPI *EFI_CONSOLE_CONTROL_PROTOCOL_LOCK_STD_IN) ( + IN struct _EFI_CONSOLE_CONTROL_PROTOCOL *This, + IN CHAR16 *Password + ) +/*++ + + Routine Description: + Lock Std In devices until Password is typed. + + Arguments: + This - Protocol instance pointer. + Password - Password needed to unlock screen. NULL means unlock keyboard + + Returns: + EFI_SUCCESS - Mode information returned. + EFI_DEVICE_ERROR - Std In not locked + +--*/ +; + + + +typedef struct _EFI_CONSOLE_CONTROL_PROTOCOL { + EFI_CONSOLE_CONTROL_PROTOCOL_GET_MODE GetMode; + EFI_CONSOLE_CONTROL_PROTOCOL_SET_MODE SetMode; + EFI_CONSOLE_CONTROL_PROTOCOL_LOCK_STD_IN LockStdIn; +} EFI_CONSOLE_CONTROL_PROTOCOL; + +//extern EFI_GUID gEfiConsoleControlProtocolGuid; + +#endif diff --git a/libeg/efiGraphicsOutput.h b/libeg/efiGraphicsOutput.h new file mode 100644 index 0000000..7f80094 --- /dev/null +++ b/libeg/efiGraphicsOutput.h @@ -0,0 +1,207 @@ +/*++ + +Copyright (c) 2006, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + + GraphicsOutput.h + +Abstract: + + Graphics Output Protocol from the UEFI 2.0 specification. + + Abstraction of a very simple graphics device. + +--*/ + +#ifndef __GRAPHICS_OUTPUT_H__ +#define __GRAPHICS_OUTPUT_H__ + +#include + +#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \ + { \ + 0x9042a9de, 0x23dc, 0x4a38, 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a \ + } + +/* typedef struct _EFI_GRAPHICS_OUTPUT_PROTOCOL EFI_GRAPHICS_OUTPUT_PROTOCOL; */ +struct _EFI_GRAPHICS_OUTPUT_PROTOCOL; + +typedef struct { + UINT32 RedMask; + UINT32 GreenMask; + UINT32 BlueMask; + UINT32 ReservedMask; +} EFI_PIXEL_BITMASK; + +typedef enum { + PixelRedGreenBlueReserved8BitPerColor, + PixelBlueGreenRedReserved8BitPerColor, + PixelBitMask, + PixelBltOnly, + PixelFormatMax +} EFI_GRAPHICS_PIXEL_FORMAT; + +typedef struct { + UINT32 Version; + UINT32 HorizontalResolution; + UINT32 VerticalResolution; + EFI_GRAPHICS_PIXEL_FORMAT PixelFormat; + EFI_PIXEL_BITMASK PixelInformation; + UINT32 PixelsPerScanLine; +} EFI_GRAPHICS_OUTPUT_MODE_INFORMATION; + +typedef +EFI_STATUS +(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE) ( + IN struct _EFI_GRAPHICS_OUTPUT_PROTOCOL *This, + IN UINT32 ModeNumber, + OUT UINTN *SizeOfInfo, + OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info + ) +/*++ + + Routine Description: + Return the current video mode information. + + Arguments: + This - Protocol instance pointer. + ModeNumber - The mode number to return information on. + SizeOfInfo - A pointer to the size, in bytes, of the Info buffer. + Info - A pointer to callee allocated buffer that returns information about ModeNumber. + + Returns: + EFI_SUCCESS - Mode information returned. + EFI_DEVICE_ERROR - A hardware error occurred trying to retrieve the video mode. + EFI_NOT_STARTED - Video display is not initialized. Call SetMode () + EFI_INVALID_PARAMETER - One of the input args was NULL. + +--*/ +; + +typedef +EFI_STATUS +(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE) ( + IN struct _EFI_GRAPHICS_OUTPUT_PROTOCOL * This, + IN UINT32 ModeNumber + ) +/*++ + + Routine Description: + Return the current video mode information. + + Arguments: + This - Protocol instance pointer. + ModeNumber - The mode number to be set. + + Returns: + EFI_SUCCESS - Graphics mode was changed. + EFI_DEVICE_ERROR - The device had an error and could not complete the request. + EFI_UNSUPPORTED - ModeNumber is not supported by this device. + +--*/ +; + +typedef EFI_UGA_PIXEL EFI_GRAPHICS_OUTPUT_BLT_PIXEL; + +typedef union { + EFI_GRAPHICS_OUTPUT_BLT_PIXEL Pixel; + UINT32 Raw; +} EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION; + +typedef enum { + EfiBltVideoFill, + EfiBltVideoToBltBuffer, + EfiBltBufferToVideo, + EfiBltVideoToVideo, + EfiGraphicsOutputBltOperationMax +} EFI_GRAPHICS_OUTPUT_BLT_OPERATION; + +typedef +EFI_STATUS +(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT) ( + IN struct _EFI_GRAPHICS_OUTPUT_PROTOCOL * This, + IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL * BltBuffer, OPTIONAL + IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation, + IN UINTN SourceX, + IN UINTN SourceY, + IN UINTN DestinationX, + IN UINTN DestinationY, + IN UINTN Width, + IN UINTN Height, + IN UINTN Delta OPTIONAL + ); + +/*++ + + Routine Description: + The following table defines actions for BltOperations: + EfiBltVideoFill - Write data from the BltBuffer pixel (SourceX, SourceY) + directly to every pixel of the video display rectangle + (DestinationX, DestinationY) (DestinationX + Width, DestinationY + Height). + Only one pixel will be used from the BltBuffer. Delta is NOT used. + EfiBltVideoToBltBuffer - Read data from the video display rectangle + (SourceX, SourceY) (SourceX + Width, SourceY + Height) and place it in + the BltBuffer rectangle (DestinationX, DestinationY ) + (DestinationX + Width, DestinationY + Height). If DestinationX or + DestinationY is not zero then Delta must be set to the length in bytes + of a row in the BltBuffer. + EfiBltBufferToVideo - Write data from the BltBuffer rectangle + (SourceX, SourceY) (SourceX + Width, SourceY + Height) directly to the + video display rectangle (DestinationX, DestinationY) + (DestinationX + Width, DestinationY + Height). If SourceX or SourceY is + not zero then Delta must be set to the length in bytes of a row in the + BltBuffer. + EfiBltVideoToVideo - Copy from the video display rectangle (SourceX, SourceY) + (SourceX + Width, SourceY + Height) .to the video display rectangle + (DestinationX, DestinationY) (DestinationX + Width, DestinationY + Height). + The BltBuffer and Delta are not used in this mode. + + Arguments: + This - Protocol instance pointer. + BltBuffer - Buffer containing data to blit into video buffer. This + buffer has a size of Width*Height*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL) + BltOperation - Operation to perform on BlitBuffer and video memory + SourceX - X coordinate of source for the BltBuffer. + SourceY - Y coordinate of source for the BltBuffer. + DestinationX - X coordinate of destination for the BltBuffer. + DestinationY - Y coordinate of destination for the BltBuffer. + Width - Width of rectangle in BltBuffer in pixels. + Height - Hight of rectangle in BltBuffer in pixels. + Delta - + + Returns: + EFI_SUCCESS - The Blt operation completed. + EFI_INVALID_PARAMETER - BltOperation is not valid. + EFI_DEVICE_ERROR - A hardware error occured writting to the video + buffer. + +--*/ +; + +typedef struct { + UINT32 MaxMode; + UINT32 Mode; + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info; + UINTN SizeOfInfo; + EFI_PHYSICAL_ADDRESS FrameBufferBase; + UINTN FrameBufferSize; +} EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE; + +typedef struct _EFI_GRAPHICS_OUTPUT_PROTOCOL { + EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE QueryMode; + EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE SetMode; + EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT Blt; + EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode; +} EFI_GRAPHICS_OUTPUT_PROTOCOL; + +extern EFI_GUID gEfiGraphicsOutputProtocolGuid; + +#endif diff --git a/libeg/efiUgaDraw.h b/libeg/efiUgaDraw.h new file mode 100644 index 0000000..bce3f24 --- /dev/null +++ b/libeg/efiUgaDraw.h @@ -0,0 +1,182 @@ +/*++ + +Copyright (c) 2004, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + +UgaDraw.h + +Abstract: + +UGA Draw protocol from the EFI 1.1 specification. + +Abstraction of a very simple graphics device. + +--*/ + +#ifndef __UGA_DRAW_H__ +#define __UGA_DRAW_H__ + +#define EFI_UGA_DRAW_PROTOCOL_GUID \ +{ \ + 0x982c298b, 0xf4fa, 0x41cb, { 0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39 } \ +} + +/* typedef struct _EFI_UGA_DRAW_PROTOCOL EFI_UGA_DRAW_PROTOCOL; */ +struct _EFI_UGA_DRAW_PROTOCOL; + +typedef +EFI_STATUS +(EFIAPI *EFI_UGA_DRAW_PROTOCOL_GET_MODE) ( + IN struct _EFI_UGA_DRAW_PROTOCOL * This, + OUT UINT32 *HorizontalResolution, + OUT UINT32 *VerticalResolution, + OUT UINT32 *ColorDepth, + OUT UINT32 *RefreshRate + ) +/*++ + +Routine Description: +Return the current video mode information. + +Arguments: +This - Protocol instance pointer. +HorizontalResolution - Current video horizontal resolution in pixels +VerticalResolution - Current video vertical resolution in pixels +ColorDepth - Current video color depth in bits per pixel +RefreshRate - Current video refresh rate in Hz. + +Returns: +EFI_SUCCESS - Mode information returned. +EFI_NOT_STARTED - Video display is not initialized. Call SetMode () +EFI_INVALID_PARAMETER - One of the input args was NULL. + +--*/ +; + +typedef +EFI_STATUS +(EFIAPI *EFI_UGA_DRAW_PROTOCOL_SET_MODE) ( + IN struct _EFI_UGA_DRAW_PROTOCOL * This, + IN UINT32 HorizontalResolution, + IN UINT32 VerticalResolution, + IN UINT32 ColorDepth, + IN UINT32 RefreshRate + ) +/*++ + +Routine Description: +Return the current video mode information. + +Arguments: +This - Protocol instance pointer. +HorizontalResolution - Current video horizontal resolution in pixels +VerticalResolution - Current video vertical resolution in pixels +ColorDepth - Current video color depth in bits per pixel +RefreshRate - Current video refresh rate in Hz. + +Returns: +EFI_SUCCESS - Mode information returned. +EFI_NOT_STARTED - Video display is not initialized. Call SetMode () + +--*/ +; + +typedef struct { + UINT8 Blue; + UINT8 Green; + UINT8 Red; + UINT8 Reserved; +} EFI_UGA_PIXEL; + +typedef union { + EFI_UGA_PIXEL Pixel; + UINT32 Raw; +} EFI_UGA_PIXEL_UNION; + +typedef enum { + EfiUgaVideoFill, + EfiUgaVideoToBltBuffer, + EfiUgaBltBufferToVideo, + EfiUgaVideoToVideo, + EfiUgaBltMax +} EFI_UGA_BLT_OPERATION; + +typedef +EFI_STATUS +(EFIAPI *EFI_UGA_DRAW_PROTOCOL_BLT) ( + IN struct _EFI_UGA_DRAW_PROTOCOL * This, + IN EFI_UGA_PIXEL * BltBuffer, OPTIONAL + IN EFI_UGA_BLT_OPERATION BltOperation, + IN UINTN SourceX, + IN UINTN SourceY, + IN UINTN DestinationX, + IN UINTN DestinationY, + IN UINTN Width, + IN UINTN Height, + IN UINTN Delta OPTIONAL + ); + +/*++ + +Routine Description: +The following table defines actions for BltOperations: +EfiUgaVideoFill - Write data from the BltBuffer pixel (SourceX, SourceY) +directly to every pixel of the video display rectangle +(DestinationX, DestinationY) (DestinationX + Width, DestinationY + Height). +Only one pixel will be used from the BltBuffer. Delta is NOT used. +EfiUgaVideoToBltBuffer - Read data from the video display rectangle +(SourceX, SourceY) (SourceX + Width, SourceY + Height) and place it in +the BltBuffer rectangle (DestinationX, DestinationY ) +(DestinationX + Width, DestinationY + Height). If DestinationX or +DestinationY is not zero then Delta must be set to the length in bytes +of a row in the BltBuffer. +EfiUgaBltBufferToVideo - Write data from the BltBuffer rectangle +(SourceX, SourceY) (SourceX + Width, SourceY + Height) directly to the +video display rectangle (DestinationX, DestinationY) +(DestinationX + Width, DestinationY + Height). If SourceX or SourceY is +not zero then Delta must be set to the length in bytes of a row in the +BltBuffer. +EfiUgaVideoToVideo - Copy from the video display rectangle (SourceX, SourceY) +(SourceX + Width, SourceY + Height) .to the video display rectangle +(DestinationX, DestinationY) (DestinationX + Width, DestinationY + Height). +The BltBuffer and Delta are not used in this mode. + +Arguments: +This - Protocol instance pointer. +BltBuffer - Buffer containing data to blit into video buffer. This +buffer has a size of Width*Height*sizeof(EFI_UGA_PIXEL) +BltOperation - Operation to perform on BlitBuffer and video memory +SourceX - X coordinate of source for the BltBuffer. +SourceY - Y coordinate of source for the BltBuffer. +DestinationX - X coordinate of destination for the BltBuffer. +DestinationY - Y coordinate of destination for the BltBuffer. +Width - Width of rectangle in BltBuffer in pixels. +Height - Hight of rectangle in BltBuffer in pixels. +Delta - + +Returns: +EFI_SUCCESS - The Blt operation completed. +EFI_INVALID_PARAMETER - BltOperation is not valid. +EFI_DEVICE_ERROR - A hardware error occured writting to the video +buffer. + +--*/ +; + +typedef struct _EFI_UGA_DRAW_PROTOCOL { + EFI_UGA_DRAW_PROTOCOL_GET_MODE GetMode; + EFI_UGA_DRAW_PROTOCOL_SET_MODE SetMode; + EFI_UGA_DRAW_PROTOCOL_BLT Blt; +} EFI_UGA_DRAW_PROTOCOL; + +extern EFI_GUID gEfiUgaDrawProtocolGuid; + +#endif diff --git a/libeg/egemb_font.h b/libeg/egemb_font.h new file mode 100644 index 0000000..fa5c043 --- /dev/null +++ b/libeg/egemb_font.h @@ -0,0 +1,302 @@ +static const UINT8 egemb_font_data[3587] = { + 0xff, 0x00, 0xdd, 0x00, 0x80, 0xff, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, + 0xbc, 0x00, 0x00, 0xff, 0x81, 0x00, 0x04, 0xff, 0xff, 0x00, 0xff, 0xff, + 0x81, 0x00, 0x02, 0xff, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x82, 0x00, + 0x00, 0xff, 0x8b, 0x00, 0x00, 0xff, 0x84, 0x00, 0x00, 0xff, 0x81, 0x00, + 0x00, 0xff, 0x84, 0x00, 0x00, 0xff, 0xa1, 0x00, 0x00, 0xff, 0x80, 0x00, + 0x80, 0xff, 0x81, 0x00, 0x01, 0xff, 0xff, 0x82, 0x00, 0x80, 0xff, 0x81, + 0x00, 0x80, 0xff, 0x83, 0x00, 0x01, 0xff, 0xff, 0x80, 0x00, 0x81, 0xff, + 0x81, 0x00, 0x80, 0xff, 0x01, 0x00, 0x00, 0x82, 0xff, 0x80, 0x00, 0x80, + 0xff, 0x81, 0x00, 0x80, 0xff, 0xaa, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, + 0xff, 0x80, 0x00, 0x01, 0xff, 0xff, 0x80, 0x00, 0x82, 0xff, 0x81, 0x00, + 0x81, 0xff, 0x00, 0x00, 0x81, 0xff, 0x80, 0x00, 0x83, 0xff, 0x01, 0x00, + 0x00, 0x83, 0xff, 0x01, 0x00, 0x00, 0x81, 0xff, 0x00, 0x00, 0x80, 0xff, + 0x00, 0x00, 0x80, 0xff, 0x00, 0x00, 0x82, 0xff, 0x80, 0x00, 0x81, 0xff, + 0x00, 0x00, 0x80, 0xff, 0x00, 0x00, 0x80, 0xff, 0x00, 0x00, 0x80, 0xff, + 0x80, 0x00, 0x80, 0xff, 0x00, 0x00, 0x83, 0xff, 0x00, 0x00, 0x80, 0xff, + 0x01, 0x00, 0x00, 0x80, 0xff, 0x80, 0x00, 0x81, 0xff, 0x81, 0x00, 0x80, + 0xff, 0x01, 0x00, 0x00, 0x82, 0xff, 0x81, 0x00, 0x04, 0xff, 0xff, 0x00, + 0xff, 0x00, 0x87, 0xff, 0x00, 0x00, 0x83, 0xff, 0x00, 0x00, 0x83, 0xff, + 0x00, 0x00, 0x82, 0xff, 0x80, 0x00, 0x82, 0xff, 0x00, 0x00, 0x80, 0xff, + 0x00, 0x00, 0x82, 0xff, 0x80, 0x00, 0x80, 0xff, 0x80, 0x00, 0x00, 0xff, + 0x84, 0x00, 0x80, 0xff, 0x90, 0x00, 0x00, 0xff, 0x87, 0x00, 0x01, 0xff, + 0xff, 0x8d, 0x00, 0x01, 0xff, 0xff, 0x88, 0x00, 0x80, 0xff, 0x85, 0x00, + 0x01, 0xff, 0xff, 0x85, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, 0x80, + 0x00, 0x01, 0xff, 0xff, 0x84, 0x00, 0x01, 0xff, 0xff, 0xe6, 0x00, 0x00, + 0xff, 0x82, 0x00, 0x00, 0xff, 0x82, 0x00, 0x00, 0xff, 0x99, 0x00, 0x00, + 0xff, 0x81, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x82, 0x00, 0x02, 0xff, + 0x00, 0xff, 0x80, 0x00, 0x80, 0xff, 0x80, 0x00, 0x02, 0xff, 0x00, 0xff, + 0x8a, 0x00, 0x00, 0xff, 0x84, 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, + 0x82, 0x00, 0x82, 0xff, 0x81, 0x00, 0x00, 0xff, 0x9a, 0x00, 0x03, 0xff, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x81, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, + 0x00, 0xff, 0x81, 0x00, 0x02, 0xff, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, + 0x83, 0x00, 0x00, 0xff, 0x82, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, + 0x00, 0xff, 0x90, 0x00, 0x01, 0xff, 0xff, 0x85, 0x00, 0x01, 0xff, 0xff, + 0x85, 0x00, 0x01, 0xff, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, + 0xff, 0x81, 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, + 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x06, 0xff, 0x00, 0x00, 0xff, 0x00, + 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, + 0x00, 0xff, 0x80, 0x00, 0x02, 0xff, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x84, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, + 0x00, 0x00, 0xff, 0x82, 0x00, 0x0e, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, + 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, + 0xff, 0x80, 0x00, 0x06, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x80, + 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x11, 0xff, 0x00, 0x00, + 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, + 0xff, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, + 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, + 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, + 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x83, 0x00, + 0x00, 0xff, 0x85, 0x00, 0x00, 0xff, 0x82, 0x00, 0x00, 0xff, 0x8b, 0x00, + 0x00, 0xff, 0x87, 0x00, 0x00, 0xff, 0x8e, 0x00, 0x00, 0xff, 0x87, 0x00, + 0x00, 0xff, 0x89, 0x00, 0x00, 0xff, 0x91, 0x00, 0x00, 0xff, 0x85, 0x00, + 0x00, 0xff, 0xb3, 0x00, 0x00, 0xff, 0xae, 0x00, 0x00, 0xff, 0x83, 0x00, + 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, 0x8a, 0x00, 0x01, 0xff, 0xff, 0x89, + 0x00, 0x00, 0xff, 0x81, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x81, 0x00, + 0x02, 0xff, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x84, 0x00, 0x00, 0xff, + 0x84, 0x00, 0x01, 0xff, 0xff, 0x82, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, + 0xff, 0x83, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, + 0xff, 0x99, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, + 0xff, 0x81, 0x00, 0x00, 0xff, 0x85, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, + 0xff, 0x81, 0x00, 0x02, 0xff, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x82, + 0x00, 0x00, 0xff, 0x87, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, + 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x01, + 0xff, 0xff, 0x83, 0x00, 0x01, 0xff, 0xff, 0x82, 0x00, 0x00, 0xff, 0x89, + 0x00, 0x00, 0xff, 0x83, 0x00, 0x0a, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, + 0xff, 0x00, 0x00, 0xff, 0xff, 0x80, 0x00, 0x02, 0xff, 0x00, 0xff, 0x80, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x83, 0x00, + 0x00, 0xff, 0x80, 0x00, 0x05, 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x82, + 0x00, 0x02, 0xff, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, + 0xff, 0x80, 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x84, 0x00, 0x00, + 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, + 0x82, 0x00, 0x0e, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, + 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, + 0x06, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x85, 0x00, + 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, + 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, + 0x80, 0x00, 0x02, 0xff, 0x00, 0xff, 0x81, 0x00, 0x02, 0xff, 0x00, 0xff, + 0x83, 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, + 0x85, 0x00, 0x00, 0xff, 0x81, 0x00, 0x02, 0xff, 0x00, 0xff, 0x8f, 0x00, + 0x80, 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0xff, 0xff, 0x81, 0x00, 0x81, + 0xff, 0x80, 0x00, 0x03, 0xff, 0xff, 0x00, 0xff, 0x80, 0x00, 0x80, 0xff, + 0x80, 0x00, 0x82, 0xff, 0x80, 0x00, 0x09, 0xff, 0xff, 0x00, 0xff, 0xff, + 0x00, 0xff, 0x00, 0xff, 0xff, 0x80, 0x00, 0x80, 0xff, 0x81, 0x00, 0x81, + 0xff, 0x80, 0x00, 0x01, 0xff, 0x00, 0x80, 0xff, 0x81, 0x00, 0x00, 0xff, + 0x80, 0x00, 0x80, 0xff, 0x08, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, + 0xff, 0xff, 0x81, 0x00, 0x80, 0xff, 0x06, 0x00, 0x00, 0xff, 0xff, 0x00, + 0xff, 0xff, 0x81, 0x00, 0x0a, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, + 0xff, 0x00, 0xff, 0xff, 0x80, 0x00, 0x81, 0xff, 0x01, 0x00, 0x00, 0x82, + 0xff, 0x07, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x80, 0xff, + 0x00, 0x00, 0x83, 0xff, 0x00, 0x00, 0x82, 0xff, 0x04, 0x00, 0x00, 0xff, + 0xff, 0x00, 0x80, 0xff, 0x00, 0x00, 0x80, 0xff, 0x00, 0x00, 0x82, 0xff, + 0x81, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, + 0x89, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x88, 0x00, 0x00, 0xff, 0x88, + 0x00, 0x82, 0xff, 0x02, 0x00, 0x00, 0xff, 0x86, 0x00, 0x01, 0xff, 0xff, + 0x80, 0x00, 0x00, 0xff, 0x84, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, + 0x83, 0x00, 0x00, 0xff, 0x82, 0x00, 0x02, 0xff, 0x00, 0xff, 0x82, 0x00, + 0x00, 0xff, 0x99, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, + 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x84, 0x00, 0x00, 0xff, 0x82, 0x00, + 0x01, 0xff, 0xff, 0x81, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, + 0x80, 0xff, 0x80, 0x00, 0x81, 0xff, 0x83, 0x00, 0x00, 0xff, 0x81, 0x00, + 0x80, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, + 0x01, 0xff, 0xff, 0x83, 0x00, 0x01, 0xff, 0xff, 0x80, 0x00, 0x01, 0xff, + 0xff, 0x82, 0x00, 0x82, 0xff, 0x81, 0x00, 0x01, 0xff, 0xff, 0x84, 0x00, + 0x07, 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x80, 0x00, 0x02, + 0xff, 0x00, 0xff, 0x80, 0x00, 0x81, 0xff, 0x80, 0x00, 0x00, 0xff, 0x83, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x02, 0xff, 0x00, 0x00, 0x80, 0xff, 0x82, + 0x00, 0x80, 0xff, 0x80, 0x00, 0x00, 0xff, 0x83, 0x00, 0x82, 0xff, 0x81, + 0x00, 0x00, 0xff, 0x84, 0x00, 0x00, 0xff, 0x80, 0x00, 0x02, 0xff, 0x00, + 0xff, 0x82, 0x00, 0x00, 0xff, 0x82, 0x00, 0x0e, 0xff, 0x00, 0xff, 0x00, + 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0x80, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x06, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, + 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, + 0x80, 0x00, 0x80, 0xff, 0x82, 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, + 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x02, 0xff, 0x00, 0xff, 0x80, 0x00, + 0x04, 0xff, 0x00, 0xff, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x82, 0x00, + 0x02, 0xff, 0x00, 0xff, 0x82, 0x00, 0x00, 0xff, 0x82, 0x00, 0x00, 0xff, + 0x83, 0x00, 0x00, 0xff, 0x85, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, + 0x80, 0x00, 0x00, 0xff, 0x8d, 0x00, 0x00, 0xff, 0x80, 0x00, 0x0a, 0xff, + 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, + 0x0a, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, + 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x82, 0x00, 0x0b, 0xff, + 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0x81, + 0x00, 0x00, 0xff, 0x84, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, + 0x00, 0xff, 0x82, 0x00, 0x00, 0xff, 0x81, 0x00, 0x0e, 0xff, 0x00, 0xff, + 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, + 0x80, 0x00, 0x0e, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, + 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0x80, 0x00, 0x01, 0xff, 0xff, 0x81, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x82, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, + 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x06, 0xff, 0x00, 0x00, 0xff, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x06, 0xff, 0x00, + 0x00, 0xff, 0x00, 0x00, 0xff, 0x82, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, + 0xff, 0x83, 0x00, 0x00, 0xff, 0x8c, 0x00, 0x00, 0xff, 0x88, 0x00, 0x00, + 0xff, 0x89, 0x00, 0x02, 0xff, 0x00, 0xff, 0x81, 0x00, 0x80, 0xff, 0x80, + 0x00, 0x80, 0xff, 0x82, 0x00, 0x00, 0xff, 0x8b, 0x00, 0x00, 0xff, 0x83, + 0x00, 0x00, 0xff, 0x82, 0x00, 0x04, 0xff, 0x00, 0xff, 0x00, 0x00, 0x84, + 0xff, 0x85, 0x00, 0x82, 0xff, 0x88, 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, + 0xff, 0x80, 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, + 0xff, 0x85, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, + 0x83, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x82, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, + 0x00, 0x81, 0xff, 0x8c, 0x00, 0x00, 0xff, 0x8f, 0x00, 0x00, 0xff, 0x82, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x04, 0xff, 0x00, 0xff, 0x00, 0xff, 0x80, + 0x00, 0x02, 0xff, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, + 0xff, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, 0x80, 0x00, 0x05, 0xff, + 0x00, 0x00, 0xff, 0x00, 0xff, 0x82, 0x00, 0x02, 0xff, 0x00, 0xff, 0x80, + 0x00, 0x02, 0xff, 0x00, 0x00, 0x80, 0xff, 0x01, 0x00, 0xff, 0x80, 0x00, + 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x81, 0x00, 0x03, 0xff, 0x00, 0x00, + 0xff, 0x80, 0x00, 0x80, 0xff, 0x82, 0x00, 0x00, 0xff, 0x82, 0x00, 0x0e, + 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x80, 0xff, 0x80, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x02, 0xff, 0x00, 0x00, 0x81, 0xff, 0x84, + 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x80, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x02, 0xff, 0x00, 0xff, 0x80, 0x00, 0x04, + 0xff, 0x00, 0xff, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, + 0xff, 0x83, 0x00, 0x00, 0xff, 0x82, 0x00, 0x00, 0xff, 0x84, 0x00, 0x00, + 0xff, 0x84, 0x00, 0x00, 0xff, 0x96, 0x00, 0x81, 0xff, 0x02, 0x00, 0x00, + 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, + 0x80, 0x00, 0x02, 0xff, 0x00, 0x00, 0x82, 0xff, 0x80, 0x00, 0x00, 0xff, + 0x82, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, + 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x84, 0x00, 0x00, 0xff, 0x80, + 0x00, 0x80, 0xff, 0x83, 0x00, 0x00, 0xff, 0x81, 0x00, 0x07, 0xff, 0x00, + 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, + 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x83, + 0x00, 0x80, 0xff, 0x81, 0x00, 0x00, 0xff, 0x82, 0x00, 0x00, 0xff, 0x80, + 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x07, 0xff, 0x00, 0x00, + 0xff, 0x00, 0xff, 0x00, 0xff, 0x80, 0x00, 0x01, 0xff, 0xff, 0x82, 0x00, + 0x03, 0xff, 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, + 0xff, 0x83, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, 0x82, 0x00, 0x03, + 0xff, 0x00, 0x00, 0xff, 0x82, 0x00, 0x00, 0xff, 0x95, 0x00, 0x82, 0xff, + 0x05, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, 0x80, + 0x00, 0x04, 0xff, 0x00, 0xff, 0x00, 0xff, 0x88, 0x00, 0x00, 0xff, 0x83, + 0x00, 0x00, 0xff, 0x8a, 0x00, 0x00, 0xff, 0x98, 0x00, 0x00, 0xff, 0x81, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x82, + 0x00, 0x00, 0xff, 0x86, 0x00, 0x02, 0xff, 0x00, 0x00, 0x83, 0xff, 0x82, + 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x82, 0x00, + 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x83, 0x00, + 0x00, 0xff, 0x8d, 0x00, 0x01, 0xff, 0xff, 0x82, 0x00, 0x82, 0xff, 0x81, + 0x00, 0x01, 0xff, 0xff, 0x82, 0x00, 0x00, 0xff, 0x81, 0x00, 0x06, 0xff, + 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x82, 0xff, 0x02, 0x00, 0x00, 0xff, + 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, 0x80, + 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x84, 0x00, 0x00, 0xff, 0x82, 0x00, + 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, + 0xff, 0x81, 0x00, 0x00, 0xff, 0x81, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, + 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x81, 0x00, 0x06, 0xff, 0x00, + 0x00, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x0a, 0xff, 0x00, 0x00, 0xff, + 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, + 0x00, 0x00, 0xff, 0x82, 0x00, 0x00, 0xff, 0x80, 0x00, 0x06, 0xff, 0x00, + 0x00, 0xff, 0x00, 0x00, 0xff, 0x84, 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, + 0xff, 0x81, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x02, + 0xff, 0x00, 0xff, 0x80, 0x00, 0x04, 0xff, 0x00, 0xff, 0x00, 0xff, 0x80, + 0x00, 0x02, 0xff, 0x00, 0xff, 0x82, 0x00, 0x00, 0xff, 0x82, 0x00, 0x00, + 0xff, 0x83, 0x00, 0x00, 0xff, 0x84, 0x00, 0x00, 0xff, 0x84, 0x00, 0x00, + 0xff, 0x95, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, + 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, 0x80, + 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x84, 0x00, 0x00, 0xff, 0x82, 0x00, + 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, + 0xff, 0x81, 0x00, 0x00, 0xff, 0x84, 0x00, 0x00, 0xff, 0x80, 0x00, 0x02, + 0xff, 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, 0x81, 0x00, 0x07, 0xff, 0x00, + 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, + 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x86, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x82, 0x00, 0x00, 0xff, 0x80, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x02, 0xff, 0x00, 0xff, 0x80, 0x00, 0x04, + 0xff, 0x00, 0xff, 0x00, 0xff, 0x80, 0x00, 0x01, 0xff, 0xff, 0x82, 0x00, + 0x02, 0xff, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, + 0x84, 0x00, 0x00, 0xff, 0x84, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, + 0x00, 0xff, 0xff, 0x82, 0x00, 0x00, 0xff, 0x97, 0x00, 0x02, 0xff, 0x00, + 0xff, 0x80, 0x00, 0x80, 0xff, 0x83, 0x00, 0x08, 0xff, 0x00, 0xff, 0x00, + 0x00, 0xff, 0x00, 0x00, 0xff, 0x89, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, + 0xff, 0x8a, 0x00, 0x00, 0xff, 0x83, 0x00, 0x01, 0xff, 0xff, 0x88, 0x00, + 0x01, 0xff, 0xff, 0x82, 0x00, 0x00, 0xff, 0x82, 0x00, 0x00, 0xff, 0x80, + 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x80, + 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x83, 0x00, + 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, + 0x80, 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, + 0x80, 0x00, 0x00, 0xff, 0x82, 0x00, 0x00, 0xff, 0x81, 0x00, 0x01, 0xff, + 0xff, 0x83, 0x00, 0x01, 0xff, 0xff, 0x82, 0x00, 0x00, 0xff, 0x89, 0x00, + 0x00, 0xff, 0x89, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, 0x80, 0x00, + 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, + 0x80, 0x00, 0x06, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, + 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x82, 0x00, + 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, + 0xff, 0x81, 0x00, 0x00, 0xff, 0x81, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, + 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x06, 0xff, + 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x0a, 0xff, 0x00, 0x00, + 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, + 0x80, 0x00, 0x00, 0xff, 0x82, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x07, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, + 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x80, 0x00, + 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x81, 0x00, 0x07, 0xff, 0x00, 0xff, + 0x00, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, + 0xff, 0x81, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, + 0xff, 0x85, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, 0x95, 0x00, 0x00, + 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, + 0x03, 0xff, 0x00, 0x00, 0xff, 0x84, 0x00, 0x00, 0xff, 0x82, 0x00, 0x00, + 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, + 0x81, 0x00, 0x00, 0xff, 0x84, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, + 0x00, 0x00, 0xff, 0x82, 0x00, 0x00, 0xff, 0x81, 0x00, 0x07, 0xff, 0x00, + 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, + 0xff, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x82, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x80, + 0x00, 0x06, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0x80, 0x00, 0x02, + 0xff, 0x00, 0xff, 0x80, 0x00, 0x0a, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, + 0x00, 0xff, 0x00, 0x00, 0xff, 0x82, 0x00, 0x01, 0xff, 0xff, 0x80, 0x00, + 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, 0x83, 0x00, + 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, 0x98, 0x00, 0x00, 0xff, 0x88, 0x00, + 0x02, 0xff, 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, 0x84, 0x00, 0x00, 0xff, + 0x81, 0x00, 0x03, 0xff, 0xff, 0x00, 0xff, 0x88, 0x00, 0x00, 0xff, 0x83, + 0x00, 0x00, 0xff, 0x8a, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, 0x89, + 0x00, 0x01, 0xff, 0xff, 0x82, 0x00, 0x00, 0xff, 0x83, 0x00, 0x80, 0xff, + 0x80, 0x00, 0x82, 0xff, 0x01, 0x00, 0x00, 0x82, 0xff, 0x80, 0x00, 0x80, + 0xff, 0x83, 0x00, 0x80, 0xff, 0x01, 0x00, 0x00, 0x80, 0xff, 0x81, 0x00, + 0x80, 0xff, 0x82, 0x00, 0x00, 0xff, 0x82, 0x00, 0x80, 0xff, 0x80, 0x00, + 0x80, 0xff, 0x82, 0x00, 0x01, 0xff, 0xff, 0x82, 0x00, 0x01, 0xff, 0xff, + 0x84, 0x00, 0x01, 0xff, 0xff, 0x85, 0x00, 0x01, 0xff, 0xff, 0x84, 0x00, + 0x01, 0xff, 0xff, 0x81, 0x00, 0x00, 0xff, 0x80, 0x00, 0x01, 0xff, 0x00, + 0x80, 0xff, 0x00, 0x00, 0x85, 0xff, 0x81, 0x00, 0x80, 0xff, 0x01, 0x00, + 0x00, 0x81, 0xff, 0x80, 0x00, 0x83, 0xff, 0x01, 0x00, 0x00, 0x80, 0xff, + 0x82, 0x00, 0x80, 0xff, 0x01, 0x00, 0x00, 0x80, 0xff, 0x00, 0x00, 0x80, + 0xff, 0x00, 0x00, 0x82, 0xff, 0x80, 0x00, 0x01, 0xff, 0xff, 0x80, 0x00, + 0x80, 0xff, 0x04, 0x00, 0x00, 0xff, 0xff, 0x00, 0x82, 0xff, 0x00, 0x00, + 0x80, 0xff, 0x00, 0x00, 0x83, 0xff, 0x02, 0x00, 0xff, 0xff, 0x80, 0x00, + 0x80, 0xff, 0x80, 0x00, 0x80, 0xff, 0x82, 0x00, 0x80, 0xff, 0x01, 0x00, + 0x00, 0x80, 0xff, 0x80, 0x00, 0x05, 0xff, 0x00, 0xff, 0x00, 0xff, 0xff, + 0x81, 0x00, 0x80, 0xff, 0x81, 0x00, 0x80, 0xff, 0x82, 0x00, 0x00, 0xff, + 0x82, 0x00, 0x06, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0x80, 0x00, + 0x03, 0xff, 0xff, 0x00, 0x00, 0x80, 0xff, 0x80, 0x00, 0x82, 0xff, 0x80, + 0x00, 0x00, 0xff, 0x85, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, 0x96, + 0x00, 0x87, 0xff, 0x81, 0x00, 0x80, 0xff, 0x81, 0x00, 0x82, 0xff, 0x01, + 0x00, 0x00, 0x81, 0xff, 0x01, 0x00, 0x00, 0x82, 0xff, 0x80, 0x00, 0x81, + 0xff, 0x00, 0x00, 0x80, 0xff, 0x00, 0x00, 0x80, 0xff, 0x00, 0x00, 0x82, + 0xff, 0x82, 0x00, 0x05, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x81, 0xff, + 0x00, 0x00, 0x82, 0xff, 0x00, 0x00, 0x87, 0xff, 0x00, 0x00, 0x80, 0xff, + 0x01, 0x00, 0x00, 0x80, 0xff, 0x80, 0x00, 0x81, 0xff, 0x81, 0x00, 0x81, + 0xff, 0x01, 0x00, 0x00, 0x82, 0xff, 0x01, 0x00, 0x00, 0x81, 0xff, 0x82, + 0x00, 0x80, 0xff, 0x80, 0x00, 0x04, 0xff, 0xff, 0x00, 0xff, 0xff, 0x80, + 0x00, 0x00, 0xff, 0x82, 0x00, 0x0a, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, + 0xff, 0x00, 0x00, 0xff, 0xff, 0x81, 0x00, 0x00, 0xff, 0x81, 0x00, 0x82, + 0xff, 0x81, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, + 0xff, 0x89, 0x00, 0x01, 0xff, 0xff, 0x96, 0x00, 0x02, 0xff, 0x00, 0xff, + 0x83, 0x00, 0x00, 0xff, 0x99, 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, 0xff, + 0x91, 0x00, 0x01, 0xff, 0xff, 0x8f, 0x00, 0x00, 0xff, 0xd1, 0x00, 0x00, + 0xff, 0x9f, 0x00, 0x80, 0xff, 0xf2, 0x00, 0x80, 0xff, 0xbf, 0x00, 0x00, + 0xff, 0x85, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, 0xff, 0xc3, 0x00, 0x00, + 0xff, 0x90, 0x00, 0x00, 0xff, 0xa3, 0x00, 0x00, 0xff, 0x87, 0x00, 0x00, + 0xff, 0xb2, 0x00, 0x00, 0xff, 0x8a, 0x00, 0x00, 0xff, 0x83, 0x00, 0x00, + 0xff, 0x83, 0x00, 0x00, 0xff, 0xca, 0x00, 0x00, 0xff, 0x81, 0x00, 0x00, + 0xff, 0x91, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0xc1, 0x00, 0x80, + 0xff, 0x88, 0x00, 0x80, 0xff, 0xc0, 0x00, 0x80, 0xff, 0x8e, 0x00, 0x80, + 0xff, 0xa3, 0x00, 0x80, 0xff, 0x85, 0x00, 0x80, 0xff, 0xaf, 0x00, 0x81, + 0xff, 0x8a, 0x00, 0x00, 0xff, 0x88, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, + 0x00, 0xff, 0x00, 0xc2, 0x00, 0x84, 0xff, 0xff, 0x00, 0xdb, 0x00, +}; +static EG_EMBEDDED_IMAGE egemb_font = { 672, 12, EG_EIPIXELMODE_ALPHA, EG_EICOMPMODE_RLE, egemb_font_data, 3587 }; diff --git a/libeg/image.c b/libeg/image.c new file mode 100644 index 0000000..5907c09 --- /dev/null +++ b/libeg/image.c @@ -0,0 +1,557 @@ +/* + * libeg/image.c + * Image handling functions + * + * Copyright (c) 2006 Christoph Pfisterer + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Christoph Pfisterer nor the names of the + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "libegint.h" +#include "refit_call_wrapper.h" + +#define MAX_FILE_SIZE (1024*1024*1024) + +// +// Basic image handling +// + +EG_IMAGE * egCreateImage(IN UINTN Width, IN UINTN Height, IN BOOLEAN HasAlpha) +{ + EG_IMAGE *NewImage; + + NewImage = (EG_IMAGE *) AllocatePool(sizeof(EG_IMAGE)); + if (NewImage == NULL) + return NULL; + NewImage->PixelData = (EG_PIXEL *) AllocatePool(Width * Height * sizeof(EG_PIXEL)); + if (NewImage->PixelData == NULL) { + FreePool(NewImage); + return NULL; + } + + NewImage->Width = Width; + NewImage->Height = Height; + NewImage->HasAlpha = HasAlpha; + return NewImage; +} + +EG_IMAGE * egCreateFilledImage(IN UINTN Width, IN UINTN Height, IN BOOLEAN HasAlpha, IN EG_PIXEL *Color) +{ + EG_IMAGE *NewImage; + + NewImage = egCreateImage(Width, Height, HasAlpha); + if (NewImage == NULL) + return NULL; + + egFillImage(NewImage, Color); + return NewImage; +} + +EG_IMAGE * egCopyImage(IN EG_IMAGE *Image) +{ + EG_IMAGE *NewImage; + + NewImage = egCreateImage(Image->Width, Image->Height, Image->HasAlpha); + if (NewImage == NULL) + return NULL; + + CopyMem(NewImage->PixelData, Image->PixelData, Image->Width * Image->Height * sizeof(EG_PIXEL)); + return NewImage; +} + +VOID egFreeImage(IN EG_IMAGE *Image) +{ + if (Image != NULL) { + if (Image->PixelData != NULL) + FreePool(Image->PixelData); + FreePool(Image); + } +} + +// +// Basic file operations +// + +EFI_STATUS egLoadFile(IN EFI_FILE* BaseDir, IN CHAR16 *FileName, + OUT UINT8 **FileData, OUT UINTN *FileDataLength) +{ + EFI_STATUS Status; + EFI_FILE_HANDLE FileHandle; + EFI_FILE_INFO *FileInfo; + UINT64 ReadSize; + UINTN BufferSize; + UINT8 *Buffer; + + Status = refit_call5_wrapper(BaseDir->Open, BaseDir, &FileHandle, FileName, EFI_FILE_MODE_READ, 0); + if (EFI_ERROR(Status)) { +// Print(L"Returning %d from egLoadFile() because of an error on open!\n", Status); + return Status; + } + + FileInfo = LibFileInfo(FileHandle); + if (FileInfo == NULL) { + refit_call1_wrapper(FileHandle->Close, FileHandle); +// Print(L"LibFileInfo() returned NULL!\n"); + return EFI_NOT_FOUND; + } + ReadSize = FileInfo->FileSize; + if (ReadSize > MAX_FILE_SIZE) + ReadSize = MAX_FILE_SIZE; + FreePool(FileInfo); + + BufferSize = (UINTN)ReadSize; // was limited to 1 GB above, so this is safe + Buffer = (UINT8 *) AllocatePool(BufferSize); + if (Buffer == NULL) { + refit_call1_wrapper(FileHandle->Close, FileHandle); + return EFI_OUT_OF_RESOURCES; + } + + Status = refit_call3_wrapper(FileHandle->Read, FileHandle, &BufferSize, Buffer); + refit_call1_wrapper(FileHandle->Close, FileHandle); + if (EFI_ERROR(Status)) { + FreePool(Buffer); + return Status; + } + + *FileData = Buffer; + *FileDataLength = BufferSize; +// Print(L"In egLoadFile(), Returning EFI_SUCCESS\n"); + return EFI_SUCCESS; +} + +static EFI_GUID ESPGuid = { 0xc12a7328, 0xf81f, 0x11d2, { 0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b } }; + +static EFI_STATUS egFindESP(OUT EFI_FILE_HANDLE *RootDir) +{ + EFI_STATUS Status; + UINTN HandleCount = 0; + EFI_HANDLE *Handles; + + Status = LibLocateHandle(ByProtocol, &ESPGuid, NULL, &HandleCount, &Handles); + if (!EFI_ERROR(Status) && HandleCount > 0) { + *RootDir = LibOpenRoot(Handles[0]); + if (*RootDir == NULL) + Status = EFI_NOT_FOUND; + FreePool(Handles); + } + return Status; +} + +EFI_STATUS egSaveFile(IN EFI_FILE* BaseDir OPTIONAL, IN CHAR16 *FileName, + IN UINT8 *FileData, IN UINTN FileDataLength) +{ + EFI_STATUS Status; + EFI_FILE_HANDLE FileHandle; + UINTN BufferSize; + + if (BaseDir == NULL) { + Status = egFindESP(&BaseDir); + if (EFI_ERROR(Status)) + return Status; + } + + Status = refit_call5_wrapper(BaseDir->Open, BaseDir, &FileHandle, FileName, + EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0); + if (EFI_ERROR(Status)) + return Status; + + BufferSize = FileDataLength; + Status = refit_call3_wrapper(FileHandle->Write, FileHandle, &BufferSize, FileData); + refit_call1_wrapper(FileHandle->Close, FileHandle); + + return Status; +} + +// +// Loading images from files and embedded data +// + +static CHAR16 * egFindExtension(IN CHAR16 *FileName) +{ + UINTN i; + + for (i = StrLen(FileName); i >= 0; i--) { + if (FileName[i] == '.') + return FileName + i + 1; + if (FileName[i] == '/' || FileName[i] == '\\') + break; + } + return FileName + StrLen(FileName); +} + +static EG_IMAGE * egDecodeAny(IN UINT8 *FileData, IN UINTN FileDataLength, + IN CHAR16 *Format, IN UINTN IconSize, IN BOOLEAN WantAlpha) +{ + EG_IMAGE *NewImage = NULL; + + // Note: The UEFI implementation in Gigabyte's Hybrid EFI is buggy and does + // a case-sensitive comparison in StriCmp rather than the case-insensitive + // comparison that the spec says should be done. As a workaround, we repeat + // the comparison twice here. + // dispatch by extension + if ((StriCmp(Format, L"BMP") == 0) || (StriCmp(Format, L"bmp") == 0)) { + NewImage = egDecodeBMP(FileData, FileDataLength, IconSize, WantAlpha); + } else if ((StriCmp(Format, L"ICNS") == 0) || (StriCmp(Format, L"icns") == 0)) { + NewImage = egDecodeICNS(FileData, FileDataLength, IconSize, WantAlpha); + } // if/else + + return NewImage; +} + +EG_IMAGE * egLoadImage(IN EFI_FILE* BaseDir, IN CHAR16 *FileName, IN BOOLEAN WantAlpha) +{ + EFI_STATUS Status; + UINT8 *FileData; + UINTN FileDataLength; + EG_IMAGE *NewImage; + + if (BaseDir == NULL || FileName == NULL) + return NULL; + + // load file + Status = egLoadFile(BaseDir, FileName, &FileData, &FileDataLength); + if (EFI_ERROR(Status)) + return NULL; + + // decode it + NewImage = egDecodeAny(FileData, FileDataLength, egFindExtension(FileName), 128, WantAlpha); + FreePool(FileData); + + return NewImage; +} + +EG_IMAGE * egLoadIcon(IN EFI_FILE* BaseDir, IN CHAR16 *FileName, IN UINTN IconSize) +{ + EFI_STATUS Status; + UINT8 *FileData; + UINTN FileDataLength; + EG_IMAGE *NewImage; + + if (BaseDir == NULL || FileName == NULL) + return NULL; + + // load file + Status = egLoadFile(BaseDir, FileName, &FileData, &FileDataLength); + if (EFI_ERROR(Status)) { +// Print(L"In egLoadIcon(), Status = %d after egLoadFile(); aborting load!\n", Status); + return NULL; + } + + // decode it + NewImage = egDecodeAny(FileData, FileDataLength, egFindExtension(FileName), IconSize, TRUE); +// Print(L"Done with egDecodeAny(), used extension '%s'\n", egFindExtension(FileName)); +// if (NewImage == NULL) +// Print(L"Returning NULL from egLoadIcon()\n"); + FreePool(FileData); + + return NewImage; +} + +EG_IMAGE * egDecodeImage(IN UINT8 *FileData, IN UINTN FileDataLength, IN CHAR16 *Format, IN BOOLEAN WantAlpha) +{ + return egDecodeAny(FileData, FileDataLength, Format, 128, WantAlpha); +} + +EG_IMAGE * egPrepareEmbeddedImage(IN EG_EMBEDDED_IMAGE *EmbeddedImage, IN BOOLEAN WantAlpha) +{ + EG_IMAGE *NewImage; + UINT8 *CompData; + UINTN CompLen; + UINTN PixelCount; + + // sanity check + if (EmbeddedImage->PixelMode > EG_MAX_EIPIXELMODE || + (EmbeddedImage->CompressMode != EG_EICOMPMODE_NONE && EmbeddedImage->CompressMode != EG_EICOMPMODE_RLE)) + return NULL; + + // allocate image structure and pixel buffer + NewImage = egCreateImage(EmbeddedImage->Width, EmbeddedImage->Height, WantAlpha); + if (NewImage == NULL) + return NULL; + + CompData = (UINT8 *)EmbeddedImage->Data; // drop const + CompLen = EmbeddedImage->DataLength; + PixelCount = EmbeddedImage->Width * EmbeddedImage->Height; + + // FUTURE: for EG_EICOMPMODE_EFICOMPRESS, decompress whole data block here + + if (EmbeddedImage->PixelMode == EG_EIPIXELMODE_GRAY || + EmbeddedImage->PixelMode == EG_EIPIXELMODE_GRAY_ALPHA) { + + // copy grayscale plane and expand + if (EmbeddedImage->CompressMode == EG_EICOMPMODE_RLE) { + egDecompressIcnsRLE(&CompData, &CompLen, PLPTR(NewImage, r), PixelCount); + } else { + egInsertPlane(CompData, PLPTR(NewImage, r), PixelCount); + CompData += PixelCount; + } + egCopyPlane(PLPTR(NewImage, r), PLPTR(NewImage, g), PixelCount); + egCopyPlane(PLPTR(NewImage, r), PLPTR(NewImage, b), PixelCount); + + } else if (EmbeddedImage->PixelMode == EG_EIPIXELMODE_COLOR || + EmbeddedImage->PixelMode == EG_EIPIXELMODE_COLOR_ALPHA) { + + // copy color planes + if (EmbeddedImage->CompressMode == EG_EICOMPMODE_RLE) { + egDecompressIcnsRLE(&CompData, &CompLen, PLPTR(NewImage, r), PixelCount); + egDecompressIcnsRLE(&CompData, &CompLen, PLPTR(NewImage, g), PixelCount); + egDecompressIcnsRLE(&CompData, &CompLen, PLPTR(NewImage, b), PixelCount); + } else { + egInsertPlane(CompData, PLPTR(NewImage, r), PixelCount); + CompData += PixelCount; + egInsertPlane(CompData, PLPTR(NewImage, g), PixelCount); + CompData += PixelCount; + egInsertPlane(CompData, PLPTR(NewImage, b), PixelCount); + CompData += PixelCount; + } + + } else { + + // set color planes to black + egSetPlane(PLPTR(NewImage, r), 0, PixelCount); + egSetPlane(PLPTR(NewImage, g), 0, PixelCount); + egSetPlane(PLPTR(NewImage, b), 0, PixelCount); + + } + + if (WantAlpha && (EmbeddedImage->PixelMode == EG_EIPIXELMODE_GRAY_ALPHA || + EmbeddedImage->PixelMode == EG_EIPIXELMODE_COLOR_ALPHA || + EmbeddedImage->PixelMode == EG_EIPIXELMODE_ALPHA)) { + + // copy alpha plane + if (EmbeddedImage->CompressMode == EG_EICOMPMODE_RLE) { + egDecompressIcnsRLE(&CompData, &CompLen, PLPTR(NewImage, a), PixelCount); + } else { + egInsertPlane(CompData, PLPTR(NewImage, a), PixelCount); + CompData += PixelCount; + } + + } else { + egSetPlane(PLPTR(NewImage, a), WantAlpha ? 255 : 0, PixelCount); + } + + return NewImage; +} + +// +// Compositing +// + +VOID egRestrictImageArea(IN EG_IMAGE *Image, + IN UINTN AreaPosX, IN UINTN AreaPosY, + IN OUT UINTN *AreaWidth, IN OUT UINTN *AreaHeight) +{ + if (AreaPosX >= Image->Width || AreaPosY >= Image->Height) { + // out of bounds, operation has no effect + *AreaWidth = 0; + *AreaHeight = 0; + } else { + // calculate affected area + if (*AreaWidth > Image->Width - AreaPosX) + *AreaWidth = Image->Width - AreaPosX; + if (*AreaHeight > Image->Height - AreaPosY) + *AreaHeight = Image->Height - AreaPosY; + } +} + +VOID egFillImage(IN OUT EG_IMAGE *CompImage, IN EG_PIXEL *Color) +{ + UINTN i; + EG_PIXEL FillColor; + EG_PIXEL *PixelPtr; + + FillColor = *Color; + if (!CompImage->HasAlpha) + FillColor.a = 0; + + PixelPtr = CompImage->PixelData; + for (i = 0; i < CompImage->Width * CompImage->Height; i++, PixelPtr++) + *PixelPtr = FillColor; +} + +VOID egFillImageArea(IN OUT EG_IMAGE *CompImage, + IN UINTN AreaPosX, IN UINTN AreaPosY, + IN UINTN AreaWidth, IN UINTN AreaHeight, + IN EG_PIXEL *Color) +{ + UINTN x, y; + EG_PIXEL FillColor; + EG_PIXEL *PixelPtr; + EG_PIXEL *PixelBasePtr; + + egRestrictImageArea(CompImage, AreaPosX, AreaPosY, &AreaWidth, &AreaHeight); + + if (AreaWidth > 0) { + FillColor = *Color; + if (!CompImage->HasAlpha) + FillColor.a = 0; + + PixelBasePtr = CompImage->PixelData + AreaPosY * CompImage->Width + AreaPosX; + for (y = 0; y < AreaHeight; y++) { + PixelPtr = PixelBasePtr; + for (x = 0; x < AreaWidth; x++, PixelPtr++) + *PixelPtr = FillColor; + PixelBasePtr += CompImage->Width; + } + } +} + +VOID egRawCopy(IN OUT EG_PIXEL *CompBasePtr, IN EG_PIXEL *TopBasePtr, + IN UINTN Width, IN UINTN Height, + IN UINTN CompLineOffset, IN UINTN TopLineOffset) +{ + UINTN x, y; + EG_PIXEL *TopPtr, *CompPtr; + + for (y = 0; y < Height; y++) { + TopPtr = TopBasePtr; + CompPtr = CompBasePtr; + for (x = 0; x < Width; x++) { + *CompPtr = *TopPtr; + TopPtr++, CompPtr++; + } + TopBasePtr += TopLineOffset; + CompBasePtr += CompLineOffset; + } +} + +VOID egRawCompose(IN OUT EG_PIXEL *CompBasePtr, IN EG_PIXEL *TopBasePtr, + IN UINTN Width, IN UINTN Height, + IN UINTN CompLineOffset, IN UINTN TopLineOffset) +{ + UINTN x, y; + EG_PIXEL *TopPtr, *CompPtr; + UINTN Alpha; + UINTN RevAlpha; + UINTN Temp; + + for (y = 0; y < Height; y++) { + TopPtr = TopBasePtr; + CompPtr = CompBasePtr; + for (x = 0; x < Width; x++) { + Alpha = TopPtr->a; + RevAlpha = 255 - Alpha; + Temp = (UINTN)CompPtr->b * RevAlpha + (UINTN)TopPtr->b * Alpha + 0x80; + CompPtr->b = (Temp + (Temp >> 8)) >> 8; + Temp = (UINTN)CompPtr->g * RevAlpha + (UINTN)TopPtr->g * Alpha + 0x80; + CompPtr->g = (Temp + (Temp >> 8)) >> 8; + Temp = (UINTN)CompPtr->r * RevAlpha + (UINTN)TopPtr->r * Alpha + 0x80; + CompPtr->r = (Temp + (Temp >> 8)) >> 8; + /* + CompPtr->b = ((UINTN)CompPtr->b * RevAlpha + (UINTN)TopPtr->b * Alpha) / 255; + CompPtr->g = ((UINTN)CompPtr->g * RevAlpha + (UINTN)TopPtr->g * Alpha) / 255; + CompPtr->r = ((UINTN)CompPtr->r * RevAlpha + (UINTN)TopPtr->r * Alpha) / 255; + */ + TopPtr++, CompPtr++; + } + TopBasePtr += TopLineOffset; + CompBasePtr += CompLineOffset; + } +} + +VOID egComposeImage(IN OUT EG_IMAGE *CompImage, IN EG_IMAGE *TopImage, IN UINTN PosX, IN UINTN PosY) +{ + UINTN CompWidth, CompHeight; + + CompWidth = TopImage->Width; + CompHeight = TopImage->Height; + egRestrictImageArea(CompImage, PosX, PosY, &CompWidth, &CompHeight); + + // compose + if (CompWidth > 0) { + if (CompImage->HasAlpha) { + CompImage->HasAlpha = FALSE; + egSetPlane(PLPTR(CompImage, a), 0, CompImage->Width * CompImage->Height); + } + + if (TopImage->HasAlpha) + egRawCompose(CompImage->PixelData + PosY * CompImage->Width + PosX, TopImage->PixelData, + CompWidth, CompHeight, CompImage->Width, TopImage->Width); + else + egRawCopy(CompImage->PixelData + PosY * CompImage->Width + PosX, TopImage->PixelData, + CompWidth, CompHeight, CompImage->Width, TopImage->Width); + } +} + +EG_IMAGE * egEnsureImageSize(IN EG_IMAGE *Image, IN UINTN Width, IN UINTN Height, IN EG_PIXEL *Color) +{ + EG_IMAGE *NewImage; + + if (Image == NULL) + return NULL; + if (Image->Width == Width && Image->Height == Height) + return Image; + + NewImage = egCreateFilledImage(Width, Height, Image->HasAlpha, Color); + if (NewImage == NULL) { + egFreeImage(Image); + return NULL; + } + egComposeImage(NewImage, Image, 0, 0); + egFreeImage(Image); + + return NewImage; +} + +// +// misc internal functions +// + +VOID egInsertPlane(IN UINT8 *SrcDataPtr, IN UINT8 *DestPlanePtr, IN UINTN PixelCount) +{ + UINTN i; + + for (i = 0; i < PixelCount; i++) { + *DestPlanePtr = *SrcDataPtr++; + DestPlanePtr += 4; + } +} + +VOID egSetPlane(IN UINT8 *DestPlanePtr, IN UINT8 Value, IN UINTN PixelCount) +{ + UINTN i; + + for (i = 0; i < PixelCount; i++) { + *DestPlanePtr = Value; + DestPlanePtr += 4; + } +} + +VOID egCopyPlane(IN UINT8 *SrcPlanePtr, IN UINT8 *DestPlanePtr, IN UINTN PixelCount) +{ + UINTN i; + + for (i = 0; i < PixelCount; i++) { + *DestPlanePtr = *SrcPlanePtr; + DestPlanePtr += 4, SrcPlanePtr += 4; + } +} + +/* EOF */ diff --git a/libeg/libeg.h b/libeg/libeg.h new file mode 100644 index 0000000..6a2b3c5 --- /dev/null +++ b/libeg/libeg.h @@ -0,0 +1,127 @@ +/* + * libeg/libeg.h + * EFI graphics library header for users + * + * Copyright (c) 2006 Christoph Pfisterer + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Christoph Pfisterer nor the names of the + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __LIBEG_LIBEG_H__ +#define __LIBEG_LIBEG_H__ + + +/* types */ + +/* This should be compatible with EFI_UGA_PIXEL */ +typedef struct { + UINT8 b, g, r, a; +} EG_PIXEL; + +typedef struct { + UINTN Width; + UINTN Height; + BOOLEAN HasAlpha; + EG_PIXEL *PixelData; +} EG_IMAGE; + +#define EG_EIPIXELMODE_GRAY (0) +#define EG_EIPIXELMODE_GRAY_ALPHA (1) +#define EG_EIPIXELMODE_COLOR (2) +#define EG_EIPIXELMODE_COLOR_ALPHA (3) +#define EG_EIPIXELMODE_ALPHA (4) +#define EG_MAX_EIPIXELMODE EG_EIPIXELMODE_ALPHA + +#define EG_EICOMPMODE_NONE (0) +#define EG_EICOMPMODE_RLE (1) +#define EG_EICOMPMODE_EFICOMPRESS (2) + +typedef struct { + UINTN Width; + UINTN Height; + UINTN PixelMode; + UINTN CompressMode; + const UINT8 *Data; + UINTN DataLength; +} EG_EMBEDDED_IMAGE; + +/* functions */ + +VOID egInitScreen(VOID); +VOID egGetScreenSize(OUT UINTN *ScreenWidth, OUT UINTN *ScreenHeight); +CHAR16 * egScreenDescription(VOID); +BOOLEAN egHasGraphicsMode(VOID); +BOOLEAN egIsGraphicsModeEnabled(VOID); +VOID egSetGraphicsModeEnabled(IN BOOLEAN Enable); +// NOTE: Even when egHasGraphicsMode() returns FALSE, you should +// call egSetGraphicsModeEnabled(FALSE) to ensure the system +// is running in text mode. egHasGraphicsMode() only determines +// if libeg can draw to the screen in graphics mode. + +EG_IMAGE * egCreateImage(IN UINTN Width, IN UINTN Height, IN BOOLEAN HasAlpha); +EG_IMAGE * egCreateFilledImage(IN UINTN Width, IN UINTN Height, IN BOOLEAN HasAlpha, IN EG_PIXEL *Color); +EG_IMAGE * egCopyImage(IN EG_IMAGE *Image); +VOID egFreeImage(IN EG_IMAGE *Image); + +EG_IMAGE * egLoadImage(IN EFI_FILE* BaseDir, IN CHAR16 *FileName, IN BOOLEAN WantAlpha); +EG_IMAGE * egLoadIcon(IN EFI_FILE* BaseDir, IN CHAR16 *FileName, IN UINTN IconSize); +EG_IMAGE * egDecodeImage(IN UINT8 *FileData, IN UINTN FileDataLength, IN CHAR16 *Format, IN BOOLEAN WantAlpha); +EG_IMAGE * egPrepareEmbeddedImage(IN EG_EMBEDDED_IMAGE *EmbeddedImage, IN BOOLEAN WantAlpha); + +EG_IMAGE * egEnsureImageSize(IN EG_IMAGE *Image, IN UINTN Width, IN UINTN Height, IN EG_PIXEL *Color); + +EFI_STATUS egLoadFile(IN EFI_FILE* BaseDir, IN CHAR16 *FileName, + OUT UINT8 **FileData, OUT UINTN *FileDataLength); +EFI_STATUS egSaveFile(IN EFI_FILE* BaseDir OPTIONAL, IN CHAR16 *FileName, + IN UINT8 *FileData, IN UINTN FileDataLength); + +VOID egFillImage(IN OUT EG_IMAGE *CompImage, IN EG_PIXEL *Color); +VOID egFillImageArea(IN OUT EG_IMAGE *CompImage, + IN UINTN AreaPosX, IN UINTN AreaPosY, + IN UINTN AreaWidth, IN UINTN AreaHeight, + IN EG_PIXEL *Color); +VOID egComposeImage(IN OUT EG_IMAGE *CompImage, IN EG_IMAGE *TopImage, IN UINTN PosX, IN UINTN PosY); + +VOID egMeasureText(IN CHAR16 *Text, OUT UINTN *Width, OUT UINTN *Height); +VOID egRenderText(IN CHAR16 *Text, IN OUT EG_IMAGE *CompImage, IN UINTN PosX, IN UINTN PosY); + +VOID egClearScreen(IN EG_PIXEL *Color); +VOID egDrawImage(IN EG_IMAGE *Image, IN UINTN ScreenPosX, IN UINTN ScreenPosY); +VOID egDrawImageArea(IN EG_IMAGE *Image, + IN UINTN AreaPosX, IN UINTN AreaPosY, + IN UINTN AreaWidth, IN UINTN AreaHeight, + IN UINTN ScreenPosX, IN UINTN ScreenPosY); + +VOID egScreenShot(VOID); + + +#endif /* __LIBEG_LIBEG_H__ */ + +/* EOF */ diff --git a/libeg/libegint.h b/libeg/libegint.h new file mode 100644 index 0000000..6bcdf1d --- /dev/null +++ b/libeg/libegint.h @@ -0,0 +1,77 @@ +/* + * libeg/libegint.h + * EFI graphics library internal header + * + * Copyright (c) 2006 Christoph Pfisterer + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Christoph Pfisterer nor the names of the + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __LIBEG_LIBEGINT_H__ +#define __LIBEG_LIBEGINT_H__ + + +#include +#include + +#include "libeg.h" + +/* types */ + +typedef EG_IMAGE * (*EG_DECODE_FUNC)(IN UINT8 *FileData, IN UINTN FileDataLength, IN UINTN IconSize, IN BOOLEAN WantAlpha); + +/* functions */ + +VOID egRestrictImageArea(IN EG_IMAGE *Image, + IN UINTN AreaPosX, IN UINTN AreaPosY, + IN OUT UINTN *AreaWidth, IN OUT UINTN *AreaHeight); +VOID egRawCopy(IN OUT EG_PIXEL *CompBasePtr, IN EG_PIXEL *TopBasePtr, + IN UINTN Width, IN UINTN Height, + IN UINTN CompLineOffset, IN UINTN TopLineOffset); +VOID egRawCompose(IN OUT EG_PIXEL *CompBasePtr, IN EG_PIXEL *TopBasePtr, + IN UINTN Width, IN UINTN Height, + IN UINTN CompLineOffset, IN UINTN TopLineOffset); + +#define PLPTR(imagevar, colorname) ((UINT8 *) &((imagevar)->PixelData->colorname)) + +VOID egDecompressIcnsRLE(IN OUT UINT8 **CompData, IN OUT UINTN *CompLen, IN UINT8 *DestPlanePtr, IN UINTN PixelCount); +VOID egInsertPlane(IN UINT8 *SrcDataPtr, IN UINT8 *DestPlanePtr, IN UINTN PixelCount); +VOID egSetPlane(IN UINT8 *DestPlanePtr, IN UINT8 Value, IN UINTN PixelCount); +VOID egCopyPlane(IN UINT8 *SrcPlanePtr, IN UINT8 *DestPlanePtr, IN UINTN PixelCount); + +EG_IMAGE * egDecodeBMP(IN UINT8 *FileData, IN UINTN FileDataLength, IN UINTN IconSize, IN BOOLEAN WantAlpha); +EG_IMAGE * egDecodeICNS(IN UINT8 *FileData, IN UINTN FileDataLength, IN UINTN IconSize, IN BOOLEAN WantAlpha); + +VOID egEncodeBMP(IN EG_IMAGE *Image, OUT UINT8 **FileData, OUT UINTN *FileDataLength); + + +#endif /* __LIBEG_LIBEGINT_H__ */ + +/* EOF */ diff --git a/libeg/load_bmp.c b/libeg/load_bmp.c new file mode 100644 index 0000000..d0092e5 --- /dev/null +++ b/libeg/load_bmp.c @@ -0,0 +1,265 @@ +/* + * libeg/load_bmp.c + * Loading function for BMP images + * + * Copyright (c) 2006 Christoph Pfisterer + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Christoph Pfisterer nor the names of the + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "libegint.h" + +// BMP structures + +#pragma pack(1) + +typedef struct { + UINT8 Blue; + UINT8 Green; + UINT8 Red; + UINT8 Reserved; +} BMP_COLOR_MAP; + +typedef struct { + CHAR8 CharB; + CHAR8 CharM; + UINT32 Size; + UINT16 Reserved[2]; + UINT32 ImageOffset; + UINT32 HeaderSize; + UINT32 PixelWidth; + UINT32 PixelHeight; + UINT16 Planes; // Must be 1 + UINT16 BitPerPixel; // 1, 4, 8, or 24 + UINT32 CompressionType; + UINT32 ImageSize; // Compressed image size in bytes + UINT32 XPixelsPerMeter; + UINT32 YPixelsPerMeter; + UINT32 NumberOfColors; + UINT32 ImportantColors; +} BMP_IMAGE_HEADER; + +#pragma pack() + +// +// Load BMP image +// + +EG_IMAGE * egDecodeBMP(IN UINT8 *FileData, IN UINTN FileDataLength, IN UINTN IconSize, IN BOOLEAN WantAlpha) +{ + EG_IMAGE *NewImage; + BMP_IMAGE_HEADER *BmpHeader; + BMP_COLOR_MAP *BmpColorMap; + UINTN x, y; + UINT8 *ImagePtr; + UINT8 *ImagePtrBase; + UINTN ImageLineOffset; + UINT8 ImageValue = 0, AlphaValue; + EG_PIXEL *PixelPtr; + UINTN Index, BitIndex; + + // read and check header + if (FileDataLength < sizeof(BMP_IMAGE_HEADER) || FileData == NULL) + return NULL; + BmpHeader = (BMP_IMAGE_HEADER *) FileData; + if (BmpHeader->CharB != 'B' || BmpHeader->CharM != 'M') + return NULL; + if (BmpHeader->CompressionType != 0) + return NULL; + if (BmpHeader->BitPerPixel != 1 && BmpHeader->BitPerPixel != 4 && + BmpHeader->BitPerPixel != 8 && BmpHeader->BitPerPixel != 24) + return NULL; + + // calculate parameters + ImageLineOffset = BmpHeader->PixelWidth; + if (BmpHeader->BitPerPixel == 24) + ImageLineOffset *= 3; + else if (BmpHeader->BitPerPixel == 1) + ImageLineOffset = (ImageLineOffset + 7) >> 3; + else if (BmpHeader->BitPerPixel == 4) + ImageLineOffset = (ImageLineOffset + 1) >> 1; + if ((ImageLineOffset % 4) != 0) + ImageLineOffset = ImageLineOffset + (4 - (ImageLineOffset % 4)); + // check bounds + if (BmpHeader->ImageOffset + ImageLineOffset * BmpHeader->PixelHeight > FileDataLength) + return NULL; + + // allocate image structure and buffer + NewImage = egCreateImage(BmpHeader->PixelWidth, BmpHeader->PixelHeight, WantAlpha); + if (NewImage == NULL) + return NULL; + AlphaValue = WantAlpha ? 255 : 0; + + // convert image + BmpColorMap = (BMP_COLOR_MAP *)(FileData + sizeof(BMP_IMAGE_HEADER)); + ImagePtrBase = FileData + BmpHeader->ImageOffset; + for (y = 0; y < BmpHeader->PixelHeight; y++) { + ImagePtr = ImagePtrBase; + ImagePtrBase += ImageLineOffset; + PixelPtr = NewImage->PixelData + (BmpHeader->PixelHeight - 1 - y) * BmpHeader->PixelWidth; + + switch (BmpHeader->BitPerPixel) { + + case 1: + for (x = 0; x < BmpHeader->PixelWidth; x++) { + BitIndex = x & 0x07; + if (BitIndex == 0) + ImageValue = *ImagePtr++; + + Index = (ImageValue >> (7 - BitIndex)) & 0x01; + PixelPtr->b = BmpColorMap[Index].Blue; + PixelPtr->g = BmpColorMap[Index].Green; + PixelPtr->r = BmpColorMap[Index].Red; + PixelPtr->a = AlphaValue; + PixelPtr++; + } + break; + + case 4: + for (x = 0; x <= BmpHeader->PixelWidth - 2; x += 2) { + ImageValue = *ImagePtr++; + + Index = ImageValue >> 4; + PixelPtr->b = BmpColorMap[Index].Blue; + PixelPtr->g = BmpColorMap[Index].Green; + PixelPtr->r = BmpColorMap[Index].Red; + PixelPtr->a = AlphaValue; + PixelPtr++; + + Index = ImageValue & 0x0f; + PixelPtr->b = BmpColorMap[Index].Blue; + PixelPtr->g = BmpColorMap[Index].Green; + PixelPtr->r = BmpColorMap[Index].Red; + PixelPtr->a = AlphaValue; + PixelPtr++; + } + if (x < BmpHeader->PixelWidth) { + ImageValue = *ImagePtr++; + + Index = ImageValue >> 4; + PixelPtr->b = BmpColorMap[Index].Blue; + PixelPtr->g = BmpColorMap[Index].Green; + PixelPtr->r = BmpColorMap[Index].Red; + PixelPtr->a = AlphaValue; + PixelPtr++; + } + break; + + case 8: + for (x = 0; x < BmpHeader->PixelWidth; x++) { + Index = *ImagePtr++; + PixelPtr->b = BmpColorMap[Index].Blue; + PixelPtr->g = BmpColorMap[Index].Green; + PixelPtr->r = BmpColorMap[Index].Red; + PixelPtr->a = AlphaValue; + PixelPtr++; + } + break; + + case 24: + for (x = 0; x < BmpHeader->PixelWidth; x++) { + PixelPtr->b = *ImagePtr++; + PixelPtr->g = *ImagePtr++; + PixelPtr->r = *ImagePtr++; + PixelPtr->a = AlphaValue; + PixelPtr++; + } + break; + + } + } + + return NewImage; +} + +// +// Save BMP image +// + +VOID egEncodeBMP(IN EG_IMAGE *Image, OUT UINT8 **FileDataReturn, OUT UINTN *FileDataLengthReturn) +{ + BMP_IMAGE_HEADER *BmpHeader; + UINT8 *FileData; + UINTN FileDataLength; + UINT8 *ImagePtr; + UINT8 *ImagePtrBase; + UINTN ImageLineOffset; + EG_PIXEL *PixelPtr; + UINTN x, y; + + ImageLineOffset = Image->Width * 3; + if ((ImageLineOffset % 4) != 0) + ImageLineOffset = ImageLineOffset + (4 - (ImageLineOffset % 4)); + + // allocate buffer for file data + FileDataLength = sizeof(BMP_IMAGE_HEADER) + Image->Height * ImageLineOffset; + FileData = AllocateZeroPool(FileDataLength); + if (FileData == NULL) { + Print(L"Error allocate %d bytes\n", FileDataLength); + *FileDataReturn = NULL; + *FileDataLengthReturn = 0; + return; + } + + // fill header + BmpHeader = (BMP_IMAGE_HEADER *)FileData; + BmpHeader->CharB = 'B'; + BmpHeader->CharM = 'M'; + BmpHeader->Size = FileDataLength; + BmpHeader->ImageOffset = sizeof(BMP_IMAGE_HEADER); + BmpHeader->HeaderSize = 40; + BmpHeader->PixelWidth = Image->Width; + BmpHeader->PixelHeight = Image->Height; + BmpHeader->Planes = 1; + BmpHeader->BitPerPixel = 24; + BmpHeader->CompressionType = 0; + BmpHeader->XPixelsPerMeter = 0xb13; + BmpHeader->YPixelsPerMeter = 0xb13; + + // fill pixel buffer + ImagePtrBase = FileData + BmpHeader->ImageOffset; + for (y = 0; y < Image->Height; y++) { + ImagePtr = ImagePtrBase; + ImagePtrBase += ImageLineOffset; + PixelPtr = Image->PixelData + (Image->Height - 1 - y) * Image->Width; + + for (x = 0; x < Image->Width; x++) { + *ImagePtr++ = PixelPtr->b; + *ImagePtr++ = PixelPtr->g; + *ImagePtr++ = PixelPtr->r; + PixelPtr++; + } + } + + *FileDataReturn = FileData; + *FileDataLengthReturn = FileDataLength; +} + +/* EOF */ diff --git a/libeg/load_icns.c b/libeg/load_icns.c new file mode 100644 index 0000000..6af234d --- /dev/null +++ b/libeg/load_icns.c @@ -0,0 +1,226 @@ +/* + * libeg/load_icns.c + * Loading function for .icns Apple icon images + * + * Copyright (c) 2006 Christoph Pfisterer + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Christoph Pfisterer nor the names of the + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "libegint.h" + +// +// Decompress .icns RLE data +// + +VOID egDecompressIcnsRLE(IN OUT UINT8 **CompData, IN OUT UINTN *CompLen, IN UINT8 *PixelData, IN UINTN PixelCount) +{ + UINT8 *cp; + UINT8 *cp_end; + UINT8 *pp; + UINTN pp_left; + UINTN len, i; + UINT8 value; + + // setup variables + cp = *CompData; + cp_end = cp + *CompLen; + pp = PixelData; + pp_left = PixelCount; + + // decode + while (cp + 1 < cp_end && pp_left > 0) { + len = *cp++; + if (len & 0x80) { // compressed data: repeat next byte + len -= 125; + if (len > pp_left) + break; + value = *cp++; + for (i = 0; i < len; i++) { + *pp = value; + pp += 4; + } + } else { // uncompressed data: copy bytes + len++; + if (len > pp_left || cp + len > cp_end) + break; + for (i = 0; i < len; i++) { + *pp = *cp++; + pp += 4; + } + } + pp_left -= len; + } + + if (pp_left > 0) { + Print(L" egDecompressIcnsRLE: still need %d bytes of pixel data\n", pp_left); + } + + // record what's left of the compressed data stream + *CompData = cp; + *CompLen = (UINTN)(cp_end - cp); +} + +// +// Load Apple .icns icons +// + +EG_IMAGE * egDecodeICNS(IN UINT8 *FileData, IN UINTN FileDataLength, IN UINTN IconSize, IN BOOLEAN WantAlpha) +{ + EG_IMAGE *NewImage; + UINT8 *Ptr, *BufferEnd, *DataPtr, *MaskPtr; + UINT32 BlockLen, DataLen, MaskLen; + UINTN FetchPixelSize, PixelCount, i; + UINT8 *CompData; + UINTN CompLen; + UINT8 *SrcPtr; + EG_PIXEL *DestPtr; + + if (FileDataLength < 8 || FileData == NULL || + FileData[0] != 'i' || FileData[1] != 'c' || FileData[2] != 'n' || FileData[3] != 's') { + // not an icns file... + return NULL; + } + + FetchPixelSize = IconSize; + for (;;) { + DataPtr = NULL; + DataLen = 0; + MaskPtr = NULL; + MaskLen = 0; + + Ptr = FileData + 8; + BufferEnd = FileData + FileDataLength; + // iterate over tagged blocks in the file + while (Ptr + 8 <= BufferEnd) { + BlockLen = ((UINT32)Ptr[4] << 24) + ((UINT32)Ptr[5] << 16) + ((UINT32)Ptr[6] << 8) + (UINT32)Ptr[7]; + if (Ptr + BlockLen > BufferEnd) // block continues beyond end of file + break; + + // extract the appropriate blocks for each pixel size + if (FetchPixelSize == 128) { + if (Ptr[0] == 'i' && Ptr[1] == 't' && Ptr[2] == '3' && Ptr[3] == '2') { + if (Ptr[8] == 0 && Ptr[9] == 0 && Ptr[10] == 0 && Ptr[11] == 0) { + DataPtr = Ptr + 12; + DataLen = BlockLen - 12; + } + } else if (Ptr[0] == 't' && Ptr[1] == '8' && Ptr[2] == 'm' && Ptr[3] == 'k') { + MaskPtr = Ptr + 8; + MaskLen = BlockLen - 8; + } + + } else if (FetchPixelSize == 48) { + if (Ptr[0] == 'i' && Ptr[1] == 'h' && Ptr[2] == '3' && Ptr[3] == '2') { + DataPtr = Ptr + 8; + DataLen = BlockLen - 8; + } else if (Ptr[0] == 'h' && Ptr[1] == '8' && Ptr[2] == 'm' && Ptr[3] == 'k') { + MaskPtr = Ptr + 8; + MaskLen = BlockLen - 8; + } + + } else if (FetchPixelSize == 32) { + if (Ptr[0] == 'i' && Ptr[1] == 'l' && Ptr[2] == '3' && Ptr[3] == '2') { + DataPtr = Ptr + 8; + DataLen = BlockLen - 8; + } else if (Ptr[0] == 'l' && Ptr[1] == '8' && Ptr[2] == 'm' && Ptr[3] == 'k') { + MaskPtr = Ptr + 8; + MaskLen = BlockLen - 8; + } + + } else if (FetchPixelSize == 16) { + if (Ptr[0] == 'i' && Ptr[1] == 's' && Ptr[2] == '3' && Ptr[3] == '2') { + DataPtr = Ptr + 8; + DataLen = BlockLen - 8; + } else if (Ptr[0] == 's' && Ptr[1] == '8' && Ptr[2] == 'm' && Ptr[3] == 'k') { + MaskPtr = Ptr + 8; + MaskLen = BlockLen - 8; + } + + } + + Ptr += BlockLen; + } + + /* FUTURE: try to load a different size and scale it later + if (DataPtr == NULL && FetchPixelSize == 32) { + FetchPixelSize = 128; + continue; + } + */ + break; + } + + if (DataPtr == NULL) + return NULL; // no image found + + // allocate image structure and buffer + NewImage = egCreateImage(FetchPixelSize, FetchPixelSize, WantAlpha); + if (NewImage == NULL) + return NULL; + PixelCount = FetchPixelSize * FetchPixelSize; + + if (DataLen < PixelCount * 3) { + + // pixel data is compressed, RGB planar + CompData = DataPtr; + CompLen = DataLen; + egDecompressIcnsRLE(&CompData, &CompLen, PLPTR(NewImage, r), PixelCount); + egDecompressIcnsRLE(&CompData, &CompLen, PLPTR(NewImage, g), PixelCount); + egDecompressIcnsRLE(&CompData, &CompLen, PLPTR(NewImage, b), PixelCount); + // possible assertion: CompLen == 0 + if (CompLen > 0) { + Print(L" egLoadICNSIcon: %d bytes of compressed data left\n", CompLen); + } + + } else { + + // pixel data is uncompressed, RGB interleaved + SrcPtr = DataPtr; + DestPtr = NewImage->PixelData; + for (i = 0; i < PixelCount; i++, DestPtr++) { + DestPtr->r = *SrcPtr++; + DestPtr->g = *SrcPtr++; + DestPtr->b = *SrcPtr++; + } + + } + + // add/set alpha plane + if (MaskPtr != NULL && MaskLen >= PixelCount && WantAlpha) + egInsertPlane(MaskPtr, PLPTR(NewImage, a), PixelCount); + else + egSetPlane(PLPTR(NewImage, a), WantAlpha ? 255 : 0, PixelCount); + + // FUTURE: scale to originally requested size if we had to load another size + + return NewImage; +} + +/* EOF */ diff --git a/libeg/screen.c b/libeg/screen.c new file mode 100644 index 0000000..f3a36c4 --- /dev/null +++ b/libeg/screen.c @@ -0,0 +1,284 @@ +/* + * libeg/screen.c + * Screen handling functions + * + * Copyright (c) 2006 Christoph Pfisterer + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Christoph Pfisterer nor the names of the + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "libegint.h" +#include "refit_call_wrapper.h" + +#include +/* #include */ +#include + +// Console defines and variables + +static EFI_GUID ConsoleControlProtocolGuid = EFI_CONSOLE_CONTROL_PROTOCOL_GUID; +static EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl = NULL; + +static EFI_GUID UgaDrawProtocolGuid = EFI_UGA_DRAW_PROTOCOL_GUID; +static EFI_UGA_DRAW_PROTOCOL *UgaDraw = NULL; + +static EFI_GUID GraphicsOutputProtocolGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; +static EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput = NULL; + +static BOOLEAN egHasGraphics = FALSE; +static UINTN egScreenWidth = 800; +static UINTN egScreenHeight = 600; + +// +// Screen handling +// + +VOID egInitScreen(VOID) +{ + EFI_STATUS Status; + UINT32 UGAWidth, UGAHeight, UGADepth, UGARefreshRate; + + // get protocols + Status = LibLocateProtocol(&ConsoleControlProtocolGuid, (VOID **) &ConsoleControl); + if (EFI_ERROR(Status)) + ConsoleControl = NULL; + + Status = LibLocateProtocol(&UgaDrawProtocolGuid, (VOID **) &UgaDraw); + if (EFI_ERROR(Status)) + UgaDraw = NULL; + + Status = LibLocateProtocol(&GraphicsOutputProtocolGuid, (VOID **) &GraphicsOutput); + if (EFI_ERROR(Status)) + GraphicsOutput = NULL; + + // get screen size + egHasGraphics = FALSE; + if (GraphicsOutput != NULL) { + egScreenWidth = GraphicsOutput->Mode->Info->HorizontalResolution; + egScreenHeight = GraphicsOutput->Mode->Info->VerticalResolution; + egHasGraphics = TRUE; + } else if (UgaDraw != NULL) { + Status = refit_call5_wrapper(UgaDraw->GetMode, UgaDraw, &UGAWidth, &UGAHeight, &UGADepth, &UGARefreshRate); + if (EFI_ERROR(Status)) { + UgaDraw = NULL; // graphics not available + } else { + egScreenWidth = UGAWidth; + egScreenHeight = UGAHeight; + egHasGraphics = TRUE; + } + } +} + +VOID egGetScreenSize(OUT UINTN *ScreenWidth, OUT UINTN *ScreenHeight) +{ + if (ScreenWidth != NULL) + *ScreenWidth = egScreenWidth; + if (ScreenHeight != NULL) + *ScreenHeight = egScreenHeight; +} + +CHAR16 * egScreenDescription(VOID) +{ + if (egHasGraphics) { + if (GraphicsOutput != NULL) { + return PoolPrint(L"Graphics Output (UEFI), %dx%d", + egScreenWidth, egScreenHeight); + } else if (UgaDraw != NULL) { + return PoolPrint(L"UGA Draw (EFI 1.10), %dx%d", + egScreenWidth, egScreenHeight); + } else { + return L"Internal Error"; + } + } else { + return L"Text Console"; + } +} + +BOOLEAN egHasGraphicsMode(VOID) +{ + return egHasGraphics; +} + +BOOLEAN egIsGraphicsModeEnabled(VOID) +{ + EFI_CONSOLE_CONTROL_SCREEN_MODE CurrentMode; + + if (ConsoleControl != NULL) { + refit_call4_wrapper(ConsoleControl->GetMode, ConsoleControl, &CurrentMode, NULL, NULL); + return (CurrentMode == EfiConsoleControlScreenGraphics) ? TRUE : FALSE; + } + + return FALSE; +} + +VOID egSetGraphicsModeEnabled(IN BOOLEAN Enable) +{ + EFI_CONSOLE_CONTROL_SCREEN_MODE CurrentMode; + EFI_CONSOLE_CONTROL_SCREEN_MODE NewMode; + + if (ConsoleControl != NULL) { + refit_call4_wrapper(ConsoleControl->GetMode, ConsoleControl, &CurrentMode, NULL, NULL); + + NewMode = Enable ? EfiConsoleControlScreenGraphics + : EfiConsoleControlScreenText; + if (CurrentMode != NewMode) + refit_call2_wrapper(ConsoleControl->SetMode, ConsoleControl, NewMode); + } +} + +// +// Drawing to the screen +// + +VOID egClearScreen(IN EG_PIXEL *Color) +{ + EFI_UGA_PIXEL FillColor; + + if (!egHasGraphics) + return; + + FillColor.Red = Color->r; + FillColor.Green = Color->g; + FillColor.Blue = Color->b; + FillColor.Reserved = 0; + + if (GraphicsOutput != NULL) { + // EFI_GRAPHICS_OUTPUT_BLT_PIXEL and EFI_UGA_PIXEL have the same + // layout, and the header from TianoCore actually defines them + // to be the same type. + refit_call10_wrapper(GraphicsOutput->Blt, GraphicsOutput, (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)&FillColor, EfiBltVideoFill, + 0, 0, 0, 0, egScreenWidth, egScreenHeight, 0); + } else if (UgaDraw != NULL) { + refit_call10_wrapper(UgaDraw->Blt, UgaDraw, &FillColor, EfiUgaVideoFill, + 0, 0, 0, 0, egScreenWidth, egScreenHeight, 0); + } +} + +VOID egDrawImage(IN EG_IMAGE *Image, IN UINTN ScreenPosX, IN UINTN ScreenPosY) +{ + if (!egHasGraphics) + return; + + if (Image->HasAlpha) { + Image->HasAlpha = FALSE; + egSetPlane(PLPTR(Image, a), 0, Image->Width * Image->Height); + } + + if (GraphicsOutput != NULL) { + refit_call10_wrapper(GraphicsOutput->Blt, GraphicsOutput, (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)Image->PixelData, EfiBltBufferToVideo, + 0, 0, ScreenPosX, ScreenPosY, Image->Width, Image->Height, 0); + } else if (UgaDraw != NULL) { + refit_call10_wrapper(UgaDraw->Blt, UgaDraw, (EFI_UGA_PIXEL *)Image->PixelData, EfiUgaBltBufferToVideo, + 0, 0, ScreenPosX, ScreenPosY, Image->Width, Image->Height, 0); + } +} + +VOID egDrawImageArea(IN EG_IMAGE *Image, + IN UINTN AreaPosX, IN UINTN AreaPosY, + IN UINTN AreaWidth, IN UINTN AreaHeight, + IN UINTN ScreenPosX, IN UINTN ScreenPosY) +{ + if (!egHasGraphics) + return; + + egRestrictImageArea(Image, AreaPosX, AreaPosY, &AreaWidth, &AreaHeight); + if (AreaWidth == 0) + return; + + if (Image->HasAlpha) { + Image->HasAlpha = FALSE; + egSetPlane(PLPTR(Image, a), 0, Image->Width * Image->Height); + } + + if (GraphicsOutput != NULL) { + refit_call10_wrapper(GraphicsOutput->Blt, GraphicsOutput, (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)Image->PixelData, EfiBltBufferToVideo, + AreaPosX, AreaPosY, ScreenPosX, ScreenPosY, AreaWidth, AreaHeight, Image->Width * 4); + } else if (UgaDraw != NULL) { + refit_call10_wrapper(UgaDraw->Blt, UgaDraw, (EFI_UGA_PIXEL *)Image->PixelData, EfiUgaBltBufferToVideo, + AreaPosX, AreaPosY, ScreenPosX, ScreenPosY, AreaWidth, AreaHeight, Image->Width * 4); + } +} + +// +// Make a screenshot +// + +VOID egScreenShot(VOID) +{ + EFI_STATUS Status; + EG_IMAGE *Image; + UINT8 *FileData; + UINTN FileDataLength; + UINTN Index; + + if (!egHasGraphics) + return; + + // allocate a buffer for the whole screen + Image = egCreateImage(egScreenWidth, egScreenHeight, FALSE); + if (Image == NULL) { + Print(L"Error egCreateImage returned NULL\n"); + goto bailout_wait; + } + + // get full screen image + if (GraphicsOutput != NULL) { + refit_call10_wrapper(GraphicsOutput->Blt, GraphicsOutput, (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)Image->PixelData, EfiBltVideoToBltBuffer, + 0, 0, 0, 0, Image->Width, Image->Height, 0); + } else if (UgaDraw != NULL) { + refit_call10_wrapper(UgaDraw->Blt, UgaDraw, (EFI_UGA_PIXEL *)Image->PixelData, EfiUgaVideoToBltBuffer, + 0, 0, 0, 0, Image->Width, Image->Height, 0); + } + + // encode as BMP + egEncodeBMP(Image, &FileData, &FileDataLength); + egFreeImage(Image); + if (FileData == NULL) { + Print(L"Error egEncodeBMP returned NULL\n"); + goto bailout_wait; + } + + // save to file on the ESP + Status = egSaveFile(NULL, L"screenshot.bmp", FileData, FileDataLength); + FreePool(FileData); + if (EFI_ERROR(Status)) { + Print(L"Error egSaveFile: %x\n", Status); + goto bailout_wait; + } + + return; + + // DEBUG: switch to text mode +bailout_wait: + egSetGraphicsModeEnabled(FALSE); + refit_call3_wrapper(BS->WaitForEvent, 1, &ST->ConIn->WaitForKey, &Index); +} + +/* EOF */ diff --git a/libeg/text.c b/libeg/text.c new file mode 100644 index 0000000..a59e8cb --- /dev/null +++ b/libeg/text.c @@ -0,0 +1,93 @@ +/* + * libeg/text.c + * Text drawing functions + * + * Copyright (c) 2006 Christoph Pfisterer + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Christoph Pfisterer nor the names of the + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "libegint.h" + +#include "egemb_font.h" +#define FONT_CELL_WIDTH (7) +#define FONT_CELL_HEIGHT (12) + +static EG_IMAGE *FontImage = NULL; + +// +// Text rendering +// + +VOID egMeasureText(IN CHAR16 *Text, OUT UINTN *Width, OUT UINTN *Height) +{ + if (Width != NULL) + *Width = StrLen(Text) * FONT_CELL_WIDTH; + if (Height != NULL) + *Height = FONT_CELL_HEIGHT; +} + +VOID egRenderText(IN CHAR16 *Text, IN OUT EG_IMAGE *CompImage, IN UINTN PosX, IN UINTN PosY) +{ + EG_PIXEL *BufferPtr; + EG_PIXEL *FontPixelData; + UINTN BufferLineOffset, FontLineOffset; + UINTN TextLength; + UINTN i, c; + + // clip the text + TextLength = StrLen(Text); + if (TextLength * FONT_CELL_WIDTH + PosX > CompImage->Width) + TextLength = (CompImage->Width - PosX) / FONT_CELL_WIDTH; + + // load the font + if (FontImage == NULL) + FontImage = egPrepareEmbeddedImage(&egemb_font, TRUE); + + // render it + BufferPtr = CompImage->PixelData; + BufferLineOffset = CompImage->Width; + BufferPtr += PosX + PosY * BufferLineOffset; + FontPixelData = FontImage->PixelData; + FontLineOffset = FontImage->Width; + for (i = 0; i < TextLength; i++) { + c = Text[i]; + if (c < 32 || c >= 127) + c = 95; + else + c -= 32; + egRawCompose(BufferPtr, FontPixelData + c * FONT_CELL_WIDTH, + FONT_CELL_WIDTH, FONT_CELL_HEIGHT, + BufferLineOffset, FontLineOffset); + BufferPtr += FONT_CELL_WIDTH; + } +} + +/* EOF */