You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know that GetPixel is directly exposed by the Skia API, whereas there is no "official" SetPixel and it uses SKCanvas.DrawPoint in the background. Still, it would be desirable for GetPixel to reverse the transformations that SetPixel performs (if the color type/space allows it).
Description
SKBitmap.SetPixel (and the drawing operations by SKCanvas that use SKColor) always treat SKColor as an unpremultiplied sRGB color and they perform every necessary transformation as per the color space, but SKBitmap.GetPixel ignores the SKImageInfo.ColorSpace property (respects only SKColorType and SKAlphaType) and may return a completely invalid color.
GetPixel should return an unpremultiplied sRGB color even if the color space transfer function or color space XYZ is not sRGB.
Actual Behavior
GetPixel successfully unpremultiplies the color if needed but fails to convert linear gamma or any non-sRGB color space to sRGB.
Basic Information
Version with issue: 2.88.3
Last known good version: Don't know, maybe never worked
IDE: Visual Studio
Platform Target Frameworks:
Windows Classic: Windows 10/11
Linux: Ubuntu 22.04
Target Devices:
Google Pixel 5 (Android Emulator on Windows)
Known workaround
A very inefficient workaround is to create a 1x1 pixel sRGB Bgra8888/Unpremul bitmap, wrap it into a new SKCanvas, copy that single pixel area into the temp bitmap, and then read the result by GetPixel on the temp bitmap.
Possible solutions, API changes
I don't know if there is anyone who relies on the current behavior but maybe a new GetPixel(int x, int y, bool forceSrgb) overload could be introduced. Or a new GetPixelSrgb(int x, int y) method.
And I also don't know if this could be solved by calling some trivial API exposed by Skia, or it should be implemented at the C# side. Maybe for the default linear color space I could use the formula mentioned in the documentation but I have no idea how I should use any custom SKColorSpaceXyz coefficients (the documentation literally does not say anything about this) or what I could do if SKColorSpace.IsNumericalTransferFunction returns false.
The text was updated successfully, but these errors were encountered:
Disclaimer
I know that
GetPixel
is directly exposed by the Skia API, whereas there is no "official"SetPixel
and it usesSKCanvas.DrawPoint
in the background. Still, it would be desirable forGetPixel
to reverse the transformations thatSetPixel
performs (if the color type/space allows it).Description
SKBitmap.SetPixel
(and the drawing operations bySKCanvas
that useSKColor
) always treatSKColor
as an unpremultiplied sRGB color and they perform every necessary transformation as per the color space, butSKBitmap.GetPixel
ignores theSKImageInfo.ColorSpace
property (respects onlySKColorType
andSKAlphaType
) and may return a completely invalid color.Code
Expected Behavior
GetPixel
should return an unpremultiplied sRGB color even if the color space transfer function or color space XYZ is not sRGB.Actual Behavior
GetPixel
successfully unpremultiplies the color if needed but fails to convert linear gamma or any non-sRGB color space to sRGB.Basic Information
Known workaround
A very inefficient workaround is to create a 1x1 pixel sRGB Bgra8888/Unpremul bitmap, wrap it into a new
SKCanvas
, copy that single pixel area into the temp bitmap, and then read the result byGetPixel
on the temp bitmap.Possible solutions, API changes
I don't know if there is anyone who relies on the current behavior but maybe a new
GetPixel(int x, int y, bool forceSrgb)
overload could be introduced. Or a newGetPixelSrgb(int x, int y)
method.And I also don't know if this could be solved by calling some trivial API exposed by Skia, or it should be implemented at the C# side. Maybe for the default linear color space I could use the formula mentioned in the documentation but I have no idea how I should use any custom
SKColorSpaceXyz
coefficients (the documentation literally does not say anything about this) or what I could do ifSKColorSpace.IsNumericalTransferFunction
returnsfalse
.The text was updated successfully, but these errors were encountered: