Last active
December 11, 2015 03:28
-
-
Save lukehorvat/4537745 to your computer and use it in GitHub Desktop.
An example of concurrent image brightness normalization in C#.
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
//determine the brightness range of this thread's image strip | |
Tuple brightnessRange = GetImagePartBrightnessRange(image, startX, startY, finishX, finishY); | |
//update the global brightness range of the entire image | |
lock (_lock) | |
{ | |
minBrightness = Math.Min(minBrightness, brightnessRange.Item1); | |
maxBrightness = Math.Max(maxBrightness, brightnessRange.Item2); | |
} | |
//wait at the barrier until all image strips have been assessed | |
barrier.Wait(); | |
//now that the brightness range of the entire image is known, normalize the brightness of the image strip | |
NormalizeImagePart(image, startX, startY, finishX, finishY, minBrightness, maxBrightness); | |
//raise event so that event listeners are notified that the image strip has been normalized | |
ImagePartNormalized(this, new ImagePartModifiedEventArgs(startX, startY, finishX, finishY)); | |
bool isLastThread = barrier.Wait(); | |
//if this thread is the last one past the barrier, then we | |
//can safely assume all image strips have been normalized | |
if (isLastThread) | |
{ | |
//raise event so that event listeners are notified that the normalization is complete | |
ImageNormalizationCompleted(this, EventArgs.Empty); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment