OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
OcPng.c
Go to the documentation of this file.
1
18#include <Base.h>
19#include <Library/DebugLib.h>
20#include <Library/BaseMemoryLib.h>
21#include <Library/OcPngLib.h>
22#include "lodepng.h"
23
24EFI_STATUS
26 IN VOID *Buffer,
27 IN UINTN Size,
28 OUT UINT32 *Width,
29 OUT UINT32 *Height
30 )
31{
32 LodePNGState State;
33 unsigned Error;
34 unsigned W;
35 unsigned H;
36
37 //
38 // Init state
39 //
40 lodepng_state_init (&State);
41 State.decoder.ignore_crc = TRUE;
43 State.decoder.zlibsettings.ignore_nlen = TRUE;
44
45 //
46 // Reads header and resets other parameters in state->info_png
47 //
48 Error = lodepng_inspect (&W, &H, &State, Buffer, Size);
49
50 lodepng_state_cleanup (&State);
51
52 if (Error != 0) {
53 DEBUG ((DEBUG_INFO, "OCPNG: Error while getting image dimensions from PNG header\n"));
54 return EFI_INVALID_PARAMETER;
55 }
56
57 *Width = (UINT32)W;
58 *Height = (UINT32)H;
59
60 return EFI_SUCCESS;
61}
62
63EFI_STATUS
65 IN VOID *Buffer,
66 IN UINTN Size,
67 OUT VOID **RawData,
68 OUT UINT32 *Width,
69 OUT UINT32 *Height,
70 OUT BOOLEAN *HasAlphaType OPTIONAL
71 )
72{
73 LodePNGState State;
74 unsigned Error;
75 unsigned W;
76 unsigned H;
77
78 //
79 // Init lodepng state
80 //
81 lodepng_state_init (&State);
83 State.info_raw.bitdepth = 8;
84 State.decoder.ignore_crc = TRUE;
86 State.decoder.zlibsettings.ignore_nlen = TRUE;
87
88 //
89 // It should return 0 on success
90 //
91 Error = lodepng_decode ((unsigned char **)RawData, &W, &H, &State, Buffer, Size);
92
93 if (Error != 0) {
94 DEBUG ((DEBUG_INFO, "OCPNG: Error while decoding PNG image - %u\n", Error));
95 lodepng_state_cleanup (&State);
96 return EFI_INVALID_PARAMETER;
97 }
98
99 *Width = (UINT32)W;
100 *Height = (UINT32)H;
101
102 if (HasAlphaType != NULL) {
103 //
104 // Check alpha layer existence
105 //
106 *HasAlphaType = lodepng_is_alpha_type (&State.info_png.color) != 0;
107 }
108
109 //
110 // Cleanup state
111 //
112 lodepng_state_cleanup (&State);
113
114 return EFI_SUCCESS;
115}
116
117EFI_STATUS
119 IN VOID *RawData,
120 IN UINT32 Width,
121 IN UINT32 Height,
122 OUT VOID **Buffer,
123 OUT UINTN *BufferSize
124 )
125{
126 unsigned Error;
127
128 //
129 // It should return 0 on success
130 //
131 Error = lodepng_encode32 ((unsigned char **)Buffer, BufferSize, RawData, Width, Height);
132
133 if (Error != 0) {
134 DEBUG ((DEBUG_INFO, "OCPNG: Error while encoding PNG image\n"));
135 return EFI_INVALID_PARAMETER;
136 }
137
138 return EFI_SUCCESS;
139}
void Error(char *FileName, uint32_t LineNumber, uint32_t ErrorCode, char *OffendingText, char *MsgFmt,...)
Definition EfiLdrImage.c:57
#define H(X, Y, Z)
Definition Md5.c:36
DMG_SIZE_DEVICE_PATH Size
EFI_STATUS OcGetPngDims(IN VOID *Buffer, IN UINTN Size, OUT UINT32 *Width, OUT UINT32 *Height)
Definition OcPng.c:25
EFI_STATUS OcDecodePng(IN VOID *Buffer, IN UINTN Size, OUT VOID **RawData, OUT UINT32 *Width, OUT UINT32 *Height, OUT BOOLEAN *HasAlphaType OPTIONAL)
Definition OcPng.c:64
EFI_STATUS OcEncodePng(IN VOID *RawData, IN UINT32 Width, IN UINT32 Height, OUT VOID **Buffer, OUT UINTN *BufferSize)
Definition OcPng.c:118
OC_TYPING_BUFFER_ENTRY Buffer[OC_TYPING_BUFFER_SIZE]
Definition OcTypingLib.h:42
#define W
Definition crc32.c:85
unsigned lodepng_inspect(unsigned *w, unsigned *h, LodePNGState *state, const unsigned char *in, size_t insize)
Definition lodepng.c:4356
unsigned lodepng_decode(unsigned char **out, unsigned *w, unsigned *h, LodePNGState *state, const unsigned char *in, size_t insize)
Definition lodepng.c:5411
void lodepng_state_cleanup(LodePNGState *state)
Definition lodepng.c:5527
unsigned lodepng_encode32(unsigned char **out, size_t *outsize, const unsigned char *image, unsigned w, unsigned h)
Definition lodepng.c:6665
unsigned lodepng_is_alpha_type(const LodePNGColorMode *info)
Definition lodepng.c:3085
void lodepng_state_init(LodePNGState *state)
Definition lodepng.c:5515
@ LCT_RGBA
Definition lodepng.h:154
LodePNGColorType colortype
Definition lodepng.h:414
unsigned bitdepth
Definition lodepng.h:415
LodePNGDecompressSettings zlibsettings
Definition lodepng.h:759
LodePNGColorMode color
Definition lodepng.h:510
LodePNGInfo info_png
Definition lodepng.h:894
LodePNGColorMode info_raw
Definition lodepng.h:893
LodePNGDecoderSettings decoder
Definition lodepng.h:888