Add histogram support to System.Drawing
- Dominant language
- C#
- Stars
- 4.9k
- Forks
- 1.1k
- Avg merge
- 20h 23m
- Merged PRs (30d)
- 103
Description
### Background
GDI+ 1.1 added support for retrieving a histogram of the colors present in a bitmap. A handful of formats can be specified, each of which uses at most four channels of data to return the desired histogram(s). For example, the `Gray` format converts the bitmap to a grayscale image and returns a single histogram based on those grayscale values. However, the `PArgb` format uses all four channels to return a histogram for the alpha channel and the premultiplied red, green, and blue channels.
This proposal is one of many to add missing GDI+ 1.1 functionality to `System.Drawing`.
### API Proposal
See the documentation for:
- [Bitmap::GetHistogram](https://docs.microsoft.com/en-us/windows/win32/api/gdiplusheaders/nf-gdiplusheaders-bitmap-gethistogram)
- [HistogramFormat](https://docs.microsoft.com/en-us/windows/win32/api/gdipluscolormatrix/ne-gdipluscolormatrix-histogramformat)
```diff
namespace System.Drawing.Imaging
{
+ public sealed class Histogram
+ {
! All formats use at least one channel.
+ public int[] Channel0 { get; }
+ public int[]? Channel1 { get; }
+ public int[]? Channel2 { get; }
+ public int[]? Channel3 { get; }
+ }
+ public enum HistogramFormat
+ {
+ Argb,
! 'P' means premultiplied. It is consistent with other members in this namespace, like PixelFormat.Format32bppPArgb.
+ PArgb,
+ Rgb,
+ Gray,
+ Blue,
+ Green,
+ Red,
+ Alpha
+ }
}
namespace System.Drawing
{
public sealed class Bitmap : System.Drawing.Image
{
+ public Histogram GetHistogram(HistogramFormat histogramFormat);
}
}
```
This requires changes to libgdiplus in order to support it on non-Windows platforms.
Contributor guide
Assessment
This issue has not been assessed yet.