Different signatures from the same image
Posted: 2006-03-10T11:20:16-07:00
While testing my DLL which interfaces MagickWand to the REXX scripting language I came across an oddity with image signatures. I converted wand/drawtest.c to a rexx script and then verified that the rexx script and the C program output the same image by doing a verbose identify (on the command line) of the two images. They both produce identical signature strings which start with "3A".
I then implemented the MagickGetImageSignature function in my DLL and used it to print out the signature directly from within the script and found that this signature is different.
I went back to the C code and modified it in two ways. First I added code such that the original version prints out the signature in a MessageBox just before and just after it writes out the file as drawtest.gif. I then converted the C code to use MagickWand and checked the signatures again.
The MessageBox in the original drawtest code shows a signature string starting with 9E before it writes out the image but starting with 3A after it writes out the image and so the signatures are different.
The MagickWand version of the C code shows the 9E string before and after writing out the image. But when I identify the images on the command line both versions (original C and MagickWand) show the 3A string.
To make the drawtest.c code work in windows I changed the main routine to a function (testit) which takes a filename string as argument, and this function is then called from the winmain routine but otherwise the code is identical to drawtest.c.
This is the change to add a signature before and after the WriteImage - it prints the 9E signature before and the 3A signature after:
and my complete code which uses MagickWand in the testit function is the following - this shows the 9E signature before and after the write:
So far I've been unable to sort out why there are different signatures before and after the ImageMagick WriteImage function and also why MagickWand's MagickWriteImage would behave differently since internally it uses WriteImage anyway.
Shouldn't all these signatures be the same?
Pete
I then implemented the MagickGetImageSignature function in my DLL and used it to print out the signature directly from within the script and found that this signature is different.
I went back to the C code and modified it in two ways. First I added code such that the original version prints out the signature in a MessageBox just before and just after it writes out the file as drawtest.gif. I then converted the C code to use MagickWand and checked the signatures again.
The MessageBox in the original drawtest code shows a signature string starting with 9E before it writes out the image but starting with 3A after it writes out the image and so the signatures are different.
The MagickWand version of the C code shows the 9E string before and after writing out the image. But when I identify the images on the command line both versions (original C and MagickWand) show the 3A string.
To make the drawtest.c code work in windows I changed the main routine to a function (testit) which takes a filename string as argument, and this function is then called from the winmain routine but otherwise the code is identical to drawtest.c.
This is the change to add a signature before and after the WriteImage - it prints the 9E signature before and the 3A signature after:
Code: Select all
SignatureImage(canvas);
signature = GetImageAttribute(canvas,"Signature");
if(signature)MessageBox(NULL,signature->value,"",MB_OK);
(void) WriteImage ( image_info, canvas );
SignatureImage(canvas);
signature = GetImageAttribute(canvas,"Signature");
if(signature)MessageBox(NULL,signature->value,"",MB_OK);
Code: Select all
Image *canvas = (Image *)NULL;
int rows, columns = 0;
const ImageAttribute *signature;
MagickWand *magick_wand;
PixelWand *p_wand = NULL;
MagickWandGenesis();
/*
* Create canvas image
*/
columns=596;
rows=842;
magick_wand = NewMagickWand();
p_wand = NewPixelWand();
PixelSetColor(p_wand,"#ffffff");
/* set the new magick wand to a 596x842 white image*/
MagickNewImage(magick_wand,columns,rows,p_wand);
canvas = magick_wand->images;
/*
* Scribble on image
*/
ScribbleImage( canvas );
/*
* Save image to file
*/
SignatureImage(canvas);
signature = GetImageAttribute(canvas,"Signature");
if(signature)MessageBox(NULL,signature->value,"",MB_OK);
MagickWriteImage(magick_wand,filename);
SignatureImage(canvas);
signature = GetImageAttribute(canvas,"Signature");
if(signature)MessageBox(NULL,signature->value,"",MB_OK);
p_wand = DestroyPixelWand(p_wand);
magick_wand = DestroyMagickWand(magick_wand);
MagickWandTerminus();
return 0;
So far I've been unable to sort out why there are different signatures before and after the ImageMagick WriteImage function and also why MagickWand's MagickWriteImage would behave differently since internally it uses WriteImage anyway.
Shouldn't all these signatures be the same?
Pete