Page 1 of 1

How to do matrix-transform by magickCore

Posted: 2009-08-03T04:16:10-07:00
by smileface
it works well(do matrix-transform and output a png file) if u using ImageMagick6.4.6-7 or higer Version
Using interface magickwand

Code: Select all

//read a image src.jpg to handler magick_wand
...
MagickSetImageMatte(magick_wand,MagickTrue);
MagickSetImageVirtualPixelMethod(magick_wand,TransparentVirtualPixelMethod);
...
MagickDistortImage(magick_wand,AffineProjectionDistortion,6,doubleArray,MagickFalse);
//want to get a transparent background PNG file
MagickWriteImage(magick_wand,"out.png");
but I using similar method in magickCore,failed.

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <magick/MagickCore.h>

int
main(int argc,char **argv)
{
   ExceptionInfo *exception;
   Image *image,*after;
   ImageInfo  *image_info;
   
   if(argc != 3)
   {
      (void)fprintf(stdout,"usage invalid!");
      exit(0);
   }
   MagickCoreGenesis(*argv,MagickTrue);
   exception=AcquireExceptionInfo();
   image_info=CloneImageInfo((ImageInfo*)NULL);
   (void)strcpy(image_info->filename,*(argv+1));
   image=ReadImage(image_info,exception);
   double  arr[6]={0.739,0,0,0.739,63,-79};
   //SetMatte(MagickTrue);   
   SetImageVirtualPixelMethod(image,8);
   after=DistortImage(image,AffineProjectionDistortion,6,arr,MagickFalse,exception);
   (void)strcpy(after->filename,argv[2]);
   WriteImage(image_info,after);
}
first i use setMatte(true),and then SetImageVirtualPixelMethod,
and last using DistortImage,but can't get the same result as using magickWand.
i found in magickCore there is a API function :

Code: Select all

MagickBooleanType DrawAffineImage(Image *image,const Image *source,
    const AffineMatrix *affine)
Do i need use this function to do matrix-transform? I am so worried about this question.

Re: How to do matrix-transform by magickCore

Posted: 2009-08-03T06:20:33-07:00
by magick
MagickWand is a wrapper around MagickCore. To replicate the MagickWand method calls, inspect the wand/magick-image.c source module. For example, MagickSetImageMatte() makes this MagickCore API call:
  • if (image->matte == MagickFalse)
    (void) SetImageOpacity(image,OpaqueOpacity);

Re: How to do matrix-transform by magickCore

Posted: 2009-08-03T10:07:03-07:00
by smileface
hi,
magick,just like u said i know the magickwand call magickCore API,and i read the source of
function 'MagickSetImageMatte',
function 'MagickSetImageVirtualPixelMethod'
function 'MagickDistortImage'.
And then i learned that what they call infact:
In MagickSetImageMatte call SetImageOpacity.
In MagickSetImageVirtualPixelMethod call SetImageVirtualPixelMethod.
In MagickDistortImage call DistortImage.
so,i modify my test program like this:

Code: Select all

  #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <magick/MagickCore.h>
int
main(int argc,char **argv)
{
   ExceptionInfo *exception;
   Image *image,*after;
   ImageInfo  *image_info;
   
   if(argc != 3)
   {
      (void)fprintf(stdout,"usage invalid!");
      exit(0);
   }
   MagickCoreGenesis(*argv,MagickTrue);
   exception=AcquireExceptionInfo();
   image_info=CloneImageInfo((ImageInfo*)NULL);
   (void)strcpy(image_info->filename,*(argv+1));
   image=ReadImage(image_info,exception);
   double  arr[6]={1.414,1.414,-1.414,1.414,0,0};
   if(image->matte == MagickFalse)
   (void)SetImageOpacity(image,OpaqueOpacity);   
   SetImageVirtualPixelMethod(image,TransparentVirtualPixelMethod);
   after=DistortImage(image,AffineProjectionDistortion,6,arr,MagickFalse,exception);
   (void)strcpy(after->filename,argv[2]);
   WriteImage(image_info,after);
}
  
But it works bad again,how to explain,and Is there sth i missed or make some wrong?please show me what is wrong?Are they equal?
I tried JPG,GIF files ,both of them failed. After call those functions ,they have black background and can'nt autofit(bestfit) width and height when needed.

Re: How to do matrix-transform by magickCore

Posted: 2009-08-06T20:02:31-07:00
by anthony
Dont save to JPG - it don't save transpareny.

Dont save to GIF it only uses boolean transparency, and many GIF display programs
even ignore that.

Save to PNG which handles full transparency and semi-transparency.


An alturnative technique (one not usally recommended) for setting the Matte channel of an image is to set the image 'type" to "TrueColorMatte" before reading the image.