Passing function pointer to ReadStream with Managed C++

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
codymanix
Posts: 19
Joined: 2008-02-20T20:49:46-07:00

Passing function pointer to ReadStream with Managed C++

Post by codymanix »

I have the following given:

size_t ImageLdr::MyStreamHandler(const MagickLib::Image *image,const void *pixels, const size_t columns)
{
}

Now I want to call ReadStream in my code:

MagickLib::Image* img = ReadStream(&imageinfo,&ImageLdr::MyStreamHandler,&ex);

But the compiler tells me "can't take address of 'MagickNet::ImageLdr::MyStreamHandler' unless creating delegate instance".

And when I create a delegate:

public delegate size_t SH(const MagickLib::Image *image,const void *pixels, const size_t columns);
SH^ sh = gcnew SH(this, &ImageLdr::MyStreamHandler);
MagickLib::Image* img = ReadStream(sh);

Then it says: "cannot convert parameter 2 from 'MagickNet::SH ^' to 'MagickLib::StreamHandler'".

So how can I pass my method to this callback function?
Last edited by codymanix on 2009-02-13T14:10:57-07:00, edited 1 time in total.
codymanix
Posts: 19
Joined: 2008-02-20T20:49:46-07:00

Re: Passing function pointer to ReadStream with Managed C++

Post by codymanix »

I got it working now, seems one cannot create function pointers from managed classes, so I use a native class now which I call from my managed class.

Not I have another problem. Some image formats like Microsoft Bitmap store the rows from bottom to top instead of top to bottom.
How can my code know that without without having to guess it from file extension?

Additionally Iam not sure how to convert the void*pixels argument into the format which I need. Is there a function like
convert_magickpixels_to_given_format(void*dst,void*src, "RGBA")?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Passing function pointer to ReadStream with Managed C++

Post by magick »

Not I have another problem. Some image formats like Microsoft Bitmap store the rows from bottom to top instead of top to bottom.
The Image structure includes an orientation member. Check image->orientation. If its not reporting correctly let us know and we will add a patch to the Subversion trunk.
Additionally Iam not sure how to convert the void*pixels argument into the format which I need. Is there a function like
convert_magickpixels_to_given_format(void*dst,void*src, "RGBA")?
Assume you ask for RGBA at depth 8, for this example, use an unsigned char pointer:

Code: Select all

unsigned char *p;
p=(unsigned char *) pixels;
red=(*p++);
green=(*p++);
blue=(*p++);
alpha=(*p++);
codymanix
Posts: 19
Joined: 2008-02-20T20:49:46-07:00

Re: Passing function pointer to ReadStream with Managed C++

Post by codymanix »

Thanks for reply!
The Image structure includes an orientation member. Check image->orientation. If its not reporting correctly let us know and we will add a patch to the Subversion trunk.
the orientation of the image the StreamHAndler gets passed seem to be always zero, whether it's a bitmap or not.
Assume you ask for RGBA at depth 8, for this example, use an unsigned char pointer:

Code: Select all

unsigned char *p;
p=(unsigned char *) pixels;
red=(*p++);
green=(*p++);
blue=(*p++);
alpha=(*p++);
Is the internal format of magick image pixels currently guaranteed to always to be in this format?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Passing function pointer to ReadStream with Managed C++

Post by magick »

If you use the streaming interface the pixels are in the format you specify. The default is CharPixel with a RGB map. In addition to streaming you can import / export pixels with ExportImagePixels() and ImportImagePixels() or you can use the pixel cache (e.g. GetAuthenticPixels()). If you use the MagickWand API, you can use pixel views to access the pixel cache in parallel.
Post Reply