From 96ed3a4188c8c23b529268abd0c6f7aa6a6363b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81kos=20Halmai?= Date: Tue, 21 Mar 2023 22:30:19 +0100 Subject: [PATCH] Allocation error removed. --- BitmapHelper.cs | 16 ++++++---------- Properties/launchSettings.json | 2 +- SL3Reader.cs | 2 +- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/BitmapHelper.cs b/BitmapHelper.cs index 46f5e04..b3a1b76 100644 --- a/BitmapHelper.cs +++ b/BitmapHelper.cs @@ -2,10 +2,8 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices.Marshalling; -namespace SL3Reader -{ - public static class BitmapHelper - { +namespace SL3Reader { + public static class BitmapHelper { public const int BitmapCombinedHeaderSize = BitmapFileHeader.Size + BitmapInfoHeader.Size + @@ -280,8 +278,7 @@ public static class BitmapHelper 56,187,240,0 /* End Palette */ }; - public static byte[] CreateBuffer(int maxHeight, int maxWidth) - { + public static byte[] CreateBuffer(int maxHeight, int maxWidth) { // (maxHeight * (maxWidth + (4 - maxWidth % 4)))); byte[] buffer = GC.AllocateUninitializedArray( BitmapCombinedHeaderSize + @@ -294,15 +291,14 @@ public static unsafe void UpdateBuffer(byte[] buffer, int height, int width, out int fullStride, out Span fileBuffer, - out Span pixelData) - { + out Span pixelData) { fullStride = width; //width + (4 - (width % 4)); fixed (byte* pBuffer = &buffer[0]) // Just formal: buffer is pre-pinned by the GC. { BitmapFileHeader* pFileHeader = (BitmapFileHeader*)pBuffer; int fileSize = (int)pFileHeader->Update(width, height); - ((BitmapInfoHeader*)(pBuffer + BitmapFileHeader.Size))->Update (width, height); - fileBuffer = new Span(pBuffer, fileSize); + ((BitmapInfoHeader*)(pBuffer + BitmapFileHeader.Size))->Update(width, height); + fileBuffer = new Span(pBuffer, fileSize); pixelData = fileBuffer[BitmapCombinedHeaderSize..]; } } diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json index 7c6419b..03262ce 100644 --- a/Properties/launchSettings.json +++ b/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "SL3Reader": { "commandName": "Project", - "commandLineArgs": "\"F:\\Sonar0000saar.sl3\" \"F:\\SS\" -route" + "commandLineArgs": "\"F:\\Sonar0000saar.sl3\" \"F:\\SS\" -ss" } } } diff --git a/SL3Reader.cs b/SL3Reader.cs index c4d038d..a399825 100644 --- a/SL3Reader.cs +++ b/SL3Reader.cs @@ -152,7 +152,7 @@ private List GetBreakPoints(List framesToCheck, out int contiguousLeng maxIndex = breakpoints.Count - 1, delta; j < maxIndex; - j += 2) { + j ++) { if (contiguousLength < (delta = breakpoints[1 + j] - breakpoints[j])) contiguousLength = delta; }