Page 1 of 1

Creating/reusing wands and images

Posted: 2014-12-08T10:53:16-07:00
by grepnold
Hi all, I'm just starting to use MagickWand's C API. I'm using it for testing some low-level pixel-level operations. I use MagickWand to open a file, I export the pixels into my own malloc'd array, mess around with it a bit and import the array back into the same image and wand. Then when I write the wand's image back to a new file, it's segfaulting on me in a malloc.

I'm not really asking for advice on that problem, for one thing I don't have the details to hand, but I see from el_supremo's useful examples that he uses multiple images per wand, and multiple wands. So the question I have at this stage, because I haven't seen it discussed anywhere, is: When should/must you create new images or wands, and when can you reuse them. Maybe it's simply not valid to change an exported pixel array and import it back?

Sorry for vagueness at this stage, don't have the details to hand but will respond to any requests for more detail.

Re: Creating/reusing wands and images

Posted: 2014-12-08T12:16:24-07:00
by snibgo
I can't be specific without seeing code, and I use only MagickCore "image" and not MagickWand "wand" (see my examples at http://im.snibgo.com/customim.htm ), but perhaps you are referencing malloced memory outside of the scope in which you defined it.

How are you doing the export to your array, and import? If you are using supported mechanisms, it should work fine. If you are using faster shortcuts, that might be the problem.

Re: Creating/reusing wands and images

Posted: 2014-12-08T13:28:38-07:00
by grepnold
Thanks snibgo. I've now proved that I can change pixels in the array and write it back, so I'm not doing something wrong with MagickWand. My code must be corrupting something.