1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:17:36 +00:00

LibGfx: Update to PNGLoader to modern dbgln_if and if constexpr logging

This commit is contained in:
Idan Horowitz 2021-04-07 17:25:22 +03:00 committed by Andreas Kling
parent 8a0f1d87c0
commit 34c05a744f

View file

@ -527,17 +527,13 @@ static bool decode_png_header(PNGLoadingContext& context)
return true; return true;
if (!context.data || context.data_size < sizeof(png_header)) { if (!context.data || context.data_size < sizeof(png_header)) {
#if PNG_DEBUG dbgln_if(PNG_DEBUG, "Missing PNG header");
dbgln("Missing PNG header");
#endif
context.state = PNGLoadingContext::State::Error; context.state = PNGLoadingContext::State::Error;
return false; return false;
} }
if (memcmp(context.data, png_header, sizeof(png_header)) != 0) { if (memcmp(context.data, png_header, sizeof(png_header)) != 0) {
#if PNG_DEBUG dbgln_if(PNG_DEBUG, "Invalid PNG header");
dbgln("Invalid PNG header");
#endif
context.state = PNGLoadingContext::State::Error; context.state = PNGLoadingContext::State::Error;
return false; return false;
} }
@ -861,18 +857,16 @@ static bool process_IHDR(ReadonlyBytes data, PNGLoadingContext& context)
context.filter_method = ihdr.filter_method; context.filter_method = ihdr.filter_method;
context.interlace_method = ihdr.interlace_method; context.interlace_method = ihdr.interlace_method;
#if PNG_DEBUG if constexpr (PNG_DEBUG) {
printf("PNG: %dx%d (%d bpp)\n", context.width, context.height, context.bit_depth); printf("PNG: %dx%d (%d bpp)\n", context.width, context.height, context.bit_depth);
printf(" Color type: %d\n", context.color_type); printf(" Color type: %d\n", context.color_type);
printf("Compress Method: %d\n", context.compression_method); printf("Compress Method: %d\n", context.compression_method);
printf(" Filter Method: %d\n", context.filter_method); printf(" Filter Method: %d\n", context.filter_method);
printf(" Interlace type: %d\n", context.interlace_method); printf(" Interlace type: %d\n", context.interlace_method);
#endif }
if (context.interlace_method != PngInterlaceMethod::Null && context.interlace_method != PngInterlaceMethod::Adam7) { if (context.interlace_method != PngInterlaceMethod::Null && context.interlace_method != PngInterlaceMethod::Adam7) {
#if PNG_DEBUG dbgln_if(PNG_DEBUG, "PNGLoader::process_IHDR: unknown interlace method: {}", context.interlace_method);
dbgln("PNGLoader::process_IHDR: unknown interlace method: {}", context.interlace_method);
#endif
return false; return false;
} }
@ -934,36 +928,31 @@ static bool process_chunk(Streamer& streamer, PNGLoadingContext& context)
{ {
u32 chunk_size; u32 chunk_size;
if (!streamer.read(chunk_size)) { if (!streamer.read(chunk_size)) {
#if PNG_DEBUG if constexpr (PNG_DEBUG)
printf("Bail at chunk_size\n"); printf("Bail at chunk_size\n");
#endif
return false; return false;
} }
u8 chunk_type[5]; u8 chunk_type[5];
chunk_type[4] = '\0'; chunk_type[4] = '\0';
if (!streamer.read_bytes(chunk_type, 4)) { if (!streamer.read_bytes(chunk_type, 4)) {
#if PNG_DEBUG if constexpr (PNG_DEBUG)
printf("Bail at chunk_type\n"); printf("Bail at chunk_type\n");
#endif
return false; return false;
} }
ReadonlyBytes chunk_data; ReadonlyBytes chunk_data;
if (!streamer.wrap_bytes(chunk_data, chunk_size)) { if (!streamer.wrap_bytes(chunk_data, chunk_size)) {
#if PNG_DEBUG if constexpr (PNG_DEBUG)
printf("Bail at chunk_data\n"); printf("Bail at chunk_data\n");
#endif
return false; return false;
} }
u32 chunk_crc; u32 chunk_crc;
if (!streamer.read(chunk_crc)) { if (!streamer.read(chunk_crc)) {
#if PNG_DEBUG if constexpr (PNG_DEBUG)
printf("Bail at chunk_crc\n"); printf("Bail at chunk_crc\n");
#endif
return false; return false;
} }
#if PNG_DEBUG if constexpr (PNG_DEBUG)
printf("Chunk type: '%s', size: %u, crc: %x\n", chunk_type, chunk_size, chunk_crc); printf("Chunk type: '%s', size: %u, crc: %x\n", chunk_type, chunk_size, chunk_crc);
#endif
if (!strcmp((const char*)chunk_type, "IHDR")) if (!strcmp((const char*)chunk_type, "IHDR"))
return process_IHDR(chunk_data, context); return process_IHDR(chunk_data, context);