From 5b31a8f114bb3792a03accb604b3a309faf1a5f0 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Mon, 4 Nov 2024 10:39:21 +0100 Subject: [PATCH] Enforce braces in if-statements --- src/NetVips.Extensions/BitmapConverter.cs | 11 +++++++++++ src/NetVips/ModuleInitializer.cs | 5 ++++- tests/NetVips.Tests/ExtensionsTests.cs | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/NetVips.Extensions/BitmapConverter.cs b/src/NetVips.Extensions/BitmapConverter.cs index c906b88..9fce265 100644 --- a/src/NetVips.Extensions/BitmapConverter.cs +++ b/src/NetVips.Extensions/BitmapConverter.cs @@ -80,7 +80,9 @@ private static Enums.BandFormat GuessBandFormat(PixelFormat pixelFormat) public static Image ToVips(this Bitmap src) { if (src == null) + { throw new ArgumentNullException(nameof(src)); + } // Let LockBits convert the pixel data to Format24bppRgb for indexed // (excluding Format8bppIndexed) and Format32bppRgb (the remaining @@ -200,7 +202,9 @@ src.PixelFormat is PixelFormat.Format1bppIndexed or PixelFormat.Format4bppIndexe finally { if (bd != null) + { src.UnlockBits(bd); + } } if (pf == PixelFormat.Format8bppIndexed) @@ -267,7 +271,9 @@ public static Image ToVips(this System.Drawing.Image src) public static Bitmap ToBitmap(this Image src) { if (src == null) + { throw new ArgumentNullException(nameof(src)); + } // Ensure image is converted to sRGB if (src.Bands >= 3) @@ -414,9 +420,14 @@ public static Bitmap ToBitmap(this Image src) finally { if (bd != null) + { dst.UnlockBits(bd); + } + if (memory != IntPtr.Zero) + { NetVips.Free(memory); + } } return dst; diff --git a/src/NetVips/ModuleInitializer.cs b/src/NetVips/ModuleInitializer.cs index 0037bc1..16e8768 100644 --- a/src/NetVips/ModuleInitializer.cs +++ b/src/NetVips/ModuleInitializer.cs @@ -104,7 +104,10 @@ public static void Initialize() Version = (Version << 8) + NetVips.Version(2, false); #if NET6_0_OR_GREATER - if (!OperatingSystem.IsWindows()) return; + if (!OperatingSystem.IsWindows()) + { + return; + } try { diff --git a/tests/NetVips.Tests/ExtensionsTests.cs b/tests/NetVips.Tests/ExtensionsTests.cs index cdd5ce8..6e8eb76 100644 --- a/tests/NetVips.Tests/ExtensionsTests.cs +++ b/tests/NetVips.Tests/ExtensionsTests.cs @@ -66,7 +66,9 @@ public void ToBitmap4Bands() private static void AssertPixelValue(byte[] expected, Bitmap actual) { if (actual.Width != 1 || actual.Height != 1) + { throw new Exception("1x1 image only"); + } // An additional band is added for greyscale images if (expected.Length == 2)