Page 1 of 1

Bug in MagickFxImage ?

Posted: 2010-08-25T16:22:33-07:00
by el_supremo
Don't know if this is a bug but cant find a programming error.
I've been trying to implement one of the IM Example commands in MagickWand and cannot get the Fx function to produce the correct result. Another user is having a similar problem with this in Magick++ - see viewtopic.php?f=18&t=14963.
The image immediately after the Negate is exactly the same as after the -negate in the command line version. But the result is not even close. See http://members.shaw.ca/el_supremo/eyes_syms.gif. The correct output is shown here http://www.smileygenerator.us/imagick6/ ... iy_symbols
This is with a compiled version of IM 6.6.3-8 on Windows XP.

Code: Select all

/*	
convert eyes.gif +matte -colorspace Gray -scale 1600% -negate \
        dpat_symbols.gif   -virtual-pixel tile  -fx 'u[floor(16*u)+1]' \
        eyes_syms.gif
*/
#include <windows.h>
#include <wand/magick_wand.h>

void test_wand(LPTSTR lpCmdLine)
{
	MagickWand *mw = NULL;
	MagickWand *mwfx = NULL;

	MagickWandGenesis();

	// Read the base image
	mw = NewMagickWand();
	MagickReadImage(mw,"eyes.gif");
	// +matte
	MagickSetImageAlphaChannel(mw,DeactivateAlphaChannel);

	// -colorspace Gray
	MagickTransformImageColorspace(mw,GRAYColorspace);

	// -scale 1600%
	MagickScaleImage(mw,16*MagickGetImageWidth(mw),16*MagickGetImageHeight(mw));
	// -negate
	MagickNegateImage(mw,MagickFalse);

	MagickReadImage(mw,"dpat_symbols.gif");

	// -virtual-pixel tile
	MagickSetImageVirtualPixelMethod(mw,TileVirtualPixelMethod);

	// -fx 'u[floor(16*u)+1]'
	mwfx = MagickFxImage(mw,"u[floor(16*u)+1]");

	/* Write the image */
	MagickWriteImage(mwfx,"eyes_syms.gif");

	/* Clean up */
	if(mw)mw = DestroyMagickWand(mw);
	if(mwfx)mwfx = DestroyMagickWand(mwfx);
	MagickWandTerminus();
}

I tried another Fx example just to see if it was specifically the one above that was at fault but there's a problem with this one too.
This code produces an almost correct image except that the colours aren't in the same order as those produced by the command line.
The output image is here http://members.shaw.ca/el_supremo/fx_test.png

Code: Select all

// convert -size 100x100 xc: +size xc:red xc:yellow xc:lime \
//          -fx 'ar=1/max(1,(i-50)*(i-50)+(j-10)*(j-10)); \
//               br=1/max(1,(i-10)*(i-10)+(j-70)*(j-70)); \
//               cr=1/max(1,(i-90)*(i-90)+(j-90)*(j-90)); \
//               (u[1]*ar+u[2]*br+u[3]*cr)/(ar+br+cr)' \
//          fx_test.gif
#include <windows.h>
#include <wand/magick_wand.h>

void test_wand(LPTSTR lpCmdLine)
{
	MagickWand *mw = NULL;
	MagickWand *mwfx = NULL;

	mw=NewMagickWand();

	MagickSetSize(mw,100,100);
	MagickReadImage(mw,"xc:");

	MagickSetSize(mw,0,0);
	MagickReadImage(mw,"xc:red");
	MagickReadImage(mw,"xc:yellow");
	MagickReadImage(mw,"xc:lime");

	mwfx = MagickFxImage(mw,"ar=1/max(1,(i-50)*(i-50)+(j-10)*(j-10)); \
							br=1/max(1,(i-10)*(i-10)+(j-70)*(j-70)); \
							cr=1/max(1,(i-90)*(i-90)+(j-90)*(j-90)); \
							(u[1]*ar+u[2]*br+u[3]*cr)/(ar+br+cr)");

	MagickWriteImage(mwfx,"fx_test.png");
	if(mw)mw = DestroyMagickWand(mw);
	if(mwfx)mwfx = DestroyMagickWand(mwfx);
	MagickWandTerminus();
}
Both command line examples work in this version of IM.
Is there a bug in MagickFxImage or am I doing something wrong?

Pete

Re: Bug in MagickFxImage ?

Posted: 2010-08-25T18:05:07-07:00
by magick
You want to set the virtual pixel setting of each image in the wand container. Try this code:

Code: Select all

   // -virtual-pixel tile
   MagickResetIterator(mw);
   while (MagickNextImage(mw) != MagickFalse)
     MagickSetImageVirtualPixelMethod(mw,TileVirtualPixelMethod);
   MagickResetIterator(mw);

Re: Bug in MagickFxImage ?

Posted: 2010-08-26T09:17:32-07:00
by el_supremo
[I'm sure I replied to this last night - try again]

Thanks Magick. That solved the problem with the first example.
The second example didn't use virtual pixel but I tried it anyway and it didn't help. It still produces the colours in a different order than the command line does.

Pete