vega / vl-convert

Utilities for converting Vega-Lite specs from the command line and Python
BSD 3-Clause "New" or "Revised" License
89 stars 9 forks source link

Fix "from_rgba returned None" panic #95

Closed jonmmease closed 10 months ago

jonmmease commented 10 months ago

Closes #94

In 0.13.0, the encode_png function was copied from tiny-skia and modified to support the ppi. The tiny-skia version is here:

https://github.com/RazrFalcon/tiny-skia/blob/d2b7abbde312a18f4c62ddc7201a32eb6e1a146f/src/pixmap.rs#L390-L419

This version uses the private PremultipliedColorU8::from_rgba_unchecked function to build pixels. I swapped this for the public PremultipliedColorU8::from_rgba function, which returns an Option that I unwraped. But it turns out the checked part is triggered for some pixels for the images in the VegaFusion test suite. This PR uses min to clamp the rgb values to the alpha value (which is what from_rgba checks).