Skip to content
Open
Changes from all commits
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
13 changes: 11 additions & 2 deletions src/Starward/Features/Screenshot/ScreenCaptureService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,21 @@ public static async Task<ColorPrimaries> GetColorPrimariesFromDisplayInformation
var iccStream = await displayInfo.GetColorProfileAsync();
if (iccStream is null)
{
return new ColorPrimaries
var p = new ColorPrimaries
{
Red = new Vector2((float)colorInfo.RedPrimary.X, (float)colorInfo.RedPrimary.Y),
Green = new Vector2((float)colorInfo.GreenPrimary.X, (float)colorInfo.GreenPrimary.Y),
Blue = new Vector2((float)colorInfo.BluePrimary.X, (float)colorInfo.BluePrimary.Y),
White = new Vector2((float)colorInfo.WhitePoint.X, (float)colorInfo.WhitePoint.Y),
};
return ArePrimariesValid(p) ? p : ColorPrimaries.BT709;
}
else
{
byte[] iccData = new byte[iccStream.Size];
await iccStream.AsStream().ReadExactlyAsync(iccData).ConfigureAwait(false);
return ICCHelper.GetColorPrimariesFromIccData(iccData);
var p = ICCHelper.GetColorPrimariesFromIccData(iccData);
return ArePrimariesValid(p) ? p : ColorPrimaries.BT709;
}
}
catch
Expand All @@ -191,6 +193,13 @@ public static async Task<ColorPrimaries> GetColorPrimariesFromDisplayInformation
}


private static bool ArePrimariesValid(ColorPrimaries p)
{
return Valid(p.Red) && Valid(p.Green) && Valid(p.Blue) && Valid(p.White);
static bool Valid(Vector2 v) => float.IsFinite(v.X) && float.IsFinite(v.Y) && v.X > 0f && v.X < 1f && v.Y > 0f && v.Y < 1f && v.X + v.Y <= 1f;
}
Comment on lines +196 to +200



/// <summary>
/// 处理图片
Expand Down