Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add histogram support to System.Drawing #8837

Open
reflectronic opened this issue Jul 23, 2020 · 3 comments
Open

Add histogram support to System.Drawing #8837

reflectronic opened this issue Jul 23, 2020 · 3 comments
Assignees
Labels
api-suggestion (1) Early API idea and discussion, it is NOT ready for implementation area-System.Drawing System.Drawing issues
Milestone

Comments

@reflectronic
Copy link

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.

@reflectronic reflectronic added the api-suggestion (1) Early API idea and discussion, it is NOT ready for implementation label Jul 23, 2020
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Drawing System.Drawing issues untriaged The team needs to look at this issue in the next triage labels Jul 23, 2020
@ghost
Copy link

ghost commented Jul 23, 2020

Tagging subscribers to this area: @safern, @tannergooding
See info in area-owners.md if you want to be subscribed.

@danmoseley
Copy link
Member

danmoseley commented Jul 23, 2020

We have to decide on what our road map is for System.Drawing and what kind of changes we want to take in it. For new code, libraries like Imagesharp and SkiaSharp may be better choices.

What are your thoughts about why it is important to extend System.Drawing? Who would use this do you expect?

Also, we would want it to work on Unix: does libgdiplus support this?

@reflectronic
Copy link
Author

One thing that System.Drawing has (which no other frameworks do) is very close integration with Winforms. Really, this isn't something important to me personally, but e.g. I originally proposed CachedBitmap when someone asked me online how they could utilize it to speed up their drawing performance. Of course, they linked me to the C++ documentation for it, and there wasn't a way to do that from C#.

I know that System.Drawing isn't .NET's finest work 😛 but these are somewhat low-effort changes. GDI+ was rev'd once; it likely won't be updated again. Most of the work on the .NET side is coming up with a decent API shape; wrapping the right APIs is trivial. I promise I'm not some weird GDI+ fan - it's just low-hanging fruit that can likely be briefly completed in one release and never touched again.

Also, we would want it to work on Unix: does libgdiplus support this?

Not at the moment. However, the same was true of CachedBitmap. I implemented that in libgdiplus, and if this is approved, I'll implement this as well.

@tannergooding tannergooding added this to the Future milestone Sep 14, 2020
@jeffschwMSFT jeffschwMSFT removed the untriaged The team needs to look at this issue in the next triage label Sep 15, 2020
@safern safern removed this from the Future milestone Jul 16, 2021
@ViktorHofer ViktorHofer added this to the Future milestone Aug 4, 2022
@JeremyKuhne JeremyKuhne transferred this issue from dotnet/runtime Mar 14, 2023
@JeremyKuhne JeremyKuhne modified the milestones: Future, .NET 8.0 Mar 14, 2023
@JeremyKuhne JeremyKuhne modified the milestones: .NET 8.0, .NET 9.0 Aug 16, 2023
@JeremyKuhne JeremyKuhne modified the milestones: .NET 9.0, .NET 10.0 Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion (1) Early API idea and discussion, it is NOT ready for implementation area-System.Drawing System.Drawing issues
Projects
None yet
Development

No branches or pull requests

8 participants