diagrams / diagrams-cairo

Cairo backend for diagrams
Other
13 stars 16 forks source link

Export Cairo.Text module again. Also, introduce `DImage R Embedded`. #66

Closed leftaroundabout closed 9 years ago

leftaroundabout commented 9 years ago

As I said, the re-newed text module seems to work fine, at least for me.

Here's another thing: The Cairo backend can so far only do external images. However, raster graphics are actually quite straightforward in Cairo. The only problem is that Graphics.Rendering.Cairo.SurfaceData is an abstract MArray, while Codec.Picture.Image uses Vector.Storable. Both aren't directly compatible, so I implemented the copying with a manual loop over the bytes/pixel-components, which is of course inefficient and particularly annoying since both types are more or less just wrappers around C-arrays of exactly the same data! So, this isn't really a good final implementation, but it does work ok. Any ideas how it could be done more efficiently, without getting too unsafe?

It's still a loop now, but rather nicer: with the ImageIPixels traversal, over entire pixels (i.e. Word32). And it's probably necessary, because the data is in fact not identical: JuicyPixels uses RGBA, while Cairo has ARGB, and one is big-endian, the other little-endian. So, effectively the red and blue channels are swapped; I implemented that with a Data.Bits rotation – probably quite optimal efficiency-wise.

leftaroundabout commented 9 years ago

Wait a moment... actually the pixel-copying doesn't work right yet, at all. The blue and red channels are swapped, for one thing... I'll fix that. Done.

byorgey commented 9 years ago

Any thoughts on this? @bergey ?

bergey commented 9 years ago

I'm not very familiar with JuicePixels or the raster parts of Cairo, but as far as I can tell, this looks good.