Move sample files out of bin directory
[fvs_assignment_project.git] / import.c
blobf697c91442869b3d52fdc0618ad9d3dbd1630bfe
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
10 under the License.
12 The Initial Developer of the Original Code is Shivang Patel.
14 Copyright(C) 2002. All Rights Reserved.
16 Authors: Shivang Patel
17 Jaap de Haan(jdh)
18 Matthias Wenzl
20 Changes: jdh -> Added support for ImageMagick that enables
21 to import files from more than 40 formats.
22 mw -> Removed deprecated, adapted for dvp lu.
24 ########################################################################*/
27 #include "import.h"
29 #include <string.h>
30 #include <stdio.h>
31 #include <magick/api.h>
35 /* imports a fingeprint image from a file */
36 FvsError_t FvsImageImport(FvsImage_t image, const FvsString_t filename)
38 ExceptionInfo exception;
39 Image* magicimage;
40 ImageInfo* magicinfo;
42 FvsError_t ret = FvsOK;
43 FvsByte_t* buffer;
44 FvsInt_t pitch;
45 FvsInt_t height;
46 FvsInt_t width;
47 FvsInt_t i;
49 /* Init Magick environment */
50 MagickCoreGenesis(".",MagickFalse);
51 GetExceptionInfo(&exception);
53 /* Create an empty imageinfo */
54 magicinfo = CloneImageInfo((ImageInfo*)NULL);
56 /* set the filename */
57 (void)strcpy(magicinfo->filename, filename);
59 /* read images */
60 magicimage = ReadImage(magicinfo, &exception);
61 if (exception.severity!=UndefinedException)
62 CatchException(&exception);
63 if (magicimage!=(Image*)NULL)
65 /* dump info for debugging purposes at the moment */
66 /* DescribeImage(magicimage, stdout, 0); */
68 /* allocate the image for Fvs */
69 ret = ImageSetSize(image,
70 (FvsInt_t)magicimage->columns,
71 (FvsInt_t)magicimage->rows);
72 if (ret==FvsOK)
74 /* get buffer and pitch */
75 buffer = ImageGetBuffer(image);
76 pitch = ImageGetPitch(image);
77 height = ImageGetHeight(image);
78 width = ImageGetWidth(image);
80 /* set image type and normalize */
81 NormalizeImage(magicimage);
83 /* copy the data */
84 for (i=0; i<height; i++)
86 ExportImagePixels(magicimage, 0, i, width, 1, "I", CharPixel,
87 buffer+i*pitch, &exception);
90 DestroyImage(magicimage);
92 else
93 ret = FvsFailure;
95 /* do cleanup */
96 DestroyImageInfo(magicinfo);
97 DestroyExceptionInfo(&exception);
98 MagickCoreTerminus();
100 return ret;