Ok, this will show me to actually try code before telling people how to do it.  
I tried to convert a mapnik image32 to CImg and of course it didn't work.   You 
have to cast the 32 bit ints into bytes.   Here's the right way (and tested):

                CImg<byte> img(reinterpret_cast<byte*>(buf.data().getData()), 
4, buf.width(), buf.height(), 1);
                img.permute_axes("yzvx");

The permute_axes properly changes it CImg's convention of band-interleaved.  
This gives you a 4 channel image (RGB + alpha).  If it's a grayscale image only 
the RGB bands are all set equal in mapnik.

If you then save it CImg will issue a warning that it's a 4 band image but that 
it will save only the first three channels as it should.

If you are dealing with only grayscale anyway and want to save some memory (or 
want just one channel) you can use one of the channel functions such as

img = img.get_channel(0);

hope this helps,

matt



> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:mapnik-users-
> [EMAIL PROTECTED] On Behalf Of Matt Hanson
> Sent: Monday, June 16, 2008 9:18 AM
> To: [email protected]
> Subject: Re: [Mapnik-users] Mapnik reprojection - how?
> 
> Fred,
> You can do what you want with CImg.  While it does have good
> documentation, there are still some functionality that isn't fully
> explained.   You want to make use of the permute_axes member function
> which allows you to specify a new ordering of pixels.   CImg normal
> axis ordering is xyzv (where by convention v is the color channel), so
> to switch to a 3 byte pixel interleaved image use:
> 
> Img = img.permute_axes("vxyz");
> 
> Then no need to write any code yourself to write the png, render to the
> Image32, convert to CImg then you can use CImg to write to png using
> CImg's ImageMagick functionality.   If you have problems you may have
> to explicitly define the ImageMagick path before including CImg.h,
> here's what the code would look like:
> 
> #define cimg_imagemagick_path "imagemagickpath"
> #include "CImg.h"
> 
> // Mapnik code and rendering to an Image32 here
> 
> CImg<long> img(img32,width,height);
> img.permute_axes("vxyz").save_graphicsmagick_external("filename.png");
> 
> Good luck!
> 
> I think you'll fine CImg an extremely useful package, it can do pretty
> much anything you can think of and if you have problems use it's
> forums.   David is quite responsive and there's been a few occasions
> where I've asked about some functionality which he then added to the
> library within a few days!
> 
> matt
> 
> 
> -----Original Message-----
> From: Frederik Ramm [mailto:[EMAIL PROTECTED]
> Sent: Friday, June 13, 2008 8:26 PM
> To: Matt Hanson
> Cc: [email protected]
> Subject: Re: [Mapnik-users] Mapnik reprojection - how?
> 
> Hi,
> 
> >  > Fred, Image32 does appear to be a pretty basic type
> >  > (yes it's a mapnik class). If you're using C++ at all (or have
> >  > the option to) I'd highly suggest you take a look at CImg...
> >
> > I'm using C++ and tend to stick what I already know (which is
> > GD and ImageMagick) but will check out CImg as well.
> 
> Ok here's an update on what I've achieved so far.
> 
> I have successfully used the cairo_renderer to draw onto a cairo
> surface
> which I subsequently rendered onto a new surface with scaling applied.
> This gives the desired result, with good quality, but unfortunately it
> is very slow (full execution time for rendering a 2° by 2° OSM styled
> map onto an 800x600 canvas - 15 seconds with cairo compared to 7
> seconds
> with AGG).
> 
> Actually applying the scaling to the cairo context used internally by
> the cairo_renderer, instead of scaling the resulting surface like I do,
> gains you a second but still the performance makes this unsuitable for
> my task.
> 
> So I went back to the idea of using the original AGG render result and
> somehow scale that bitmap before returning it. Unfortunately, neither
> GD
> nor ImageMagick nor CImg have a convenient method to work with the kind
> of interleaved data store that backs the Image32 type (GD stores an
> array of interleaved three-byte pixels and the alpha value is
> elsewhere;
> ImageMagick has 64bit pixels; CImg uses a non-interlaved four byte
> store, while Image32 is an interleaved four byte store). Somewhat
> exasperated, I did the ugliest thing and had Mapnik write the image to
> disk for me, then called ImageMagick externally to scale the PNG file,
> then read it back in - which adds an extra half second to processing
> but
> at least works for testing.
> 
> Since I don't need top-notch image quality for this corner case where
> the WMS client requests non-matching width/height, I will perhaps try
> the homebrew way of simply duplicating or dropping full lines in the
> PNG
> output to achieve the desired height. I have to roll my own PNG output
> from Image32 anyway because (unlike cairo which supports callback
> output) the existing Mapnik code will only create PNG files on disk and
> not in memory, where I need them if I want to return them to the user.
> 
> If anyone in the know reads this and has some insight to share, do
> speak up.
> 
> Bye
> Frederik
> 
> --
> Frederik Ramm  ##  eMail [EMAIL PROTECTED]  ##  N49°00'09"
> E008°23'33"
> _______________________________________________
> Mapnik-users mailing list
> [email protected]
> https://lists.berlios.de/mailman/listinfo/mapnik-users
_______________________________________________
Mapnik-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/mapnik-users

Reply via email to