plotters
plotters copied to clipboard
[BUG] Unintuitive handling of RGBA images in BitMapElement
Describe the bug
I wanted to draw icons on a plot. BitMapElement seemed to be the way to do it, and there was no constructor for it so I used the From<(Coord, image::DynamicImage)> implementation instead. My icon was rather simple; a black cog with a transparent background. However, plotters actually rendered... a completely black square.
At this point I have understood why this happens, but it took me 150 minutes of frustrating debugging work to find the root cause of this issue: https://github.com/38/plotters/blob/master/src/element/image.rs#L171 The problem is that plotters converts images into full-opaque images internally, discarding the transparency information along the way. For that reason, my pretty icon got turned into a black square.
I can think of several possible ways to improve/fix the situation:
- instead of
From<(Coord, DynamicImage)>, takeFrom<(Coord, DynamicImage, Color)>. Then, don't discard transparency but replace it with the given color instead- (On that note, might as well make a proper constructor
BitMapElement::new(Coord, DynamicImage, Color)instead of the From implementation. This kind of use is not what From/Into is meant for)
- (On that note, might as well make a proper constructor
- have RGBA support right in BitMapElement itself
Version Information 0.3.0
The library doesn't seem to know RGBA internally at all, since it is not implemented as a PixelFormat.
Any update on this?