Drawing.BitmapFromArgbs: Handle Rgba colortype#4648
Conversation
Note that ARGB <-> BGRA and ABGR <-> RGBA due to endianness, Microsoft prefers the first notation but Skia prefers the second.
|
Thanks for your quick response, I found an similar bug report: mono/SkiaSharp#1492 (comment). |
|
What is interesting is that the coloring of the heatmap is OK when using it in a Jupiter environment. So I'm a little worried that this fix might break this option. The code I used in .Net Interactive: |
Good instincts, it does indeed break it, though it seems inconsistent after making changes, there may be some sort of caching in polyglot notebooks that's causing trouble with local packages if those packages are updated. I suspect I'll have better luck making a CLI app to debug this more reliably. I suspect the issue could be that we're trying to intuit the colour type from the platform (by using the default colour type for an In any case, this does seem like a more fragile solution than I'd expected, and that we do in many places fix the color type to Rgba, and never to Bgra. It makes me think that the solution should be to just create an |
|
Hi @bclehmann, I see this is still marked as a draft PR. Do you want me to merge it in for the next release (about 24 hours from now), or give you more time to look into this? I'm in favor of splitting this into two functions and hiding the call behind a feature flag (defaulting to the present behavior) if you are unsure how to proceed at this time. Thanks for this PR and your input! It always makes me happy to see bit twiddling :) Hope your 2025 is off to a great start! |
It should be ready for review now, I've implemented the solution I should've from the start. I'm no longer able to test the behaviour in a .NET notebook, since it seems like my updates to my local package are no longer respected? Some weird caching problem I'm sure. But the current solution should be much less fragile, frankly if this issue still shows up it would be because of a Skia bug (e.g. ignoring the SKColorType field). I would still welcome more testing, since it does freak me out that .NET notebook no longer responds to changes to the ScottPlot dll.
Alas the bit twiddling is now gone, sorry to disappoint.
So far I have no complaints, hope you're keeping well! |
|
The fix seems reasonable. I would like to validate it, are there any written instructions how to validate these changes that are not yet published using NuGet? |
There are instructions on building from source here: https://scottplot.net/faq/environment/ It looks like right now it's pretty simple, but there used to be more specific instructions for people building on older .NET SDKs (specifically ones that don't support the newest language features). You might also want to unload certain projects, either because they take a long time to build or because you don't have the prerequisites installed (the Maui projects are a good candidate, since they can take a while to build and they require a bunch of extra SDKs for mobile development). And of course you want the code from this branch, feel free to ignore this section if you're familiar with git. It's very convenient if you have the github CLI installed, since you can just do this: git clone https://github.com/scottplot/scottplot
cd scottplot
gh pr checkout 4648If you don't have the github CLI I think you want this, but I have to admit I haven't done this in a while git clone https://github.com/scottplot/scottplot
cd scottplot
git remote add bclehmann https://github.com/bclehmann/scottplot
git fetch bclehmann
git checkout --track bclehmann/fix/heatmap-rgbaYou can also just clone my fork directly, and then you won't have to set up another remote: git clone https://github.com/bclehmann/scottplot
cd scottplot
git fetch
git checkout --track origin/fix/heatmap-rgbaIf you have the github desktop app you can also use the checkout with github desktop button: If you did all of that right then running If you want to test in a NET notebook you can use ScottPlot.zip, just change Also note that there are both v4 and v5 ScottPlot solution files, you want v5. |
@ssharks note that I'll be pushing a new version to NuGet approximately 24 hours from now, so you're welcome to verify it works as expected after going live 👍 |
|
Thanks @bclehmann and @swharden. This morning I updated the NuGet package and was able to remove the workaround and have proper colors. |

This fixes #4647, which is most easily replicated by launching the Blazor Web Assembly demo.
As I said in #4647 (comment) I might want to get rid of the bit swizzling and just add a
Color.Abgr(the endian-swapped version of Rgba) property and deprecateBitmapFromArgbsin place of a version that takes aColorstruct. I haven't done so in this PR because I figured I'd have more and better thoughts on a day that isn't new years 🙃.