1 /*########################################################################
3 The contents of this file are subject to the Mozilla Public License
4 Version 1.0(the "License"); You may NOT use this file except in
5 compliance with the License. You may obtain a copy of the License at
6 http:// www.mozilla.org/MPL/
7 Software distributed under the License is distributed on an "AS IS"
8 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9 the License for the specific language governing rights and limitations
12 The Initial Developer of the Original Code is Shivang Patel.
14 Copyright(C) 2002. All Rights Reserved.
16 Authors: Shivang Patel
20 Changes: jdh -> Added support for ImageMagick that enables
21 to export files to more than 40 formats.
22 mw -> Removed deprecated.
24 ########################################################################*/
31 #include <magick/api.h>
34 /* imports a fingeprint image from a file */
35 FvsError_t
FvsImageExport(const FvsImage_t image
, const FvsString_t filename
)
37 ExceptionInfo exception
;
41 FvsError_t ret
= FvsOK
;
48 /* get buffer, size and pitch from the input image */
49 buffer
= ImageGetBuffer(image
);
50 pitch
= ImageGetPitch(image
);
51 height
= ImageGetHeight(image
);
52 width
= ImageGetWidth(image
);
54 /* Init Magick environment */
55 MagickCoreGenesis(".",MagickFalse
);
56 //InitializeMagick(".");
57 GetExceptionInfo(&exception
);
59 /* Create an empty imageinfo */
60 magicinfo
= CloneImageInfo((ImageInfo
*)NULL
);
64 magicimage
= ConstituteImage(width
, height
, "I", CharPixel
, buffer
, &exception
);
65 if (exception
.severity
!=UndefinedException
)
66 CatchException(&exception
);
67 if (magicimage
!=(Image
*)NULL
)
70 for (i
=0; i
<height
; i
++)
72 ImportImagePixels(magicimage
, 0, i
, width
, 1, "I", CharPixel
,
75 /* save the image to file */
76 (void)strcpy(magicimage
->filename
, filename
);
77 magicimage
->colorspace
= GRAYColorspace
;
78 magicimage
->depth
= 8;
79 WriteImage(magicinfo
, magicimage
);
81 /* dump info for debugging purposes */
82 /* DescribeImage(magicimage, stdout, 0); */
84 DestroyImage(magicimage
);
90 DestroyImageInfo(magicinfo
);
91 DestroyExceptionInfo(&exception
);
101 /* The WAND interface is pretty buggy... use the old API */
103 /* exports a fingeprint image to a file */
104 FvsError_t
FvsImageExport(const FvsImage_t image
, const FvsString_t filename
)
112 FvsError_t ret
= FvsOK
;
116 wand
= NewMagickWand();
119 /* extract parameters */
120 buffer
= ImageGetBuffer(image
);
121 width
= ImageGetWidth(image
);
122 height
= ImageGetHeight(image
);
123 pitch
= ImageGetPitch(image
);
125 /* allocate a new buffer for the pixel data */
126 out
= (FvsByte_t
*)malloc(width
*height
);
129 for (i
=0; i
<height
; i
++)
130 memcpy(out
+i
*width
, buffer
+i
*pitch
, width
);
132 /* out now contains the picture data in a contiguous buffer */
133 MagickSetSize(wand
, width
, height
);
134 MagickSetImagePixels(wand
, 0, 0, width
, height
, "I", CharPixel
, out
);
137 MagickWriteImage(wand
, filename
);
145 DestroyMagickWand(wand
);