-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Improve RGB Min Max evaluation performance by using 2 or 3 comparison… #50622
Changes from 1 commit
7a0fabe
59d5387
8341fe2
03644b6
5c109b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -487,12 +487,42 @@ private void GetRgbValues(out int r, out int g, out int b) | |||||||
b = (int)(value & ARGBBlueMask) >> ARGBBlueShift; | ||||||||
} | ||||||||
|
||||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||||||||
private void MinMaxRgb(out int min, out int max, int r, int g, int b) | ||||||||
{ | ||||||||
if (b < g) { | ||||||||
if (b < r) { | ||||||||
min = b; | ||||||||
if (r < g) { | ||||||||
max = g; | ||||||||
} else { | ||||||||
max = r; | ||||||||
} | ||||||||
} else { | ||||||||
min = r; | ||||||||
max = g; | ||||||||
} | ||||||||
} else { | ||||||||
if (r < b) { | ||||||||
max = b; | ||||||||
if (g < r) { | ||||||||
min = g; | ||||||||
} else { | ||||||||
min = r; | ||||||||
} | ||||||||
} else { | ||||||||
max = r; | ||||||||
min = g; | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
public float GetBrightness() | ||||||||
{ | ||||||||
GetRgbValues(out int r, out int g, out int b); | ||||||||
|
||||||||
int min = Math.Min(Math.Min(r, g), b); | ||||||||
int max = Math.Max(Math.Max(r, g), b); | ||||||||
int min, max; | ||||||||
MinMaxRgb(out min, out max, r, g, b); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, updated. |
||||||||
|
||||||||
return (max + min) / (byte.MaxValue * 2f); | ||||||||
} | ||||||||
|
@@ -504,8 +534,8 @@ public float GetHue() | |||||||
if (r == g && g == b) | ||||||||
return 0f; | ||||||||
|
||||||||
int min = Math.Min(Math.Min(r, g), b); | ||||||||
int max = Math.Max(Math.Max(r, g), b); | ||||||||
int min, max; | ||||||||
MinMaxRgb(out min, out max, r, g, b); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, updated. |
||||||||
|
||||||||
float delta = max - min; | ||||||||
float hue; | ||||||||
|
@@ -531,8 +561,8 @@ public float GetSaturation() | |||||||
if (r == g && g == b) | ||||||||
return 0f; | ||||||||
|
||||||||
int min = Math.Min(Math.Min(r, g), b); | ||||||||
int max = Math.Max(Math.Max(r, g), b); | ||||||||
int min, max; | ||||||||
MinMaxRgb(out min, out max, r, g, b); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, updated. |
||||||||
|
||||||||
int div = max + min; | ||||||||
if (div > byte.MaxValue) | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move trailing braces to their own lines for consistency with existing .NET code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, updated.