1 /*########################################################################
3 * Copyright(C) 2002-2007. All Rights Reserved.
5 * Authors: Shivang Patel
8 * Changes: jdh -> Added support for ImageMagick that enables
9 * to export files to more than 40 formats.
10 * This is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2, or (at your option) any later
15 * This is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * You should have received a copy of the GNU General Public License with
21 * the fvs source package as the
22 * file COPYING. If not, write to the Free Software Foundation, Inc.,
23 * 59 Temple Place - Suite 330, Boston, MA
25 ########################################################################*/
34 A fingerprint image structure, a fingerprint image is a 256 gray level
35 image. This should be enough to do accurate processing. This image
36 class defines a common format for all algorithms running in this
37 suite. Images may be imported from different sources such as files,
38 network data, databases,...
40 typedef struct iFvsImage_t
42 FvsByte_t
*pimg
; /* 8 bit image array */
43 FvsInt_t w
; /* width of image */
44 FvsInt_t h
; /* height of image */
45 FvsInt_t pitch
; /* pitch */
46 FvsImageFlag_t flags
; /* flags */
47 FvsInt_t dpi
; /* dots per inch */
51 FvsImage_t
ImageCreate()
53 iFvsImage_t
* p
= NULL
;
55 p
= (FvsImage_t
)malloc(sizeof(iFvsImage_t
));
62 p
->flags
= FvsImageGray
; /* default flag */
68 void ImageDestroy(FvsImage_t image
)
70 iFvsImage_t
* p
= NULL
;
73 (void)ImageSetSize(image
, 0, 0);
79 FvsError_t
ImageSetFlag(FvsImage_t img
, const FvsImageFlag_t flag
)
81 iFvsImage_t
* image
= (iFvsImage_t
*)img
;
87 FvsError_t
ImageSetDPI(FvsImage_t img
, const FvsInt_t dpi
)
89 iFvsImage_t
* image
= (iFvsImage_t
*)img
;
95 FvsInt_t
ImageGetDPI(const FvsImage_t img
)
97 iFvsImage_t
* image
= (iFvsImage_t
*)img
;
102 FvsImageFlag_t
ImageGetFlag(const FvsImage_t img
)
104 iFvsImage_t
* image
= (iFvsImage_t
*)img
;
109 FvsError_t
ImageSetSize(FvsImage_t img
, const FvsInt_t width
, const FvsInt_t height
)
111 iFvsImage_t
* image
= (iFvsImage_t
*)img
;
112 FvsError_t nRet
= FvsOK
;
113 FvsInt_t newsize
= width
*height
;
115 /* special case for zero size */
118 if (image
->pimg
!=NULL
)
129 if (image
->h
*image
->w
!= newsize
)
135 /* This allocates the amount of memory need for the image structure */
136 image
->pimg
= (uint8_t*)malloc((size_t)newsize
);
139 if (image
->pimg
== NULL
)
145 image
->pitch
= width
;
151 FvsError_t
ImageCopy(FvsImage_t destination
, const FvsImage_t source
)
153 iFvsImage_t
* dest
= (iFvsImage_t
*)destination
;
154 iFvsImage_t
* src
= (iFvsImage_t
*)source
;
155 FvsError_t nRet
= FvsOK
;
157 nRet
= ImageSetSize(dest
, src
->w
, src
->h
);
160 memcpy(dest
->pimg
, src
->pimg
, (size_t)src
->h
*src
->w
);
163 dest
->flags
= src
->flags
;
169 FvsError_t
ImageClear(FvsImage_t img
)
171 return ImageFlood(img
, 0);
175 FvsError_t
ImageFlood(FvsImage_t img
, const FvsByte_t value
)
177 FvsError_t nRet
= FvsOK
;
178 iFvsImage_t
* image
= (iFvsImage_t
*)img
;
179 if (image
==NULL
) return FvsMemory
;
180 if (image
->pimg
!=NULL
)
181 memset(image
->pimg
, (int)value
, (size_t)(image
->h
*image
->w
));
186 /* set a pixel value in the picture */
187 void ImageSetPixel(FvsImage_t img
, const FvsInt_t x
, const FvsInt_t y
, const FvsByte_t val
)
189 iFvsImage_t
* image
= (iFvsImage_t
*)img
;
190 int address
= y
* image
->w
+ x
;
191 image
->pimg
[address
] = val
;
195 /* This function returns the pixel for the x and y value */
196 FvsByte_t
ImageGetPixel(const FvsImage_t img
, const FvsInt_t x
, const FvsInt_t y
)
198 iFvsImage_t
* image
= (iFvsImage_t
*)img
;
199 /* position in array */
200 int address
= y
* image
->pitch
+ x
;
201 return image
->pimg
[address
];
205 /* returns a pointer to the image buffer */
206 FvsByte_t
* ImageGetBuffer(FvsImage_t img
)
208 iFvsImage_t
* image
= (iFvsImage_t
*)img
;
209 if (image
==NULL
) return NULL
;
214 /* retrieve width and height */
215 FvsInt_t
ImageGetWidth(const FvsImage_t img
)
217 iFvsImage_t
* image
= (iFvsImage_t
*)img
;
218 if (image
==NULL
) return -1;
223 FvsInt_t
ImageGetHeight(const FvsImage_t img
)
225 iFvsImage_t
* image
= (iFvsImage_t
*)img
;
226 if (image
==NULL
) return -1;
231 FvsInt_t
ImageGetSize(const FvsImage_t img
)
233 iFvsImage_t
* image
= (iFvsImage_t
*)img
;
234 if (image
==NULL
) return 0;
235 return image
->h
* image
->w
;
238 /* get the pitch pixel(x,y) pos is at x + y * pitch */
239 FvsInt_t
ImageGetPitch(const FvsImage_t img
)
241 iFvsImage_t
* image
= (iFvsImage_t
*)img
;
242 if (image
==NULL
) return -1;
246 FvsBool_t
ImageCompareSize(const FvsImage_t image1
, const FvsImage_t image2
)
248 if (ImageGetWidth(image1
)!=ImageGetWidth(image2
))
250 if (ImageGetHeight(image1
)!=ImageGetHeight(image2
))