plotters icon indicating copy to clipboard operation
plotters copied to clipboard

[BUG] Unintuitive handling of RGBA images in BitMapElement

Open kangalio opened this issue 5 years ago • 2 comments

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:

  1. instead of From<(Coord, DynamicImage)>, take From<(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)
  2. have RGBA support right in BitMapElement itself

Version Information 0.3.0

kangalio avatar Oct 10 '20 12:10 kangalio

The library doesn't seem to know RGBA internally at all, since it is not implemented as a PixelFormat.

kmod-midori avatar Nov 29 '20 12:11 kmod-midori

Any update on this?

itohatweb avatar Dec 20 '21 16:12 itohatweb