MCPcopy Create free account
hub / github.com/ddnet/ddnet / LoadPng

Method LoadPng

src/engine/gfx/image_loader.cpp:136–272  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134}
135
136bool CImageLoader::LoadPng(CByteBufferReader &Reader, const char *pContextName, CImageInfo &Image, int &PngliteIncompatible)
137{
138 CUserErrorStruct UserErrorStruct = {&Reader, pContextName, {}};
139
140 if(setjmp(UserErrorStruct.m_JmpBuf))
141 {
142 return false;
143 }
144
145 png_structp pPngStruct = png_create_read_struct(PNG_LIBPNG_VER_STRING, &UserErrorStruct, PngErrorCallback, PngWarningCallback);
146 if(pPngStruct == nullptr)
147 {
148 log_error("png", "libpng internal failure: png_create_read_struct failed.");
149 return false;
150 }
151
152 png_infop pPngInfo = nullptr;
153 png_bytepp pRowPointers = nullptr;
154 int Height = 0; // ensure this is not undefined for the Cleanup function
155 const auto &&Cleanup = [&]() {
156 if(pRowPointers != nullptr)
157 {
158 for(int y = 0; y < Height; ++y)
159 {
160 delete[] pRowPointers[y];
161 }
162 }
163 delete[] pRowPointers;
164 if(pPngInfo != nullptr)
165 {
166 png_destroy_info_struct(pPngStruct, &pPngInfo);
167 }
168 png_destroy_read_struct(&pPngStruct, nullptr, nullptr);
169 };
170 if(setjmp(UserErrorStruct.m_JmpBuf))
171 {
172 Cleanup();
173 return false;
174 }
175
176 pPngInfo = png_create_info_struct(pPngStruct);
177 if(pPngInfo == nullptr)
178 {
179 Cleanup();
180 log_error("png", "libpng internal failure: png_create_info_struct failed.");
181 return false;
182 }
183
184 png_byte aSignature[8];
185 if(!Reader.Read(aSignature, sizeof(aSignature)) || png_sig_cmp(aSignature, 0, sizeof(aSignature)) != 0)
186 {
187 Cleanup();
188 log_error("png", "file is not a valid PNG file (signature mismatch).");
189 return false;
190 }
191
192 png_set_read_fn(pPngStruct, (png_bytep)&Reader, PngReadDataCallback);
193 png_set_sig_bytes(pPngStruct, sizeof(aSignature));

Callers 15

LoadGameSkinMethod · 0.45
LoadEmoticonsSkinMethod · 0.45
LoadParticlesSkinMethod · 0.45
LoadHudSkinMethod · 0.45
LoadExtrasSkinMethod · 0.45
LoadSkinDirectMethod · 0.45
RunMethod · 0.45
GetEntitiesMethod · 0.45
MenuImageScanMethod · 0.45
LoadSkinPartMethod · 0.45
LoadXmasHatMethod · 0.45
LoadBotDecorationMethod · 0.45

Calls 10

mem_copyFunction · 0.85
PngliteIncompatibilityFunction · 0.85
io_read_allFunction · 0.85
io_closeFunction · 0.85
FormatNameMethod · 0.80
ReadMethod · 0.45
ErrorMethod · 0.45
DataSizeMethod · 0.45
FreeMethod · 0.45

Tested by

no test coverage detected