Make clang build as silent as possible
[fvs_assignment_project.git] / export.c
blobced95501d606f3f7b15ef90748b794c7a3667b13
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 (mw)
20 Changes: jdh -> Added support for ImageMagick that enables
21 to export files to more than 40 formats.
22 mw -> Removed deprecated.
24 ########################################################################*/
27 #include "import.h"
29 #include <stdio.h>
30 #include <string.h>
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;
38 Image* magicimage;
39 ImageInfo* magicinfo;
41 FvsError_t ret = FvsOK;
42 FvsByte_t* buffer;
43 FvsInt_t pitch;
44 FvsInt_t height;
45 FvsInt_t width;
46 FvsInt_t i;
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);
61 magicinfo->depth = 8;
63 /* create image */
64 magicimage = ConstituteImage(width, height, "I", CharPixel, buffer, &exception);
65 if (exception.severity!=UndefinedException)
66 CatchException(&exception);
67 if (magicimage!=(Image*)NULL)
69 /* copy the data */
70 for (i=0; i<height; i++)
72 ImportImagePixels(magicimage, 0, i, width, 1, "I", CharPixel,
73 buffer+i*pitch);
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);
86 else
87 ret = FvsFailure;
89 /* do cleanup */
90 DestroyImageInfo(magicinfo);
91 DestroyExceptionInfo(&exception);
92 MagickCoreTerminus();
95 return ret;
99 #if 0
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)
106 MagickWand* wand;
107 FvsByte_t* buffer;
108 FvsByte_t* out;
109 FvsInt_t pitch;
110 FvsInt_t height;
111 FvsInt_t width;
112 FvsError_t ret = FvsOK;
113 FvsInt_t i;
115 /* Init Magick */
116 wand = NewMagickWand();
117 if (wand!=NULL)
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);
127 if (out!=NULL)
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);
136 /* write data */
137 MagickWriteImage(wand, filename);
139 free(out);
141 else
142 ret = FvsMemory;
144 /* do cleanup */
145 DestroyMagickWand(wand);
147 else
148 ret = FvsMemory;
150 return ret;
153 #endif