image order in MagickMontageImage

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
mlin@pelmorex.com

image order in MagickMontageImage

Post by mlin@pelmorex.com »

Hi,

I have a project that need to merge a few tiles in one image. I use MagickMontageImage and the order of the tiles does not follow the read in order, while the command line tool of Montage works with the tile read in order. Any help or suggestion? Thanks
The sample code is as follows:
int main(int argc,char **argv)
{

MagickBooleanType status;
MagickWand *tile, *image, *int_image;
DrawingWand *d_wand;
MagickWandGenesis();
image=NewMagickWand();
status=MagickReadImage(image,"1.png");
status=MagickReadImage(image,"2.png");
status=MagickReadImage(image,"3.png");
status=MagickReadImage(image,"4.png");
status=MagickReadImage(image,"5.png");
status=MagickReadImage(image,"6.png");
status=MagickReadImage(image,"7.png");
status=MagickReadImage(image,"8.png");
status=MagickReadImage(image,"9.png");
PixelWand *p_wand;
p_wand = NewPixelWand();
PixelSetColor(p_wand,"none");
d_wand = NewDrawingWand();
char geo[10];
memset(geo, '\0', sizeof(geo));
sprintf(geo, "3x3+0+0");

int_image = MagickMontageImage(image, d_wand, geo,"50x50+0+0",ConcatenateMode,"0x0+0+0");
image=DestroyMagickWand(image);
d_wand = DestroyDrawingWand(d_wand);
p_wand = DestroyPixelWand(p_wand);
int_image=DestroyMagickWand(int_image);
MagickWandTerminus();
return(0);
}
Last edited by mlin@pelmorex.com on 2010-09-01T10:47:11-07:00, edited 1 time in total.
mlin@pelmorex.com

Re: image order in MagickMontageImage

Post by mlin@pelmorex.com »

also I saw memory leak in the function:
==18347== 428 bytes in 18 blocks are definitely lost in loss record 20 of 34
==18347== at 0x4A05809: malloc (vg_replace_malloc.c:149)
==18347== by 0x320E01C283: FcStrCopy (in /usr/lib64/libfontconfig.so.1.1.0)
==18347== by 0x320E01F518: (within /usr/lib64/libfontconfig.so.1.1.0)
==18347== by 0x3747809E94: (within /lib64/libexpat.so.0.5.0)
==18347== by 0x374780AB53: (within /lib64/libexpat.so.0.5.0)
==18347== by 0x374780BBB8: (within /lib64/libexpat.so.0.5.0)
==18347== by 0x374780CC2A: (within /lib64/libexpat.so.0.5.0)
==18347== by 0x3747803ED0: XML_ParseBuffer (in /lib64/libexpat.so.0.5.0)
==18347== by 0x320E01E8B7: FcConfigParseAndLoad (in /usr/lib64/libfontconfig.so.1.1.0)
==18347== by 0x320E01EB44: FcConfigParseAndLoad (in /usr/lib64/libfontconfig.so.1.1.0)
==18347== by 0x320E01EF97: (within /usr/lib64/libfontconfig.so.1.1.0)
==18347== by 0x3747809E94: (within /lib64/libexpat.so.0.5.0)
==18347== by 0x374780AB53: (within /lib64/libexpat.so.0.5.0)
==18347== by 0x374780BBB8: (within /lib64/libexpat.so.0.5.0)
==18347== by 0x374780CC2A: (within /lib64/libexpat.so.0.5.0)
==18347== by 0x3747803ED0: XML_ParseBuffer (in /lib64/libexpat.so.0.5.0)
==18347== by 0x320E01E8B7: FcConfigParseAndLoad (in /usr/lib64/libfontconfig.so.1.1.0)
==18347== by 0x320E0143A1: FcInitLoadConfig (in /usr/lib64/libfontconfig.so.1.1.0)
==18347== by 0x320E014405: FcInitLoadConfigAndFonts (in /usr/lib64/libfontconfig.so.1.1.0)
==18347== by 0x3A17580D8D: LoadFontConfigFonts (in /usr/lib64/libMagickCore.so.3.0.0)
==18347== by 0x3A17581F19: GetTypeInfo (in /usr/lib64/libMagickCore.so.3.0.0)
==18347== by 0x3A175825B1: GetTypeInfoByFamily (in /usr/lib64/libMagickCore.so.3.0.0)
==18347== by 0x3A17442E60: (within /usr/lib64/libMagickCore.so.3.0.0)
==18347== by 0x3A174434D3: GetTypeMetrics (in /usr/lib64/libMagickCore.so.3.0.0)
==18347== by 0x3A175105AA: MontageImageList (in /usr/lib64/libMagickCore.so.3.0.0)
==18347== by 0x3A170A99AC: MagickMontageImage (in /usr/lib64/libMagickWand.so.3.0.0)
==18347== by 0x40201A: main (fftile_p.c:217)
==18347==
==18347==
==18347== 2,016 bytes in 7 blocks are possibly lost in loss record 25 of 34
==18347== at 0x4A04B32: calloc (vg_replace_malloc.c:279)
==18347== by 0x373F40FC82: _dl_allocate_tls (in /lib64/ld-2.5.so)
==18347== by 0x3740406904: pthread_create@@GLIBC_2.2.5 (in /lib64/libpthread-2.5.so)
==18347== by 0x3A168042B1: (within /usr/lib64/libgomp.so.1.0.0)
==18347== by 0x3A174FBCA4: SetImageBackgroundColor (in /usr/lib64/libMagickCore.so.3.0.0)
==18347== by 0x3A17510B61: MontageImageList (in /usr/lib64/libMagickCore.so.3.0.0)
==18347== by 0x3A170A99AC: MagickMontageImage (in /usr/lib64/libMagickWand.so.3.0.0)
==18347== by 0x40201A: main (fftile_p.c:217)
==18347== 2,592 (2,304 direct, 288 indirect) bytes in 9 blocks are definitely lost in loss record 27 of 34
==18347== at 0x4A05809: malloc (vg_replace_malloc.c:149)
==18347== by 0x320E019BCB: (within /usr/lib64/libfontconfig.so.1.1.0)
==18347== by 0x320E01A4D1: (within /usr/lib64/libfontconfig.so.1.1.0)
==18347== by 0x320E01A5D4: (within /usr/lib64/libfontconfig.so.1.1.0)
==18347== by 0x320E01F44B: (within /usr/lib64/libfontconfig.so.1.1.0)
==18347== by 0x3747809E94: (within /lib64/libexpat.so.0.5.0)
==18347== by 0x374780AB53: (within /lib64/libexpat.so.0.5.0)
==18347== by 0x374780BBB8: (within /lib64/libexpat.so.0.5.0)
==18347== by 0x374780CC2A: (within /lib64/libexpat.so.0.5.0)
==18347== by 0x3747803ED0: XML_ParseBuffer (in /lib64/libexpat.so.0.5.0)
==18347== by 0x320E01E8B7: FcConfigParseAndLoad (in /usr/lib64/libfontconfig.so.1.1.0)
==18347== by 0x320E01EB44: FcConfigParseAndLoad (in /usr/lib64/libfontconfig.so.1.1.0)
==18347== by 0x320E01EF97: (within /usr/lib64/libfontconfig.so.1.1.0)
==18347== by 0x3747809E94: (within /lib64/libexpat.so.0.5.0)
==18347== by 0x374780AB53: (within /lib64/libexpat.so.0.5.0)
==18347== by 0x374780BBB8: (within /lib64/libexpat.so.0.5.0)
==18347== by 0x374780CC2A: (within /lib64/libexpat.so.0.5.0)
==18347== by 0x3747803ED0: XML_ParseBuffer (in /lib64/libexpat.so.0.5.0)
==18347== by 0x320E01E8B7: FcConfigParseAndLoad (in /usr/lib64/libfontconfig.so.1.1.0)
==18347== by 0x320E0143A1: FcInitLoadConfig (in /usr/lib64/libfontconfig.so.1.1.0)
==18347== by 0x320E014405: FcInitLoadConfigAndFonts (in /usr/lib64/libfontconfig.so.1.1.0)
==18347== by 0x320E0144DC: FcInit (in /usr/lib64/libfontconfig.so.1.1.0)
==18347== by 0x320E00CB51: FcConfigGetCurrent (in /usr/lib64/libfontconfig.so.1.1.0)
==18347== by 0x320E01618E: FcFontList (in /usr/lib64/libfontconfig.so.1.1.0)
==18347== by 0x3A17580DFC: LoadFontConfigFonts (in /usr/lib64/libMagickCore.so.3.0.0)
==18347== by 0x3A17581F19: GetTypeInfo (in /usr/lib64/libMagickCore.so.3.0.0)
==18347== by 0x3A175825B1: GetTypeInfoByFamily (in /usr/lib64/libMagickCore.so.3.0.0)
==18347== by 0x3A17442E60: (within /usr/lib64/libMagickCore.so.3.0.0)
==18347== by 0x3A174434D3: GetTypeMetrics (in /usr/lib64/libMagickCore.so.3.0.0)
==18347== by 0x3A175105AA: MontageImageList (in /usr/lib64/libMagickCore.so.3.0.0)
==18347== by 0x3A170A99AC: MagickMontageImage (in /usr/lib64/libMagickWand.so.3.0.0)
==18347== by 0x40201A: main (fftile_p.c:217)


any suggestion/help?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: image order in MagickMontageImage

Post by magick »

After each MagickReadImage(), move the iterator with MagickSetLastIterator():
  • status=MagickReadImage(image,"1.png");
    MagickSetLastIterator(image);
    status=MagickReadImage(image,"2.png");
    MagickSetLastIterator(image);
Concerning the memory leak. Don't forget to destroy the drawing wand:
  • d_wand=DestroyDrawingWand(d_wand);
mlin@pelmorex.com

Re: image order in MagickMontageImage

Post by mlin@pelmorex.com »

magick wrote:After each MagickReadImage(), move the iterator with MagickSetLastIterator():
  • status=MagickReadImage(image,"1.png");
    MagickSetLastIterator(image);
    status=MagickReadImage(image,"2.png");
    MagickSetLastIterator(image);
Concerning the memory leak. Don't forget to destroy the drawing wand:
  • d_wand=DestroyDrawingWand(d_wand);

Thanks. the order is right now. great help.
Valgrind complains MagickMontageImage function memory leak. any suggestion?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: image order in MagickMontageImage

Post by magick »

The complaints appear to be coming from the font-config delegate library, not ImageMagick. There is also a bit of memory left over by the Posix threads. Both of these are outside our control. One posting says "most of your reported leaks are false positives due to gobject's use of glib's slice allocator.". We added a DestroyPixelWand(p_wand) to your code and valgrind reports:
  • ==23230== LEAK SUMMARY:
    ==23230== definitely lost: 0 bytes in 0 blocks
    ==23230== indirectly lost: 0 bytes in 0 blocks
mlin@pelmorex.com

Re: image order in MagickMontageImage

Post by mlin@pelmorex.com »

Thanks. Great help.
greta
Posts: 1
Joined: 2011-03-24T08:50:16-07:00
Authentication code: 8675308

Re: image order in MagickMontageImage

Post by greta »

Hi,

I am also new to imageMagick, and i'm trying to use the same method as mlin@pelmorex.com did, the MagickMontageImage method,
but the magic wand i receive as result is 0x0 (empty). I am using the version 6.6.1-5 of imageMagick libraries compiled for
iPhone.

Here the code i'm trying to execute:

Code: Select all

MagickWand *image, magick_wand;
        DrawingWand *d_wand;
        MagickWandGenesis();
        image=NewMagickWand();
        status=MagickReadImage(image,"t1.jpeg");
        status=MagickReadImage(image,"t2.jpeg");
        status=MagickReadImage(image,"t3.jpeg");
        status=MagickReadImage(image,"t4.jpeg");
        
        PixelWand *p_wand;
        p_wand = NewPixelWand();
        PixelSetColor(p_wand,"none");
        d_wand = NewDrawingWand();
        char geo[10];
        memset(geo, '\0', sizeof(geo));
        
        magick_wand = MagickMontageImage(image, d_wand, "1x1+0+0","50x50+0+0",ConcatenateMode,"15x15+3+3");
        image=DestroyMagickWand(image);
        d_wand = DestroyDrawingWand(d_wand);
        p_wand = DestroyPixelWand(p_wand);
Can someone help me please?

Regards
Post Reply