Home

Awesome

HPPH

C# High Performance Pixel Handling

Summary

This library contains helpers to work with color data (currently only 24 and 32 bit byte data) in a somewhat performance-optimized fully in C#.

It consists of the following packages:

PackageDescription
HPPHCore-package, containg all the features described below
HPPH.System.DrawingContains extensions to convert Images from and to System.Drawing.Bitmaps
HPPH.SkiaSharpContains extensions to convert Images from and to SkiaSharp images and bitmaps

Supported Operations

All of the currently supported operations are briefly described below. More are to come.

Benchmarks are all run on an Ryzen 9 5900X. Reference is always a simple approach like looping over the data performing the operation.
The data used is always the full set of sample_data to cover a variaty of images.

Image

An abstraction layer for handling pixel-grids.

Supports all of the operations below and things like allocation-free region selection, iteration and copying of rows, colums or whole images/regions.

Sum

Optimized summarization of colors into 4 longs (one for each channel).

MethodMeanErrorStdDevAllocated
PixelHelper_3BPP107.3 μs0.21 μs0.20 μs528 B
PixelHelper_4BPP167.7 μs0.85 μs0.71 μs528 B
Reference_3BPP1,683.3 μs18.87 μs17.65 μs529 B
Reference_4BPP1,619.5 μs9.08 μs7.58 μs529 B

Average

Averages some colors into a single color of the same format.

MethodMeanErrorStdDevAllocated
PixelHelper_3BPP108.2 μs0.41 μs0.34 μs56 B
PixelHelper_4BPP169.0 μs2.29 μs2.14 μs64 B
Reference_3BPP1,654.9 μs12.06 μs11.28 μs705 B
Reference_4BPP1,613.4 μs21.11 μs18.71 μs713 B

Min-Max

Gets the minimum and maximum value for each channel of the given color data.

MethodMeanErrorStdDevAllocated
PixelHelper_3BPP106.2 μs0.38 μs0.35 μs312 B
PixelHelper_4BPP139.2 μs1.94 μs1.82 μs312 B
Reference_3BPP3,838.1 μs35.40 μs31.38 μs314 B
Reference_4BPP4,456.9 μs21.06 μs19.70 μs315 B

Sort

Sorts color data by a single channel (Red, Green, Blue or Alpha).
The algorithm is stable.

This benchmark is somewhat flawed as it's effectivly running on pre-sorted data, which does not affect the PixelHelper, but might affect the Reference.

It's also using Linq.OrderBy which is not ideal performance-wise and requires some unneccessary allocations to fit the API, but Array/Span.Sort is not stable, which the PixelHelper is so that wouldn't be a fair comparison.)

MethodMeanErrorStdDevAllocated
PixelHelper_3BPP4.084 ms0.0084 ms0.0075 ms6 B
PixelHelper_4BPP2.687 ms0.0102 ms0.0091 ms3 B
Reference_3BPP59.883 ms0.5693 ms0.5325 ms43118222 B
Reference_4BPP59.599 ms0.4866 ms0.4551 ms52355952 B

Quantization

Creates a color-palette of a given size for some color-data.
Currently only a simple but fast variation using the median-cut algorithm is implemented. It's also limited to sizes being a power of 2.

A more quality focused implementation without the size limitation is planned.

Conversion

Converts from one color format to another.
All of the included formats can freely be converted between each other.

Allocation-free in-place conversion is only supported for formats of same size (both 24 or 32 bit).

MethodMeanErrorStdDevAllocated
RGBToBGR1.487 ms0.0221 ms0.0196 ms9073.58 KB
RGBToBGRA1.676 ms0.0330 ms0.0353 ms12064.76 KB
RGBAToABGR1.766 ms0.0348 ms0.0476 ms12084.93 KB
ARGBToBGR1.533 ms0.0072 ms0.0064 ms9085.36 KB
RGBToBGR_InPlace1.025 ms0.0021 ms0.0017 ms34.47 KB
RGBAToABGR_InPlace1.054 ms0.0023 ms0.0020 ms34.16 KB