1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:27:45 +00:00

Everywhere: Replace a bundle of dbg with dbgln.

These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.
This commit is contained in:
asynts 2021-01-16 13:43:08 +01:00 committed by Andreas Kling
parent 9229ba0fe9
commit d69a8a9958
3 changed files with 68 additions and 51 deletions

View file

@ -351,3 +351,9 @@ constexpr bool debug_job = true;
#else #else
constexpr bool debug_job = false; constexpr bool debug_job = false;
#endif #endif
#ifdef GIF_DEBUG
constexpr bool debug_gif = true;
#else
constexpr bool debug_gif = false;
#endif

View file

@ -474,7 +474,7 @@ static bool decode_bmp_header(BMPLoadingContext& context)
u16 header = streamer.read_u16(); u16 header = streamer.read_u16();
if (header != 0x4d42) { if (header != 0x4d42) {
dbgln<debug_bmp>("BMP has invalid magic header number: {:04x}", header); dbgln<debug_bmp>("BMP has invalid magic header number: {:#04x}", header);
context.state = BMPLoadingContext::State::Error; context.state = BMPLoadingContext::State::Error;
return false; return false;
} }
@ -490,8 +490,10 @@ static bool decode_bmp_header(BMPLoadingContext& context)
streamer.drop_bytes(4); streamer.drop_bytes(4);
context.data_offset = streamer.read_u32(); context.data_offset = streamer.read_u32();
dbgln<debug_bmp>("BMP file size: {}", context.file_size); if constexpr (debug_bmp) {
dbgln<debug_bmp>("BMP data offset: {}", context.data_offset); dbgln("BMP file size: {}", context.file_size);
dbgln("BMP data offset: {}", context.data_offset);
}
if (context.data_offset >= context.file_size) { if (context.data_offset >= context.file_size) {
dbgln<debug_bmp>("BMP data offset is beyond file end?!"); dbgln<debug_bmp>("BMP data offset is beyond file end?!");
@ -547,9 +549,11 @@ static bool decode_bmp_core_dib(BMPLoadingContext& context, Streamer& streamer)
return false; return false;
} }
dbgln<debug_bmp>("BMP width: {}", core.width); if constexpr (debug_bmp) {
dbgln<debug_bmp>("BMP height: {}", core.height); dbgln("BMP width: {}", core.width);
dbgln<debug_bmp>("BMP bpp: {}", core.bpp); dbgln("BMP height: {}", core.height);
dbgln("BMP bits_per_pixel: {}", core.bpp);
}
return true; return true;
} }
@ -594,9 +598,11 @@ static bool decode_bmp_osv2_dib(BMPLoadingContext& context, Streamer& streamer,
return false; return false;
} }
dbgln<debug_bmp>("BMP width: {}", core.width); if constexpr (debug_bmp) {
dbgln<debug_bmp>("BMP height: {}", core.height); dbgln("BMP width: {}", core.width);
dbgln<debug_bmp>("BMP bpp: {}", core.bpp); dbgln("BMP height: {}", core.height);
dbgln("BMP bits_per_pixel: {}", core.bpp);
}
if (short_variant) if (short_variant)
return true; return true;
@ -632,12 +638,14 @@ static bool decode_bmp_osv2_dib(BMPLoadingContext& context, Streamer& streamer,
// ColorEncoding (4) + Identifier (4) // ColorEncoding (4) + Identifier (4)
streamer.drop_bytes(8); streamer.drop_bytes(8);
dbgln<debug_bmp>("BMP compression: {}", info.compression); if constexpr (debug_bmp) {
dbgln<debug_bmp>("BMP image size: {}", info.image_size); dbgln("BMP compression: {}", info.compression);
dbgln<debug_bmp>("BMP horizontal res: {}", info.horizontal_resolution); dbgln("BMP image size: {}", info.image_size);
dbgln<debug_bmp>("BMP vertical res: {}", info.vertical_resolution); dbgln("BMP horizontal res: {}", info.horizontal_resolution);
dbgln<debug_bmp>("BMP colors: {}", info.number_of_palette_colors); dbgln("BMP vertical res: {}", info.vertical_resolution);
dbgln<debug_bmp>("BMP important colors: {}", info.number_of_important_palette_colors); dbgln("BMP colors: {}", info.number_of_palette_colors);
dbgln("BMP important colors: {}", info.number_of_important_palette_colors);
}
return true; return true;
} }
@ -670,12 +678,14 @@ static bool decode_bmp_info_dib(BMPLoadingContext& context, Streamer& streamer)
if (info.number_of_important_palette_colors == 0) if (info.number_of_important_palette_colors == 0)
info.number_of_important_palette_colors = info.number_of_palette_colors; info.number_of_important_palette_colors = info.number_of_palette_colors;
dbgln<debug_bmp>("BMP compression: {}", info.compression); if constexpr (debug_bmp) {
dbgln<debug_bmp>("BMP image size: {}", info.image_size); dbgln("BMP compression: {}", info.compression);
dbgln<debug_bmp>("BMP horizontal resolution: {}", info.horizontal_resolution); dbgln("BMP image size: {}", info.image_size);
dbgln<debug_bmp>("BMP vertical resolution: {}", info.vertical_resolution); dbgln("BMP horizontal res: {}", info.horizontal_resolution);
dbgln<debug_bmp>("BMP palette colors: {}", info.number_of_palette_colors); dbgln("BMP vertical res: {}", info.vertical_resolution);
dbgln<debug_bmp>("BMP important palette colors: {}", info.number_of_important_palette_colors); dbgln("BMP colors: {}", info.number_of_palette_colors);
dbgln("BMP important colors: {}", info.number_of_important_palette_colors);
}
return true; return true;
} }
@ -689,9 +699,11 @@ static bool decode_bmp_v2_dib(BMPLoadingContext& context, Streamer& streamer)
context.dib.info.masks.append(streamer.read_u32()); context.dib.info.masks.append(streamer.read_u32());
context.dib.info.masks.append(streamer.read_u32()); context.dib.info.masks.append(streamer.read_u32());
dbgln<debug_bmp>("BMP red mask: {:08x}", context.dib.info.masks[0]); if constexpr (debug_bmp) {
dbgln<debug_bmp>("BMP green mask: {:08x}", context.dib.info.masks[1]); dbgln("BMP red mask: {:#08x}", context.dib.info.masks[0]);
dbgln<debug_bmp>("BMP blue mask: {:08x}", context.dib.info.masks[2]); dbgln("BMP green mask: {:#08x}", context.dib.info.masks[1]);
dbgln("BMP blue mask: {:#08x}", context.dib.info.masks[2]);
}
return true; return true;
} }
@ -707,12 +719,12 @@ static bool decode_bmp_v3_dib(BMPLoadingContext& context, Streamer& streamer)
// suite results. // suite results.
if (context.dib.info.compression == Compression::ALPHABITFIELDS) { if (context.dib.info.compression == Compression::ALPHABITFIELDS) {
context.dib.info.masks.append(streamer.read_u32()); context.dib.info.masks.append(streamer.read_u32());
dbgln<debug_bmp>("BMP alpha mask: {:08x}", context.dib.info.masks[3]); dbgln<debug_bmp>("BMP alpha mask: {:#08x}", context.dib.info.masks[3]);
} else if (context.dib_size() >= 56 && context.dib.core.bpp >= 16) { } else if (context.dib_size() >= 56 && context.dib.core.bpp >= 16) {
auto mask = streamer.read_u32(); auto mask = streamer.read_u32();
if ((context.dib.core.bpp == 32 && mask != 0) || context.dib.core.bpp == 16) { if ((context.dib.core.bpp == 32 && mask != 0) || context.dib.core.bpp == 16) {
context.dib.info.masks.append(mask); context.dib.info.masks.append(mask);
dbgln<debug_bmp>("BMP alpha mask: {:08x}", mask); dbgln<debug_bmp>("BMP alpha mask: {:#08x}", mask);
} }
} else { } else {
streamer.drop_bytes(4); streamer.drop_bytes(4);
@ -733,11 +745,13 @@ static bool decode_bmp_v4_dib(BMPLoadingContext& context, Streamer& streamer)
v4.blue_endpoint = { streamer.read_i32(), streamer.read_i32(), streamer.read_i32() }; v4.blue_endpoint = { streamer.read_i32(), streamer.read_i32(), streamer.read_i32() };
v4.gamma_endpoint = { streamer.read_u32(), streamer.read_u32(), streamer.read_u32() }; v4.gamma_endpoint = { streamer.read_u32(), streamer.read_u32(), streamer.read_u32() };
dbgln<debug_bmp>("BMP color space: {}", v4.color_space); if constexpr (debug_bmp) {
dbgln<debug_bmp>("BMP red endpoint: {}", v4.red_endpoint); dbgln("BMP color space: {}", v4.color_space);
dbgln<debug_bmp>("BMP green endpoint: {}", v4.green_endpoint); dbgln("BMP red endpoint: {}", v4.red_endpoint);
dbgln<debug_bmp>("BMP blue endpoint: {}", v4.blue_endpoint); dbgln("BMP green endpoint: {}", v4.green_endpoint);
dbgln<debug_bmp>("BMP gamma endpoint: {}", v4.gamma_endpoint); dbgln("BMP blue endpoint: {}", v4.blue_endpoint);
dbgln("BMP gamma endpoint: {}", v4.gamma_endpoint);
}
return true; return true;
} }
@ -752,9 +766,11 @@ static bool decode_bmp_v5_dib(BMPLoadingContext& context, Streamer& streamer)
v5.profile_data = streamer.read_u32(); v5.profile_data = streamer.read_u32();
v5.profile_size = streamer.read_u32(); v5.profile_size = streamer.read_u32();
dbgln<debug_bmp>("BMP intent: {}", v5.intent); if constexpr (debug_bmp) {
dbgln<debug_bmp>("BMP profile data: {}", v5.profile_data); dbgln("BMP intent: {}", v5.intent);
dbgln<debug_bmp>("BMP profile size: {}", v5.profile_size); dbgln("BMP profile data: {}", v5.profile_data);
dbgln("BMP profile size: {}", v5.profile_size);
}
return true; return true;
} }
@ -915,7 +931,7 @@ static bool uncompress_bmp_rle_data(BMPLoadingContext& context, ByteBuffer& buff
{ {
// RLE-compressed images cannot be stored top-down // RLE-compressed images cannot be stored top-down
if (context.dib.core.height < 0) { if (context.dib.core.height < 0) {
dbgln("BMP is top-down and RLE compressed"); dbgln<debug_bmp>("BMP is top-down and RLE compressed");
context.state = BMPLoadingContext::State::Error; context.state = BMPLoadingContext::State::Error;
return false; return false;
} }

View file

@ -26,6 +26,7 @@
#include <AK/Array.h> #include <AK/Array.h>
#include <AK/ByteBuffer.h> #include <AK/ByteBuffer.h>
#include <AK/Debug.h>
#include <AK/LexicalPath.h> #include <AK/LexicalPath.h>
#include <AK/MappedFile.h> #include <AK/MappedFile.h>
#include <AK/MemoryStream.h> #include <AK/MemoryStream.h>
@ -36,8 +37,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
//#define GIF_DEBUG
namespace Gfx { namespace Gfx {
// Row strides and offsets for each interlace pass. // Row strides and offsets for each interlace pass.
@ -213,16 +212,16 @@ public:
} }
if (m_current_code > m_code_table.size()) { if (m_current_code > m_code_table.size()) {
#ifdef GIF_DEBUG dbgln<debug_gif>("Corrupted LZW stream, invalid code: {} at bit index {}, code table size: {}",
dbg() << "Corrupted LZW stream, invalid code: " << m_current_code << " at bit index: " m_current_code,
<< m_current_bit_index << ", code table size: " << m_code_table.size(); m_current_bit_index,
#endif m_code_table.size());
return {}; return {};
} else if (m_current_code == m_code_table.size() && m_output.is_empty()) { } else if (m_current_code == m_code_table.size() && m_output.is_empty()) {
#ifdef GIF_DEBUG dbgln<debug_gif>("Corrupted LZW stream, valid new code but output buffer is empty: {} at bit index {}, code table size: {}",
dbg() << "Corrupted LZW stream, valid new code but output buffer is empty: " << m_current_code m_current_code,
<< " at bit index: " << m_current_bit_index << ", code table size: " << m_code_table.size(); m_current_bit_index,
#endif m_code_table.size());
return {}; return {};
} }
@ -528,16 +527,12 @@ static bool load_gif_frame_descriptors(GIFLoadingContext& context)
if (extension_type == 0xFF) { if (extension_type == 0xFF) {
if (sub_block.size() != 14) { if (sub_block.size() != 14) {
#ifdef GIF_DEBUG dbgln<debug_gif>("Unexpected application extension size: {}", sub_block.size());
dbg() << "Unexpected application extension size: " << sub_block.size();
#endif
continue; continue;
} }
if (sub_block[11] != 1) { if (sub_block[11] != 1) {
#ifdef GIF_DEBUG dbgln<debug_gif>("Unexpected application extension format");
dbgln("Unexpected application extension format");
#endif
continue; continue;
} }