forked from ko-vasilev/hearthstone-autosquelch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
unknown
committed
Oct 21, 2017
1 parent
787f35e
commit 74c6169
Showing
4 changed files
with
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#region | ||
|
||
using System.Drawing; | ||
|
||
#endregion | ||
|
||
namespace Hearthstone_Deck_Tracker.Exporting | ||
{ | ||
public class HueAndBrightness | ||
{ | ||
public HueAndBrightness(double hue, double brightness) | ||
{ | ||
Hue = hue; | ||
Brightness = brightness; | ||
} | ||
|
||
public double Hue { get; } | ||
public double Brightness { get; } | ||
|
||
public static HueAndBrightness GetAverage(Bitmap bmp, double saturationThreshold = 0.05) | ||
{ | ||
var totalHue = 0.0f; | ||
var totalBrightness = 0.0f; | ||
var validPixels = 0; | ||
for(var i = 0; i < bmp.Width; i++) | ||
{ | ||
for(var j = 0; j < bmp.Height; j++) | ||
{ | ||
var pixel = bmp.GetPixel(i, j); | ||
|
||
//ignore sparkle | ||
if(pixel.GetSaturation() > saturationThreshold) | ||
{ | ||
totalHue += pixel.GetHue(); | ||
totalBrightness += pixel.GetBrightness(); | ||
validPixels++; | ||
} | ||
} | ||
} | ||
|
||
return new HueAndBrightness(totalHue / validPixels, totalBrightness / validPixels); | ||
} | ||
} | ||
} |
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