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

Improve RGB Min Max evaluation performance by using 2 or 3 comparison… #50622

Merged
merged 5 commits into from
Apr 6, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int min, max;
MinMaxRgb(out min, out max, r, g, b);
MinMaxRgb(out int min, out int max, r, g, b);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated.


return (max + min) / (byte.MaxValue * 2f);
}
Expand All @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int min, max;
MinMaxRgb(out min, out max, r, g, b);
MinMaxRgb(out int min, out int max, r, g, b);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated.


float delta = max - min;
float hue;
Expand All @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int min, max;
MinMaxRgb(out min, out max, r, g, b);
MinMaxRgb(out int min, out int max, r, g, b);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated.


int div = max + min;
if (div > byte.MaxValue)
Expand Down