Skip to content

Add histogram support to System.Drawing #8837

@reflectronic

Description

@reflectronic

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:

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.

Metadata

Metadata

Assignees

Labels

api-suggestion(1) Early API idea and discussion, it is NOT ready for implementationarea-System.DrawingSystem.Drawing issues

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions