Skip to content

Commit

Permalink
Fighting 2 extra bytes.
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusfriedman committed Oct 21, 2024
1 parent aa8aa5a commit 1fac6cb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Codecs/Image/Jpeg/JpegImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,13 @@ private void WriteStartOfFrame(byte functionCode, Stream stream)
sof[i] = frameComponent;
}
}
stream.Write(sof.Array, sof.Offset, sof.Count);
WriteMarker(stream, sof);
}

private void WriteStartOfScan(Stream stream)
{
var numberOfComponents = ImageFormat.Components.Length;
var sos = new StartOfScan(numberOfComponents);
using var sos = new StartOfScan(numberOfComponents);
// Set the Ss, Se, Ah, and Al fields
// These values are typical for a baseline or progessive JPEG but not lossless. (1-7)
sos.Ss = 0; // Start of spectral selection
Expand Down Expand Up @@ -282,7 +282,7 @@ private void WriteStartOfScan(Stream stream)
sos[i] = componentSelector;
}
}
stream.Write(sos.Array, sos.Offset, sos.Count);
WriteMarker(stream, sos);
}

private void WriteMarker(Stream stream, Marker marker)
Expand Down
7 changes: 6 additions & 1 deletion Codecs/Image/Jpeg/JpegUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ public static void TestSave()
using (var stream = new MemoryStream())
{
image.Save(stream);
Console.WriteLine(stream.Length > 0 ? "Pass" : "Fail");
stream.Position = 0;
using (var jpgImage = JpegImage.FromStream(stream))
{
if (jpgImage.Width != 100) throw new Exception();
if (jpgImage.Height != 100) throw new Exception();
}
}
}

Expand Down

0 comments on commit 1fac6cb

Please sign in to comment.