diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-05-01 21:10:08 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-01 21:25:06 +0200 |
commit | 6cf59b6ae96aeeb8c0da957a07f913c4fa38467f (patch) | |
tree | b3f1691b59c3280993d4a8c2866f821ae15c1875 /Userland/Libraries/LibGfx | |
parent | 4e6f03a860595f9eb2628e12ddbd333e26b0622f (diff) | |
download | serenity-6cf59b6ae96aeeb8c0da957a07f913c4fa38467f.zip |
Everywhere: Turn #if *_DEBUG into dbgln_if/if constexpr
Diffstat (limited to 'Userland/Libraries/LibGfx')
-rw-r--r-- | Userland/Libraries/LibGfx/GIFLoader.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/ICOLoader.cpp | 77 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/JPGLoader.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Painter.cpp | 18 |
4 files changed, 44 insertions, 63 deletions
diff --git a/Userland/Libraries/LibGfx/GIFLoader.cpp b/Userland/Libraries/LibGfx/GIFLoader.cpp index 2948ea736b..d8b60c0dbb 100644 --- a/Userland/Libraries/LibGfx/GIFLoader.cpp +++ b/Userland/Libraries/LibGfx/GIFLoader.cpp @@ -350,9 +350,7 @@ static bool decode_frame(GIFLoadingContext& context, size_t frame_index) while (true) { Optional<u16> code = decoder.next_code(); if (!code.has_value()) { -#if GIF_DEBUG - dbgln("Unexpectedly reached end of gif frame data"); -#endif + dbgln_if(GIF_DEBUG, "Unexpectedly reached end of gif frame data"); return false; } @@ -499,9 +497,7 @@ static bool load_gif_frame_descriptors(GIFLoadingContext& context) if (extension_type == 0xF9) { if (sub_block.size() != 4) { -#if GIF_DEBUG - dbgln("Unexpected graphic control size"); -#endif + dbgln_if(GIF_DEBUG, "Unexpected graphic control size"); continue; } diff --git a/Userland/Libraries/LibGfx/ICOLoader.cpp b/Userland/Libraries/LibGfx/ICOLoader.cpp index c6e5c99557..2c8755aeb0 100644 --- a/Userland/Libraries/LibGfx/ICOLoader.cpp +++ b/Userland/Libraries/LibGfx/ICOLoader.cpp @@ -169,25 +169,22 @@ static bool load_ico_directory(ICOLoadingContext& context) for (size_t i = 0; i < image_count.value(); ++i) { auto maybe_desc = decode_ico_direntry(stream); if (!maybe_desc.has_value()) { -#if ICO_DEBUG - printf("load_ico_directory: error loading entry: %lu\n", i); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_directory: error loading entry: %lu\n", i); return false; } auto& desc = maybe_desc.value(); if (desc.offset + desc.size < desc.offset // detect integer overflow || (desc.offset + desc.size) > context.data_size) { -#if ICO_DEBUG - printf("load_ico_directory: offset: %lu size: %lu doesn't fit in ICO size: %lu\n", - desc.offset, desc.size, context.data_size); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_directory: offset: %lu size: %lu doesn't fit in ICO size: %lu\n", + desc.offset, desc.size, context.data_size); return false; } -#if ICO_DEBUG - printf("load_ico_directory: index %zu width: %u height: %u offset: %lu size: %lu\n", - i, desc.width, desc.height, desc.offset, desc.size); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_directory: index %zu width: %u height: %u offset: %lu size: %lu\n", + i, desc.width, desc.height, desc.offset, desc.size); context.images.append(desc); } context.largest_index = find_largest_image(context); @@ -203,16 +200,14 @@ static bool load_ico_bmp(ICOLoadingContext& context, ImageDescriptor& desc) memcpy(&info, context.data + desc.offset, sizeof(info)); if (info.size != sizeof(info)) { -#if ICO_DEBUG - printf("load_ico_bmp: info size: %u, expected: %lu\n", info.size, sizeof(info)); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_bmp: info size: %u, expected: %lu\n", info.size, sizeof(info)); return false; } if (info.width < 0) { -#if ICO_DEBUG - printf("load_ico_bmp: width %d < 0\n", info.width); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_bmp: width %d < 0\n", info.width); return false; } bool topdown = false; @@ -222,37 +217,32 @@ static bool load_ico_bmp(ICOLoadingContext& context, ImageDescriptor& desc) } if (info.planes != 1) { -#if ICO_DEBUG - printf("load_ico_bmp: planes: %d != 1", info.planes); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_bmp: planes: %d != 1", info.planes); return false; } if (info.bpp != 32) { -#if ICO_DEBUG - printf("load_ico_bmp: unsupported bpp: %u\n", info.bpp); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_bmp: unsupported bpp: %u\n", info.bpp); return false; } -#if ICO_DEBUG - printf("load_ico_bmp: width: %d height: %d direction: %s bpp: %d size_image: %u\n", - info.width, info.height, topdown ? "TopDown" : "BottomUp", info.bpp, info.size_image); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_bmp: width: %d height: %d direction: %s bpp: %d size_image: %u\n", + info.width, info.height, topdown ? "TopDown" : "BottomUp", info.bpp, info.size_image); if (info.compression != 0 || info.palette_size != 0 || info.important_colors != 0) { -#if ICO_DEBUG - printf("load_ico_bmp: following fields must be 0: compression: %u palette_size: %u important_colors: %u\n", - info.compression, info.palette_size, info.important_colors); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_bmp: following fields must be 0: compression: %u palette_size: %u important_colors: %u\n", + info.compression, info.palette_size, info.important_colors); return false; } if (info.width != desc.width || info.height != 2 * desc.height) { -#if ICO_DEBUG - printf("load_ico_bmp: size mismatch: ico %dx%d, bmp %dx%d\n", - desc.width, desc.height, info.width, info.height); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_bmp: size mismatch: ico %dx%d, bmp %dx%d\n", + desc.width, desc.height, info.width, info.height); return false; } @@ -261,10 +251,9 @@ static bool load_ico_bmp(ICOLoadingContext& context, ImageDescriptor& desc) size_t required_len = desc.height * (desc.width * sizeof(BMP_ARGB) + mask_row_len); size_t available_len = desc.size - sizeof(info); if (required_len > available_len) { -#if ICO_DEBUG - printf("load_ico_bmp: required_len: %lu > available_len: %lu\n", - required_len, available_len); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_bmp: required_len: %lu > available_len: %lu\n", + required_len, available_len); return false; } @@ -310,17 +299,15 @@ static bool load_ico_bitmap(ICOLoadingContext& context, Optional<size_t> index) if (png_decoder.sniff()) { desc.bitmap = png_decoder.bitmap(); if (!desc.bitmap) { -#if ICO_DEBUG - printf("load_ico_bitmap: failed to load PNG encoded image index: %lu\n", real_index); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_bitmap: failed to load PNG encoded image index: %lu\n", real_index); return false; } return true; } else { if (!load_ico_bmp(context, desc)) { -#if ICO_DEBUG - printf("load_ico_bitmap: failed to load BMP encoded image index: %lu\n", real_index); -#endif + if constexpr (ICO_DEBUG) + printf("load_ico_bitmap: failed to load BMP encoded image index: %lu\n", real_index); return false; } return true; diff --git a/Userland/Libraries/LibGfx/JPGLoader.cpp b/Userland/Libraries/LibGfx/JPGLoader.cpp index b6115379b0..1c2aefc209 100644 --- a/Userland/Libraries/LibGfx/JPGLoader.cpp +++ b/Userland/Libraries/LibGfx/JPGLoader.cpp @@ -247,9 +247,7 @@ static Optional<u8> get_next_symbol(HuffmanStreamState& hstream, const HuffmanTa } } -#if JPG_DEBUG - dbgln("If you're seeing this...the jpeg decoder needs to support more kinds of JPEGs!"); -#endif + dbgln_if(JPG_DEBUG, "If you're seeing this...the jpeg decoder needs to support more kinds of JPEGs!"); return {}; } diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index 80a5456cdb..d98e8a45f1 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -1880,11 +1880,11 @@ void Painter::fill_path(Path& path, Color color, WindingRule winding_rule) quick_sort(active_list, [](const auto& line0, const auto& line1) { return line1.x < line0.x; }); -#if FILL_PATH_DEBUG - if ((int)scanline % 10 == 0) { - draw_text(IntRect(active_list.last().x - 20, scanline, 20, 10), String::number((int)scanline)); + if constexpr (FILL_PATH_DEBUG) { + if ((int)scanline % 10 == 0) { + draw_text(IntRect(active_list.last().x - 20, scanline, 20, 10), String::number((int)scanline)); + } } -#endif if (active_list.size() > 1) { auto winding_number { winding_rule == WindingRule::Nonzero ? 1 : 0 }; @@ -1952,12 +1952,12 @@ void Painter::fill_path(Path& path, Color color, WindingRule winding_rule) } } -#if FILL_PATH_DEBUG - size_t i { 0 }; - for (auto& segment : segments) { - draw_line(Point<int>(segment.from), Point<int>(segment.to), Color::from_hsv(i++ * 360.0 / segments.size(), 1.0, 1.0), 1); + if constexpr (FILL_PATH_DEBUG) { + size_t i { 0 }; + for (auto& segment : segments) { + draw_line(Point<int>(segment.from), Point<int>(segment.to), Color::from_hsv(i++ * 360.0 / segments.size(), 1.0, 1.0), 1); + } } -#endif } void Painter::blit_disabled(const IntPoint& location, const Gfx::Bitmap& bitmap, const IntRect& rect, const Palette& palette) |