-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #66
- Loading branch information
Showing
9 changed files
with
151 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using Microsoft.Graphics.Canvas; | ||
using Microsoft.Graphics.Canvas.Effects; | ||
using Windows.Foundation; | ||
using Windows.UI; | ||
|
||
namespace Fotografix | ||
{ | ||
public sealed class Histogram | ||
{ | ||
private const int NumBins = 256; | ||
private const int Height = 100; | ||
|
||
private readonly float[] r; | ||
private readonly float[] g; | ||
private readonly float[] b; | ||
|
||
public Histogram(float[] r, float[] g, float[] b) | ||
{ | ||
this.r = r; | ||
this.g = g; | ||
this.b = b; | ||
} | ||
|
||
public static Histogram Compute(ICanvasImage image, Rect rect, ICanvasResourceCreator resourceCreator) | ||
{ | ||
float[] r = CanvasImage.ComputeHistogram(image, rect, resourceCreator, EffectChannelSelect.Red, NumBins); | ||
float[] g = CanvasImage.ComputeHistogram(image, rect, resourceCreator, EffectChannelSelect.Green, NumBins); | ||
float[] b = CanvasImage.ComputeHistogram(image, rect, resourceCreator, EffectChannelSelect.Blue, NumBins); | ||
return new Histogram(r, g, b); | ||
} | ||
|
||
public static Size RenderSize => new Size(NumBins, Height); | ||
|
||
public void Draw(CanvasDrawingSession ds) | ||
{ | ||
float s = Height / 0.025f; | ||
|
||
void Draw(float[] x, Color color) | ||
{ | ||
for (int i = 0; i < NumBins; i++) | ||
{ | ||
ds.DrawLine(i, Height, i, Height - s * x[i], color); | ||
} | ||
} | ||
|
||
ds.Blend = CanvasBlend.Add; | ||
Draw(r, Color.FromArgb(255, 255, 0, 0)); | ||
Draw(g, Color.FromArgb(255, 0, 255, 0)); | ||
Draw(b, Color.FromArgb(255, 0, 0, 255)); | ||
} | ||
|
||
public CanvasBitmap ExportToCanvasBitmap(ICanvasResourceCreator resourceCreator) | ||
{ | ||
var rt = new CanvasRenderTarget(resourceCreator, NumBins, Height, 96); | ||
|
||
using (var ds = rt.CreateDrawingSession()) | ||
{ | ||
ds.Clear(Colors.Transparent); | ||
Draw(ds); | ||
} | ||
|
||
return rt; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters