Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
a1b9cac
Add 5-6-5 BMP encoding and keep decoded palettes
JimBobSquarePants Nov 13, 2026
6d2707d
Replace BMP 16-bit layout with color types and report BGR
JimBobSquarePants Nov 13, 2026
14ef643
Read BMP V5 profiles only when they are embedded
JimBobSquarePants Nov 13, 2026
137a386
Merge remote-tracking branch 'origin/main' into js/bmp-layouts
JimBobSquarePants Nov 15, 2026
ef72b01
Select HEIF encoder profiles once with SelectValidProfile
JimBobSquarePants Nov 17, 2026
40d5497
Share palette index packing and write BMP rows without per-byte writes
JimBobSquarePants Nov 17, 2026
3315948
Add BMP RLE8/RLE4 encode and encoder + metadata compression for BMP a…
JimBobSquarePants Nov 17, 2026
3f4b886
Write ANI frames as ICO or CUR only, store reused frames once, and va…
JimBobSquarePants Nov 17, 2026
d4b2c8b
Add BMP, ICO and CUR color table bound tests
JimBobSquarePants Nov 17, 2026
66ab0ba
Merge remote-tracking branch 'origin/main' into js/bmp-layouts
JimBobSquarePants Nov 17, 2026
0657588
Add BMP Huffman 1D read and write with shared CCITT code
JimBobSquarePants Nov 23, 2026
3bc1f37
Normalize segment integrity handling and keep decodable pixels from d…
JimBobSquarePants Nov 24, 2026
529661c
Update BMP benchmark results
JimBobSquarePants Nov 24, 2026
4a53f2e
Merge branch 'main' into js/bmp-layouts
JimBobSquarePants Nov 24, 2026
3ea82f9
Copy BMP quantizer options only for indexed output and read options f…
JimBobSquarePants Nov 24, 2026
c9ae580
Split long comment sentences and remove semicolons in comments
JimBobSquarePants Nov 24, 2026
0c9195d
Copy the cached TIFF test bytes before the planar strip test changes …
JimBobSquarePants Nov 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/ImageSharp/Advanced/AotCompilerTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ private static void AotCompilePixelOperations<TPixel>()

operations.FromBgra5551Bytes(default, default, default, default);
operations.ToBgra5551Bytes(default, default, default, default);

operations.FromBgr565Bytes(default, default, default, default);
operations.ToBgr565Bytes(default, default, default, default);
}

/// <summary>
Expand Down
23 changes: 23 additions & 0 deletions src/ImageSharp/Common/Helpers/ColorNumerics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,29 @@ public static uint From16BitTo32Bit(ushort component)
public static uint From8BitTo32Bit(byte component)
=> (uint)(component * 16843009);

/// <summary>
/// Scales an unsigned normalized value to another bit depth: <c>round(value * destinationMax / sourceMax)</c>.
/// </summary>
/// <remarks>
/// The Direct3D 11.3 Functional Specification, sections 3.2.3.5 and 3.2.3.6, gives the UNORM to FLOAT and FLOAT to
/// UNORM conversions. With exact arithmetic, the two conversions in sequence give this result. See
/// https://microsoft.github.io/DirectX-Specs/d3d/archive/D3D11_3_FunctionalSpec.htm.
/// <para/>
/// Each maximum is <c>2^n - 1</c>, an odd number. <c>value * destinationMax / sourceMax</c> is never <c>k + 1/2</c>
/// for an integer <c>k</c>. That result needs <c>2 * value * destinationMax = sourceMax * (2k + 1)</c>, but the
/// left side is even and the right side is odd. Thus the integer division of
/// <c>value * destinationMax + sourceMax / 2</c> by <c>sourceMax</c> is the rounded value. Callers pass constant
/// maximums, so the JIT replaces the division with a multiply and a shift. The caller makes sure that
/// <c>value * destinationMax + sourceMax / 2</c> fits in 32 bits.
/// </remarks>
/// <param name="value">The value, from 0 to <paramref name="sourceMax"/>.</param>
/// <param name="sourceMax">The maximum value at the source bit depth.</param>
/// <param name="destinationMax">The maximum value at the destination bit depth.</param>
/// <returns>The scaled value, from 0 to <paramref name="destinationMax"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint ScaleUnorm(uint value, uint sourceMax, uint destinationMax)
=> ((value * destinationMax) + (sourceMax / 2)) / sourceMax;

/// <summary>
/// Returns how many bits are required to store the specified number of colors.
/// Performs a Log2() on the value.
Expand Down
43 changes: 43 additions & 0 deletions src/ImageSharp/Compression/Ccitt/BitWriterUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

namespace SixLabors.ImageSharp.Compression.Ccitt;

/// <summary>
/// Writes 1-bit pixels to rows. The first pixel of a row is the most significant bit of its first byte.
/// </summary>
internal static class BitWriterUtils
{
/// <summary>
/// Sets a range of bits to 1.
/// </summary>
/// <param name="row">The destination row.</param>
/// <param name="start">The first bit.</param>
/// <param name="count">The number of bits.</param>
public static void SetBits(Span<byte> row, int start, int count)
{
if (count == 0)
{
return;
}

int end = start + count;
int first = start >> 3;
int last = (end - 1) >> 3;

// The first byte keeps its bits before the start: 0xFF >> (start mod 8) selects the bits from the start. The last
// byte keeps its bits after the end: 0xFF << (8 - (end mod 8)) selects the bits before the end.
byte firstMask = (byte)(0xFF >> (start & 7));
byte lastMask = (byte)(0xFF << ((8 - (end & 7)) & 7));

if (first == last)
{
row[first] |= (byte)(firstMask & lastMask);
return;
}

row[first] |= firstMask;
row[(first + 1)..last].Fill(0xFF);
row[last] |= lastMask;
}
}
20 changes: 20 additions & 0 deletions src/ImageSharp/Compression/Ccitt/CcittBitOrder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

namespace SixLabors.ImageSharp.Compression.Ccitt;

/// <summary>
/// Defines the order of the CCITT code bits in each byte of the compressed data.
/// </summary>
internal enum CcittBitOrder
{
/// <summary>
/// The first code bit is the most significant bit of the byte.
/// </summary>
MostSignificantBitFirst = 0,

/// <summary>
/// The first code bit is the least significant bit of the byte.
/// </summary>
LeastSignificantBitFirst = 1
}
Loading
Loading