TimeBeanDithering 1.2.0

dotnet add package TimeBeanDithering --version 1.2.0
                    
NuGet\Install-Package TimeBeanDithering -Version 1.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TimeBeanDithering" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TimeBeanDithering" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="TimeBeanDithering" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TimeBeanDithering --version 1.2.0
                    
#r "nuget: TimeBeanDithering, 1.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TimeBeanDithering@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TimeBeanDithering&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=TimeBeanDithering&version=1.2.0
                    
Install as a Cake Tool

Dithering

.NET implementation of dithering

<p align="left"> <img src="https://github.com/TimeBean/Dithering/blob/main/Examples/Bayer4x4PalettePico8.png?raw=true" height="120"/> <img src="https://github.com/TimeBean/Dithering/blob/main/Examples/Bayer8x8PaletteObraDinnIBM.png?raw=true" height="120"/> <img src="https://github.com/TimeBean/Dithering/blob/main/Examples/StuckiLinear8x.png?raw=true" height="120"/> </p>

All variant preview

More examples can be found in Examples/

Usage

// load file
using var input = File.OpenRead(@"Examples/Mirana.png");

// get bitmap from file stream
using var originalBitmap = SKBitmap.Decode(input);

            
// stats
var width = originalBitmap.Width;
var height = originalBitmap.Height;
var rowBytes = originalBitmap.RowBytes;
var bytesPerPixel = originalBitmap.BytesPerPixel;

// pixelSpan that will be modified
var pixelSpan = originalBitmap.GetPixelSpan();

// reduces the number of colors to a fixed palette (e.g. 4 colors)
var quantizer = new LinearQuantizer(4);

// applies error diffusion dithering using Floyd–Steinberg
var processor = new FloydSteinbergProcessor(width, height, rowBytes, bytesPerPixel);

// dithring itself
var dithered = processor.Process(pixelSpan, quantizer);

// copy dithered span to original span
dithered.CopyTo(pixelSpan);

// save bitmap to file
var fileName = $"Out/dithered.png";
SaveBitmap(originalBitmap, fileName);

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

GNU GPL v3

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 44 3/2/2026
1.1.0 45 3/1/2026
1.0.0 40 2/28/2026