Skip to content

Commit

Permalink
Allocation error removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
halmaia committed Mar 21, 2023
1 parent edfe97a commit 96ed3a4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
16 changes: 6 additions & 10 deletions BitmapHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
Expand Down Expand Up @@ -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<byte>(
BitmapCombinedHeaderSize +
Expand All @@ -294,15 +291,14 @@ public static unsafe void UpdateBuffer(byte[] buffer,
int height, int width,
out int fullStride,
out Span<byte> fileBuffer,
out Span<byte> pixelData)
{
out Span<byte> 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<byte>(pBuffer, fileSize);
((BitmapInfoHeader*)(pBuffer + BitmapFileHeader.Size))->Update(width, height);
fileBuffer = new Span<byte>(pBuffer, fileSize);
pixelData = fileBuffer[BitmapCombinedHeaderSize..];
}
}
Expand Down
2 changes: 1 addition & 1 deletion Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"SL3Reader": {
"commandName": "Project",
"commandLineArgs": "\"F:\\Sonar0000saar.sl3\" \"F:\\SS\" -route"
"commandLineArgs": "\"F:\\Sonar0000saar.sl3\" \"F:\\SS\" -ss"
}
}
}
2 changes: 1 addition & 1 deletion SL3Reader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private List<int> GetBreakPoints(List<int> framesToCheck, out int contiguousLeng
maxIndex = breakpoints.Count - 1,
delta;
j < maxIndex;
j += 2) {
j ++) {
if (contiguousLength < (delta = breakpoints[1 + j] - breakpoints[j]))
contiguousLength = delta;
}
Expand Down

0 comments on commit 96ed3a4

Please sign in to comment.